fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_round_box.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
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. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 // Box drawing code for an obscure box type.
20 // These box types are in separate files so they are not linked
21 // in if not used.
22 
23 #include <FL/Fl.H>
24 #include <FL/fl_draw.H>
25 
26 // A compiler from a certain very large software company will not compile
27 // the function pointer assignment due to the name conflict with fl_arc.
28 // This function is to fix that:
29 static void fl_arc_i(int x,int y,int w,int h,double a1,double a2) {
30  fl_arc(x,y,w,h,a1,a2);
31 }
32 
34 
35 static void draw(int which, int x,int y,int w,int h, int inset, Fl_Color color)
36 {
37  if (inset*2 >= w) inset = (w-1)/2;
38  if (inset*2 >= h) inset = (h-1)/2;
39  x += inset;
40  y += inset;
41  w -= 2*inset;
42  h -= 2*inset;
43  int d = w <= h ? w : h;
44  if (d <= 1) return;
45  fl_color(color);
46  void (*f)(int,int,int,int,double,double);
47  f = (which==FILL) ? fl_pie : fl_arc_i;
48  if (which >= CLOSED) {
49  f(x+w-d, y, d, d, w<=h ? 0 : -90, w<=h ? 180 : 90);
50  f(x, y+h-d, d, d, w<=h ? 180 : 90, w<=h ? 360 : 270);
51  } else if (which == UPPER_LEFT) {
52  f(x+w-d, y, d, d, 45, w<=h ? 180 : 90);
53  f(x, y+h-d, d, d, w<=h ? 180 : 90, 225);
54  } else { // LOWER_RIGHT
55  f(x, y+h-d, d, d, 225, w<=h ? 360 : 270);
56  f(x+w-d, y, d, d, w<=h ? 360 : 270, 360+45);
57  }
58  if (which == FILL) {
59  if (w < h)
60  fl_rectf(x, y+d/2, w, h-(d&-2));
61  else if (w > h)
62  fl_rectf(x+d/2, y, w-(d&-2), h);
63  } else {
64  if (w < h) {
65  if (which != UPPER_LEFT) fl_yxline(x+w-1, y+d/2-1, y+h-d/2+1);
66  if (which != LOWER_RIGHT) fl_yxline(x, y+d/2-1, y+h-d/2+1);
67  } else if (w > h) {
68  if (which != UPPER_LEFT) fl_xyline(x+d/2-1, y+h-1, x+w-d/2+1);
69  if (which != LOWER_RIGHT) fl_xyline(x+d/2-1, y, x+w-d/2+1);
70  }
71  }
72 }
73 
74 extern const uchar* fl_gray_ramp();
75 
76 void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor) {
77  const uchar *g = fl_gray_ramp();
78  draw(FILL, x, y, w, h, 2, Fl::box_color(bgcolor));
79  draw(UPPER_LEFT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'N']);
80  draw(UPPER_LEFT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'H']);
81  draw(UPPER_LEFT, x, y, w, h, 0, (Fl_Color)g[(int)'N']);
82  draw(UPPER_LEFT, x, y, w, h, 1, (Fl_Color)g[(int)'H']);
83  draw(LOWER_RIGHT, x, y, w, h, 0, (Fl_Color)g[(int)'S']);
84  draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'U']);
85  draw(LOWER_RIGHT, x, y, w, h, 1, (Fl_Color)g[(int)'U']);
86  draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'W']);
87  draw(CLOSED, x, y, w, h, 2, (Fl_Color)g[(int)'A']);
88 }
89 
90 void fl_round_up_box(int x, int y, int w, int h, Fl_Color bgcolor) {
91  const uchar *g = fl_gray_ramp();
92  draw(FILL, x, y, w, h, 2, Fl::box_color(bgcolor));
93  draw(LOWER_RIGHT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'H']);
94  draw(LOWER_RIGHT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'N']);
95  draw(LOWER_RIGHT, x, y, w, h, 1, (Fl_Color)g[(int)'H']);
96  draw(LOWER_RIGHT, x, y, w, h, 2, (Fl_Color)g[(int)'N']);
97  draw(UPPER_LEFT, x, y, w, h, 2, (Fl_Color)g[(int)'U']);
98  draw(UPPER_LEFT, x+1, y, w-2, h, 1, (Fl_Color)g[(int)'S']);
99  draw(UPPER_LEFT, x, y, w, h, 1, (Fl_Color)g[(int)'W']);
100  draw(UPPER_LEFT, x+1, y, w-2, h, 0, (Fl_Color)g[(int)'U']);
101  draw(CLOSED, x, y, w, h, 0, (Fl_Color)g[(int)'A']);
102 }
103 
108  return _FL_ROUND_UP_BOX;
109 }
110 
111 //
112 // End of "$Id$".
113 //
Fl_Box_Draw_F
void() Fl_Box_Draw_F(int x, int y, int w, int h, Fl_Color color)
Definition: Fl.H:89
draw
static void draw(int which, int x, int y, int w, int h, int inset, Fl_Color color)
Definition: fl_round_box.cxx:35
Fl.H
Fl::box_color
static Fl_Color box_color(Fl_Color)
Definition: fl_boxtype.cxx:69
fl_rectf
void fl_rectf(int x, int y, int w, int h)
Definition: fl_draw.H:206
Fl_Color
unsigned int Fl_Color
Definition: Enumerations.H:934
fl_internal_boxtype
void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F *)
Definition: fl_boxtype.cxx:404
fl_gray_ramp
const uchar * fl_gray_ramp()
Definition: fl_boxtype.cxx:60
fl_round_down_box
void fl_round_down_box(int x, int y, int w, int h, Fl_Color bgcolor)
Definition: fl_round_box.cxx:76
Fl_Boxtype
Fl_Boxtype
Definition: Enumerations.H:603
fl_color
void fl_color(Fl_Color c)
Definition: fl_draw.H:52
LOWER_RIGHT
Definition: fl_round_box.cxx:33
UPPER_LEFT
Definition: fl_round_box.cxx:33
_FL_ROUND_UP_BOX
see figure 1
Definition: Enumerations.H:627
fl_xyline
void fl_xyline(int x, int y, int x1)
Definition: fl_draw.H:255
fl_draw.H
utility header to pull drawing functions together
fl_arc
void fl_arc(int x, int y, int w, int h, double a1, double a2)
Definition: fl_draw.H:304
fl_pie
void fl_pie(int x, int y, int w, int h, double a1, double a2)
Definition: fl_draw.H:317
fl_yxline
void fl_yxline(int x, int y, int y1)
Definition: fl_draw.H:270
fl_arc_i
static void fl_arc_i(int x, int y, int w, int h, double a1, double a2)
Definition: fl_round_box.cxx:29
color
void color(int n)
Definition: gl2opengl.h:29
FILL
Definition: fl_round_box.cxx:33
x
int x
Definition: test.c:73
y
int y
Definition: test.c:74
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
_FL_ROUND_DOWN_BOX
see figure 1
Definition: Enumerations.H:628
fl_round_up_box
void fl_round_up_box(int x, int y, int w, int h, Fl_Color bgcolor)
Definition: fl_round_box.cxx:90
CLOSED
Definition: fl_round_box.cxx:33
uchar
unsigned char uchar
Definition: fl_types.h:30
fl_define_FL_ROUND_UP_BOX
Fl_Boxtype fl_define_FL_ROUND_UP_BOX()
Definition: fl_round_box.cxx:105