summaryrefslogtreecommitdiff
path: root/gfxtest.c
diff options
context:
space:
mode:
Diffstat (limited to 'gfxtest.c')
-rw-r--r--gfxtest.c468
1 files changed, 468 insertions, 0 deletions
diff --git a/gfxtest.c b/gfxtest.c
new file mode 100644
index 0000000..3feebc9
--- /dev/null
+++ b/gfxtest.c
@@ -0,0 +1,468 @@
+/*
+
+ 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 "gfx.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 TestRotate(void)
+{
+ GFXEvent e;
+ int q;
+ int x1,y1,x2,y2;
+
+ GFX_clear(BLACK);
+
+ q=FALSE;
+ x1=200;
+ y1=0;
+ x2=0;
+ y2=-190;
+
+ 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:
+ Rotate(0,0,&x1,&y1,10.0);
+ Rotate(0,0,&x2,&y2,-10.0);
+
+ GFX_plot(e.mouse.x+x1,e.mouse.y+y1,RCOL);
+ GFX_plot(e.mouse.x+x2,e.mouse.y+y2,RCOL);
+ break;
+ }
+ }
+}
+
+
+void TestScale(void)
+{
+ GFXEvent e;
+ int q;
+ int f;
+ int x,y;
+
+ GFX_clear(BLACK);
+
+ q=FALSE;
+ x=10;
+ y=10;
+ f=0;
+
+ 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:
+ if (((f++)%20)>10)
+ Scale(0,0,&x,&y,0.9);
+ else
+ Scale(0,0,&x,&y,1.1);
+
+ GFX_plot(e.mouse.x+x,e.mouse.y+y,RCOL);
+ break;
+ }
+ }
+}
+
+
+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;
+ }
+ }
+}
+
+
+int viDOOM(int argc,char *argv[])
+{
+ static struct
+ {
+ char *t;
+ char k;
+ void (*func)(void);
+ } test[]= {
+ {"Test printing",'P',TestPrint},
+ {"Test mouse",'M',TestMouse},
+ {"Test rectangles",'B',TestRect},
+ {"Test screen dimensions",'D',TestDim},
+ {"Test EDIT Rotate",'R',TestRotate},
+ {"Test EDIT Scale",'S',TestScale},
+ {"Test colours",'C',TestCol},
+ {"Test drawing",'G',TestDraw},
+ {"Test bitmap",'X',TestBm},
+ {"Test keyboard",'K',TestKey},
+ {NULL,0,NULL}
+ };
+
+ GFXKey k;
+ int quit;
+ int f;
+
+ GFX_init();
+ GFX_open(SCRW,SCRH);
+
+ quit=FALSE;
+
+ while(!quit)
+ {
+ GFX_clear(BLACK);
+ GFX_print(0,0,RED,"Select (ESC quit):");
+
+ f=0;
+ while(test[f].t)
+ {
+ GFX_print(0,GFX_fh()*(f+2),WHITE,"%c - %s",test[f].k,test[f].t);
+ f++;
+ }
+
+ GFX_redraw();
+ GFX_waitkey(&k);
+
+ if (k.code==GFX_ESC)
+ quit=TRUE;
+ else
+ {
+ f=0;
+ while(test[f].t)
+ {
+ if (toupper(k.ascii)==test[f].k)
+ test[f].func();
+ f++;
+ }
+ }
+ }
+
+ return(EXIT_SUCCESS);
+}