blob: ca7f009d4085adf44e33c3b3a89f1aa1d2c86fea [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: fl_rounded_box.cxx 7903 2010-11-28 21:06:39Z matt $"
3//
4// Rounded 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#include <FL/Fl.H>
29#include <FL/fl_draw.H>
30
31#define RN 5
32#define RS 15
33#define BW 3
34
35static double offset[RN] = { 0.0, 0.07612, 0.29289, 0.61732, 1.0};
36
37static void rbox(int fill, int x, int y, int w, int h) {
38 int i;
39 int rsx ,rsy, rs;
40 rsx = w*2/5; rsy = h*2/5;
41 if (rsx > rsy) rs = rsy; else rs = rsx;
42 if (rs > RS) rs = RS;
43 rsx = rs; rsy = rs;
44
45 if (fill) fl_begin_polygon(); else fl_begin_loop();
46 for (i=0; i<RN; i++)
47 fl_vertex(x + offset[RN-i-1]*rsx, y + offset[i] * rsy);
48 for (i=0; i<RN; i++)
49 fl_vertex(x + offset[i]*rsx, y + h-1 - offset[RN-i-1] * rsy);
50 for (i=0; i<RN; i++)
51 fl_vertex(x + w-1 - offset[RN-i-1]*rsx, y + h-1 - offset[i] * rsy);
52 for (i=0; i<RN; i++)
53 fl_vertex(x + w-1 - offset[i]*rsx, y + offset[RN-i-1] * rsy);
54 if (fill) fl_end_polygon(); else fl_end_loop();
55}
56
57static void fl_rflat_box(int x, int y, int w, int h, Fl_Color c) {
58 fl_color(c); rbox(1, x, y, w, h); rbox(0, x, y, w, h);
59}
60
61static void fl_rounded_frame(int x, int y, int w, int h, Fl_Color c) {
62 fl_color(c); rbox(0, x, y, w, h);
63}
64
65static void fl_rounded_box(int x, int y, int w, int h, Fl_Color c) {
66 fl_color(c); rbox(1, x, y, w, h);
67 fl_color(FL_BLACK); rbox(0, x, y, w, h);
68}
69
70static void fl_rshadow_box(int x, int y, int w, int h, Fl_Color c) {
71 // draw shadow:
72 fl_color(FL_DARK3);
73 rbox(1, x+BW, y+BW, w, h);
74 rbox(0, x+BW, y+BW, w, h);
75 // draw the box:
76 fl_rounded_box(x, y, w, h, c);
77}
78
79extern void fl_internal_boxtype(Fl_Boxtype, Fl_Box_Draw_F*);
80
81Fl_Boxtype fl_define_FL_ROUNDED_BOX() {
82 fl_internal_boxtype(_FL_ROUNDED_FRAME, fl_rounded_frame);
83 fl_internal_boxtype(_FL_ROUNDED_BOX, fl_rounded_box);
84 return _FL_ROUNDED_BOX;
85}
86
87Fl_Boxtype fl_define_FL_RFLAT_BOX() {
88 fl_internal_boxtype(_FL_RFLAT_BOX, fl_rflat_box);
89 return _FL_RFLAT_BOX;
90}
91
92Fl_Boxtype fl_define_FL_RSHADOW_BOX() {
93 fl_internal_boxtype(_FL_RSHADOW_BOX, fl_rshadow_box);
94 return _FL_RSHADOW_BOX;
95}
96
97//
98// End of "$Id: fl_rounded_box.cxx 7903 2010-11-28 21:06:39Z matt $".
99//