themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / Fl_Light_Button.cxx
blob5da26e72c96ba97c6107913a45cc44ffddc61df9
1 //
2 // "$Id: Fl_Light_Button.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Lighted button widget for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
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
21 // USA.
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.
35 #include <FL/Fl.H>
36 #include <FL/Fl_Light_Button.H>
37 #include <FL/fl_draw.H>
38 #include "flstring.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();
44 int W;
45 int dx, dy;
47 W = labelsize();
48 dx = Fl::box_dx(box()) + 2;
49 dy = (h() - W) / 2;
50 // if (dy < 0) dy = 0; // neg. offset o.k. for vertical centering
52 if (down_box()) {
53 // draw other down_box() styles:
54 switch (down_box()) {
55 case FL_DOWN_BOX :
56 case FL_UP_BOX :
57 // Check box...
58 draw_box(down_box(), x()+dx, y()+dy, W, W, FL_BACKGROUND2_COLOR);
59 if (value()) {
60 if (Fl::scheme() && !strcmp(Fl::scheme(), "gtk+")) {
61 fl_color(FL_SELECTION_COLOR);
62 } else {
63 fl_color(col);
65 int tx = x() + dx + 3;
66 int tw = W - 6;
67 int d1 = tw/3;
68 int d2 = tw-d1;
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);
75 break;
76 case _FL_ROUND_DOWN_BOX :
77 case _FL_ROUND_UP_BOX :
78 // Radio button...
79 draw_box(down_box(), x()+dx, y()+dy, W, W, FL_BACKGROUND2_COLOR);
80 if (value()) {
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);
88 tW --;
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));
92 } else fl_color(col);
94 switch (tW) {
95 // Larger circles draw fine...
96 default :
97 fl_pie(x() + tdx, y() + tdy, tW, tW, 0.0, 360.0);
98 break;
100 // Small circles don't draw well on many systems...
101 case 6 :
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);
105 break;
107 case 5 :
108 case 4 :
109 case 3 :
110 fl_rectf(x() + tdx + 1, y() + tdy, tW - 2, tW);
111 fl_rectf(x() + tdx, y() + tdy + 1, tW, tW - 2);
112 break;
114 case 2 :
115 case 1 :
116 fl_rectf(x() + tdx, y() + tdy, tW, tW);
117 break;
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);
125 break;
126 default :
127 draw_box(down_box(), x()+dx, y()+dy, W, W, col);
128 break;
130 } else {
131 // if down_box() is zero, draw light button style:
132 int hh = h()-2*dy - 2;
133 int ww = W/2+1;
134 int xx = dx;
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); */
140 /* } else { */
141 draw_box(FL_THIN_DOWN_BOX, x()+xx, y()+dy+1, ww, hh, col);
142 /* } */
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) {
150 switch (event) {
151 case FL_RELEASE:
152 if (box()) redraw();
153 default:
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 $".