1 /* 2 =========================================================================== 3 Copyright (C) 1999-2005 Id Software, Inc. 4 5 This file is part of Quake III Arena source code. 6 7 Quake III Arena source code is free software; you can redistribute it 8 and/or modify it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2 of the License, 10 or (at your option) any later version. 11 12 Quake III Arena source code is distributed in the hope that it will be 13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with Quake III Arena source code; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 =========================================================================== 21 */ 22 #ifndef __UI_SHARED_H 23 #define __UI_SHARED_H 24 25 26 #include "../qcommon/q_shared.h" 27 #include "../renderer/tr_types.h" 28 #include "../client/keycodes.h" 29 30 #include "../../ui/menudef.h" 31 32 #define MAX_MENUNAME 32 33 #define MAX_ITEMTEXT 64 34 #define MAX_ITEMACTION 64 35 #define MAX_MENUDEFFILE 4096 36 #define MAX_MENUFILE 32768 37 #define MAX_MENUS 64 38 #define MAX_MENUITEMS 96 39 #define MAX_COLOR_RANGES 10 40 #define MAX_OPEN_MENUS 16 41 42 #define WINDOW_MOUSEOVER 0x00000001 // mouse is over it, non exclusive 43 #define WINDOW_HASFOCUS 0x00000002 // has cursor focus, exclusive 44 #define WINDOW_VISIBLE 0x00000004 // is visible 45 #define WINDOW_GREY 0x00000008 // is visible but grey ( non-active ) 46 #define WINDOW_DECORATION 0x00000010 // for decoration only, no mouse, keyboard, etc.. 47 #define WINDOW_FADINGOUT 0x00000020 // fading out, non-active 48 #define WINDOW_FADINGIN 0x00000040 // fading in 49 #define WINDOW_MOUSEOVERTEXT 0x00000080 // mouse is over it, non exclusive 50 #define WINDOW_INTRANSITION 0x00000100 // window is in transition 51 #define WINDOW_FORECOLORSET 0x00000200 // forecolor was explicitly set ( used to color alpha images or not ) 52 #define WINDOW_HORIZONTAL 0x00000400 // for list boxes and sliders, vertical is default this is set of horizontal 53 #define WINDOW_LB_LEFTARROW 0x00000800 // mouse is over left/up arrow 54 #define WINDOW_LB_RIGHTARROW 0x00001000 // mouse is over right/down arrow 55 #define WINDOW_LB_THUMB 0x00002000 // mouse is over thumb 56 #define WINDOW_LB_PGUP 0x00004000 // mouse is over page up 57 #define WINDOW_LB_PGDN 0x00008000 // mouse is over page down 58 #define WINDOW_ORBITING 0x00010000 // item is in orbit 59 #define WINDOW_OOB_CLICK 0x00020000 // close on out of bounds click 60 #define WINDOW_WRAPPED 0x00040000 // manually wrap text 61 #define WINDOW_AUTOWRAPPED 0x00080000 // auto wrap text 62 #define WINDOW_FORCED 0x00100000 // forced open 63 #define WINDOW_POPUP 0x00200000 // popup 64 #define WINDOW_BACKCOLORSET 0x00400000 // backcolor was explicitly set 65 #define WINDOW_TIMEDVISIBLE 0x00800000 // visibility timing ( NOT implemented ) 66 67 68 // CGAME cursor type bits 69 #define CURSOR_NONE 0x00000001 70 #define CURSOR_ARROW 0x00000002 71 #define CURSOR_SIZER 0x00000004 72 73 #ifdef CGAME 74 #define STRING_POOL_SIZE 128*1024 75 #else 76 #define STRING_POOL_SIZE 384*1024 77 #endif 78 #define MAX_STRING_HANDLES 4096 79 80 #define MAX_SCRIPT_ARGS 12 81 #define MAX_EDITFIELD 256 82 83 #define ART_FX_BASE "menu/art/fx_base" 84 #define ART_FX_BLUE "menu/art/fx_blue" 85 #define ART_FX_CYAN "menu/art/fx_cyan" 86 #define ART_FX_GREEN "menu/art/fx_grn" 87 #define ART_FX_RED "menu/art/fx_red" 88 #define ART_FX_TEAL "menu/art/fx_teal" 89 #define ART_FX_WHITE "menu/art/fx_white" 90 #define ART_FX_YELLOW "menu/art/fx_yel" 91 92 #define ASSET_GRADIENTBAR "ui/assets/gradientbar2.tga" 93 #define ASSET_SCROLLBAR "ui/assets/scrollbar.tga" 94 #define ASSET_SCROLLBAR_ARROWDOWN "ui/assets/scrollbar_arrow_dwn_a.tga" 95 #define ASSET_SCROLLBAR_ARROWUP "ui/assets/scrollbar_arrow_up_a.tga" 96 #define ASSET_SCROLLBAR_ARROWLEFT "ui/assets/scrollbar_arrow_left.tga" 97 #define ASSET_SCROLLBAR_ARROWRIGHT "ui/assets/scrollbar_arrow_right.tga" 98 #define ASSET_SCROLL_THUMB "ui/assets/scrollbar_thumb.tga" 99 #define ASSET_SLIDER_BAR "ui/assets/slider2.tga" 100 #define ASSET_SLIDER_THUMB "ui/assets/sliderbutt_1.tga" 101 #define SCROLLBAR_SIZE 16.0 102 #define SLIDER_WIDTH 96.0 103 #define SLIDER_HEIGHT 16.0 104 #define SLIDER_THUMB_WIDTH 12.0 105 #define SLIDER_THUMB_HEIGHT 20.0 106 #define NUM_CROSSHAIRS 10 107 108 typedef struct { 109 const char *command; 110 const char *args[MAX_SCRIPT_ARGS]; 111 } scriptDef_t; 112 113 114 typedef struct { 115 float x; // horiz position 116 float y; // vert position 117 float w; // width 118 float h; // height; 119 } rectDef_t; 120 121 typedef rectDef_t Rectangle; 122 123 // FIXME: do something to separate text vs window stuff 124 typedef struct { 125 Rectangle rect; // client coord rectangle 126 Rectangle rectClient; // screen coord rectangle 127 const char *name; // 128 const char *group; // if it belongs to a group 129 const char *cinematicName; // cinematic name 130 int cinematic; // cinematic handle 131 int style; // 132 int border; // 133 int ownerDraw; // ownerDraw style 134 int ownerDrawFlags; // show flags for ownerdraw items 135 float borderSize; // 136 int flags; // visible, focus, mouseover, cursor 137 Rectangle rectEffects; // for various effects 138 Rectangle rectEffects2; // for various effects 139 int offsetTime; // time based value for various effects 140 int nextTime; // time next effect should cycle 141 vec4_t foreColor; // text color 142 vec4_t backColor; // border color 143 vec4_t borderColor; // border color 144 vec4_t outlineColor; // border color 145 qhandle_t background; // background asset 146 } windowDef_t; 147 148 typedef windowDef_t Window; 149 150 typedef struct { 151 vec4_t color; 152 float low; 153 float high; 154 } colorRangeDef_t; 155 156 // FIXME: combine flags into bitfields to save space 157 // FIXME: consolidate all of the common stuff in one structure for menus and items 158 // THINKABOUTME: is there any compelling reason not to have items contain items 159 // and do away with a menu per say.. major issue is not being able to dynamically allocate 160 // and destroy stuff.. Another point to consider is adding an alloc free call for vm's and have 161 // the engine just allocate the pool for it based on a cvar 162 // many of the vars are re-used for different item types, as such they are not always named appropriately 163 // the benefits of c++ in DOOM will greatly help crap like this 164 // FIXME: need to put a type ptr that points to specific type info per type 165 // 166 #define MAX_LB_COLUMNS 16 167 168 typedef struct columnInfo_s { 169 int pos; 170 int width; 171 int maxChars; 172 } columnInfo_t; 173 174 typedef struct listBoxDef_s { 175 int startPos; 176 int endPos; 177 int drawPadding; 178 int cursorPos; 179 float elementWidth; 180 float elementHeight; 181 int elementStyle; 182 int numColumns; 183 columnInfo_t columnInfo[MAX_LB_COLUMNS]; 184 const char *doubleClick; 185 qboolean notselectable; 186 } listBoxDef_t; 187 188 typedef struct editFieldDef_s { 189 float minVal; // edit field limits 190 float maxVal; // 191 float defVal; // 192 float range; // 193 int maxChars; // for edit fields 194 int maxPaintChars; // for edit fields 195 int paintOffset; // 196 } editFieldDef_t; 197 198 #define MAX_MULTI_CVARS 32 199 200 typedef struct multiDef_s { 201 const char *cvarList[MAX_MULTI_CVARS]; 202 const char *cvarStr[MAX_MULTI_CVARS]; 203 float cvarValue[MAX_MULTI_CVARS]; 204 int count; 205 qboolean strDef; 206 } multiDef_t; 207 208 typedef struct modelDef_s { 209 int angle; 210 vec3_t origin; 211 float fov_x; 212 float fov_y; 213 int rotationSpeed; 214 } modelDef_t; 215 216 #define CVAR_ENABLE 0x00000001 217 #define CVAR_DISABLE 0x00000002 218 #define CVAR_SHOW 0x00000004 219 #define CVAR_HIDE 0x00000008 220 221 typedef struct itemDef_s { 222 Window window; // common positional, border, style, layout info 223 Rectangle textRect; // rectangle the text ( if any ) consumes 224 int type; // text, button, radiobutton, checkbox, textfield, listbox, combo 225 int alignment; // left center right 226 int textalignment; // ( optional ) alignment for text within rect based on text width 227 float textalignx; // ( optional ) text alignment x coord 228 float textaligny; // ( optional ) text alignment x coord 229 float textscale; // scale percentage from 72pts 230 int textStyle; // ( optional ) style, normal and shadowed are it for now 231 const char *text; // display text 232 void *parent; // menu owner 233 qhandle_t asset; // handle to asset 234 const char *mouseEnterText; // mouse enter script 235 const char *mouseExitText; // mouse exit script 236 const char *mouseEnter; // mouse enter script 237 const char *mouseExit; // mouse exit script 238 const char *action; // select script 239 const char *onFocus; // select script 240 const char *leaveFocus; // select script 241 const char *cvar; // associated cvar 242 const char *cvarTest; // associated cvar for enable actions 243 const char *enableCvar; // enable, disable, show, or hide based on value, this can contain a list 244 int cvarFlags; // what type of action to take on cvarenables 245 sfxHandle_t focusSound; 246 int numColors; // number of color ranges 247 colorRangeDef_t colorRanges[MAX_COLOR_RANGES]; 248 float special; // used for feeder id's etc.. diff per type 249 int cursorPos; // cursor position in characters 250 void *typeData; // type specific data ptr's 251 } itemDef_t; 252 253 typedef struct { 254 Window window; 255 const char *font; // font 256 qboolean fullScreen; // covers entire screen 257 int itemCount; // number of items; 258 int fontIndex; // 259 int cursorItem; // which item as the cursor 260 int fadeCycle; // 261 float fadeClamp; // 262 float fadeAmount; // 263 const char *onOpen; // run when the menu is first opened 264 const char *onClose; // run when the menu is closed 265 const char *onESC; // run when the menu is closed 266 const char *soundName; // background loop sound for menu 267 268 vec4_t focusColor; // focus color for items 269 vec4_t disableColor; // focus color for items 270 itemDef_t *items[MAX_MENUITEMS]; // items this menu contains 271 } menuDef_t; 272 273 typedef struct { 274 const char *fontStr; 275 const char *cursorStr; 276 const char *gradientStr; 277 fontInfo_t textFont; 278 fontInfo_t smallFont; 279 fontInfo_t bigFont; 280 qhandle_t cursor; 281 qhandle_t gradientBar; 282 qhandle_t scrollBarArrowUp; 283 qhandle_t scrollBarArrowDown; 284 qhandle_t scrollBarArrowLeft; 285 qhandle_t scrollBarArrowRight; 286 qhandle_t scrollBar; 287 qhandle_t scrollBarThumb; 288 qhandle_t buttonMiddle; 289 qhandle_t buttonInside; 290 qhandle_t solidBox; 291 qhandle_t sliderBar; 292 qhandle_t sliderThumb; 293 sfxHandle_t menuEnterSound; 294 sfxHandle_t menuExitSound; 295 sfxHandle_t menuBuzzSound; 296 sfxHandle_t itemFocusSound; 297 float fadeClamp; 298 int fadeCycle; 299 float fadeAmount; 300 float shadowX; 301 float shadowY; 302 vec4_t shadowColor; 303 float shadowFadeClamp; 304 qboolean fontRegistered; 305 306 // player settings 307 qhandle_t fxBasePic; 308 qhandle_t fxPic[7]; 309 qhandle_t crosshairShader[NUM_CROSSHAIRS]; 310 311 } cachedAssets_t; 312 313 typedef struct { 314 const char *name; 315 void (*handler) (itemDef_t *item, char** args); 316 } commandDef_t; 317 318 typedef struct { 319 qhandle_t (*registerShaderNoMip) (const char *p); 320 void (*setColor) (const vec4_t v); 321 void (*drawHandlePic) (float x, float y, float w, float h, qhandle_t asset); 322 void (*drawStretchPic) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); 323 void (*drawText) (float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style ); 324 int (*textWidth) (const char *text, float scale, int limit); 325 int (*textHeight) (const char *text, float scale, int limit); 326 qhandle_t (*registerModel) (const char *p); 327 void (*modelBounds) (qhandle_t model, vec3_t min, vec3_t max); 328 void (*fillRect) ( float x, float y, float w, float h, const vec4_t color); 329 void (*drawRect) ( float x, float y, float w, float h, float size, const vec4_t color); 330 void (*drawSides) (float x, float y, float w, float h, float size); 331 void (*drawTopBottom) (float x, float y, float w, float h, float size); 332 void (*clearScene) ( void ); 333 void (*addRefEntityToScene) (const refEntity_t *re ); 334 void (*renderScene) ( const refdef_t *fd ); 335 void (*registerFont) (const char *pFontname, int pointSize, fontInfo_t *font); 336 void (*ownerDrawItem) (float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, float special, float scale, vec4_t color, qhandle_t shader, int textStyle); 337 float (*getValue) (int ownerDraw); 338 qboolean (*ownerDrawVisible) (int flags); 339 void (*runScript)(char **p); 340 void (*getTeamColor)(vec4_t *color); 341 void (*getCVarString)(const char *cvar, char *buffer, int bufsize); 342 float (*getCVarValue)(const char *cvar); 343 void (*setCVar)(const char *cvar, const char *value); 344 void (*drawTextWithCursor)(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style); 345 void (*setOverstrikeMode)(qboolean b); 346 qboolean (*getOverstrikeMode)( void ); 347 void (*startLocalSound)( sfxHandle_t sfx, int channelNum ); 348 qboolean (*ownerDrawHandleKey)(int ownerDraw, int flags, float *special, int key); 349 int (*feederCount)(float feederID); 350 const char *(*feederItemText)(float feederID, int index, int column, qhandle_t *handle); 351 qhandle_t (*feederItemImage)(float feederID, int index); 352 void (*feederSelection)(float feederID, int index); 353 void (*keynumToStringBuf)( int keynum, char *buf, int buflen ); 354 void (*getBindingBuf)( int keynum, char *buf, int buflen ); 355 void (*setBinding)( int keynum, const char *binding ); 356 void (*executeText)(int exec_when, const char *text ); 357 void (*Error)(int level, const char *error, ...); 358 void (*Print)(const char *msg, ...); 359 void (*Pause)(qboolean b); 360 int (*ownerDrawWidth)(int ownerDraw, float scale); 361 sfxHandle_t (*registerSound)(const char *name, qboolean compressed); 362 void (*startBackgroundTrack)( const char *intro, const char *loop); 363 void (*stopBackgroundTrack)( void ); 364 int (*playCinematic)(const char *name, float x, float y, float w, float h); 365 void (*stopCinematic)(int handle); 366 void (*drawCinematic)(int handle, float x, float y, float w, float h); 367 void (*runCinematicFrame)(int handle); 368 369 float yscale; 370 float xscale; 371 float bias; 372 int realTime; 373 int frameTime; 374 int cursorx; 375 int cursory; 376 qboolean debug; 377 378 cachedAssets_t Assets; 379 380 glconfig_t glconfig; 381 qhandle_t whiteShader; 382 qhandle_t gradientImage; 383 qhandle_t cursor; 384 float FPS; 385 386 } displayContextDef_t; 387 388 const char *String_Alloc(const char *p); 389 void String_Init( void ); 390 void String_Report( void ); 391 void Init_Display(displayContextDef_t *dc); 392 void Display_ExpandMacros(char * buff); 393 void Menu_Init(menuDef_t *menu); 394 void Item_Init(itemDef_t *item); 395 void Menu_PostParse(menuDef_t *menu); 396 menuDef_t *Menu_GetFocused( void ); 397 void Menu_HandleKey(menuDef_t *menu, int key, qboolean down); 398 void Menu_HandleMouseMove(menuDef_t *menu, float x, float y); 399 void Menu_ScrollFeeder(menuDef_t *menu, int feeder, qboolean down); 400 qboolean Float_Parse(char **p, float *f); 401 qboolean Color_Parse(char **p, vec4_t *c); 402 qboolean Int_Parse(char **p, int *i); 403 qboolean Rect_Parse(char **p, rectDef_t *r); 404 qboolean String_Parse(char **p, const char **out); 405 qboolean Script_Parse(char **p, const char **out); 406 qboolean PC_Float_Parse(int handle, float *f); 407 qboolean PC_Color_Parse(int handle, vec4_t *c); 408 qboolean PC_Int_Parse(int handle, int *i); 409 qboolean PC_Rect_Parse(int handle, rectDef_t *r); 410 qboolean PC_String_Parse(int handle, const char **out); 411 qboolean PC_Script_Parse(int handle, const char **out); 412 int Menu_Count( void ); 413 void Menu_New(int handle); 414 void Menu_PaintAll( void ); 415 menuDef_t *Menus_ActivateByName(const char *p); 416 void Menu_Reset( void ); 417 qboolean Menus_AnyFullScreenVisible( void ); 418 void Menus_Activate(menuDef_t *menu); 419 420 displayContextDef_t *Display_GetContext( void ); 421 void *Display_CaptureItem(int x, int y); 422 qboolean Display_MouseMove(void *p, int x, int y); 423 int Display_CursorType(int x, int y); 424 qboolean Display_KeyBindPending( void ); 425 void Menus_OpenByName(const char *p); 426 menuDef_t *Menus_FindByName(const char *p); 427 void Menus_ShowByName(const char *p); 428 void Menus_CloseByName(const char *p); 429 void Display_HandleKey(int key, qboolean down, int x, int y); 430 void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t); 431 void Menus_CloseAll( void ); 432 void Menu_Paint(menuDef_t *menu, qboolean forcePaint); 433 void Menu_SetFeederSelection(menuDef_t *menu, int feeder, int index, const char *name); 434 void Display_CacheAll( void ); 435 436 void *UI_Alloc( int size ); 437 void UI_InitMemory( void ); 438 qboolean UI_OutOfMemory( void ); 439 440 void Controls_GetConfig( void ); 441 void Controls_SetConfig(qboolean restart); 442 void Controls_SetDefaults( void ); 443 444 int trap_PC_AddGlobalDefine( char *define ); 445 int trap_PC_LoadSource( const char *filename ); 446 int trap_PC_FreeSource( int handle ); 447 int trap_PC_ReadToken( int handle, pc_token_t *pc_token ); 448 int trap_PC_SourceFileAndLine( int handle, char *filename, int *line ); 449 450 #endif 451