1 | // see awdemo for a (slightly out of date) demonstration of direct graphics without |
---|
2 | // canvas support |
---|
3 | |
---|
4 | /* ----------------------------------------------------------------- |
---|
5 | * Module: TESTBED/TB_extern.cxx |
---|
6 | * |
---|
7 | * Description: the meat of this demonstration of AWT and WINDOW |
---|
8 | * use - careful, as we had to start tons of stuff |
---|
9 | * to get here, even if we'll never need most of it |
---|
10 | * (trees, db, ...) |
---|
11 | * |
---|
12 | * See AWT, PH_dtree, ... for a larger example |
---|
13 | * ----------------------------------------------------------------- |
---|
14 | */ |
---|
15 | |
---|
16 | /* |
---|
17 | * $Header$ |
---|
18 | * |
---|
19 | * $Log$ |
---|
20 | * Revision 1.1 2000/11/23 09:41:16 westram |
---|
21 | * Initial revision |
---|
22 | * |
---|
23 | * Revision 1.2 1995/03/13 16:53:19 jakobi |
---|
24 | * *** empty log message *** |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | #include <stdio.h> |
---|
29 | #include <stdlib.h> |
---|
30 | |
---|
31 | // string functions and db stuff |
---|
32 | #include <arbdb.h> |
---|
33 | #include <arbdbt.h> |
---|
34 | |
---|
35 | // window stuff |
---|
36 | #include <aw_root.hxx> |
---|
37 | #include <aw_window.hxx> |
---|
38 | #include <aw_awars.hxx> |
---|
39 | // here we set some stuff for zoomtext and other defaults |
---|
40 | #include <aw_preset.hxx> |
---|
41 | #include <awt_preset.hxx> |
---|
42 | |
---|
43 | // ton's of stuff for canvas support (which simply should allow |
---|
44 | // us to concentrate on our core functions instead of doing |
---|
45 | // lowlevel display games) |
---|
46 | #include <awt_canvas.hxx> |
---|
47 | #include "awt_tree.hxx" |
---|
48 | #include "awt_dtree.hxx" |
---|
49 | |
---|
50 | // more stuff, just needed to startup the filerequester |
---|
51 | // awt.hxx is req'd for filereq |
---|
52 | #include <awt.hxx> |
---|
53 | //#include <awt_nds.hxx> |
---|
54 | #include <awt_tree_cb.hxx> |
---|
55 | |
---|
56 | #include "tb_extern.hxx" |
---|
57 | |
---|
58 | |
---|
59 | /* ----------------------------------------------------------------- |
---|
60 | * Class: AWT_graphic_testbed |
---|
61 | * |
---|
62 | * Description: derived class to interface with AWT. |
---|
63 | * these routines display our graphics |
---|
64 | * ----------------------------------------------------------------- |
---|
65 | */ |
---|
66 | |
---|
67 | AWT_graphic_testbed::AWT_graphic_testbed(void):AWT_graphic() { |
---|
68 | exports.dont_fit_x = 0; |
---|
69 | exports.dont_fit_y = 0; |
---|
70 | exports.left_offset = 100; |
---|
71 | exports.right_offset = 100; |
---|
72 | exports.top_offset = 30; |
---|
73 | exports.bottom_offset = 30; |
---|
74 | } |
---|
75 | |
---|
76 | // this is used for evaluating commands/actions in the canvas, |
---|
77 | // necessary dummies (input in the canvas, ...) |
---|
78 | // see AWT_dtree,cxx:AWT_graphic_tree |
---|
79 | void AWT_graphic_testbed::command(AW_device *device, AWT_COMMAND_MODE cmd, int button, AW_event_type type, AW_pos x, AW_pos y, AW_clicked_line *cl, AW_clicked_text *ct) { |
---|
80 | AWUSE(device); AWUSE(cmd); AWUSE(button); AWUSE(type); |
---|
81 | AWUSE(x); AWUSE(y); AWUSE(cl); AWUSE(ct); |
---|
82 | } |
---|
83 | |
---|
84 | // called by canvas to display/create the objects to be displayed |
---|
85 | // canvas simply calls us, it would be our job here to box larger subparts and |
---|
86 | // ask clip, whether we really have to look into that box (see WINDOW/AW_xfigfont.hxx/zoomtext1 as example) |
---|
87 | void AWT_graphic_testbed::show(AW_device *device) { |
---|
88 | // central cross |
---|
89 | device->line(AWT_GC_CURSOR,-1.0,0.0,1.0,0.0,AW_ALL,0,0); |
---|
90 | device->line(AWT_GC_CURSOR,0.0,1.0,0.0,-1.0,AW_ALL,0,0); |
---|
91 | // title |
---|
92 | device->text(AWT_GC_CURSOR, "testforme", -1.0, -1.0, 0.0, AW_SCREEN, 0, 0); |
---|
93 | // set devices for this text (just don't move fixed sized text (like standard text) into the size device...) |
---|
94 | AW_bitset bitset=AW_SCREEN; |
---|
95 | if (tbd_bitset) bitset=tbd_bitset; |
---|
96 | // run the test function |
---|
97 | if(tbd_function) |
---|
98 | device->zoomtext((int)tbd_gc,tbd_string,tbd_x,tbd_y,tbd_height, |
---|
99 | tbd_alignment,tbd_rotation,bitset, |
---|
100 | tbd_cl1,tbd_cl2); |
---|
101 | else |
---|
102 | device->zoomtext4line((int)tbd_gc,tbd_string,tbd_height, |
---|
103 | tbd_x0,tbd_y0,tbd_x1,tbd_y1, |
---|
104 | tbd_alignmentx,tbd_alignmenty,bitset, |
---|
105 | tbd_cl1,tbd_cl2); |
---|
106 | } |
---|
107 | |
---|
108 | // necessary dummy, otherwise cc would theatralically cry 'virtual class' and die |
---|
109 | void AWT_graphic_testbed::info(AW_device *device, AW_pos x, AW_pos y, AW_clicked_line *cl, AW_clicked_text *ct) { |
---|
110 | aw_message("INFO MESSAGE"); |
---|
111 | AWUSE(device); AWUSE(x); AWUSE(y); AWUSE(cl); AWUSE(ct); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | // |
---|
116 | // presets |
---|
117 | // |
---|
118 | |
---|
119 | |
---|
120 | // a small gc manager is needed to tell AW_presets what we like to offer in the userinterface ... |
---|
121 | AW_gc_manager AWT_graphic_testbed::init_devices(AW_window *window, AW_device * device, AWT_canvas *canvas ,AW_CL cl) { |
---|
122 | AW_gc_manager preset_window = |
---|
123 | AW_manage_GC(window, device, AWT_GC_CURSOR, AWT_GC_CURSOR+5, AW_GCM_DATA_AREA, |
---|
124 | (AW_CB)AWT_resize_cb, (AW_CL)canvas, cl, |
---|
125 | "", |
---|
126 | "CURSOR", |
---|
127 | "SELECTED", |
---|
128 | "SEL. & NOT", |
---|
129 | "NOT SEL.", |
---|
130 | "ETC", |
---|
131 | 0 ); |
---|
132 | return preset_window; |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | // |
---|
137 | // testbed stuff: userinterface related routines - callback, etc |
---|
138 | // |
---|
139 | |
---|
140 | void tb_exit(AW_window *aw_window) { |
---|
141 | AWUSE(aw_window); |
---|
142 | exit(0); |
---|
143 | } |
---|
144 | |
---|
145 | // generate and show current gfx - the "TEST" button |
---|
146 | void tb_action(AW_window *aw_window,AW_CL canvas) { |
---|
147 | AW_device *device=aw_window->get_device(AW_MIDDLE_AREA); |
---|
148 | tb_reload(aw_window->get_root(), (AWT_canvas *)canvas); |
---|
149 | } |
---|
150 | |
---|
151 | // generate current gfx |
---|
152 | AWT_graphic *tb_gen_gfx(void) { |
---|
153 | AWT_graphic_testbed *gfx = new AWT_graphic_testbed; |
---|
154 | return (AWT_graphic *)gfx; |
---|
155 | } |
---|
156 | |
---|
157 | // (re)display gfx (canvas then calls ->show) |
---|
158 | void tb_reload(AW_root *awr, AWT_canvas *canvas) { |
---|
159 | AWUSE(awr); |
---|
160 | canvas->zoom_reset(); |
---|
161 | AWT_expose_cb(0,canvas,0); |
---|
162 | } |
---|
163 | |
---|
164 | // here we create the main window, menues, ... and a physical zoom mode |
---|
165 | AW_window * create_tb_main_window(AW_root *awr) { |
---|
166 | AW_gc_manager aw_gc_manager; // not used? |
---|
167 | AWT_graphic *gfx=tb_gen_gfx(); |
---|
168 | |
---|
169 | AW_window_menu_modes *awm = new AW_window_menu_modes(); |
---|
170 | awm->init(awr,"ARB_TB", 800,600,0,0); |
---|
171 | |
---|
172 | awm->button_length(5); |
---|
173 | |
---|
174 | // dummy tree |
---|
175 | AWT_canvas *canvas = new AWT_canvas(gb_main,(AW_window *)awm,gfx,aw_gc_manager) ; |
---|
176 | tb_reload(awr,canvas);// load it for the first time... |
---|
177 | |
---|
178 | awm->create_menu( 0, "File", "F", "nt_file.hlp", F_ALL ); |
---|
179 | awm->insert_menu_topic(0,"Save Defaults (in ~/.arb_prop/testawt.awt)","D","savedef.hlp",F_ALL, (AW_CB) AW_save_defaults, 0, 0 ); |
---|
180 | awm->insert_menu_topic(0,"Reset Physical Zoom", "P","rst_phys_zoom.hlp",F_ALL, (AW_CB)NT_reset_pzoom_cb, (AW_CL) canvas, 0 ); |
---|
181 | awm->insert_menu_topic( 0, "Quit", "Q","quit.hlp", F_ALL, (AW_CB)tb_exit, 0, 0 ); |
---|
182 | |
---|
183 | // PJ restructured preferences |
---|
184 | awm->create_menu(0,"Properties","r","properties.hlp", F_ALL); |
---|
185 | awm->insert_menu_topic(0,"Application: Fonts, etc", "F","props_frame.hlp", F_ALL, AW_POPUP, (AW_CL)AWT_preset_window, 0 ); |
---|
186 | awm->insert_menu_topic(0,"TestSetup", "T","nt_props_tree.hlp",F_ALL, AW_POPUP, (AW_CL)tb_preset_tree_window, 0); |
---|
187 | awm->insert_menu_topic(0,"DataDisplay: Fonts, etc", "D","nt_props_data.hlp",F_ALL, AW_POPUP, (AW_CL)AW_create_gc_window, (AW_CL)aw_gc_manager ); |
---|
188 | |
---|
189 | awm->create_mode( 0, "zoom.bitmap", "mode_pzoom.hlp", F_ALL, (AW_CB)nt_mode_event, |
---|
190 | (AW_CL)canvas, |
---|
191 | (AW_CL)AWT_MODE_ZOOM |
---|
192 | ); |
---|
193 | |
---|
194 | |
---|
195 | awm->at(5,2); |
---|
196 | awm->auto_space(0,-2); |
---|
197 | awm->shadow_width(1); |
---|
198 | |
---|
199 | int db_actx,db_acty; |
---|
200 | awm->get_at_position( &db_actx,&db_acty ); |
---|
201 | awm->callback(tb_action,(AW_CL) canvas); |
---|
202 | awm->button_length(20); |
---|
203 | awm->create_button("Test","Test"); |
---|
204 | |
---|
205 | awm->at_newline(); |
---|
206 | awm->auto_space(-2,-2); |
---|
207 | |
---|
208 | awm->at_newline(); |
---|
209 | int db_specx,db_specy; |
---|
210 | awm->get_at_position( &db_specx,&db_specy ); |
---|
211 | awm->set_info_area_height( db_specy+6 ); |
---|
212 | |
---|
213 | awm->set_bottom_area_height( 0 ); |
---|
214 | |
---|
215 | return (AW_window *)awm; |
---|
216 | |
---|
217 | } |
---|
218 | |
---|
219 | // parameter setup panel for the user |
---|
220 | AW_window *tb_preset_tree_window( AW_root *root ) { |
---|
221 | |
---|
222 | AW_window_simple *aws = new AW_window_simple; |
---|
223 | const int tabstop = 400; |
---|
224 | |
---|
225 | // window sizes |
---|
226 | |
---|
227 | aws->init( root, "Test Options", 600, 600, 400, 300 ); |
---|
228 | aws->label_length( 25 ); |
---|
229 | aws->button_length( 20 ); |
---|
230 | |
---|
231 | aws->at ( 10,10 ); |
---|
232 | aws->auto_space(10,10); |
---|
233 | aws->callback ( AW_POPDOWN ); |
---|
234 | aws->create_button( "CLOSE", "CLOSE", "C" ); |
---|
235 | |
---|
236 | // aws->callback ( (AW_CB0)AW_save_defaults ); |
---|
237 | // aws->create_button( "SAVE", "SAVE", "S" ); |
---|
238 | aws->at_newline(); |
---|
239 | |
---|
240 | // No Help, as we usually do not know the associated help file from within presets of AW Lib |
---|
241 | |
---|
242 | aws->create_option_menu( "vectorfont/active", "Data font type", "1" ); |
---|
243 | aws->insert_option ( "Use vectorfont", " ", (int) 1); |
---|
244 | aws->insert_option ( "Use standard font", " ", (int) 0); |
---|
245 | aws->update_option_menu(); |
---|
246 | aws->at_newline(); |
---|
247 | |
---|
248 | AW_preset_create_scale_chooser(aws,"vectorfont/userscale","VF: absolute scaling"); |
---|
249 | aws->create_input_field( "vectorfont/userscale",6); |
---|
250 | aws->at_newline(); |
---|
251 | |
---|
252 | aws->create_button("Testdataset","Testdataset"); |
---|
253 | aws->at_newline(); |
---|
254 | |
---|
255 | aws->create_option_menu("tbd_function","Vector font type","1"); |
---|
256 | aws->insert_option("Zoomtext"," ", (int) 1); |
---|
257 | aws->insert_option("Zoomtext4Line"," ", (int) 0); |
---|
258 | aws->update_option_menu(); |
---|
259 | aws->at_newline(); |
---|
260 | |
---|
261 | // WARNING: labels are just labels for other elements, so don't tab here... |
---|
262 | |
---|
263 | aws->label("GC"); |
---|
264 | aws->create_input_field("tbd_gc",10); |
---|
265 | aws->at_newline(); |
---|
266 | |
---|
267 | aws->label("String"); |
---|
268 | aws->create_input_field("tbd_string",10); |
---|
269 | aws->at_newline(); |
---|
270 | |
---|
271 | aws->label("Height"); |
---|
272 | aws->create_input_field("tbd_height",10); |
---|
273 | aws->at_newline(); |
---|
274 | |
---|
275 | aws->label("Bitset"); |
---|
276 | aws->create_input_field("tbd_bitset",10); |
---|
277 | aws->at_newline(); |
---|
278 | |
---|
279 | aws->label("CL1"); |
---|
280 | aws->create_input_field("tbd_cl1",10); |
---|
281 | aws->at_newline(); |
---|
282 | |
---|
283 | aws->label("CL2"); |
---|
284 | aws->create_input_field("tbd_cl2",10); |
---|
285 | aws->at_newline(); |
---|
286 | |
---|
287 | aws->create_button(0,"Zoomtext Parameters"); |
---|
288 | |
---|
289 | aws->at_newline(); |
---|
290 | |
---|
291 | aws->label("x/y"); |
---|
292 | aws->create_input_field("tbd_x",10); |
---|
293 | aws->at_x(tabstop); |
---|
294 | aws->create_input_field("tbd_y",10); |
---|
295 | aws->at_newline(); |
---|
296 | |
---|
297 | aws->label("alignment"); |
---|
298 | aws->create_input_field("tbd_alignment",10); |
---|
299 | aws->at_newline(); |
---|
300 | |
---|
301 | aws->label("rotation"); |
---|
302 | aws->create_input_field("tbd_rotation",10); |
---|
303 | aws->at_newline(); |
---|
304 | |
---|
305 | aws->create_button(0,"Zoomtext4line Parameters"); |
---|
306 | aws->at_newline(); |
---|
307 | |
---|
308 | aws->label("x0/y0 x1/y1"); |
---|
309 | aws->create_input_field("tbd_x0",10); |
---|
310 | aws->at_x(tabstop); |
---|
311 | aws->create_input_field("tbd_y0",10); |
---|
312 | aws->at_x(tabstop); |
---|
313 | aws->at_newline(); |
---|
314 | aws->label(" "); |
---|
315 | aws->create_input_field("tbd_x1",10); |
---|
316 | aws->at_x(tabstop); |
---|
317 | aws->create_input_field("tbd_y1",10); |
---|
318 | aws->at_newline(); |
---|
319 | |
---|
320 | aws->label("alignment x/y"); |
---|
321 | aws->create_input_field("tbd_alignmentx",10); |
---|
322 | aws->at_x(tabstop); |
---|
323 | aws->create_input_field("tbd_alignmenty",10); |
---|
324 | aws->at_newline(); |
---|
325 | |
---|
326 | aws->window_fit(); |
---|
327 | return (AW_window *)aws; |
---|
328 | |
---|
329 | } |
---|
330 | |
---|