Author: matt
Date: 2012-05-02 13:23:49 -0700 (Wed, 02 May 2012)
New Revision: 9433
Log:
Fixing fltk3::Button
Modified:
branches/branch-3.0/include/fltk3/ReturnButton.h
branches/branch-3.0/include/fltk3/run.h
branches/branch-3.0/src/fltk3/Button.cxx
branches/branch-3.0/src/fltk3/ReturnButton.cxx
branches/branch-3.0/src/fltk3/boxtype.cxx
branches/branch-3.0/src/fltk3/run.cxx
Modified: branches/branch-3.0/include/fltk3/ReturnButton.h
===================================================================
--- branches/branch-3.0/include/fltk3/ReturnButton.h 2012-05-02 19:47:07 UTC
(rev 9432)
+++ branches/branch-3.0/include/fltk3/ReturnButton.h 2012-05-02 20:23:49 UTC
(rev 9433)
@@ -43,7 +43,7 @@
\image latex fltk3::ReturnButton.png "fltk3::ReturnButton" width=4cm
*/
class FLTK3_EXPORT ReturnButton : public Button {
-
+
protected:
void draw();
@@ -54,8 +54,8 @@
position, size, and label string. The default boxtype is fltk3::UP_BOX.
<P> The inherited destructor deletes the button.
*/
- ReturnButton(int X, int Y, int W, int H,const char *l=0)
- : Button(X,Y,W,H,l) {}
+ ReturnButton(int X, int Y, int W, int H,const char *l=0);
+
};
}
Modified: branches/branch-3.0/include/fltk3/run.h
===================================================================
--- branches/branch-3.0/include/fltk3/run.h 2012-05-02 19:47:07 UTC (rev
9432)
+++ branches/branch-3.0/include/fltk3/run.h 2012-05-02 20:23:49 UTC (rev
9433)
@@ -49,6 +49,7 @@
class Window;
class Label;
class Image;
+ class Rectangle;
// Keep avoiding having the socket deps at that level but make sure it will
work in both 32 & 64 bit builds
#if defined(WIN32) && !defined(__CYGWIN__)
@@ -696,7 +697,7 @@
int compose(int &del);
void compose_reset();
int event_inside(int,int,int,int);
- int event_inside(const fltk3::Widget*);
+ int event_inside(const fltk3::Rectangle*);
int test_shortcut(fltk3::Shortcut);
// event destinations:
Modified: branches/branch-3.0/src/fltk3/Button.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Button.cxx 2012-05-02 19:47:07 UTC (rev
9432)
+++ branches/branch-3.0/src/fltk3/Button.cxx 2012-05-02 20:23:49 UTC (rev
9433)
@@ -38,13 +38,15 @@
// them are implemented by setting the type() value and testing it
// here. This includes fltk3::RadioButton and fltk3::ToggleButton
+
/**
- Sets the current value of the button.
- A non-zero value sets the button to 1 (ON), and zero sets it to 0 (OFF).
- \param[in] v button value.
- \see set(), clear()
+ Sets the current value of the button.
+ A non-zero value sets the button to 1 (ON), and zero sets it to 0 (OFF).
+ \param[in] v button value.
+ \see set(), clear()
*/
-int fltk3::Button::value(int v) {
+int fltk3::Button::value(int v)
+{
v = v ? 1 : 0;
oldval = v;
clear_changed();
@@ -58,11 +60,13 @@
}
}
+
/**
- Turns on this button and turns off all other radio buttons in the group
- (calling \c value(1) or \c set() does not do this).
+ Turns on this button and turns off all other radio buttons in the group
+ (calling \c value(1) or \c set() does not do this).
*/
-void fltk3::Button::setonly() { // set this radio button on, turn others off
+void fltk3::Button::setonly()
+{
value(1);
fltk3::Group* g = parent();
fltk3::Widget*const* a = g->array();
@@ -72,8 +76,9 @@
}
}
-void fltk3::Button::draw() {
- printf("Drawing button %s\n", label());
+
+void fltk3::Button::draw()
+{
if (type() == fltk3::HIDDEN_BUTTON) return;
fltk3::Color col;
if (value()) {
@@ -95,96 +100,97 @@
if (fltk3::focus() == this) draw_focus();
}
-int fltk3::Button::handle(int event) {
+
+int fltk3::Button::handle(int event)
+{
int newval;
switch (event) {
- case fltk3::ENTER: /* FALLTHROUGH */
- case fltk3::LEAVE:
-// if ((value_?selection_color():color())==fltk3::GRAY) redraw();
- return 1;
- case fltk3::PUSH:
- if (fltk3::visible_focus() && handle(fltk3::FOCUS)) fltk3::focus(this);
- case fltk3::DRAG:
- if (fltk3::event_inside(this)) {
- if (type() == fltk3::RADIO_BUTTON) {
- newval = 1;
+ case fltk3::ENTER: /* FALLTHROUGH */
+ case fltk3::LEAVE:
+ // if ((value_?selection_color():color())==fltk3::GRAY) redraw();
+ return 1;
+ case fltk3::PUSH:
+ if (fltk3::visible_focus() && handle(fltk3::FOCUS)) fltk3::focus(this);
+ case fltk3::DRAG:
+ if (fltk3::event_inside(0, 0, w(), h())) {
+ if (type() == fltk3::RADIO_BUTTON) {
+ newval = 1;
+ } else {
+ newval = !oldval;
+ }
} else {
- newval = !oldval;
+ clear_changed();
+ newval = oldval;
}
- } else {
- clear_changed();
- newval = oldval;
- }
- if (newval != value_) {
- value_ = newval;
- set_changed();
- redraw();
- if (when() & fltk3::WHEN_CHANGED) do_callback();
- }
- return 1;
- case fltk3::RELEASE:
- if (value_ == oldval) {
- if (when() & fltk3::WHEN_NOT_CHANGED) do_callback();
+ if (newval != value_) {
+ value_ = newval;
+ set_changed();
+ redraw();
+ if (when() & fltk3::WHEN_CHANGED) do_callback();
+ }
return 1;
- }
- set_changed();
- if (type() == fltk3::RADIO_BUTTON) setonly();
- else if (type() == fltk3::TOGGLE_BUTTON) oldval = value_;
- else {
- value(oldval);
- set_changed();
- if (when() & fltk3::WHEN_CHANGED) {
- fltk3::WidgetTracker wp(this);
- do_callback();
- if (wp.deleted()) return 1;
+ case fltk3::RELEASE:
+ if (value_ == oldval) {
+ if (when() & fltk3::WHEN_NOT_CHANGED) do_callback();
+ return 1;
}
- }
- if (when() & fltk3::WHEN_RELEASE) do_callback();
- return 1;
- case fltk3::SHORTCUT:
- if (!(shortcut() ?
- fltk3::test_shortcut(shortcut()) : test_shortcut())) return 0;
- if (fltk3::visible_focus() && handle(fltk3::FOCUS)) fltk3::focus(this);
- goto triggered_by_keyboard;
- case fltk3::FOCUS : /* FALLTHROUGH */
- case fltk3::UNFOCUS :
- if (fltk3::visible_focus()) {
- if (box() == fltk3::NO_BOX) {
- // Widgets with the fltk3::NO_BOX boxtype need a parent to
- // redraw, since it is responsible for redrawing the
- // background...
- int X = x() > 0 ? x() - 1 : 0;
- int Y = y() > 0 ? y() - 1 : 0;
- if (window()) window()->damage(fltk3::DAMAGE_ALL, X, Y, w() + 2, h() +
2);
- } else redraw();
- return 1;
- } else return 0;
- case fltk3::KEYBOARD :
- if (fltk3::focus() == this && fltk3::event_key() == ' ' &&
- !(fltk3::event_state() & (fltk3::SHIFT | fltk3::CTRL | fltk3::ALT |
fltk3::META))) {
set_changed();
- triggered_by_keyboard:
- fltk3::WidgetTracker wp(this);
- if (type() == fltk3::RADIO_BUTTON) {
- if (!value_) {
- setonly();
- if (when() & fltk3::WHEN_CHANGED) do_callback();
- }
- } else if (type() == fltk3::TOGGLE_BUTTON) {
- value(!value());
- if (when() & fltk3::WHEN_CHANGED) do_callback();
- } else {
- simulate_key_action();
+ if (type() == fltk3::RADIO_BUTTON) setonly();
+ else if (type() == fltk3::TOGGLE_BUTTON) oldval = value_;
+ else {
+ value(oldval);
+ set_changed();
+ if (when() & fltk3::WHEN_CHANGED) {
+ fltk3::WidgetTracker wp(this);
+ do_callback();
+ if (wp.deleted()) return 1;
+ }
}
- if (wp.deleted()) return 1;
if (when() & fltk3::WHEN_RELEASE) do_callback();
return 1;
- }
- default:
- return 0;
+ case fltk3::SHORTCUT:
+ if (!(shortcut() ?
+ fltk3::test_shortcut(shortcut()) : test_shortcut())) return 0;
+ if (fltk3::visible_focus() && handle(fltk3::FOCUS)) fltk3::focus(this);
+ goto triggered_by_keyboard;
+ case fltk3::FOCUS : /* FALLTHROUGH */
+ case fltk3::UNFOCUS :
+ if (fltk3::visible_focus()) {
+ if (box() == fltk3::NO_BOX) {
+ // Widgets with the fltk3::NO_BOX boxtype need a parent to
+ // redraw, since it is responsible for redrawing the
+ // background...
+ if (parent()) parent()->damage(fltk3::DAMAGE_ALL, -1, -1, w() + 2,
h() + 2);
+ } else redraw();
+ return 1;
+ } else return 0;
+ case fltk3::KEYBOARD :
+ if (fltk3::focus() == this && fltk3::event_key() == ' ' &&
+ !(fltk3::event_state() & (fltk3::SHIFT | fltk3::CTRL | fltk3::ALT |
fltk3::META))) {
+ set_changed();
+ triggered_by_keyboard:
+ fltk3::WidgetTracker wp(this);
+ if (type() == fltk3::RADIO_BUTTON) {
+ if (!value_) {
+ setonly();
+ if (when() & fltk3::WHEN_CHANGED) do_callback();
+ }
+ } else if (type() == fltk3::TOGGLE_BUTTON) {
+ value(!value());
+ if (when() & fltk3::WHEN_CHANGED) do_callback();
+ } else {
+ simulate_key_action();
+ }
+ if (wp.deleted()) return 1;
+ if (when() & fltk3::WHEN_RELEASE) do_callback();
+ return 1;
+ }
+ default:
+ return 0;
}
}
+
void fltk3::Button::simulate_key_action()
{
if (key_release_tracker) {
@@ -197,6 +203,7 @@
fltk3::add_timeout(0.15, key_release_timeout, key_release_tracker);
}
+
void fltk3::Button::key_release_timeout(void *d)
{
fltk3::WidgetTracker *wt = (fltk3::WidgetTracker*)d;
@@ -212,13 +219,16 @@
delete wt;
}
+
/**
- The constructor creates the button using the given position, size and label.
- \param[in] X, Y, W, H position and size of the widget
- \param[in] L widget label, default is no label
+ The constructor creates the button using the given position, size and label.
+ \param[in] X, Y, W, H position and size of the widget
+ \param[in] L widget label, default is no label
*/
fltk3::Button::Button(int X, int Y, int W, int H, const char *L)
-: fltk3::Widget(X,Y,W,H,L) {
+: fltk3::Widget(X,Y,W,H,L)
+{
+ set_group_relative(); // FIXME:
box(fltk3::UP_BOX);
down_box(fltk3::NO_BOX);
value_ = oldval = 0;
Modified: branches/branch-3.0/src/fltk3/ReturnButton.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/ReturnButton.cxx 2012-05-02 19:47:07 UTC
(rev 9432)
+++ branches/branch-3.0/src/fltk3/ReturnButton.cxx 2012-05-02 20:23:49 UTC
(rev 9433)
@@ -29,7 +29,16 @@
#include <fltk3/ReturnButton.h>
#include <fltk3/draw.h>
-int fl_return_arrow(int x, int y, int w, int h) {
+
+fltk3::ReturnButton::ReturnButton(int X, int Y, int W, int H,const char *l)
+: Button(X,Y,W,H,l)
+{
+ set_group_relative();
+}
+
+
+int fl_return_arrow(int x, int y, int w, int h)
+{
int size = w; if (h<size) size = h;
int d = (size+2)/4; if (d<3) d = 3;
int t = (size+9)/12; if (t<1) t = 1;
@@ -47,18 +56,22 @@
return 1;
}
-void fltk3::ReturnButton::draw() {
+
+void fltk3::ReturnButton::draw()
+{
if (type() == fltk3::HIDDEN_BUTTON) return;
draw_box(value() ? (down_box()?down_box():fltk3::down(box())) : box(),
value() ? selection_color() : color());
int W = h();
if (w()/3 < W) W = w()/3;
- fl_return_arrow(x()+w()-W-4, y(), W, h());
- draw_label(x(), y(), w()-W+4, h());
+ fl_return_arrow(w()-W-4, 0, W, h());
+ draw_label(0, 0, w()-W+4, h());
if (fltk3::focus() == this) draw_focus();
}
-int fltk3::ReturnButton::handle(int event) {
+
+int fltk3::ReturnButton::handle(int event)
+{
if (event == fltk3::SHORTCUT &&
(fltk3::event_key() == fltk3::EnterKey || fltk3::event_key() ==
fltk3::KPEnterKey)) {
simulate_key_action();
Modified: branches/branch-3.0/src/fltk3/boxtype.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/boxtype.cxx 2012-05-02 19:47:07 UTC (rev
9432)
+++ branches/branch-3.0/src/fltk3/boxtype.cxx 2012-05-02 20:23:49 UTC (rev
9433)
@@ -466,9 +466,18 @@
((fltk3::Image*)img)->draw(x_+(w_-img->w())/2, y_+(h_-img->h())/2);
}
}
-/** Draws a box of type t, of color c at the widget's position and size. */
-void fltk3::Widget::draw_box(fltk3::Boxtype t, fltk3::Color c) const {
- draw_box(t, x_, y_, w_, h_, c);
+
+
+/**
+ Draws a box of type t, of color c at the widget's position and size.
+ */
+void fltk3::Widget::draw_box(fltk3::Boxtype t, fltk3::Color c) const
+{
+ if (is_group_relative()) {
+ draw_box(t, 0, 0, w_, h_, c);
+ } else {
+ draw_box(t, x_, y_, w_, h_, c);
+ }
}
/** Draws a box of type t, of color c at the position X,Y and size W,H. */
void fltk3::Widget::draw_box(fltk3::Boxtype t, int X, int Y, int W, int H,
fltk3::Color c) const {
Modified: branches/branch-3.0/src/fltk3/run.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/run.cxx 2012-05-02 19:47:07 UTC (rev
9432)
+++ branches/branch-3.0/src/fltk3/run.cxx 2012-05-02 20:23:49 UTC (rev
9433)
@@ -214,7 +214,7 @@
\param[in] o child widget to be tested
\return non-zero, if mouse event is inside the widget
*/
-int fltk3::event_inside(const fltk3::Widget *o) /*const*/ {
+int fltk3::event_inside(const fltk3::Rectangle *o) /*const*/ {
int mx = e_x - o->x();
int my = e_y - o->y();
return (mx >= 0 && mx < o->w() && my >= 0 && my < o->h());
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit