themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / fl_round_box.cxx
blobf5a802ce04d9f4ead637648500dfe3565182b78e
1 //
2 // "$Id: fl_round_box.cxx 8630 2011-05-01 12:45:29Z AlbrechtS $"
3 //
4 // Round box drawing routines 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 // Box drawing code for an obscure box type.
29 // These box types are in separate files so they are not linked
30 // in if not used.
32 #include <FL/Fl.H>
33 #include <FL/fl_draw.H>
35 // A compiler from a certain very large software company will not compile
36 // the function pointer assignment due to the name conflict with fl_arc.
37 // This function is to fix that:
38 static void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
39 fl_arc(x,y,w,h,a1,a2);
42 enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};
44 static void draw(int which, int x,int y,int w,int h, int inset, Fl_Color color)
46 if (inset*2 >= w) inset = (w-1)/2;
47 if (inset*2 >= h) inset = (h-1)/2;
48 x += inset;
49 y += inset;
50 w -= 2*inset;
51 h -= 2*inset;
52 int d = w <= h ? w : h;
53 if (d <= 1) return;
54 fl_color(color);
55 fl_line_style(0,1);
56 void (*f)(int,int,int,int,double,double);
57 f = (which==FILL) ? fl_pie : fl_arc_i;
58 if (which >= CLOSED) {
59 f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
60 f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
61 } else if (which == UPPER_LEFT) {
62 f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
63 f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
64 } else { // LOWER_RIGHT
65 f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
66 f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
68 if (which == FILL) {
69 if (w < h)
70 fl_rectf(x, y+d/2, w, h-(d&-2));
71 else if (w > h)
72 fl_rectf(x+d/2, y, w-(d&-2), h);
73 } else {
74 if (w < h) {
75 if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
76 if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
77 } else if (w > h) {
78 if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
79 if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
82 fl_line_style(0);
85 extern uchar* fl_gray_ramp();
87 void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor) {
88 uchar *g = fl_gray_ramp();
89 draw(FILL, x, y, w, h, 2, bgcolor);
90 draw(UPPER_LEFT, x+1, y, w-2, h, 0, (Fl_Color)g['N']);
91 draw(UPPER_LEFT, x+1, y, w-2, h, 1, (Fl_Color)g['H']);
92 draw(UPPER_LEFT, x, y, w, h, 0, (Fl_Color)g['N']);
93 draw(UPPER_LEFT, x, y, w, h, 1, (Fl_Color)g['H']);
94 draw(LOWER_RIGHT, x, y, w, h, 0, (Fl_Color)g['S']);
95 draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g['U']);
96 draw(LOWER_RIGHT, x, y, w, h, 1, (Fl_Color)g['U']);
97 draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g['W']);
98 draw(CLOSED, x, y, w, h, 2, (Fl_Color)g['A']);
101 void fl_round_up_box(int x, int y, int w, int h, Fl_Color bgcolor) {
102 uchar *g = fl_gray_ramp();
103 draw(FILL, x, y, w, h, 2, bgcolor);
104 draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g['H']);
105 draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g['N']);
106 draw(LOWER_RIGHT, x, y, w, h, 1, (Fl_Color)g['H']);
107 draw(LOWER_RIGHT, x, y, w, h, 2, (Fl_Color)g['N']);
108 draw(UPPER_LEFT, x, y, w, h, 2, (Fl_Color)g['U']);
109 draw(UPPER_LEFT, x+1, y, w-2, h, 1, (Fl_Color)g['S']);
110 draw(UPPER_LEFT, x, y, w, h, 1, (Fl_Color)g['W']);
111 draw(UPPER_LEFT, x+1, y, w-2, h, 0, (Fl_Color)g['U']);
112 draw(CLOSED, x, y, w, h, 0, (Fl_Color)g['A']);
115 extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
116 Fl_Boxtype fl_define_FL_ROUND_UP_BOX() {
117 fl_internal_boxtype(_FL_ROUND_DOWN_BOX, fl_round_down_box);
118 fl_internal_boxtype(_FL_ROUND_UP_BOX, fl_round_up_box);
119 return _FL_ROUND_UP_BOX;
123 // End of "$Id: fl_round_box.cxx 8630 2011-05-01 12:45:29Z AlbrechtS $".