1 | // |
---|
2 | // "$Id: label.cxx 6626 2009-01-12 14:52:45Z fabien $" |
---|
3 | // |
---|
4 | // Label test program 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_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> |
---|
36 | |
---|
37 | #include <math.h> |
---|
38 | #ifndef M_PI |
---|
39 | #define M_PI 3.141592654 |
---|
40 | #endif |
---|
41 | |
---|
42 | Fl_Toggle_Button *leftb,*rightb,*clipb; |
---|
43 | //Fl_Box *text; |
---|
44 | Fl_Input *input; |
---|
45 | Fl_Hor_Value_Slider *fonts; |
---|
46 | Fl_Hor_Value_Slider *sizes; |
---|
47 | Fl_Hor_Value_Slider *angles; |
---|
48 | Fl_Double_Window *window; |
---|
49 | |
---|
50 | //code taken from fl_engraved_label.cxx |
---|
51 | class Rotated_Label_Box : public Fl_Widget{ |
---|
52 | protected: |
---|
53 | void draw(){ |
---|
54 | draw_box(); |
---|
55 | fl_font(labelfont(), labelsize()); |
---|
56 | fl_color(labelcolor()); |
---|
57 | int dx(0),dy(0); |
---|
58 | |
---|
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){ |
---|
63 | dx=dy=0; |
---|
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); |
---|
67 | }else{ |
---|
68 | dy=(int)(sin(M_PI*(double)rt_angle/180.)*(double)dx); |
---|
69 | dx=(int)(-cos(M_PI*(double)rt_angle/180.)*(double)dx); |
---|
70 | dx/=2;dy/=2; |
---|
71 | } |
---|
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); |
---|
75 | else{ |
---|
76 | fl_draw(rt_angle,rt_text,x()+w()/2+dx,y()+h()/2+dy); |
---|
77 | } |
---|
78 | fl_pop_clip(); |
---|
79 | draw_label(); |
---|
80 | } |
---|
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]); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
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); |
---|
91 | } |
---|
92 | |
---|
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}, |
---|
97 | {0,0,0}}; |
---|
98 | innards(X, Y, data, 7); |
---|
99 | } |
---|
100 | |
---|
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}, |
---|
105 | {0,0,0}}; |
---|
106 | innards(X, Y, data, 7); |
---|
107 | } |
---|
108 | |
---|
109 | public: |
---|
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(); |
---|
113 | }; |
---|
114 | int rt_angle; |
---|
115 | const char* rt_text; |
---|
116 | Fl_Align rt_align; |
---|
117 | }*text; |
---|
118 | |
---|
119 | |
---|
120 | void button_cb(Fl_Widget *,void *) { |
---|
121 | int i = 0; |
---|
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; |
---|
126 | window->redraw(); |
---|
127 | } |
---|
128 | |
---|
129 | void font_cb(Fl_Widget *,void *) { |
---|
130 | text->labelfont(int(fonts->value())); |
---|
131 | window->redraw(); |
---|
132 | } |
---|
133 | |
---|
134 | void size_cb(Fl_Widget *,void *) { |
---|
135 | text->labelsize(int(sizes->value())); |
---|
136 | window->redraw(); |
---|
137 | } |
---|
138 | void angle_cb(Fl_Widget *,void *) { |
---|
139 | text->rt_angle=(int)angles->value(); |
---|
140 | window->redraw(); |
---|
141 | } |
---|
142 | |
---|
143 | void input_cb(Fl_Widget *,void *) { |
---|
144 | text->rt_text=input->value(); |
---|
145 | window->redraw(); |
---|
146 | } |
---|
147 | |
---|
148 | void normal_cb(Fl_Widget *,void *) { |
---|
149 | text->labeltype(FL_NORMAL_LABEL); |
---|
150 | window->redraw(); |
---|
151 | } |
---|
152 | |
---|
153 | void shadow_cb(Fl_Widget *,void *) { |
---|
154 | text->labeltype(FL_SHADOW_LABEL); |
---|
155 | window->redraw(); |
---|
156 | } |
---|
157 | |
---|
158 | void embossed_cb(Fl_Widget *,void *) { |
---|
159 | text->labeltype(FL_EMBOSSED_LABEL); |
---|
160 | window->redraw(); |
---|
161 | } |
---|
162 | |
---|
163 | void engraved_cb(Fl_Widget *,void *) { |
---|
164 | text->labeltype(FL_ENGRAVED_LABEL); |
---|
165 | window->redraw(); |
---|
166 | } |
---|
167 | |
---|
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}, |
---|
173 | {0}}; |
---|
174 | |
---|
175 | int main(int argc, char **argv) { |
---|
176 | window = new Fl_Double_Window(400,425); |
---|
177 | |
---|
178 | angles= new Fl_Hor_Value_Slider(50,400,350,25,"Angle:"); |
---|
179 | angles->align(FL_ALIGN_LEFT); |
---|
180 | angles->bounds(-360,360); |
---|
181 | angles->step(1); |
---|
182 | angles->value(0); |
---|
183 | angles->callback(angle_cb); |
---|
184 | |
---|
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); |
---|
189 | |
---|
190 | sizes= new Fl_Hor_Value_Slider(50,350,350,25,"Size:"); |
---|
191 | sizes->align(FL_ALIGN_LEFT); |
---|
192 | sizes->bounds(1,64); |
---|
193 | sizes->step(1); |
---|
194 | sizes->value(14); |
---|
195 | sizes->callback(size_cb); |
---|
196 | |
---|
197 | fonts=new Fl_Hor_Value_Slider(50,325,350,25,"Font:"); |
---|
198 | fonts->align(FL_ALIGN_LEFT); |
---|
199 | fonts->bounds(0,15); |
---|
200 | fonts->step(1); |
---|
201 | fonts->value(0); |
---|
202 | fonts->callback(font_cb); |
---|
203 | |
---|
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); |
---|
212 | g->end(); |
---|
213 | |
---|
214 | Fl_Choice *c = new Fl_Choice(50,275,200,25); |
---|
215 | c->menu(choices); |
---|
216 | |
---|
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); |
---|
221 | window->end(); |
---|
222 | window->show(argc,argv); |
---|
223 | return Fl::run(); |
---|
224 | } |
---|
225 | |
---|
226 | // |
---|
227 | // End of "$Id: label.cxx 6626 2009-01-12 14:52:45Z fabien $". |
---|
228 | // |
---|