summaryrefslogtreecommitdiff
path: root/gfxtest.c
blob: 2392f90832f01370b3d08b05ad148f246969a328 (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
/*

    viDOOM - level editor for DOOM

    Copyright (C) 2000  Ian Cowburn (ianc@noddybox.demon.co.uk)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    -------------------------------------------------------------------------

    Test program for GFX interface
*/
static const char rcs_id[]="$Id$";

#include "config.h"
#include "globals.h"
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include "gfx.h"
#include "platgui.h"
#include "editvar.h"
#include "mem.h"

#define SCRW    640
#define SCRH    480

#define RND(x)	(rand()%(x))
#define RCOL	V_RGB(RND(255),RND(255),RND(255))

void TestPrint(void)
{
    int f;

    GFX_clear(BLACK);

    GFX_print(0,0,WHITE,"Top left");
    GFX_print(0,SCRH-GFX_fh(),WHITE,"Bottom left");
    GFX_print(SCRW-GFX_fw()*strlen("Top right"),0,WHITE,"Top right");
    GFX_print(SCRW-GFX_fw()*strlen("Bottom right"),
    		SCRH-GFX_fh(),WHITE,"Bottom right");

    for(f=1;f<4;f++)
        GFX_print(0,100+f*GFX_fh(),WHITE,"Row %d",f);

    GFX_redraw();
    GFX_waitkey(NULL);
}


void TestMouse(void)
{
    GFXEvent e;
    int q;
    int f;

    GFX_clear(BLACK);

    q=FALSE;

    while(!q)
    	{
	GFX_redraw();
	GFX_await_input_full(&e);

	switch(e.type)
	    {
	    case GFX_KEY_EVENT:
	        if (e.key.code==GFX_ESC)
		    q=TRUE;

	        if (e.key.code==GFX_ENTER)
		    GFX_clear(BLACK);
		break;

	    case GFX_MOUSE_EVENT:
		f=0;
	        if (e.mouse.b&GFX_BUTLEFT)
		    f|=0xff0000;
	        if (e.mouse.b&GFX_BUTMIDDLE)
		    f|=0xff00;
	        if (e.mouse.b&GFX_BUTRIGHT)
		    f|=0xff;

		if (f==0)
		    f=0x808080;

		GFX_frect(0,0,SCRW,GFX_fh(),BLACK);
		GFX_print(0,0,WHITE,"x:%-4d  y:%-4d  b:%c%c%c",
				e.mouse.x,e.mouse.y,
				e.mouse.b&GFX_BUTLEFT ? 'L':' ',
				e.mouse.b&GFX_BUTMIDDLE ? 'M':' ',
				e.mouse.b&GFX_BUTRIGHT ? 'R':' ');

		GFX_plot(e.mouse.x,e.mouse.y,f);
		break;
	    }
	}
}


void TestRect(void)
{
    int f,w;
    int ox,oy;

    ox=20;
    oy=100;

    for(w=3;w>-4;w--)
    	{
	GFX_clear(BLACK);

	GFX_print(0,0,WHITE,"Width/height %d",w);

	for(f=0;f<5;f++)
	    {
	    GFX_plot(ox+f*20,oy+20,WHITE);
	    GFX_rect(ox+f*20+10,oy+20,w,w,WHITE);

	    GFX_plot(ox+f*20,oy+40,WHITE);
	    GFX_frect(ox+f*20+10,oy+40,w,w,WHITE);

	    GFX_plot(ox+f*20,oy+60,WHITE);
	    GFX_rect(ox+f*20+10,oy+60,w,w*2,WHITE);

	    GFX_plot(ox+f*20,oy+80,WHITE);
	    GFX_frect(ox+f*20+10,oy+80,w,w*2,WHITE);

	    GFX_plot(ox+f*20,oy+100,WHITE);
	    GFX_rect(ox+f*20+10,oy+100,w*2,w,WHITE);

	    GFX_plot(ox+f*20,oy+120,WHITE);
	    GFX_frect(ox+f*20+10,oy+120,w*2,w,WHITE);
	    }

	GFX_redraw();
	GFX_waitkey(NULL);
	}
}


void TestDim(void)
{
    GFX_clear(BLACK);

    GFX_line(0,0,SCRW-1,0,WHITE);
    GFX_line(0,SCRH-1,SCRW-1,SCRH-1,WHITE);

    GFX_line(0,0,0,SCRH-1,WHITE);
    GFX_line(SCRW-1,0,SCRW-1,SCRH-1,WHITE);

    GFX_line(0,0,SCRW-1,SCRH-1,WHITE);
    GFX_line(SCRW-1,0,0,SCRH-1,WHITE);

    GFX_print(20,SCRH/2,WHITE,"GFX_line()");

    GFX_redraw();
    GFX_waitkey(NULL);

    GFX_clear(BLACK);

    GFX_rect(0,0,SCRW,SCRH,WHITE);
    GFX_print(20,SCRH/2,WHITE,"GFX_rect()");

    GFX_redraw();
    GFX_waitkey(NULL);

    GFX_clear(BLACK);

    GFX_frect(0,0,SCRW,SCRH,RED);
    GFX_print(20,SCRH/2,WHITE,"GFX_frect()");

    GFX_redraw();
    GFX_waitkey(NULL);
}


void TestCol(void)
{
    GFX_clear(BLACK);

    GFX_frect(0,0,SCRW,10,WHITE);
    GFX_print(0,10,WHITE,"WHITE");

    GFX_frect(0,20,SCRW,10,RED);
    GFX_print(0,30,RED,"RED");

    GFX_frect(0,40,SCRW,10,BLUE);
    GFX_print(0,50,BLUE,"BLUE");

    GFX_frect(0,60,SCRW,10,GREEN);
    GFX_print(0,70,GREEN,"GREEN");

    GFX_frect(0,80,SCRW,10,GREY(128));
    GFX_print(0,90,GREY(128),"GREY(128)");

    GFX_redraw();
    GFX_waitkey(NULL);
}

static void TestDraw(void)
{
    int f;

    GFX_clear(BLACK);

    for(f=0;f<100;f++)
    	GFX_plot(f,10,WHITE);
    GFX_print(0,22,WHITE,"GFX_plot()");

    GFX_line(0,40,99,40,WHITE);
    GFX_print(0,42,WHITE,"GFX_line()");

    GFX_rect(0,60,100,10,WHITE);
    GFX_print(0,70,WHITE,"GFX_rect()");

    GFX_frect(0,80,100,10,WHITE);
    GFX_print(0,90,WHITE,"GFX_frect()");

    GFX_circle(50,150,50,WHITE);
    GFX_print(50,150,WHITE,"GFX_circle()");

    GFX_fcircle(50,250,50,GREEN);
    GFX_print(50,250,WHITE,"GFX_fircle()");

    for(f=101;f>=99;f--)
    	{
	GFX_line(f,0,f,100,RED);
	GFX_redraw();
	GFX_waitkey(NULL);
	}
}


static void TestBm(void)
{
    static unsigned char data[64]=
				    {
					0,0,0,0,0,0,0,0,
					0,1,1,1,1,1,1,0,
					0,1,2,2,0,0,1,0,
					0,1,2,2,0,0,1,1,
					0,1,0,0,2,2,1,1,
					0,1,0,0,2,2,1,0,
					0,1,1,1,1,1,1,0,
					0,0,0,1,1,0,0,0,
				    };
    GFX_IMAGE i;
    GFX_BITMAP bm;
    int f;

    bm.w=8;
    bm.h=8;
    bm.pal[0]=BLACK;
    bm.pal[1]=RED;
    bm.pal[2]=WHITE;
    bm.data=data;

    i=GFX_create_image(&bm);
    GFX_clear(GREEN);

    for(f=0;f<100;f++)
	{
    	GFX_draw_image(i,f,f);
	GFX_redraw();
	}

    GFX_waitkey(NULL);
    GFX_fill_screen(i);
    GFX_redraw();
    GFX_waitkey(NULL);

    GFX_destroy_image(i);
}


void TestKey(void)
{
    GFXEvent e;
    int q;

    q=FALSE;

    GFX_clear(BLACK);

    while(!q)
    	{
	GFX_print(0,0,WHITE,"Press key or mouse button to quit");
	GFX_redraw();
	GFX_clear(BLACK);
	GFX_await_input(&e);

	switch(e.type)
	    {
	    case GFX_KEY_EVENT:
		GFX_print(0,100,WHITE,".code   %d",e.key.code);
		GFX_print(0,100+GFX_fh()*2,WHITE,".ascii  %d (%c)",e.key.ascii,
				isprint(e.key.ascii) ? e.key.ascii : '?');

		GFX_print(0,100+GFX_fh()*4,WHITE,".modif  %c%c%c",
					e.key.shift ? 'S':' ',
					e.key.ctrl ? 'C':' ',
					e.key.alt ? 'A':' ');
		break;

	    case GFX_MOUSE_EVENT:
		q=TRUE;
		break;
	    }
	}
}


void TestGui(void)
{
    static PLAT_PICKLIST cpl[]=
			    {
				{"CPL 1",1},
				{"CPL 2",2},
				{"CPL 23",23},
				{"CPL 10",10},
				{"CPL 0",0},
    				{NULL,0},
			    };

    static char *pl_short[]=
    	{
	    "Picklist entry 0",
	    "Picklist entry 1", "Picklist entry 2", "Picklist entry 3",
	    NULL
	};

    static char *pl_d_short[]=
    	{
	    "Picklist entry 0", "Picklist entry 1", 
	    NULL
	};

    static char *pl[]=
    	{
	    "Picklist entry 0",
	    "Picklist entry 1", "Picklist entry 2", "Picklist entry 3",
	    "Picklist entry 4", "Picklist entry 5", "Picklist entry 6",
	    "Picklist entry 7", "Picklist entry 8", "Picklist entry 9",
	    "Picklist entry 10", "Picklist entry 11", "Picklist entry 12",
	    "Picklist entry 13", "Picklist entry 14", "Picklist entry 15",
	    "Picklist entry 16", "Picklist entry 17", "Picklist entry 18",
	    "Picklist entry 19", "Picklist entry 20", "Picklist entry 21",
	    "Picklist entry 22", "Picklist entry 23", "Picklist entry 24",
	    "Picklist entry 25", "Picklist entry 26", "Picklist entry 27",
	    "Picklist entry 28", "Picklist entry 29", "Picklist entry 30",
	    "Picklist entry 31", "Picklist entry 32", "Picklist entry 33",
	    "Picklist entry 34", "Picklist entry 35", "Picklist entry 36",
	    "Picklist entry 37", "Picklist entry 38", "Picklist entry 39",
	    "Picklist entry 40", "Picklist entry 41", "Picklist entry 42",
	    "Picklist entry 43", "Picklist entry 44", "Picklist entry 45",
	    "Picklist entry 46", "Picklist entry 47", "Picklist entry 48",
	    "Picklist entry 49", "Picklist entry 50", "Picklist entry 51",
	    "Picklist entry 52", "Picklist entry 53", "Picklist entry 54",
	    "Picklist entry 55", "Picklist entry 56", "Picklist entry 57",
	    "Picklist entry 58", "Picklist entry 59", "Picklist entry 60",
	    "Picklist entry 61", "Picklist entry 62", "Picklist entry 63",
	    "Picklist entry 64", "Picklist entry 65", "Picklist entry 66",
	    "Picklist entry 67", "Picklist entry 68", "Picklist entry 69",
	    "Picklist entry 70", "Picklist entry 71", "Picklist entry 72",
	    "Picklist entry 73", "Picklist entry 74", "Picklist entry 75",
	    "Picklist entry 76", "Picklist entry 77", "Picklist entry 78",
	    "Picklist entry 79", "Picklist entry 80", "Picklist entry 81",
	    "Picklist entry 82", "Picklist entry 83", "Picklist entry 84",
	    "Picklist entry 85", "Picklist entry 86", "Picklist entry 87",
	    "Picklist entry 88", "Picklist entry 89", "Picklist entry 90",
	    "Picklist entry 91", "Picklist entry 92", "Picklist entry 93",
	    "Picklist entry 94", "Picklist entry 95", "Picklist entry 96",
	    "Picklist entry 97", "Picklist entry 98", "Picklist entry 99",
	    NULL
	};

    static PLAT_IMG_PICKLIST ipl[]=
			    {
				{"IPL 1 (BLUE)",NULL,1},
				{"IPL 2",NULL,2},
				{"IPL 23 (GREEN)",NULL,23},
				{"IPL 10",NULL,10},
				{"IPL 0 (RED)",NULL,0},
    				{NULL,NULL,0},
			    };

    static PLAT_MENU ch2[]= {
    				{"Opt3",3,NULL},
    				{"Opt4",4,NULL},
    				{NULL,0,NULL},
			    };

    static PLAT_MENU ch1[]= {
    				{"Opt1",1,NULL},
    				{"Opt2",2,NULL},
    				{"Child 2",0,ch2},
    				{NULL,0,NULL},
			    };

    static char *pl_text[17]={"Opt 1","Opt 2","Opt 3","Opt 4","Opt 5",
			      "Opt 6","Opt 7","Opt 8","Opt 9","Opt 10",
			      "Opt 11","Opt 12","Opt 13","Opt 14","Opt 15",
			      "Opt 16",
			      "A very very very very long option"};

    static PLAT_DIALOG dialog[6]={
				    {"String",PLAT_DIAL_STRING,{0}},
				    {"Integer",PLAT_DIAL_INTEGER,{0}},
				    {"Double",PLAT_DIAL_DOUBLE,{0}},
				    {"Picklist 1",PLAT_DIAL_PICKLIST,{0}},
				    {"Picklist 2",PLAT_DIAL_PICKLIST,{0}},
				    {"Picklist 3",PLAT_DIAL_PICKLIST,{0}},
				 };

    static PLAT_RADIO radio[]= {
				{"Radio 0",0},
				{"Radio 2",2},
				{"Radio 4",4},
				{"Radio 8",8},
				{"Radio -33",-33},
				{NULL,0}
			       };

    int cur_radio=4;

    static PLAT_MULTI multi[]= {
				{"Opt 1",0,TRUE},
				{"Opt 2",0,FALSE},
				{"Opt 3",0,FALSE},
				{"Group 1.1",1,TRUE},
				{"Group 1.2",1,FALSE},
				{"Group 1.3",1,FALSE},
				{"Opt 4",0,FALSE},
				{"Group 2.1",2,FALSE},
				{"Group 2.2",2,TRUE},
				{"Opt 5",0,FALSE},
				{NULL,0,0}
			       };

    PLAT_DIALOG work_dial[6];

    static PLAT_MENU menu[]={
				{"Recursive",0,menu},
				{"Child 1",0,ch1},
				{"Test fsel and file_view",100,NULL},
				{"Test text edit",101,NULL},
				{"Test picklist",102,NULL},
				{"Test client data picklist",103,NULL},
				{"Test client data image picklist",104,NULL},
				{"Test DIALOG",105,NULL},
				{"Test GUI_alert()",106,NULL},
				{"Test GUI_yesno()",107,NULL},
				{"Test GUI_yesno_all()",108,NULL},
				{"Test GUI_radio_box()",109,NULL},
				{"Test GUI_multi_box()",110,NULL},
				{"Quit",999,NULL},
				{NULL,0,NULL},
			    };
    static char *text=NULL;

    int opt;
    char s[80];
    char *path;
    char *new;
    int ret;

    strcpy(dialog[0].data.s,"String");
    dialog[1].data.i=123;
    dialog[2].data.d=1.23;

    dialog[3].data.pl.no=17;
    dialog[3].data.pl.current=0;
    dialog[3].data.pl.text=pl_text;

    dialog[4].data.pl.no=2;
    dialog[4].data.pl.current=0;
    dialog[4].data.pl.text=pl_d_short;

    dialog[5].data.pl.no=100;
    dialog[5].data.pl.current=0;
    dialog[5].data.pl.text=pl;

    opt=0;

    if (!text)
    	{
	GFX_BITMAP bm;
	int c;
	int f;

	text=Strdup("Test text\nof two lines follwed by\n"
		    "a big line (nnA - nnP):\n"
			"123456790A 123456790B 123456790C 123456790D "
			"123456790E 123456790F 123456790G 123456790H "
			"123456790I 123456790J 123456790K 123456790L "
			"123456790M 123456790N 123456790O 123456790P <END>"
			);
	bm.pal[0]=BLACK;

	c=0xff;

	for(f=0;f<3;f++)
	    {
	    int w,h;

	    w=256-(f)*64;
	    h=256-(f)*64;
	    bm.w=w;
	    bm.h=h;
	    bm.pal[1]=c;
	    bm.data=Grab(w*h);

	    memset(bm.data,1,w*h);
	    ipl[f*2].img=GFX_create_image(&bm);
	    Release(bm.data);
	    c=c<<8;
	    }
	}

    while(opt!=999)
    	{
	opt=GUI_menu("Menu",10,10,menu,-1);

	switch(opt)
	    {
	    case 100:
		if (GUI_yesno("Use filter?"))
		    path=GUI_fsel("File selector","",".c");
		else
		    path=GUI_fsel("File selector","",NULL);

		if (path)
		    {
		    GUI_view_file(path,path);
		    Release(path);
		    }

	    	break;

	    case 101:
	    	new=GUI_text_edit("Test",text);

		if (new)
		    {
		    Release(text);
		    text=new;
		    }
		break;

	    case 102:
	    	ret=GUI_picklist("Long Picklist",pl);
		sprintf(s,"You chose option|%d",ret);
		GUI_yesno(s);

	    	ret=GUI_picklist("Short Picklist",pl_short);
		sprintf(s,"You chose option|%d",ret);
		GUI_yesno(s);
		break;

	    case 103:
	    	ret=GUI_client_picklist("Client Picklist",cpl,-1);
		sprintf(s,"You chose option|%d",ret);
		GUI_yesno(s);
		break;

	    case 104:
	    	ret=GUI_image_picklist("Image Picklist",ipl,-1);
		sprintf(s,"You chose option|%d",ret);
		GUI_yesno(s);
		break;

	    case 105:
		memcpy(&work_dial,&dialog,sizeof(dialog));

	    	if (GUI_dialog("Dialog",6,work_dial))
		    memcpy(&dialog,&work_dial,sizeof(dialog));
		break;

	    case 106:
	    	GUI_alert("This is a long title","Text1","OK");
	    	GUI_alert("T","Longer text 1|Longer text 2","OK");
	    	GUI_alert("T","Text1","Longer button text");
		break;

	    case 107:
		if (GUI_yesno("Pick"))
		    GUI_alert("Answer","YES","OK");
		else
		    GUI_alert("Answer","NO","OK");

		if (GUI_yesno("With a much much much MUCH longer string|"
						"and some multiple|lines"))
		    GUI_alert("Answer","YES","OK");
		else
		    GUI_alert("Answer","NO","OK");

		break;

	    case 108:
	        GUI_start_yesno_all();

		if (GUI_yesno_all("Pick"))
		    GUI_alert("Pick","YES","OK");
		else
		    GUI_alert("Pick","NO","OK");

		if (GUI_yesno_all("With a much much much MUCH longer string|"
						"and some multiple|lines"))
		    GUI_alert("Long string","YES","OK");
		else
		    GUI_alert("Long string","NO","OK");

		if (GUI_yesno_all("Pick 2"))
		    GUI_alert("Pick 2","YES","OK");
		else
		    GUI_alert("Pick 2","NO","OK");

		if (GUI_yesno_all("Pick 3"))
		    GUI_alert("Pick 3","YES","OK");
		else
		    GUI_alert("Pick 3","NO","OK");

	    	break;

	    case 109:
	    	ret=GUI_radio_box("Radio Box",radio,cur_radio,-666);
		sprintf(s,"You chose option|%d",ret);
		GUI_yesno(s);
		cur_radio=ret;
	    	break;

	    case 110:
	    	GUI_multi_box("Multi Box",multi);
	    	break;

	    case 999:
	    	break;

	    default:
		sprintf(s,"You chose option|%d",opt);
		GUI_alert("Other",s,"OK");
		break;
	    }
	}
}

#define PERF_COUNT	1000000

time_t PerfClr(time_t start)
{
    int f;

    for(f=0;f<PERF_COUNT;f++)
    	GFX_clear(BLACK);

    return time(NULL)-start;
}


time_t PerfRect(time_t start)
{
    int f;

    for(f=0;f<PERF_COUNT;f++)
    	GFX_rect(10,10,600,600,WHITE);

    return time(NULL)-start;
}


time_t PerfFRect(time_t start)
{
    int f;

    for(f=0;f<PERF_COUNT;f++)
    	GFX_frect(10,10,600,600,WHITE);

    return time(NULL)-start;
}


time_t PerfPlot(time_t start)
{
    int f;

    for(f=0;f<PERF_COUNT;f++)
    	GFX_plot(10,10,WHITE);

    return time(NULL)-start;
}


time_t PerfLine(time_t start)
{
    int f;

    for(f=0;f<PERF_COUNT;f++)
    	GFX_line(10,10,610,610,WHITE);

    return time(NULL)-start;
}


time_t PerfLRect(time_t start)
{
    int f;

    for(f=0;f<PERF_COUNT;f++)
	{
    	GFX_line(10,10,610,610,WHITE);
    	GFX_line(610,610,610,610,WHITE);
    	GFX_line(610,610,10,610,WHITE);
    	GFX_line(10,610,10,10,WHITE);
	}

    return time(NULL)-start;
}


time_t PerfCirc(time_t start)
{
    int f;

    for(f=0;f<PERF_COUNT;f++)
    	GFX_circle(10,10,600,WHITE);

    return time(NULL)-start;
}


void TestPerformance(void)
{
    static struct
    	{
	char	*t;
	time_t	(*func)(time_t);
	} test[]= {
		    {"Clear screen",PerfClr},
		    {"Rectangles",PerfRect},
		    {"Filled rectangles",PerfFRect},
		    {"Plot",PerfPlot},
		    {"Line",PerfLine},
		    {"Rectangles using GFX_line",PerfLRect},
		    {"Circles",PerfCirc},
		    {NULL,NULL}
		  };

    PLAT_MENU pm[32];
    int quit;
    time_t t;
    int f;

    quit=FALSE;

    GFX_clear(BLACK);
    GFX_print(0,0,RED,"Select:");

    while(!quit)
    	{
	f=0;
	while(test[f].t)
	    {
	    pm[f].text=test[f].t;
	    pm[f].client_index=f;
	    pm[f].child=NULL;
	    f++;
	    }

	pm[f].text=NULL;

	GFX_redraw();

	if ((f=GUI_menu("Performance",16,16,pm,-1))==-1)
	    quit=TRUE;
	else
	    {
	    t=time(NULL);
	    while (time(NULL)==t);

	    t=test[f].func(time(NULL));

	    GFX_clear(BLACK);
	    GFX_print(0,0,WHITE,"Test %s completed in %ld seconds",test[f].t,t);
	    GFX_redraw();
	    }
	}
}




int viDOOM(int argc,char *argv[])
{
    static struct
    	{
	char	*t;
	void	(*func)(void);
	} test[]= {
		    {"Test printing",TestPrint},
		    {"Test mouse",TestMouse},
		    {"Test rectangles",TestRect},
		    {"Test screen dimensions",TestDim},
		    {"Test colours",TestCol},
		    {"Test drawing",TestDraw},
		    {"Test bitmap",TestBm},
		    {"Test keyboard",TestKey},
		    {"Test GUI",TestGui},
		    {"Test Performance",TestPerformance},
		    {NULL,NULL}
		  };

    PLAT_MENU pm[32];
    int quit;
    int f;

    INI_Load("vidoom.ini");
    GFX_init();
    GFX_open(SCRW,SCRH);
    GUI_setscreen(SCRW,SCRH);

    quit=FALSE;

    while(!quit)
    	{
	GFX_clear(BLACK);
	GFX_print(0,0,RED,"Select:");

	f=0;
	while(test[f].t)
	    {
	    pm[f].text=test[f].t;
	    pm[f].client_index=f;
	    pm[f].child=NULL;
	    f++;
	    }

	pm[f].text=NULL;

	GFX_redraw();

	if ((f=GUI_menu("GFXTEST",16,16,pm,-1))==-1)
	    quit=TRUE;
	else
	    test[f].func();
	}

    return(EXIT_SUCCESS);
}