-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlabel.cxx
201 lines (174 loc) · 5.29 KB
/
label.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//
// "$Id$"
//
// Label test program for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2006 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
#include <fltk/run.h>
#include <fltk/Window.h>
#include <fltk/Box.h>
#include <fltk/ValueSlider.h>
#include <fltk/ToggleButton.h>
#include <fltk/Input.h>
#include <fltk/MenuBuild.h>
#include <fltk/Choice.h>
#include <fltk/draw.h>
#include <fltk/Font.h>
#include <fltk/xpmImage.h>
using namespace fltk;
ToggleButton *leftb,*rightb,*topb,*bottomb,*insideb,*centerb,*clipb,*wrapb;
Widget *textbox;
Input *input;
ValueSlider *fontslider;
ValueSlider *sizes;
Window *window;
void button_cb(Widget *,void *) {
int i = 0;
if (leftb->value()) i |= ALIGN_LEFT;
if (rightb->value()) i |= ALIGN_RIGHT;
if (topb->value()) i |= ALIGN_TOP;
if (bottomb->value()) i |= ALIGN_BOTTOM;
if (insideb->value()) i |= ALIGN_INSIDE;
if (centerb->value()) i |= ALIGN_CENTER;
if (clipb->value()) i |= ALIGN_CLIP;
if (wrapb->value()) i |= ALIGN_WRAP;
textbox->align(i);
window->redraw();
}
void font_cb(Widget *,void *) {
//Widget::default_style->leading_ = int(fontslider->value());
textbox->labelfont(font(int(fontslider->value())));
window->redraw();
}
void size_cb(Widget *,void *) {
textbox->labelsize((float)sizes->value());
window->redraw();
}
void input_cb(Widget *,void *) {
textbox->label(input->value());
window->redraw();
}
void normal_cb(Widget *,void *) {
textbox->labeltype(NORMAL_LABEL);
window->redraw();
}
void symbol_cb(Widget *,void *) {
textbox->labeltype(SYMBOL_LABEL);
if (input->value()[0] != '@') {
input->static_value("@->");
textbox->label("@->");
}
window->redraw();
}
void shadow_cb(Widget *,void *) {
textbox->labeltype(SHADOW_LABEL);
window->redraw();
}
void embossed_cb(Widget *,void *) {
textbox->labeltype(EMBOSSED_LABEL);
window->redraw();
}
void engraved_cb(Widget *,void *) {
textbox->labeltype(ENGRAVED_LABEL);
window->redraw();
}
static void load_menu(Choice* c) {
c->begin();
new fltk::Item("NORMAL_LABEL",0,normal_cb);
new fltk::Item("SYMBOL_LABEL",0,symbol_cb);
new fltk::Item("SHADOW_LABEL",0,shadow_cb);
new fltk::Item("ENGRAVED_LABEL",0,engraved_cb);
new fltk::Item("EMBOSSED_LABEL",0,embossed_cb);
c->end();
}
#include "porsche.xpm"
xpmImage theimage(porsche_xpm);
void image_cb(Widget* w, void*) {
textbox->image(((Button*)w)->value() ? &theimage : 0);
window->redraw();
}
void inactive_cb(Widget* w, void*) {
if (((Button*)w)->value()) textbox->deactivate(); else textbox->activate();
window->redraw();
}
const char* const initial = "The quick brown fox jumps over the lazy dog.";
int main(int argc, char **argv) {
window = new Window(400,400);
window->set_double_buffer();
window->begin();
textbox= new Widget(100,75,200,100,initial);
textbox->box(ENGRAVED_BOX);
Choice *c = new Choice(50,275,200,25);
load_menu(c);
ToggleButton* b = new ToggleButton(250,275,50,25,"image");
b->callback(image_cb);
b = new ToggleButton(300,275,50,25,"inactive");
b->callback(inactive_cb);
Group *g = new Group(0,300,400,25);
g->resizable(g);
g->begin();
leftb = new ToggleButton(0,0,50,25,"left");
leftb->callback(button_cb);
rightb = new ToggleButton(50,0,50,25,"right");
rightb->callback(button_cb);
topb = new ToggleButton(100,0,50,25,"top");
topb->callback(button_cb);
bottomb = new ToggleButton(150,0,50,25,"bottom");
bottomb->callback(button_cb);
insideb = new ToggleButton(200,0,50,25,"inside");
insideb->callback(button_cb);
centerb = new ToggleButton(250,0,50,25,"center");
centerb->callback(button_cb);
wrapb = new ToggleButton(300,0,50,25,"wrap");
wrapb->callback(button_cb);
clipb = new ToggleButton(350,0,50,25,"clip");
clipb->callback(button_cb);
g->end();
fontslider=new ValueSlider(50,325,350,25,"Font:");
fontslider->type(Slider::TICK_ABOVE);
fontslider->clear_flag(ALIGN_MASK);
fontslider->set_flag(ALIGN_LEFT);
fontslider->range(0,15);
fontslider->step(1);
fontslider->value(0);
fontslider->callback(font_cb);
sizes= new ValueSlider(50,350,350,25,"Size:");
sizes->type(Slider::TICK_ABOVE|Slider::LOG);
sizes->clear_flag(ALIGN_MASK);
sizes->set_flag(ALIGN_LEFT);
sizes->range(1,64);
//sizes->step(1);
sizes->value(14);
sizes->callback(size_cb);
input = new Input(50,375,350,25);
input->static_value(initial);
input->when(WHEN_CHANGED);
input->callback(input_cb);
window->resizable(textbox);
window->end();
window->show(argc,argv);
return run();
}
//
// End of "$Id$".
//