2
PLIB - A Suite of Portable Game Libraries
3
Copyright (C) 2001 Steve Baker
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
For further information visit http://plib.sourceforge.net
21
$Id: widget_list.cxx,v 1.15 2002/09/01 12:04:51 ude Exp $
1
24
// Sample program to create a copy of each widget in PUI
23
56
\***********************************/
27
int button_box_window ;
28
puButtonBox *button_box ;
42
int popup_menu_window ;
43
puPopupMenu *popup_menu ;
54
int arrow_button_window ;
55
puArrowButton *arrow_button ;
60
int file_picker_window ;
61
puFilePicker *file_picker ;
64
puBiSlider *bislider ;
66
int trislider_window ;
67
puTriSlider *trislider ;
69
int vertical_menu_window ;
70
puVerticalMenu *vertical_menu ;
72
int dialog_box_window ;
73
puDialogBox *dialog_box ;
75
int large_input_window ;
76
puLargeInput *large_input ;
58
static int main_window ;
60
static int button_box_window ;
61
static puButtonBox *button_box ;
63
static int frame_window ;
64
static puFrame *frame ;
66
static int text_window ;
69
static int button_window ;
70
static puButton *button ;
71
static puText *button_text ;
73
static int one_shot_window ;
74
static puOneShot *one_shot ;
76
static int popup_menu_window ;
77
static puPopupMenu *popup_menu ;
79
static int menu_bar_window ;
80
static puMenuBar *menu_bar ;
82
static int input_window ;
83
static puInput *input ;
85
static int slider_window ;
86
static puSlider *slider ;
88
static int arrow_button_window ;
89
static puArrowButton *arrow_button ;
91
static int dial_window ;
94
static int list_box_window ;
95
static puListBox *list_box ;
97
static int file_selector_window ;
98
static puFileSelector *file_selector ;
100
static int bislider_window ;
101
static puBiSlider *bislider ;
103
static int trislider_window ;
104
static puTriSlider *trislider ;
106
static int vertical_menu_window ;
107
static puVerticalMenu *vertical_menu ;
109
static int dialog_box_window ;
110
static puDialogBox *dialog_box ;
112
static int large_input_window ;
113
static puLargeInput *large_input ;
115
static int combo_box_window ;
116
static puComboBox *combo_box ;
118
static int select_box_window ;
119
static puSelectBox *select_box ;
121
//static fntTexFont *tim ;
154
193
/* Menu bar entries: */
156
char *file_submenu [] = { "Exit", "Close", "========", "Print", "========", "Save", "New", NULL } ;
157
puCallback file_submenu_cb [] = { exit_cb, exit_cb, NULL, NULL , NULL, NULL, NULL, NULL } ;
195
static char *file_submenu [] = { "Exit", "Close", "========", "Print", "========", "Save", "New", NULL } ;
196
static puCallback file_submenu_cb [] = { exit_cb, exit_cb, NULL, NULL , NULL, NULL, NULL, NULL } ;
159
char *edit_submenu [] = { "Do nothing.", NULL } ;
198
static char *edit_submenu [] = { "Do nothing.", NULL } ;
160
199
puCallback edit_submenu_cb [] = { NULL, NULL } ;
162
char *help_submenu [] = { "About...", "Help", NULL } ;
201
static char *help_submenu [] = { "About...", "Help", NULL } ;
163
202
puCallback help_submenu_cb [] = { NULL, NULL, NULL } ;
166
205
int main ( int argc, char **argv )
170
207
glutInitWindowPosition( 100, 0 ) ;
171
208
glutInitWindowSize ( 640, 480 ) ;
172
209
glutInit ( &argc, argv ) ;
173
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ) ;
210
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ) ;
174
211
main_window = glutCreateWindow ( "PUI Widget List" ) ;
175
212
glutDisplayFunc ( displayfn ) ;
176
213
glutKeyboardFunc ( keyfn ) ;
177
214
glutSpecialFunc ( specialfn ) ;
178
215
glutMouseFunc ( mousefn ) ;
179
216
glutMotionFunc ( motionfn ) ;
180
218
glutPassiveMotionFunc ( motionfn ) ;
181
glutIdleFunc ( displayfn ) ;
186
224
puShowCursor () ;
189
tim = new fntTexFont ;
190
tim -> load ( "../fnt/data/times_bold.txf" ) ;
191
puFont times_medium ( tim, 12 ) ;
192
puSetDefaultFonts ( times_medium, times_medium ) ;
227
//tim = new fntTexFont ;
228
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
229
//puFont times_medium ( tim, 12 ) ;
230
//puSetDefaultFonts ( times_medium, times_medium ) ;
193
231
puSetDefaultStyle ( PUSTYLE_SMALL_SHADED ) ;
194
puSetDefaultColourScheme ( 0.8, 0.8, 0.8, 1.0) ;
232
puSetDefaultColourScheme ( 0.8f, 0.8f, 0.8f, 1.0f ) ;
196
235
/* Set up the secondary windows and their widgets */
203
242
glutSpecialFunc ( specialfn ) ;
204
243
glutMouseFunc ( mousefn ) ;
205
244
glutMotionFunc ( motionfn ) ;
206
246
glutPassiveMotionFunc ( motionfn ) ;
207
glutIdleFunc ( displayfn ) ;
209
tim -> load ( "../fnt/data/times_bold.txf" ) ;
249
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
211
251
char *button_box_entries [] = { "First Entry", "Second Entry", "Third Entry", NULL } ;
212
252
button_box = new puButtonBox ( 10, 10, 130, 80, button_box_entries, TRUE ) ;
213
253
button_box->setLabel ( "Label" ) ;
214
button_box->setLegend ( "Legend" ) ;
216
256
frame_window = glutCreateWindow ( "Frame Window" ) ;
217
257
glutPositionWindow ( 200, 100 ) ;
221
261
glutSpecialFunc ( specialfn ) ;
222
262
glutMouseFunc ( mousefn ) ;
223
263
glutMotionFunc ( motionfn ) ;
224
265
glutPassiveMotionFunc ( motionfn ) ;
225
glutIdleFunc ( displayfn ) ;
227
tim -> load ( "../fnt/data/times_bold.txf" ) ;
268
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
229
270
frame = new puFrame ( 10, 10, 130, 80 ) ;
230
271
frame->setLabel ( "Label" ) ;
231
272
frame->setLegend ( "Legend" ) ;
233
275
text_window = glutCreateWindow ( "Text Window" ) ;
234
276
glutPositionWindow ( 200, 100 ) ;
235
277
glutReshapeWindow ( 180, 100 ) ;
238
280
glutSpecialFunc ( specialfn ) ;
239
281
glutMouseFunc ( mousefn ) ;
240
282
glutMotionFunc ( motionfn ) ;
241
284
glutPassiveMotionFunc ( motionfn ) ;
242
glutIdleFunc ( displayfn ) ;
244
tim -> load ( "../fnt/data/times_bold.txf" ) ;
287
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
246
289
text = new puText ( 10, 10 ) ;
247
290
text->setLabel ( "Label" ) ;
248
text->setLegend ( "Legend" ) ;
250
293
button_window = glutCreateWindow ( "Button Window" ) ;
251
294
glutPositionWindow ( 200, 100 ) ;
252
glutReshapeWindow ( 180, 100 ) ;
295
glutReshapeWindow ( 220, 160 ) ;
253
296
glutDisplayFunc ( displayfn ) ;
254
297
glutKeyboardFunc ( keyfn ) ;
255
298
glutSpecialFunc ( specialfn ) ;
256
299
glutMouseFunc ( mousefn ) ;
257
300
glutMotionFunc ( motionfn ) ;
258
302
glutPassiveMotionFunc ( motionfn ) ;
259
glutIdleFunc ( displayfn ) ;
261
tim -> load ( "../fnt/data/times_bold.txf" ) ;
263
button = new puButton ( 10, 10, 90, 30 ) ;
305
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
307
button_text = new puText ( 5, 6 ) ;
308
button_text->setLabel ( "XCHECK:" ) ;
310
button = new puButton ( 90, 10, 90+16, 10+16, PUBUTTON_XCHECK ) ;
311
button->setLabelPlace ( PUPLACE_CENTERED_RIGHT ) ;
312
button->setLabel ( "Label" ) ;
313
button->setValue ( 1 ) ;
315
button_text = new puText ( 5, 36 ) ;
316
button_text->setLabel ( "VCHECK:" ) ;
318
button = new puButton ( 90, 40, 90+16, 40+16, PUBUTTON_VCHECK ) ;
319
button->setLabelPlace ( PUPLACE_CENTERED_RIGHT ) ;
320
button->setLabel ( "Label" ) ;
321
button->setValue ( 1 ) ;
323
button_text = new puText ( 5, 66 ) ;
324
button_text->setLabel ( "CIRCLE:" ) ;
326
button = new puButton ( 90, 70, 90+16, 70+16, PUBUTTON_CIRCLE ) ;
327
button->setLabelPlace ( PUPLACE_CENTERED_RIGHT ) ;
328
button->setLabel ( "Label" ) ;
329
button->setValue ( 1 ) ;
331
button_text = new puText ( 5, 96 ) ;
332
button_text->setLabel ( "RADIO:" ) ;
334
button = new puButton ( 90, 100, 90+16, 100+16, PUBUTTON_RADIO ) ;
335
button->setLabelPlace ( PUPLACE_CENTERED_RIGHT ) ;
336
button->setLabel ( "Label" ) ;
337
button->setValue ( 1 ) ;
339
button_text = new puText ( 5, 128 ) ;
340
button_text->setLabel ( "NORMAL:" ) ;
342
button = new puButton ( 90, 130, 170, 150 ) ;
343
button->setLabelPlace ( PUPLACE_CENTERED_RIGHT ) ;
264
344
button->setLabel ( "Label" ) ;
265
345
button->setLegend ( "Legend" ) ;
266
346
button->setValue ( 1 ) ;
267
puText *button_text = new puText ( 10, 40 ) ;
268
button_text->setLabel ( "(Button pressed in)" ) ;
270
349
one_shot_window = glutCreateWindow ( "One Shot Window" ) ;
271
350
glutPositionWindow ( 200, 100 ) ;
275
354
glutSpecialFunc ( specialfn ) ;
276
355
glutMouseFunc ( mousefn ) ;
277
356
glutMotionFunc ( motionfn ) ;
278
358
glutPassiveMotionFunc ( motionfn ) ;
279
glutIdleFunc ( displayfn ) ;
281
tim -> load ( "../fnt/data/times_bold.txf" ) ;
361
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
283
363
one_shot = new puOneShot ( 10, 10, 90, 30 ) ;
284
364
one_shot->setLabel ( "Label" ) ;
285
365
one_shot->setLegend ( "Legend" ) ;
287
368
popup_menu_window = glutCreateWindow ( "Popup Menu Window" ) ;
288
369
glutPositionWindow ( 200, 100 ) ;
289
370
glutReshapeWindow ( 80, 100 ) ;
292
373
glutSpecialFunc ( specialfn ) ;
293
374
glutMouseFunc ( mousefn ) ;
294
375
glutMotionFunc ( motionfn ) ;
295
377
glutPassiveMotionFunc ( motionfn ) ;
296
glutIdleFunc ( displayfn ) ;
298
tim -> load ( "../fnt/data/times_bold.txf" ) ;
380
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
300
382
popup_menu = new puPopupMenu ( 10, 10 ) ;
301
popup_menu->setLabel ( "Label" ) ;
302
popup_menu->setLegend ( "Legend" ) ;
303
383
popup_menu->add_item ( "Cut", NULL ) ;
304
384
popup_menu->add_item ( "Copy", NULL ) ;
305
385
popup_menu->add_item ( "Paste", NULL ) ;
338
419
glutSpecialFunc ( specialfn ) ;
339
420
glutMouseFunc ( mousefn ) ;
340
421
glutMotionFunc ( motionfn ) ;
341
423
glutPassiveMotionFunc ( motionfn ) ;
342
glutIdleFunc ( displayfn ) ;
344
tim -> load ( "../fnt/data/times_bold.txf" ) ;
426
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
346
428
input = new puInput ( 10, 10, 90, 30 ) ;
347
429
input->setLabel ( "Label" ) ;
348
input->setLegend ( "Legend" ) ;
350
432
slider_window = glutCreateWindow ( "Slider Window" ) ;
351
433
glutPositionWindow ( 200, 100 ) ;
355
437
glutSpecialFunc ( specialfn ) ;
356
438
glutMouseFunc ( mousefn ) ;
357
439
glutMotionFunc ( motionfn ) ;
358
441
glutPassiveMotionFunc ( motionfn ) ;
359
glutIdleFunc ( displayfn ) ;
361
tim -> load ( "../fnt/data/times_bold.txf" ) ;
363
slider = new puSlider ( 10, 10, 120, 0 ) ;
444
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
446
slider = new puSlider ( 10, 10, 120, FALSE ) ;
364
447
slider->setLabel ( "Label" ) ;
365
448
slider->setLegend ( "Legend" ) ;
367
451
arrow_button_window = glutCreateWindow ( "Arrow Button Window" ) ;
368
452
glutPositionWindow ( 200, 100 ) ;
369
453
glutReshapeWindow ( 180, 100 ) ;
372
456
glutSpecialFunc ( specialfn ) ;
373
457
glutMouseFunc ( mousefn ) ;
374
458
glutMotionFunc ( motionfn ) ;
375
460
glutPassiveMotionFunc ( motionfn ) ;
376
glutIdleFunc ( displayfn ) ;
378
tim -> load ( "../fnt/data/times_bold.txf" ) ;
463
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
380
465
arrow_button = new puArrowButton ( 10, 10, 50, 50, PUARROW_RIGHT ) ;
381
466
arrow_button->setLabel ( "Label" ) ;
382
arrow_button->setLegend ( "Legend" ) ;
384
469
dial_window = glutCreateWindow ( "Dial Window" ) ;
385
470
glutPositionWindow ( 200, 100 ) ;
389
474
glutSpecialFunc ( specialfn ) ;
390
475
glutMouseFunc ( mousefn ) ;
391
476
glutMotionFunc ( motionfn ) ;
392
478
glutPassiveMotionFunc ( motionfn ) ;
393
glutIdleFunc ( displayfn ) ;
395
tim -> load ( "../fnt/data/times_bold.txf" ) ;
481
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
397
483
dial = new puDial ( 10, 10, 60 ) ;
398
484
dial->setLabel ( "Label" ) ;
399
485
dial->setLegend ( "Legend" ) ;
401
file_picker_window = glutCreateWindow ( "File Picker Window" ) ;
402
glutPositionWindow ( 200, 100 ) ;
403
glutReshapeWindow ( 300, 200 ) ;
404
glutDisplayFunc ( displayfn ) ;
405
glutKeyboardFunc ( keyfn ) ;
406
glutSpecialFunc ( specialfn ) ;
407
glutMouseFunc ( mousefn ) ;
408
glutMotionFunc ( motionfn ) ;
409
glutPassiveMotionFunc ( motionfn ) ;
410
glutIdleFunc ( displayfn ) ;
412
tim -> load ( "../fnt/data/times_bold.txf" ) ;
414
file_picker = new puFilePicker ( 10, 10, 280, 180, "." ) ;
415
file_picker->setLabel ( "Label" ) ;
416
file_picker->setLegend ( "Legend" ) ;
488
list_box_window = glutCreateWindow ( "List Box Window" ) ;
489
glutPositionWindow ( 200, 100 ) ;
490
glutReshapeWindow ( 180, 100 ) ;
491
glutDisplayFunc ( displayfn ) ;
492
glutKeyboardFunc ( keyfn ) ;
493
glutSpecialFunc ( specialfn ) ;
494
glutMouseFunc ( mousefn ) ;
495
glutMotionFunc ( motionfn ) ;
497
glutPassiveMotionFunc ( motionfn ) ;
500
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
502
char *list_box_entries [] = { "First Entry", "Second Entry", "Third Entry", "Very long Entry that will get truncated", NULL } ;
503
list_box = new puListBox ( 10, 10, 130, 80, list_box_entries ) ;
504
list_box->setLabel ( "Label" ) ;
507
file_selector_window = glutCreateWindow ( "File Selector Window" ) ;
508
glutPositionWindow ( 200, 100 ) ;
509
glutReshapeWindow ( 300, 220 ) ;
510
glutDisplayFunc ( displayfn ) ;
511
glutKeyboardFunc ( keyfn ) ;
512
glutSpecialFunc ( specialfn ) ;
513
glutMouseFunc ( mousefn ) ;
514
glutMotionFunc ( motionfn ) ;
516
glutPassiveMotionFunc ( motionfn ) ;
519
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
521
file_selector = new puFileSelector ( 10, 10, 280, 200, "." ) ;
418
524
bislider_window = glutCreateWindow ( "BiSlider Window" ) ;
419
525
glutPositionWindow ( 200, 100 ) ;
423
529
glutSpecialFunc ( specialfn ) ;
424
530
glutMouseFunc ( mousefn ) ;
425
531
glutMotionFunc ( motionfn ) ;
426
533
glutPassiveMotionFunc ( motionfn ) ;
427
glutIdleFunc ( displayfn ) ;
429
tim -> load ( "../fnt/data/times_bold.txf" ) ;
431
bislider = new puBiSlider ( 10, 10, 120, 0 ) ;
536
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
538
bislider = new puBiSlider ( 10, 10, 120, FALSE ) ;
432
539
bislider->setLabel ( "Label" ) ;
433
540
bislider->setLegend ( "Legend" ) ;
434
541
bislider->setMaxValue ( 20 ) ;
435
542
bislider->setCurrentMin ( 4 ) ;
436
543
bislider->setCurrentMax ( 15 ) ;
438
546
trislider_window = glutCreateWindow ( "TriSlider Window" ) ;
439
547
glutPositionWindow ( 200, 100 ) ;
440
548
glutReshapeWindow ( 100, 200 ) ;
443
551
glutSpecialFunc ( specialfn ) ;
444
552
glutMouseFunc ( mousefn ) ;
445
553
glutMotionFunc ( motionfn ) ;
446
555
glutPassiveMotionFunc ( motionfn ) ;
447
glutIdleFunc ( displayfn ) ;
449
tim -> load ( "../fnt/data/times_bold.txf" ) ;
451
trislider = new puTriSlider ( 20, 10, 180, 1 ) ;
558
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
560
trislider = new puTriSlider ( 20, 10, 180, TRUE ) ;
452
561
trislider->setLabel ( "Label" ) ;
453
562
trislider->setLegend ( "Legend" ) ;
454
563
trislider->setMaxValue ( 20 ) ;
487
597
glutSpecialFunc ( specialfn ) ;
488
598
glutMouseFunc ( mousefn ) ;
489
599
glutMotionFunc ( motionfn ) ;
490
601
glutPassiveMotionFunc ( motionfn ) ;
491
glutIdleFunc ( displayfn ) ;
493
tim -> load ( "../fnt/data/times_bold.txf" ) ;
604
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
495
606
dialog_box = new puDialogBox ( 10, 10 ) ;
496
dialog_box->setLabel ( "Label" ) ;
497
dialog_box->setLegend ( "Legend" ) ;
498
607
new puOneShot ( 20, 20, "OK" ) ;
499
608
new puOneShot ( 100, 20, "Cancel" ) ;
500
609
puText *dialog_text = new puText ( 20, 60 ) ;
510
620
glutSpecialFunc ( specialfn ) ;
511
621
glutMouseFunc ( mousefn ) ;
512
622
glutMotionFunc ( motionfn ) ;
513
624
glutPassiveMotionFunc ( motionfn ) ;
514
glutIdleFunc ( displayfn ) ;
516
tim -> load ( "../fnt/data/times_bold.txf" ) ;
627
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
518
629
large_input = new puLargeInput ( 10, 10, 240, 180, 2, 20 ) ;
519
630
large_input->setLabel ( "Label" ) ;
520
large_input->setLegend ( "Legend" ) ;
521
631
large_input->setText ( "This is text in the Large Input widget.\n"
522
632
"This is a second line of text" ) ;
635
combo_box_window = glutCreateWindow ( "Combo Box window" ) ;
636
glutPositionWindow ( 200, 100 ) ;
637
glutReshapeWindow ( 300, 200 ) ;
638
glutDisplayFunc ( displayfn ) ;
639
glutKeyboardFunc ( keyfn ) ;
640
glutSpecialFunc ( specialfn ) ;
641
glutMouseFunc ( mousefn ) ;
642
glutMotionFunc ( motionfn ) ;
644
glutPassiveMotionFunc ( motionfn ) ;
647
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
649
char *combo_box_entries [] = { "First Entry", "Second Entry", "Third Entry", "Fourth Entry", "Sixth Entry", "Seventh Entry", NULL } ;
650
combo_box = new puComboBox ( 10, 158, 250, 190,
651
combo_box_entries ) ;
652
/* Don't do that in your own application ! */
653
combo_box -> __getPopupMenu() -> reveal() ;
654
combo_box->setLabel ( "Label" ) ;
657
select_box_window = glutCreateWindow ( "Select Box window" ) ;
658
glutPositionWindow ( 200, 100 ) ;
659
glutReshapeWindow ( 300, 60 ) ;
660
glutDisplayFunc ( displayfn ) ;
661
glutKeyboardFunc ( keyfn ) ;
662
glutSpecialFunc ( specialfn ) ;
663
glutMouseFunc ( mousefn ) ;
664
glutMotionFunc ( motionfn ) ;
666
glutPassiveMotionFunc ( motionfn ) ;
669
//tim -> load ( "../fnt/data/old/times_bold.txf" ) ;
671
glEnable ( GL_BLEND ) ;
672
glAlphaFunc ( GL_GEQUAL, 0.1f ) ;
673
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
675
select_box = new puSelectBox ( 10, 14, 250, 46,
676
combo_box_entries ) ;
677
select_box->setLabel ( "Label" ) ;
524
679
glutMainLoop () ;