1 | // |
---|
2 | // "$Id$" |
---|
3 | // |
---|
4 | // Another forms demo for the Fast Light Tool Kit (FLTK). |
---|
5 | // |
---|
6 | // This is an XForms program with very few changes. |
---|
7 | // Search for "fltk" to find all changes necessary to port to fltk. |
---|
8 | // |
---|
9 | // This demo show the different boxtypes. Note that some |
---|
10 | // boxtypes are not appropriate for some objects |
---|
11 | // |
---|
12 | // Copyright 1998-2005 by Bill Spitzak and others. |
---|
13 | // |
---|
14 | // This library is free software; you can redistribute it and/or |
---|
15 | // modify it under the terms of the GNU Library General Public |
---|
16 | // License as published by the Free Software Foundation; either |
---|
17 | // version 2 of the License, or (at your option) any later version. |
---|
18 | // |
---|
19 | // This library is distributed in the hope that it will be useful, |
---|
20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
22 | // Library General Public License for more details. |
---|
23 | // |
---|
24 | // You should have received a copy of the GNU Library General Public |
---|
25 | // License along with this library; if not, write to the Free Software |
---|
26 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
27 | // USA. |
---|
28 | // |
---|
29 | // Please report all bugs and problems on the following page: |
---|
30 | // |
---|
31 | // http://www.fltk.org/str.php |
---|
32 | // |
---|
33 | |
---|
34 | #include <FL/forms.H> // changed for fltk |
---|
35 | |
---|
36 | static int border = 1; // changed from FL_TRANSIENT for fltk |
---|
37 | // (this is so the close box and Esc work to close the window) |
---|
38 | |
---|
39 | typedef struct { int val; const char *name; } VN_struct; |
---|
40 | #define VN(a) {a,#a} |
---|
41 | |
---|
42 | // static VN_struct gmode[] = |
---|
43 | // { |
---|
44 | // VN(StaticGray), VN(GrayScale), VN(StaticColor), |
---|
45 | // VN(PseudoColor), VN(TrueColor), VN(DirectColor), |
---|
46 | // }; |
---|
47 | |
---|
48 | static VN_struct btypes[]= |
---|
49 | { |
---|
50 | {FL_NO_BOX,"no box"}, |
---|
51 | {FL_UP_BOX, "up box"}, |
---|
52 | {FL_DOWN_BOX,"down box"}, |
---|
53 | {FL_BORDER_BOX,"border box"}, |
---|
54 | {FL_SHADOW_BOX,"shadow box"}, |
---|
55 | {FL_FLAT_BOX,"flat box"}, |
---|
56 | {FL_FRAME_BOX,"frame box"}, |
---|
57 | {FL_EMBOSSED_BOX,"embossed box"}, |
---|
58 | {FL_ROUNDED_BOX,"rounded box"}, |
---|
59 | {FL_RFLAT_BOX,"rflat box"}, |
---|
60 | {FL_RSHADOW_BOX,"rshadow box"}, // renamed for fltk |
---|
61 | {FL_OVAL_BOX,"oval box"}, |
---|
62 | {FL_ROUNDED3D_UPBOX,"rounded3d upbox"}, |
---|
63 | {FL_ROUNDED3D_DOWNBOX,"rounded3d downbox"}, |
---|
64 | {FL_OVAL3D_UPBOX,"oval3d upbox"}, |
---|
65 | {FL_OVAL3D_DOWNBOX,"oval3d downbox"}, |
---|
66 | {FL_PLASTIC_UP_BOX,"plastic upbox"}, |
---|
67 | {FL_PLASTIC_DOWN_BOX,"plastic downbox"}, |
---|
68 | /* sentinel */ |
---|
69 | {-1} |
---|
70 | }; |
---|
71 | |
---|
72 | #include "pixmaps/srs.xbm" |
---|
73 | |
---|
74 | /*************** Callback **********************/ |
---|
75 | |
---|
76 | FL_FORM *form; |
---|
77 | Fl_Widget *tobj[18], *exitob, *btypeob, *modeob; |
---|
78 | |
---|
79 | void |
---|
80 | boxtype_cb (Fl_Widget * ob, long) |
---|
81 | { |
---|
82 | int i, req_bt = fl_get_choice(ob) - 1; |
---|
83 | static int lastbt = -1; |
---|
84 | |
---|
85 | if(lastbt != req_bt) |
---|
86 | { |
---|
87 | fl_freeze_form (form); |
---|
88 | fl_redraw_form (form); |
---|
89 | for (i = 0; i < 18; i++) |
---|
90 | fl_set_object_boxtype (tobj[i], (Fl_Boxtype)btypes[req_bt].val); |
---|
91 | fl_unfreeze_form (form); |
---|
92 | lastbt = req_bt; |
---|
93 | fl_redraw_form(form); // added for fltk |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | void |
---|
98 | mode_cb (Fl_Widget *, long) |
---|
99 | { |
---|
100 | // static int lval = -1; |
---|
101 | // int val = fl_get_choice (ob) -1; |
---|
102 | // int db = 0; |
---|
103 | |
---|
104 | // if (val == lval || val < 0) |
---|
105 | // return; |
---|
106 | |
---|
107 | // fl_hide_form (form); |
---|
108 | // if (!fl_mode_capable (gmode[val].val, 0)) |
---|
109 | // { |
---|
110 | // fl_set_choice(ob, lval); |
---|
111 | // val = lval; |
---|
112 | // } |
---|
113 | |
---|
114 | // fl_set_graphics_mode (gmode[val].val, db); |
---|
115 | // fl_show_form (form, FL_PLACE_GEOMETRY, border, "Box types"); |
---|
116 | |
---|
117 | // lval = val; |
---|
118 | } |
---|
119 | |
---|
120 | /*************** Creation Routines *********************/ |
---|
121 | |
---|
122 | void |
---|
123 | create_form_form (void) |
---|
124 | { |
---|
125 | Fl_Widget *obj; |
---|
126 | |
---|
127 | form = fl_bgn_form(FL_NO_BOX, 720, 520); |
---|
128 | obj = fl_add_box(FL_UP_BOX, 0, 0, 720, 520, ""); |
---|
129 | fl_set_object_color(obj, FL_BLUE, FL_COL1); |
---|
130 | obj = fl_add_box(FL_DOWN_BOX, 10, 90, 700, 420, ""); |
---|
131 | fl_set_object_color(obj, FL_COL1, FL_COL1); |
---|
132 | obj = fl_add_box(FL_DOWN_BOX, 10, 10, 700, 70, ""); |
---|
133 | fl_set_object_color(obj, FL_SLATEBLUE, FL_COL1); |
---|
134 | tobj[0] = obj = fl_add_box(FL_UP_BOX, 30, 110, 110, 110, "Box"); |
---|
135 | tobj[1] = obj = fl_add_text(FL_NORMAL_TEXT, 30, 240, 110, 30, "Text"); |
---|
136 | tobj[2] = obj = fl_add_bitmap(FL_NORMAL_BITMAP, 40, 280, 90, 80, "Bitmap"); |
---|
137 | fl_set_object_lcol(obj, FL_BLUE); |
---|
138 | tobj[3] = obj = fl_add_chart(FL_BAR_CHART, 160, 110, 160, 110, "Chart"); |
---|
139 | tobj[4] = obj = fl_add_clock(FL_ANALOG_CLOCK, 40, 390, 90, 90, "Clock"); |
---|
140 | //fl_set_object_dblbuffer(tobj[4],1); // removed for fltk |
---|
141 | tobj[5]=obj=fl_add_button(FL_NORMAL_BUTTON, 340, 110, 120, 30, "Button"); |
---|
142 | tobj[6]=obj=fl_add_lightbutton(FL_PUSH_BUTTON,340,150,120,30,"Lightbutton"); |
---|
143 | tobj[7]=obj=fl_add_roundbutton(FL_PUSH_BUTTON,340,190,120,30,"Roundbutton"); |
---|
144 | tobj[8]=obj=fl_add_slider(FL_VERT_SLIDER, 160, 250, 40, 230, "Slider"); |
---|
145 | tobj[9]=obj=fl_add_valslider(FL_VERT_SLIDER, 220, 250, 40, 230, "Valslider"); |
---|
146 | tobj[10]=obj=fl_add_dial (FL_LINE_DIAL, 280, 250, 100, 100, "Dial"); |
---|
147 | tobj[11]=obj=fl_add_positioner(FL_NORMAL_POSITIONER,280,380,150,100, "Positioner"); |
---|
148 | tobj[12]=obj=fl_add_counter (FL_NORMAL_COUNTER,480,110,210,30, "Counter"); |
---|
149 | tobj[13]=obj=fl_add_input (FL_NORMAL_INPUT, 520,170,170,30, "Input"); |
---|
150 | tobj[14]=obj=fl_add_menu (FL_PUSH_MENU, 400, 240, 100, 30, "Menu"); |
---|
151 | tobj[15]=obj=fl_add_choice (FL_NORMAL_CHOICE, 580, 250, 110, 30, "Choice"); |
---|
152 | tobj[16]=obj=fl_add_timer (FL_VALUE_TIMER, 580, 210, 110, 30, "Timer"); |
---|
153 | //fl_set_object_dblbuffer(tobj[16], 1); // removed for fltk |
---|
154 | tobj[17]=obj=fl_add_browser (FL_NORMAL_BROWSER,450,300,240, 180, "Browser"); |
---|
155 | exitob=obj= fl_add_button (FL_NORMAL_BUTTON, 590, 30, 100, 30, "Exit"); |
---|
156 | btypeob=obj= fl_add_choice (FL_NORMAL_CHOICE,110,30, 130, 30, "Boxtype"); |
---|
157 | fl_set_object_callback (obj, boxtype_cb, 0); |
---|
158 | modeob = obj=fl_add_choice(FL_NORMAL_CHOICE,370,30,130,30,"Graphics mode"); |
---|
159 | fl_set_object_callback (obj, mode_cb, 0); |
---|
160 | fl_end_form (); |
---|
161 | } |
---|
162 | /*---------------------------------------*/ |
---|
163 | |
---|
164 | void |
---|
165 | create_the_forms (void) |
---|
166 | { |
---|
167 | create_form_form (); |
---|
168 | } |
---|
169 | |
---|
170 | /*************** Main Routine ***********************/ |
---|
171 | |
---|
172 | const char *browserlines[] = { |
---|
173 | " ", "@C1@c@l@bObjects Demo", " ", |
---|
174 | "This demo shows you all", "objects that currently", |
---|
175 | "exist in the Forms Library.", " ", |
---|
176 | "You can change the boxtype", "of the different objects", |
---|
177 | "using the buttons at the", "top of the form. Note that", |
---|
178 | "some combinations might not", "look too good. Also realize", |
---|
179 | "that for all object classes", "many different types are", |
---|
180 | "available with different", "behaviour.", " ", |
---|
181 | "With this demo you can also", "see the effect of the drawing", |
---|
182 | "mode on the appearance of the","objects.", |
---|
183 | 0 |
---|
184 | }; |
---|
185 | |
---|
186 | |
---|
187 | int |
---|
188 | main (int argc, char *argv[]) |
---|
189 | { |
---|
190 | FL_COLOR c = FL_BLACK; |
---|
191 | const char **p; |
---|
192 | VN_struct *vn; |
---|
193 | |
---|
194 | fl_initialize(&argc, argv, "FormDemo", 0, 0); |
---|
195 | create_the_forms (); |
---|
196 | fl_set_bitmap_data (tobj[2], sorceress_width, sorceress_height, sorceress_bits); |
---|
197 | fl_add_chart_value (tobj[3], 15, "item 1", c++); |
---|
198 | fl_add_chart_value (tobj[3], 5, "item 2", c++); |
---|
199 | fl_add_chart_value (tobj[3], -10, "item 3", c++); |
---|
200 | fl_add_chart_value (tobj[3], 25, "item 4", c++); |
---|
201 | fl_set_menu (tobj[14], "item 1|item 2|item 3|item 4|item 5"); |
---|
202 | fl_addto_choice (tobj[15], "item 1"); |
---|
203 | fl_addto_choice (tobj[15], "item 2"); |
---|
204 | fl_addto_choice (tobj[15], "item 3"); |
---|
205 | fl_addto_choice (tobj[15], "item 4"); |
---|
206 | fl_addto_choice (tobj[15], "item 5"); |
---|
207 | fl_set_timer (tobj[16], 1000.0); |
---|
208 | |
---|
209 | for ( p = browserlines; *p; p++) |
---|
210 | fl_add_browser_line (tobj[17], *p); |
---|
211 | |
---|
212 | for ( vn = btypes; vn->val >= 0; vn++) |
---|
213 | fl_addto_choice(btypeob, vn->name); |
---|
214 | |
---|
215 | // { |
---|
216 | // int i; |
---|
217 | // VN_struct *g = gmode, *gs = g + sizeof (gmode) / sizeof (gmode[0]); |
---|
218 | // for (i = 1; g < gs; g++, i++) |
---|
219 | // { |
---|
220 | // fl_addto_choice (modeob, g->name); |
---|
221 | // if(!fl_mode_capable(g->val, 0)) |
---|
222 | // fl_set_choice_item_mode(modeob, i, FL_PUP_GRAY); |
---|
223 | // } |
---|
224 | // } |
---|
225 | // fl_set_choice (modeob, fl_vmode+1); |
---|
226 | |
---|
227 | fl_show_form (form, FL_PLACE_MOUSE, border, "Box types"); |
---|
228 | |
---|
229 | while (fl_do_forms () != exitob) |
---|
230 | ; |
---|
231 | |
---|
232 | return 0; |
---|
233 | } |
---|
234 | |
---|
235 | // |
---|
236 | // End of "$Id$". |
---|
237 | // |
---|