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_rounded_box.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // Rounded box drawing routines for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2016 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 #include <FL/Fl.H>
20 #include <FL/fl_draw.H>
21 
22 // Constants for rounded corner drawing algorithm:
23 //
24 // RN = number of segments per corner (must match offset array size)
25 // RS = max. corner radius
26 // BW = box shadow width
27 
28 #define RN 5
29 #define RS 15
30 #define BW 3
31 
32 static double offset[RN] = { 0.0, 0.07612, 0.29289, 0.61732, 1.0};
33 
34 static inline void fl_vertex_r(double x, double y) {
35  fl_vertex(x + 0.5, y + 0.5);
36 }
37 
38 static void rbox(int fill, int x, int y, int w, int h) {
39  int i;
40  int rs, rsy;
41  rs = w*2/5; rsy = h*2/5;
42  if (rs > rsy) rs = rsy; // use smaller radius
43  if (rs > RS) rs = RS;
44  if (rs == 5) rs = 4; // use only even sizes for small corners (STR #2943)
45  if (rs == 7) rs = 8; // note: 8 is better than 6 (really)
46 
47  if (fill) fl_begin_polygon(); else fl_begin_loop();
48  for (i=0; i<RN; i++)
49  fl_vertex_r(x + offset[RN-i-1]*rs, y + offset[i] * rs);
50  for (i=0; i<RN; i++)
51  fl_vertex_r(x + offset[i]*rs, y + h-1 - offset[RN-i-1] * rs);
52  for (i=0; i<RN; i++)
53  fl_vertex_r(x + w-1 - offset[RN-i-1]*rs, y + h-1 - offset[i] * rs);
54  for (i=0; i<RN; i++)
55  fl_vertex_r(x + w-1 - offset[i]*rs, y + offset[RN-i-1] * rs);
56  if (fill) fl_end_polygon(); else fl_end_loop();
57 }
58 
59 static void fl_rflat_box(int x, int y, int w, int h, Fl_Color c) {
61  rbox(1, x, y, w, h); rbox(0, x, y, w, h);
62 }
63 
64 static void fl_rounded_frame(int x, int y, int w, int h, Fl_Color c) {
66  rbox(0, x, y, w, h);
67 }
68 
69 static void fl_rounded_box(int x, int y, int w, int h, Fl_Color c) {
71  rbox(1, x, y, w, h);
72  fl_color(FL_BLACK); rbox(0, x, y, w, h);
73 }
74 
75 static void fl_rshadow_box(int x, int y, int w, int h, Fl_Color c) {
76  // draw shadow:
78  rbox(1, x+BW, y+BW, w, h);
79  rbox(0, x+BW, y+BW, w, h);
80  // draw the box:
81  fl_rounded_box(x, y, w, h, c);
82 }
83 
85 
89  return _FL_ROUNDED_BOX;
90 }
91 
94  return _FL_RFLAT_BOX;
95 }
96 
99  return _FL_RSHADOW_BOX;
100 }
101 
102 //
103 // End of "$Id$".
104 //
Fl_Box_Draw_F
void() Fl_Box_Draw_F(int x, int y, int w, int h, Fl_Color color)
Definition: Fl.H:89
fl_rounded_frame
static void fl_rounded_frame(int x, int y, int w, int h, Fl_Color c)
Definition: fl_rounded_box.cxx:64
Fl.H
fl_vertex_r
static void fl_vertex_r(double x, double y)
Definition: fl_rounded_box.cxx:34
fl_internal_boxtype
void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F *)
Definition: fl_boxtype.cxx:404
Fl_Color
unsigned int Fl_Color
Definition: Enumerations.H:934
fl_rshadow_box
static void fl_rshadow_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_rounded_box.cxx:75
fl_begin_polygon
void fl_begin_polygon()
Definition: fl_draw.H:374
fl_rflat_box
static void fl_rflat_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_rounded_box.cxx:59
_FL_ROUNDED_FRAME
see figure 1
Definition: Enumerations.H:625
Fl_Boxtype
Fl_Boxtype
Definition: Enumerations.H:603
RN
#define RN
Definition: fl_rounded_box.cxx:28
_FL_RFLAT_BOX
see figure 1
Definition: Enumerations.H:626
fl_color
void fl_color(Fl_Color c)
Definition: fl_draw.H:52
fl_define_FL_RSHADOW_BOX
Fl_Boxtype fl_define_FL_RSHADOW_BOX()
Definition: fl_rounded_box.cxx:97
fl_define_FL_RFLAT_BOX
Fl_Boxtype fl_define_FL_RFLAT_BOX()
Definition: fl_rounded_box.cxx:92
offset
static double offset[5]
Definition: fl_rounded_box.cxx:32
fl_begin_loop
void fl_begin_loop()
Definition: fl_draw.H:370
FL_BLACK
const Fl_Color FL_BLACK
Definition: Enumerations.H:956
Fl::set_box_color
static void set_box_color(Fl_Color)
Definition: fl_boxtype.cxx:93
fl_end_loop
void fl_end_loop()
Definition: fl_draw.H:436
_FL_ROUNDED_BOX
see figure 1
Definition: Enumerations.H:623
fl_draw.H
utility header to pull drawing functions together
fl_rounded_box
static void fl_rounded_box(int x, int y, int w, int h, Fl_Color c)
Definition: fl_rounded_box.cxx:69
fl_end_polygon
void fl_end_polygon()
Definition: fl_draw.H:440
rbox
static void rbox(int fill, int x, int y, int w, int h)
Definition: fl_rounded_box.cxx:38
x
int x
Definition: test.c:73
_FL_RSHADOW_BOX
see figure 1
Definition: Enumerations.H:624
y
int y
Definition: test.c:74
fl_define_FL_ROUNDED_BOX
Fl_Boxtype fl_define_FL_ROUNDED_BOX()
Definition: fl_rounded_box.cxx:86
fl_vertex
void fl_vertex(double x, double y)
Definition: fl_draw.H:379
RS
#define RS
Definition: fl_rounded_box.cxx:29
BW
#define BW
Definition: fl_rounded_box.cxx:30
FL_DARK3
const Fl_Color FL_DARK3
Definition: Enumerations.H:946