2 // "$Id: label.cxx 6626 2009-01-12 14:52:45Z fabien $"
4 // Label test program for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
29 #include <FL/Fl_Double_Window.H>
30 #include <FL/Fl_Box.H>
31 #include <FL/Fl_Hor_Value_Slider.H>
32 #include <FL/Fl_Toggle_Button.H>
33 #include <FL/Fl_Input.H>
34 #include <FL/Fl_Choice.H>
35 #include <FL/fl_draw.H>
39 #define M_PI 3.141592654
42 Fl_Toggle_Button
*leftb
,*rightb
,*clipb
;
45 Fl_Hor_Value_Slider
*fonts
;
46 Fl_Hor_Value_Slider
*sizes
;
47 Fl_Hor_Value_Slider
*angles
;
48 Fl_Double_Window
*window
;
50 //code taken from fl_engraved_label.cxx
51 class Rotated_Label_Box
: public Fl_Widget
{
55 fl_font(labelfont(), labelsize());
56 fl_color(labelcolor());
59 if(rt_align
&FL_ALIGN_CLIP
)fl_push_clip(x(),y(),w(),h());
60 else fl_push_no_clip();
61 fl_measure(rt_text
,dx
,dy
);
62 if(rt_align
&FL_ALIGN_LEFT
){
64 }else if(rt_align
&FL_ALIGN_RIGHT
){
65 dy
=(int)(-sin(M_PI
*(double)(rt_angle
+180)/180.)*(double)dx
);
66 dx
=(int)(cos(M_PI
*(double)(rt_angle
+180)/180.)*(double)dx
);
68 dy
=(int)(sin(M_PI
*(double)rt_angle
/180.)*(double)dx
);
69 dx
=(int)(-cos(M_PI
*(double)rt_angle
/180.)*(double)dx
);
72 if(labeltype()==FL_SHADOW_LABEL
)shadow_label(x()+w()/2+dx
,y()+h()/2+dy
);
73 else if(labeltype()==FL_ENGRAVED_LABEL
)engraved_label(x()+w()/2+dx
,y()+h()/2+dy
);
74 else if(labeltype()==FL_EMBOSSED_LABEL
)embossed_label(x()+w()/2+dx
,y()+h()/2+dy
);
76 fl_draw(rt_angle
,rt_text
,x()+w()/2+dx
,y()+h()/2+dy
);
81 void innards(int X
, int Y
, int data
[][3], int n
){
82 for (int i
= 0; i
< n
; i
++) {
83 fl_color((Fl_Color
)(i
< n
-1 ? data
[i
][2] : labelcolor()));
84 fl_draw(rt_angle
,rt_text
, X
+data
[i
][0], Y
+data
[i
][1]);
88 void shadow_label(int X
, int Y
){
89 static int data
[2][3] = {{2,2,FL_DARK3
},{0,0,0}};
90 innards(X
, Y
, data
, 2);
93 void engraved_label(int X
, int Y
){
94 static int data
[7][3] = {
95 {1,0,FL_LIGHT3
},{1,1,FL_LIGHT3
},{0,1,FL_LIGHT3
},
96 {-1,0,FL_DARK3
},{-1,-1,FL_DARK3
},{0,-1,FL_DARK3
},
98 innards(X
, Y
, data
, 7);
101 void embossed_label(int X
, int Y
){
102 static int data
[7][3] = {
103 {-1,0,FL_LIGHT3
},{-1,-1,FL_LIGHT3
},{0,-1,FL_LIGHT3
},
104 {1,0,FL_DARK3
},{1,1,FL_DARK3
},{0,1,FL_DARK3
},
106 innards(X
, Y
, data
, 7);
110 Rotated_Label_Box(int X
, int Y
, int W
, int H
, const char*L
=0):
111 Fl_Widget(X
,Y
,W
,H
,L
),rt_angle(0),rt_align((Fl_Align
)0){
112 rt_text
=input
->value();
120 void button_cb(Fl_Widget
*,void *) {
122 if (leftb
->value()) i
|= FL_ALIGN_LEFT
;
123 if (rightb
->value()) i
|= FL_ALIGN_RIGHT
;
124 if (clipb
->value()) i
|= FL_ALIGN_CLIP
;
125 text
->rt_align
=(Fl_Align
)i
;
129 void font_cb(Fl_Widget
*,void *) {
130 text
->labelfont(int(fonts
->value()));
134 void size_cb(Fl_Widget
*,void *) {
135 text
->labelsize(int(sizes
->value()));
138 void angle_cb(Fl_Widget
*,void *) {
139 text
->rt_angle
=(int)angles
->value();
143 void input_cb(Fl_Widget
*,void *) {
144 text
->rt_text
=input
->value();
148 void normal_cb(Fl_Widget
*,void *) {
149 text
->labeltype(FL_NORMAL_LABEL
);
153 void shadow_cb(Fl_Widget
*,void *) {
154 text
->labeltype(FL_SHADOW_LABEL
);
158 void embossed_cb(Fl_Widget
*,void *) {
159 text
->labeltype(FL_EMBOSSED_LABEL
);
163 void engraved_cb(Fl_Widget
*,void *) {
164 text
->labeltype(FL_ENGRAVED_LABEL
);
168 Fl_Menu_Item choices
[] = {
169 {"FL_NORMAL_LABEL",0,normal_cb
},
170 {"FL_SHADOW_LABEL",0,shadow_cb
},
171 {"FL_ENGRAVED_LABEL",0,engraved_cb
},
172 {"FL_EMBOSSED_LABEL",0,embossed_cb
},
175 int main(int argc
, char **argv
) {
176 window
= new Fl_Double_Window(400,425);
178 angles
= new Fl_Hor_Value_Slider(50,400,350,25,"Angle:");
179 angles
->align(FL_ALIGN_LEFT
);
180 angles
->bounds(-360,360);
183 angles
->callback(angle_cb
);
185 input
= new Fl_Input(50,375,350,25);
186 input
->static_value("Rotate Me!!!");
187 input
->when(FL_WHEN_CHANGED
);
188 input
->callback(input_cb
);
190 sizes
= new Fl_Hor_Value_Slider(50,350,350,25,"Size:");
191 sizes
->align(FL_ALIGN_LEFT
);
195 sizes
->callback(size_cb
);
197 fonts
=new Fl_Hor_Value_Slider(50,325,350,25,"Font:");
198 fonts
->align(FL_ALIGN_LEFT
);
202 fonts
->callback(font_cb
);
204 Fl_Group
*g
= new Fl_Group(50,300,350,25);
205 leftb
= new Fl_Toggle_Button(50,300,50,25,"left");
206 leftb
->callback(button_cb
);
207 rightb
= new Fl_Toggle_Button(100,300,50,25,"right");
208 rightb
->callback(button_cb
);
209 clipb
= new Fl_Toggle_Button(350,300,50,25,"clip");
210 clipb
->callback(button_cb
);
211 g
->resizable(rightb
);
214 Fl_Choice
*c
= new Fl_Choice(50,275,200,25);
217 text
= new Rotated_Label_Box(100,75,200,100,"Widget with rotated text");
218 text
->box(FL_FRAME_BOX
);
219 text
->align(FL_ALIGN_BOTTOM
);
220 window
->resizable(text
);
222 window
->show(argc
,argv
);
227 // End of "$Id: label.cxx 6626 2009-01-12 14:52:45Z fabien $".