diff options
author | Ian C <ianc@noddybox.co.uk> | 2011-06-09 13:46:28 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2011-06-09 13:46:28 +0000 |
commit | a9022b5972dc49d86f617a27940fafe9c4d0e7e7 (patch) | |
tree | 61405aa4ade91ed1057f863ddf118ceb38e14f8e /gui.c |
Initial import of (very old) vidoom sources.
Diffstat (limited to 'gui.c')
-rw-r--r-- | gui.c | 337 |
1 files changed, 337 insertions, 0 deletions
@@ -0,0 +1,337 @@ +/* + + 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" +#include "names.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}; + +static char **level_list=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]; + va_list va; + + va_start(va,fmt); + vsprintf(p,fmt,va); + va_end(va); + + GUI_alert(title,p,"OK"); +} + + +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]; + char **orig; + int no; + + switch(level_style) + { + case DOOM_LEVELS: + orig=doom_levels; + break; + + case ULTIMATE_DOOM_LEVELS: + orig=ult_doom_levels; + break; + + case DOOM_2_LEVELS: + orig=doom2_levels; + break; + + default: + orig=doom_levels; + break; + } + + if (!level_list) + { + no=0; + while(orig[no++]); + + level_list=Grab(sizeof(char *)*no); + + for(f=0;f<no-1;f++) + { + strcpy(s,orig[f]); + strcat(s," - "); + strcat(s,MapName(orig[f])); + level_list[f]=Strdup(s); + } + + level_list[no-1]=NULL; + } + + f=GUI_picklist(prompt,level_list); + + if (f<0) + return(NULL); + + strcpy(s,orig[f]); + return(s); +} + + +/* END OF FILE */ |