summaryrefslogtreecommitdiff
path: root/gui.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2011-06-09 13:57:32 +0000
committerIan C <ianc@noddybox.co.uk>2011-06-09 13:57:32 +0000
commit0f12083fdb14ae813e419500918b95cb83070586 (patch)
tree93f855836faede895a4c37d12dcc46a8c5fbb835 /gui.c
Added copies of old numbered releases.0.01
Diffstat (limited to 'gui.c')
-rw-r--r--gui.c391
1 files changed, 391 insertions, 0 deletions
diff --git a/gui.c b/gui.c
new file mode 100644
index 0000000..a7e41dc
--- /dev/null
+++ b/gui.c
@@ -0,0 +1,391 @@
+/*
+
+ 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
+
+ -------------------------------------------------------------------------
+
+ Generic GUI type routines
+
+*/
+static const char rcs_id[]="$Id$";
+
+#include "config.h"
+#include "globals.h"
+
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "gui.h"
+#include "platgui.h"
+#include "mem.h"
+#include "ini.h"
+
+/* ---------------------------------------- VARS
+*/
+#define GUI_INI "GUI"
+
+#define GUI_BORDER (fh/2)
+#define GUI_BORDERFULL (GUI_BORDER*2)
+
+#define GUI_TITLEH (fh*2)
+#define GUI_TITLEOFF (fh/2)
+#define GUI_FOOTERH (fh*2)
+#define GUI_FOOTEROFF (fh/2)
+
+#define GUI_BEVEL 2
+
+#define MAXLINES 512
+#define MAXTEXT 4096
+
+#define ANY_CLOSE "Press any key/mouse button to close"
+#define ESC_CLOSE "Press ESC key to close"
+
+#define VIEW_LEN 70
+
+int GUI_HI=GREY(210);
+int GUI_MID=GREY(180);
+int GUI_LO=GREY(140);
+int GUI_TEXT=WHITE;
+int GUI_TEXTSHADOW=BLACK;
+int GUI_TEXTBOLD=BLACK;
+
+static INI_Table gui_ini[]=
+ {
+ {INI_INT,GUI_INI,"high",&GUI_HI,NULL},
+ {INI_INT,GUI_INI,"mid",&GUI_MID,NULL},
+ {INI_INT,GUI_INI,"low",&GUI_LO,NULL},
+ {INI_INT,GUI_INI,"text",&GUI_TEXT,NULL},
+ {INI_INT,GUI_INI,"shadow",&GUI_TEXTSHADOW,NULL},
+ {INI_INT,GUI_INI,"bold",&GUI_TEXTBOLD,NULL}
+ };
+
+static int SCRW;
+static int SCRH;
+static int fw;
+static int fh;
+
+static char *doom_levels[]=
+ {"E1M1","E1M2","E1M3","E1M4","E1M5",
+ "E1M6","E1M7","E1M8","E1M9",
+ "E2M1","E2M2","E2M3","E2M4","E2M5",
+ "E2M6","E2M7","E2M8","E2M9",
+ "E3M1","E3M2","E3M3","E3M4","E3M5",
+ "E3M6","E3M7","E3M8","E3M9",NULL};
+
+static char *ult_doom_levels[]=
+ {"E1M1","E1M2","E1M3","E1M4","E1M5",
+ "E1M6","E1M7","E1M8","E1M9",
+ "E2M1","E2M2","E2M3","E2M4","E2M5",
+ "E2M6","E2M7","E2M8","E2M9",
+ "E3M1","E3M2","E3M3","E3M4","E3M5",
+ "E3M6","E3M7","E3M8","E3M9",
+ "E4M1","E4M2","E4M3","E4M4","E4M5",
+ "E4M6","E4M7","E4M8","E4M9",NULL};
+
+static char *doom2_levels[]=
+ {"MAP01","MAP02","MAP03","MAP04","MAP05",
+ "MAP06","MAP07","MAP08","MAP09","MAP10",
+ "MAP11","MAP12","MAP13","MAP14","MAP15",
+ "MAP16","MAP17","MAP18","MAP19","MAP20",
+ "MAP21","MAP22","MAP23","MAP24","MAP25",
+ "MAP26","MAP27","MAP28","MAP29","MAP30",
+ "MAP31","MAP32",NULL};
+
+
+/* ---------------------------------------- PRIVATE FUNCTIONS
+*/
+
+static void CalcBounding(char *text,int *num,char *t[],int min_len,
+ int *x,int *y,int *w,int *h)
+{
+ int no;
+ int f;
+ char *p;
+
+ no=0;
+ p=strtok(text,"|");
+
+ while(p)
+ {
+ t[no++]=p;
+ p=strtok(NULL,"|");
+ }
+
+ t[no]=NULL;
+
+ *h=fh*no+GUI_BORDERFULL;
+
+ for(f=0;f<no;f++)
+ if (strlen(t[f])>min_len)
+ min_len=strlen(t[f]);
+
+ *num=no;
+ *w=fw*min_len+GUI_BORDERFULL;
+ *x=SCRW/2-*w/2;
+ *y=SCRH/2-*h/2;
+}
+
+
+static void DrawBox(int x,int y,int w,int h,int bevel)
+{
+ int f;
+
+ GFX_frect(x,y,w,h,GUI_MID);
+
+ for(f=0;f<bevel;f++)
+ {
+ GFX_line(x+1+f,y+h-1-f,x+w-1-f,y+h-1-f,GUI_LO);
+ GFX_line(x+w-1-f,y+1+f,x+w-1-f,y+h-1-f,GUI_LO);
+ GFX_line(x+f,y+f,x+w-1-f,y+f,GUI_HI);
+ GFX_line(x+f,y+f,x+f,y+h-1-f,GUI_HI);
+ }
+}
+
+
+static void DrawTitle(int x,int y,int w,char *title)
+{
+ GFX_print((x+w/2)-(strlen(title)*fw)/2,y+GUI_TITLEOFF,
+ GUI_TEXTBOLD,"%s",title);
+ GFX_line(x+GUI_BEVEL,y+GUI_TITLEOFF+fh,x+w-GUI_BEVEL-1,
+ y+GUI_TITLEOFF+fh,GUI_HI);
+ GFX_line(x+GUI_BEVEL,y+GUI_TITLEOFF+fh+1,x+w-GUI_BEVEL-1,
+ y+GUI_TITLEOFF+fh+1,GUI_LO);
+}
+
+
+static void DrawText(int x,int y,char *p)
+{
+ /*
+ if ((STRNEQ("HTTP:",p))||(STRNEQ("FTP:",p))||(STRNEQ("MAILTO:",p)))
+ {
+ GFX_print(x+1,y+1,WHITE,"%s",p);
+ GFX_print(x,y,V_RGB(0x60,0x60,0xff),"%s",p);
+ }
+ else
+ */
+ {
+ if (GUI_TEXTSHADOW!=GUI_TEXT)
+ GFX_print(x+1,y+1,GUI_TEXTSHADOW,"%s",p);
+
+ GFX_print(x,y,GUI_TEXT,"%s",p);
+ }
+}
+
+
+/* ---------------------------------------- EXPORTED FUNCTIONS
+*/
+
+void GuiSetScreen(int w,int h)
+{
+ INI_GetTable(gui_ini,INI_TAB_SIZE(gui_ini));
+
+ SCRW=w;
+ SCRH=h;
+ fw=GFX_fw();
+ fh=GFX_fh()+2;
+}
+
+
+void GuiInfoBox(char *title,char *fmt,...)
+{
+ static char p[MAXTEXT];
+ char *t[MAXLINES];
+ int no,x,y,w,h;
+ int f;
+ GFXEvent ev;
+ va_list va;
+
+ va_start(va,fmt);
+ vsprintf(p,fmt,va);
+ va_end(va);
+
+ CalcBounding(p,&no,t,MAX(strlen(ANY_CLOSE),strlen(title)),&x,&y,&w,&h);
+ h+=GUI_TITLEH+GUI_FOOTERH;
+
+ DrawBox(x,y,w,h,GUI_BEVEL);
+
+ for(f=0;f<no;f++)
+ DrawText((SCRW-strlen(t[f])*fw)/2,y+GUI_BORDER+GUI_TITLEH+fh*f,t[f]);
+
+ DrawTitle(x,y,w,title);
+
+ GFX_print((SCRW-strlen(ANY_CLOSE)*fw)/2,y+h-GUI_FOOTERH+GUI_FOOTEROFF-1,
+ GUI_TEXTBOLD,"%s",ANY_CLOSE);
+
+ GFX_redraw();
+ GFX_bounce();
+ GFX_await_input(&ev);
+ GFX_bounce();
+}
+
+
+void GuiDrawInfoBox(char *title,int px,int py,int centre,char *fmt,...)
+{
+ static char p[MAXTEXT];
+ char *t[MAXLINES];
+ int no,x,y,w,h;
+ int f;
+ va_list va;
+ int cen;
+
+ va_start(va,fmt);
+ vsprintf(p,fmt,va);
+ va_end(va);
+
+ CalcBounding(p,&no,t,strlen(title),&x,&y,&w,&h);
+ h+=GUI_TITLEH;
+
+ switch(px)
+ {
+ case GUI_CENTRE:
+ break;
+ case GUI_FLUSH_LEFT:
+ x=0;
+ break;
+ case GUI_FLUSH_RIGHT:
+ x=SCRW-w-1;
+ break;
+ default:
+ x=px;
+ break;
+ }
+
+ switch(py)
+ {
+ case GUI_CENTRE:
+ break;
+ case GUI_FLUSH_TOP:
+ y=0;
+ break;
+ case GUI_FLUSH_LOWER:
+ y=SCRH-h-1;
+ break;
+ default:
+ y=py;
+ break;
+ }
+
+ cen=(x+w/2);
+
+ DrawBox(x,y,w,h,GUI_BEVEL);
+
+ for(f=0;f<no;f++)
+ if (centre)
+ DrawText(cen-strlen(t[f])*(fw/2)+1,
+ y+GUI_BORDER+GUI_TITLEH+fh*f+1,t[f]);
+ else
+ DrawText(x+GUI_BEVEL+GUI_BORDER,y+GUI_BORDER+GUI_TITLEH+fh*f,t[f]);
+
+ DrawTitle(x,y,w,title);
+}
+
+
+char *GuiPickLevel(char *prompt)
+{
+ int f;
+ static char s[256];
+
+ switch(level_style)
+ {
+ case DOOM_LEVELS:
+ f=GUI_picklist(prompt,doom_levels);
+
+ if (f<0)
+ return(NULL);
+
+ strcpy(s,doom_levels[f]);
+ break;
+
+ case ULTIMATE_DOOM_LEVELS:
+ f=GUI_picklist(prompt,ult_doom_levels);
+
+ if (f<0)
+ return(NULL);
+
+ strcpy(s,ult_doom_levels[f]);
+ break;
+
+ case DOOM_2_LEVELS:
+ f=GUI_picklist(prompt,doom2_levels);
+
+ if (f<0)
+ return(NULL);
+
+ strcpy(s,doom2_levels[f]);
+ break;
+ }
+
+ return(s);
+}
+
+
+void ViewFile(char *title, char *file)
+{
+ FILE *fp;
+ int no;
+ char s[VIEW_LEN];
+ char **line;
+ int f;
+
+ if ((fp=fopen(file,"r")))
+ {
+ no=0;
+ fgets(s,VIEW_LEN,fp);
+
+ while(!feof(fp))
+ {
+ no++;
+ fgets(s,VIEW_LEN,fp);
+ }
+
+ no++;
+
+ fclose(fp);
+
+ line=Grab(sizeof(char *)*(no+1));
+
+ f=0;
+ fp=fopen(file,"r");
+
+ fgets(s,VIEW_LEN,fp);
+
+ while(!feof(fp))
+ {
+ line[f++]=Strdup(s);
+ fgets(s,VIEW_LEN,fp);
+ }
+
+ line[f++]=Strdup("<END OF FILE>");
+ line[f]=NULL;
+
+ GUI_picklist(title,line);
+
+ for(f=0;f<no;f++)
+ Release(line[f]);
+
+ Release(line);
+ }
+ else
+ GuiInfoBox("ERROR","ViewFile couldn't open:%s",file);
+}
+
+
+
+/* END OF FILE */