1 //
2 // "$Id: fl_round_box.cxx 6537 2008-12-02 17:21:36Z matt $"
3 //
4 // Round box drawing routines for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2005 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.
12 //
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.
17 //
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 //     http://www.fltk.org/str.php
26 //
27 
28 // Box drawing code for an obscure box type.
29 // These box types are in seperate files so they are not linked
30 // in if not used.
31 
32 #include <FL/Fl.H>
33 #include <FL/fl_draw.H>
34 
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:
fl_arc_i(int x,int y,int w,int h,double a1,double a2)38 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);
40 }
41 
42 enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};
43 
draw(int which,int x,int y,int w,int h,int inset,unsigned int color)44 static void draw(int which, int x,int y,int w,int h, int inset, unsigned int color)
45 {
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   void (*f)(int,int,int,int,double,double);
56   f = (which==FILL) ? fl_pie : fl_arc_i;
57   if (which >= CLOSED) {
58     f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
59     f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
60   } else if (which == UPPER_LEFT) {
61     f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
62     f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
63   } else { // LOWER_RIGHT
64     f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
65     f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
66   }
67   if (which == FILL) {
68     if (w < h)
69       fl_rectf(x, y+d/2, w, h-(d&-2));
70     else if (w > h)
71       fl_rectf(x+d/2, y, w-(d&-2), h);
72   } else {
73     if (w < h) {
74       if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
75       if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
76     } else if (w > h) {
77       if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
78       if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
79     }
80   }
81 }
82 
83 extern uchar* fl_gray_ramp();
84 
fl_round_down_box(int x,int y,int w,int h,Fl_Color bgcolor)85 void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor) {
86   uchar *g = fl_gray_ramp();
87   draw(FILL,	    x,   y, w,   h, 2, bgcolor);
88   draw(UPPER_LEFT,  x+1, y, w-2, h, 0, g['N']);
89   draw(UPPER_LEFT,  x+1, y, w-2, h, 1, g['H']);
90   draw(UPPER_LEFT,  x,   y, w,   h, 0, g['N']);
91   draw(UPPER_LEFT,  x,   y, w,   h, 1, g['H']);
92   draw(LOWER_RIGHT, x,   y, w,   h, 0, g['S']);
93   draw(LOWER_RIGHT, x+1, y, w-2, h, 0, g['U']);
94   draw(LOWER_RIGHT, x,   y, w,   h, 1, g['U']);
95   draw(LOWER_RIGHT, x+1, y, w-2, h, 1, g['W']);
96   draw(CLOSED,	    x,   y, w,   h, 2, g['A']);
97 }
98 
fl_round_up_box(int x,int y,int w,int h,Fl_Color bgcolor)99 void fl_round_up_box(int x, int y, int w, int h, Fl_Color bgcolor) {
100   uchar *g = fl_gray_ramp();
101   draw(FILL,	    x,   y, w,   h, 2, bgcolor);
102   draw(LOWER_RIGHT, x+1, y, w-2, h, 0, g['H']);
103   draw(LOWER_RIGHT, x+1, y, w-2, h, 1, g['N']);
104   draw(LOWER_RIGHT, x,   y, w,   h, 1, g['H']);
105   draw(LOWER_RIGHT, x,   y, w,   h, 2, g['N']);
106   draw(UPPER_LEFT,  x,   y, w,   h, 2, g['U']);
107   draw(UPPER_LEFT,  x+1, y, w-2, h, 1, g['S']);
108   draw(UPPER_LEFT,  x,   y, w,   h, 1, g['W']);
109   draw(UPPER_LEFT,  x+1, y, w-2, h, 0, g['U']);
110   draw(CLOSED,	    x,   y, w,   h, 0, g['A']);
111 }
112 
113 extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
fl_define_FL_ROUND_UP_BOX()114 Fl_Boxtype fl_define_FL_ROUND_UP_BOX() {
115   fl_internal_boxtype(_FL_ROUND_DOWN_BOX, fl_round_down_box);
116   fl_internal_boxtype(_FL_ROUND_UP_BOX, fl_round_up_box);
117   return _FL_ROUND_UP_BOX;
118 }
119 
120 //
121 // End of "$Id: fl_round_box.cxx 6537 2008-12-02 17:21:36Z matt $".
122 //
123