From 11fb78008c317f0aaaf0d41e9e462d7b2836d6b0 Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Wed, 24 Jun 2009 22:08:55 +0000 Subject: [PATCH] Resolution-dependent symbols exported to scripts. --- reaction/ta_ui/ui_main.c | 74 +++++++++++++++++++++++++++++++++++--- reaction/ta_ui/ui_shared.c | 25 +++++++++---- reaction/ta_ui/ui_shared.h | 6 ++++ reaction/uifiles/menudef.h | 1 + 4 files changed, 95 insertions(+), 11 deletions(-) diff --git a/reaction/ta_ui/ui_main.c b/reaction/ta_ui/ui_main.c index 097a37f5..1babae94 100644 --- a/reaction/ta_ui/ui_main.c +++ b/reaction/ta_ui/ui_main.c @@ -539,6 +539,7 @@ int vmMain(int command, int arg0, int arg1, int arg2, int arg3, int arg4, int ar return -1; } + /* ========================== UI_FileExists @@ -557,6 +558,62 @@ qboolean UI_FileExists(const char *filename) return qfalse; } +// Makro - temporary file with #define's +static const char* s_symbols_temp_file_name = "ui/runtime.h"; + + +static void FS_WriteText(fileHandle_t file, const char* text) +{ + trap_FS_Write(text, strlen(text), file); +} + + +static void DefineSymbol(fileHandle_t f, const char* name, const char* value) +{ + char buffer[512]; + + if (value && *value) + Com_sprintf(buffer, sizeof(buffer), "#define %s %s\n", name, value); + else + Com_sprintf(buffer, sizeof(buffer), "#define %s\n", name); + + FS_WriteText(f, va("#ifdef %s\n", name)); + FS_WriteText(f, va("# undef %s\n", name)); + FS_WriteText(f, va("#endif // def %s\n", name)); + + FS_WriteText(f, buffer); +} + + +static void UI_ExportSymbols() +{ + // Makro - this is a hack that allows us to export resolution-dependent symbols to the scripts. + // We could call trap_PC_AddGlobalDefine, but there's no undefine function... + + fileHandle_t f; + const char* fname = s_symbols_temp_file_name; + if (trap_FS_FOpenFile(fname, &f, FS_WRITE) >= 0) + { + DefineSymbol(f, "UI_MINX", va("%.0f", uiInfo.uiDC.min[0])); + DefineSymbol(f, "UI_MINY", va("%.0f", uiInfo.uiDC.min[1])); + DefineSymbol(f, "UI_MAXX", va("%.0f", uiInfo.uiDC.max[0])); + DefineSymbol(f, "UI_MAXY", va("%.0f", uiInfo.uiDC.max[1])); + + trap_FS_FCloseFile(f); + } + else + Com_Error(ERR_FATAL, "Could not create temporary UI symbol file!\n", fname); +} + +static void UI_CleanUpSymbols() +{ + fileHandle_t f; + const char* fname = s_symbols_temp_file_name; + if (trap_FS_FOpenFile(fname, &f, FS_WRITE) >= 0) + trap_FS_FCloseFile(f); +} + + //Makro - registers an asset; path is relative to the assetsPath qhandle_t Asset_RegisterShaderNoMip(const char *path) { @@ -1592,6 +1649,7 @@ _UI_Shutdown */ void _UI_Shutdown(void) { + UI_CleanUpSymbols(); trap_LAN_SaveCachedServers(); } @@ -8095,7 +8153,6 @@ static void UI_MakeExtensionsList() } } - /* ================= UI_Init @@ -8239,8 +8296,15 @@ void _UI_Init(qboolean inGameLoad) AssetCache(); + uiInfo.uiDC.min[0] = 0.5f * (SCREEN_WIDTH - SCREEN_HEIGHT * uiInfo.uiDC.glconfig.vidWidth / (float)uiInfo.uiDC.glconfig.vidHeight); + uiInfo.uiDC.min[1] = 0; + uiInfo.uiDC.max[0] = SCREEN_WIDTH - uiInfo.uiDC.min[0]; + uiInfo.uiDC.max[1] = SCREEN_HEIGHT; + start = trap_Milliseconds(); + UI_ExportSymbols(); + uiInfo.teamCount = 0; uiInfo.characterCount = 0; uiInfo.aliasCount = 0; @@ -8371,10 +8435,10 @@ UI_MouseEvent */ void _UI_MouseEvent(int dx, int dy) { - const int MIN_X = (int)(0.5f * (SCREEN_WIDTH - SCREEN_HEIGHT * uiInfo.uiDC.glconfig.vidWidth / (float)uiInfo.uiDC.glconfig.vidHeight)); - const int MAX_X = SCREEN_WIDTH - MIN_X; - const int MIN_Y = 0; - const int MAX_Y = SCREEN_HEIGHT; + const int MIN_X = (int)uiInfo.uiDC.min[0]; + const int MIN_Y = (int)uiInfo.uiDC.min[1]; + const int MAX_X = (int)uiInfo.uiDC.max[0]; + const int MAX_Y = (int)uiInfo.uiDC.max[1]; //Makro - added tablet code if (ui_RQ3_tabletMode.integer) diff --git a/reaction/ta_ui/ui_shared.c b/reaction/ta_ui/ui_shared.c index 431a6b05..1678ee5f 100644 --- a/reaction/ta_ui/ui_shared.c +++ b/reaction/ta_ui/ui_shared.c @@ -507,19 +507,32 @@ qboolean PC_Float_Parse(int handle, float *f) if (!trap_PC_ReadToken(handle, &token)) return qfalse; - if (token.string[0] == '-') { + + while (token.type == TT_PUNCTUATION) + { + if (token.string[0] != '-') + { + PC_SourceError(handle, "expected float but found %s\n", token.string); + return qfalse; + } + if (!trap_PC_ReadToken(handle, &token)) return qfalse; - negative = qtrue; + + negative ^= qtrue; } - if (token.type != TT_NUMBER) { + + if (token.type != TT_NUMBER) + { PC_SourceError(handle, "expected float but found %s\n", token.string); return qfalse; } + if (negative) - *f = -token.floatvalue; + *f = -atof(token.string); else - *f = token.floatvalue; + *f = atof(token.string); + return qtrue; } @@ -601,7 +614,7 @@ qboolean PC_Int_Parse(int handle, int *i) PC_SourceError(handle, "expected integer but found %s\n", token.string); return qfalse; } - *i = token.intvalue; + *i = atoi(token.string); if (negative) *i = -*i; return qtrue; diff --git a/reaction/ta_ui/ui_shared.h b/reaction/ta_ui/ui_shared.h index bb9077ea..7381df09 100644 --- a/reaction/ta_ui/ui_shared.h +++ b/reaction/ta_ui/ui_shared.h @@ -123,6 +123,8 @@ #define WINDOW_RANDOM_TCGEN 0x04000000 //Makro - parent is moved around when this item is clicked #define WINDOW_MENU_ANCHOR 0x08000000 +//Makro - window is fullscreen +#define WINDOW_FULLSCREEN 0x10000000 // CGAME cursor type bits #define CURSOR_NONE 0x00000001 @@ -615,6 +617,10 @@ typedef struct { //Makro - gl extensions const char *glExtensions[MAX_NUM_GL_EXTENSIONS]; int numGlExtensions; + + // Makro - total screen extents (which can go outside 0,0-640,480 for wide screens) + float min[2]; + float max[2]; } displayContextDef_t; const char *String_Alloc(const char *p); diff --git a/reaction/uifiles/menudef.h b/reaction/uifiles/menudef.h index 385341d2..d960af32 100644 --- a/reaction/uifiles/menudef.h +++ b/reaction/uifiles/menudef.h @@ -1,3 +1,4 @@ +#include "ui/runtime.h" #define ITEM_TYPE_TEXT 0 // simple text #define ITEM_TYPE_BUTTON 1 // button, basically text with a border