Debian Codegraph @

code/ui/ui_shared.h

raw symbols SCIP
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 "../renderercommon/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 qboolean videoMode;
207 } multiDef_t;
208
209 typedef struct modelDef_s {
210 int angle;
211 vec3_t origin;
212 float fov_x;
213 float fov_y;
214 int rotationSpeed;
215 } modelDef_t;
216
217 #define CVAR_ENABLE 0x00000001
218 #define CVAR_DISABLE 0x00000002
219 #define CVAR_SHOW 0x00000004
220 #define CVAR_HIDE 0x00000008
221
222 typedef struct itemDef_s {
223 Window window; // common positional, border, style, layout info
224 Rectangle textRect; // rectangle the text ( if any ) consumes
225 int type; // text, button, radiobutton, checkbox, textfield, listbox, combo
226 int alignment; // left center right
227 int textalignment; // ( optional ) alignment for text within rect based on text width
228 float textalignx; // ( optional ) text alignment x coord
229 float textaligny; // ( optional ) text alignment x coord
230 float textscale; // scale percentage from 72pts
231 int textStyle; // ( optional ) style, normal and shadowed are it for now
232 const char *text; // display text
233 void *parent; // menu owner
234 qhandle_t asset; // handle to asset
235 const char *mouseEnterText; // mouse enter script
236 const char *mouseExitText; // mouse exit script
237 const char *mouseEnter; // mouse enter script
238 const char *mouseExit; // mouse exit script
239 const char *action; // select script
240 const char *onFocus; // select script
241 const char *leaveFocus; // select script
242 const char *cvar; // associated cvar
243 const char *cvarTest; // associated cvar for enable actions
244 const char *enableCvar; // enable, disable, show, or hide based on value, this can contain a list
245 int cvarFlags; // what type of action to take on cvarenables
246 sfxHandle_t focusSound;
247 int numColors; // number of color ranges
248 colorRangeDef_t colorRanges[MAX_COLOR_RANGES];
249 float special; // used for feeder id's etc.. diff per type
250 int cursorPos; // cursor position in characters
251 void *typeData; // type specific data ptr's
252 } itemDef_t;
253
254 typedef struct {
255 Window window;
256 const char *font; // font
257 qboolean fullScreen; // covers entire screen
258 int itemCount; // number of items;
259 int fontIndex; //
260 int cursorItem; // which item as the cursor
261 int fadeCycle; //
262 float fadeClamp; //
263 float fadeAmount; //
264 const char *onOpen; // run when the menu is first opened
265 const char *onClose; // run when the menu is closed
266 const char *onESC; // run when the menu is closed
267 const char *soundName; // background loop sound for menu
268
269 vec4_t focusColor; // focus color for items
270 vec4_t disableColor; // focus color for items
271 itemDef_t *items[MAX_MENUITEMS]; // items this menu contains
272 } menuDef_t;
273
274 typedef struct {
275 const char *fontStr;
276 const char *cursorStr;
277 const char *gradientStr;
278 fontInfo_t textFont;
279 fontInfo_t smallFont;
280 fontInfo_t bigFont;
281 qhandle_t cursor;
282 qhandle_t gradientBar;
283 qhandle_t scrollBarArrowUp;
284 qhandle_t scrollBarArrowDown;
285 qhandle_t scrollBarArrowLeft;
286 qhandle_t scrollBarArrowRight;
287 qhandle_t scrollBar;
288 qhandle_t scrollBarThumb;
289 qhandle_t buttonMiddle;
290 qhandle_t buttonInside;
291 qhandle_t solidBox;
292 qhandle_t sliderBar;
293 qhandle_t sliderThumb;
294 sfxHandle_t menuEnterSound;
295 sfxHandle_t menuExitSound;
296 sfxHandle_t menuBuzzSound;
297 sfxHandle_t itemFocusSound;
298 float fadeClamp;
299 int fadeCycle;
300 float fadeAmount;
301 float shadowX;
302 float shadowY;
303 vec4_t shadowColor;
304 float shadowFadeClamp;
305 qboolean fontRegistered;
306
307 // player settings
308 qhandle_t fxBasePic;
309 qhandle_t fxPic[7];
310 qhandle_t crosshairShader[NUM_CROSSHAIRS];
311
312 } cachedAssets_t;
313
314 typedef struct {
315 const char *name;
316 void (*handler) (itemDef_t *item, char** args);
317 } commandDef_t;
318
319 typedef struct {
320 qhandle_t (*registerShaderNoMip) (const char *p);
321 void (*setColor) (const vec4_t v);
322 void (*drawHandlePic) (float x, float y, float w, float h, qhandle_t asset);
323 void (*drawStretchPic) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader );
324 void (*drawText) (float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style );
325 int (*textWidth) (const char *text, float scale, int limit);
326 int (*textHeight) (const char *text, float scale, int limit);
327 qhandle_t (*registerModel) (const char *p);
328 void (*modelBounds) (qhandle_t model, vec3_t min, vec3_t max);
329 void (*fillRect) ( float x, float y, float w, float h, const vec4_t color);
330 void (*drawRect) ( float x, float y, float w, float h, float size, const vec4_t color);
331 void (*drawSides) (float x, float y, float w, float h, float size);
332 void (*drawTopBottom) (float x, float y, float w, float h, float size);
333 void (*clearScene) ( void );
334 void (*addRefEntityToScene) (const refEntity_t *re );
335 void (*renderScene) ( const refdef_t *fd );
336 void (*registerFont) (const char *pFontname, int pointSize, fontInfo_t *font);
337 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);
338 float (*getValue) (int ownerDraw);
339 qboolean (*ownerDrawVisible) (int flags);
340 void (*runScript)(char **p);
341 void (*getTeamColor)(vec4_t *color);
342 void (*getCVarString)(const char *cvar, char *buffer, int bufsize);
343 float (*getCVarValue)(const char *cvar);
344 void (*setCVar)(const char *cvar, const char *value);
345 void (*drawTextWithCursor)(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style);
346 void (*setOverstrikeMode)(qboolean b);
347 qboolean (*getOverstrikeMode)( void );
348 void (*startLocalSound)( sfxHandle_t sfx, int channelNum );
349 qboolean (*ownerDrawHandleKey)(int ownerDraw, int flags, float *special, int key);
350 int (*feederCount)(float feederID);
351 const char *(*feederItemText)(float feederID, int index, int column, qhandle_t *handle);
352 qhandle_t (*feederItemImage)(float feederID, int index);
353 void (*feederSelection)(float feederID, int index);
354 void (*keynumToStringBuf)( int keynum, char *buf, int buflen );
355 void (*getBindingBuf)( int keynum, char *buf, int buflen );
356 void (*setBinding)( int keynum, const char *binding );
357 void (*executeText)(int exec_when, const char *text );
358 void (*Error)(int level, const char *error, ...) Q_NO_RETURN Q_PRINTF_FUNC(2, 3);
359 void (*Print)(const char *msg, ...) Q_PRINTF_FUNC(1, 2);
360 void (*Pause)(qboolean b);
361 int (*ownerDrawWidth)(int ownerDraw, float scale);
362 sfxHandle_t (*registerSound)(const char *name, qboolean compressed);
363 void (*startBackgroundTrack)( const char *intro, const char *loop);
364 void (*stopBackgroundTrack)( void );
365 int (*playCinematic)(const char *name, float x, float y, float w, float h);
366 void (*stopCinematic)(int handle);
367 void (*drawCinematic)(int handle, float x, float y, float w, float h);
368 void (*runCinematicFrame)(int handle);
369
370 float yscale;
371 float xscale;
372 float bias;
373 int realTime;
374 int frameTime;
375 int cursorx;
376 int cursory;
377 qboolean debug;
378
379 cachedAssets_t Assets;
380
381 glconfig_t glconfig;
382 qhandle_t whiteShader;
383 qhandle_t gradientImage;
384 qhandle_t cursor;
385 float FPS;
386
387 } displayContextDef_t;
388
389 const char *String_Alloc(const char *p);
390 void String_Init( void );
391 void String_Report( void );
392 void Init_Display(displayContextDef_t *dc);
393 void Display_ExpandMacros(char * buff);
394 void Menu_Init(menuDef_t *menu);
395 void Item_Init(itemDef_t *item);
396 void Menu_PostParse(menuDef_t *menu);
397 menuDef_t *Menu_GetFocused( void );
398 void Menu_HandleKey(menuDef_t *menu, int key, qboolean down);
399 void Menu_HandleMouseMove(menuDef_t *menu, float x, float y);
400 void Menu_ScrollFeeder(menuDef_t *menu, int feeder, qboolean down);
401 qboolean Float_Parse(char **p, float *f);
402 qboolean Color_Parse(char **p, vec4_t *c);
403 qboolean Int_Parse(char **p, int *i);
404 qboolean Rect_Parse(char **p, rectDef_t *r);
405 qboolean String_Parse(char **p, const char **out);
406 qboolean Script_Parse(char **p, const char **out);
407 qboolean PC_Float_Parse(int handle, float *f);
408 qboolean PC_Color_Parse(int handle, vec4_t *c);
409 qboolean PC_Int_Parse(int handle, int *i);
410 qboolean PC_Rect_Parse(int handle, rectDef_t *r);
411 qboolean PC_String_Parse(int handle, const char **out);
412 qboolean PC_Script_Parse(int handle, const char **out);
413 int Menu_Count( void );
414 void Menu_New(int handle);
415 void Menu_PaintAll( void );
416 menuDef_t *Menus_ActivateByName(const char *p);
417 void Menu_Reset( void );
418 qboolean Menus_AnyFullScreenVisible( void );
419 void Menus_Activate(menuDef_t *menu);
420
421 int UI_SelectForKey(int key);
422 displayContextDef_t *Display_GetContext( void );
423 void *Display_CaptureItem(int x, int y);
424 qboolean Display_MouseMove(void *p, int x, int y);
425 int Display_CursorType(int x, int y);
426 qboolean Display_KeyBindPending( void );
427 void Menus_OpenByName(const char *p);
428 menuDef_t *Menus_FindByName(const char *p);
429 void Menus_ShowByName(const char *p);
430 void Menus_CloseByName(const char *p);
431 void Display_HandleKey(int key, qboolean down, int x, int y);
432 void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t);
433 void Menus_CloseAll( void );
434 void Menu_Paint(menuDef_t *menu, qboolean forcePaint);
435 void Menu_SetFeederSelection(menuDef_t *menu, int feeder, int index, const char *name);
436 void Display_CacheAll( void );
437
438 void *UI_Alloc( int size );
439 void UI_InitMemory( void );
440 qboolean UI_OutOfMemory( void );
441
442 void Controls_GetConfig( void );
443 void Controls_SetConfig(qboolean restart);
444 void Controls_SetDefaults( void );
445
446 int trap_PC_AddGlobalDefine( char *define );
447 int trap_PC_LoadSource( const char *filename );
448 int trap_PC_FreeSource( int handle );
449 int trap_PC_ReadToken( int handle, pc_token_t *pc_token );
450 int trap_PC_SourceFileAndLine( int handle, char *filename, int *line );
451
452 #endif