blob: f5a802ce04d9f4ead637648500dfe3565182b78e [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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 separate 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:
38static 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
42enum {UPPER_LEFT, LOWER_RIGHT, CLOSED, FILL};
43
44static void draw(int which, int x,int y,int w,int h, int inset, Fl_Color 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 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);
67 }
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);
80 }
81 }
82 fl_line_style(0);
83}
84
85extern uchar* fl_gray_ramp();
86
87void 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']);
99}
100
101void 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']);
113}
114
115extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
116Fl_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;
120}
121
122//
123// End of "$Id: fl_round_box.cxx 8630 2011-05-01 12:45:29Z AlbrechtS $".
124//