2 // "$Id: Fl_Light_Button.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Lighted button widget for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // Subclass of Fl_Button where the "box" indicates whether it is
29 // pushed or not, and the "down box" is drawn small and square on
30 // the left to indicate the current state.
32 // The default down_box of zero draws a rectangle designed to look
33 // just like Flame's buttons.
36 #include <FL/Fl_Light_Button.H>
37 #include <FL/fl_draw.H>
40 void Fl_Light_Button::draw() {
41 if (box()) draw_box(this==Fl::pushed() ? fl_down(box()) : box(), color());
42 Fl_Color col
= value() ? (active_r() ? selection_color() :
43 fl_inactive(selection_color())) : color();
48 dx
= Fl::box_dx(box()) + 2;
50 // if (dy < 0) dy = 0; // neg. offset o.k. for vertical centering
53 // draw other down_box() styles:
58 draw_box(down_box(), x()+dx
, y()+dy
, W
, W
, FL_BACKGROUND2_COLOR
);
60 if (Fl::scheme() && !strcmp(Fl::scheme(), "gtk+")) {
61 fl_color(FL_SELECTION_COLOR
);
65 int tx
= x() + dx
+ 3;
69 int ty
= y() + dy
+ (W
+d2
)/2-d1
-2;
70 for (int n
= 0; n
< 3; n
++, ty
++) {
71 fl_line(tx
, ty
, tx
+d1
, ty
+d1
);
72 fl_line(tx
+d1
, ty
+d1
, tx
+tw
-1, ty
+d1
-d2
+1);
76 case _FL_ROUND_DOWN_BOX
:
77 case _FL_ROUND_UP_BOX
:
79 draw_box(down_box(), x()+dx
, y()+dy
, W
, W
, FL_BACKGROUND2_COLOR
);
81 int tW
= (W
- Fl::box_dw(down_box())) / 2 + 1;
82 if ((W
- tW
) & 1) tW
++; // Make sure difference is even to center
83 int tdx
= dx
+ (W
- tW
) / 2;
84 int tdy
= dy
+ (W
- tW
) / 2;
86 if (Fl::scheme() && !strcmp(Fl::scheme(), "gtk+")) {
87 fl_color(FL_SELECTION_COLOR
);
89 fl_pie(x() + tdx
- 1, y() + tdy
- 1, tW
+ 3, tW
+ 3, 0.0, 360.0);
90 fl_arc(x() + tdx
- 1, y() + tdy
- 1, tW
+ 3, tW
+ 3, 0.0, 360.0);
91 fl_color(fl_color_average(FL_WHITE
, FL_SELECTION_COLOR
, 0.2f
));
95 // Larger circles draw fine...
97 fl_pie(x() + tdx
, y() + tdy
, tW
, tW
, 0.0, 360.0);
100 // Small circles don't draw well on many systems...
102 fl_rectf(x() + tdx
+ 2, y() + tdy
, tW
- 4, tW
);
103 fl_rectf(x() + tdx
+ 1, y() + tdy
+ 1, tW
- 2, tW
- 2);
104 fl_rectf(x() + tdx
, y() + tdy
+ 2, tW
, tW
- 4);
110 fl_rectf(x() + tdx
+ 1, y() + tdy
, tW
- 2, tW
);
111 fl_rectf(x() + tdx
, y() + tdy
+ 1, tW
, tW
- 2);
116 fl_rectf(x() + tdx
, y() + tdy
, tW
, tW
);
120 if (Fl::scheme() && !strcmp(Fl::scheme(), "gtk+")) {
121 fl_color(fl_color_average(FL_WHITE
, FL_SELECTION_COLOR
, 0.5));
122 fl_arc(x() + tdx
, y() + tdy
, tW
+ 1, tW
+ 1, 60.0, 180.0);
127 draw_box(down_box(), x()+dx
, y()+dy
, W
, W
, col
);
131 // if down_box() is zero, draw light button style:
132 int hh
= h()-2*dy
- 2;
135 if (w()<ww
+2*xx
) xx
= (w()-ww
)/2;
136 /* if (Fl::scheme() && !strcmp(Fl::scheme(), "plastic")) { */
137 /* col = active_r() ? selection_color() : fl_inactive(selection_color()); */
138 /* fl_color(value() ? col : fl_color_average(col, FL_BLACK, 0.5f)); */
139 /* fl_pie(x()+xx, y()+dy+1, ww, hh, 0, 360); */
141 draw_box(FL_THIN_DOWN_BOX
, x()+xx
, y()+dy
+1, ww
, hh
, col
);
143 dx
= (ww
+ 2 * dx
- W
) / 2;
145 draw_label(x()+W
+2*dx
, y(), w()-W
-2*dx
, h());
146 if (Fl::focus() == this) draw_focus();
149 int Fl_Light_Button::handle(int event
) {
154 return Fl_Button::handle(event
);
159 Creates a new Fl_Light_Button widget using the given
160 position, size, and label string.
161 <P>The destructor deletes the check button.
163 Fl_Light_Button::Fl_Light_Button(int X
, int Y
, int W
, int H
, const char* l
)
164 : Fl_Button(X
, Y
, W
, H
, l
) {
165 type(FL_TOGGLE_BUTTON
);
166 selection_color(FL_YELLOW
);
167 align(FL_ALIGN_LEFT
|FL_ALIGN_INSIDE
);
171 // End of "$Id: Fl_Light_Button.cxx 7903 2010-11-28 21:06:39Z matt $".