00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __UI_SHARED_H
00023 #define __UI_SHARED_H
00024
00025
00026 #include "../game/q_shared.h"
00027 #include "../cgame/tr_types.h"
00028 #include "keycodes.h"
00029
00030 #include "../../ui/menudef.h"
00031
00032 #define MAX_MENUNAME 32
00033 #define MAX_ITEMTEXT 64
00034 #define MAX_ITEMACTION 64
00035 #define MAX_MENUDEFFILE 4096
00036 #define MAX_MENUFILE 32768
00037 #define MAX_MENUS 64
00038 #define MAX_MENUITEMS 96
00039 #define MAX_COLOR_RANGES 10
00040 #define MAX_OPEN_MENUS 16
00041
00042 #define WINDOW_MOUSEOVER 0x00000001 // mouse is over it, non exclusive
00043 #define WINDOW_HASFOCUS 0x00000002 // has cursor focus, exclusive
00044 #define WINDOW_VISIBLE 0x00000004 // is visible
00045 #define WINDOW_GREY 0x00000008 // is visible but grey ( non-active )
00046 #define WINDOW_DECORATION 0x00000010 // for decoration only, no mouse, keyboard, etc..
00047 #define WINDOW_FADINGOUT 0x00000020 // fading out, non-active
00048 #define WINDOW_FADINGIN 0x00000040 // fading in
00049 #define WINDOW_MOUSEOVERTEXT 0x00000080 // mouse is over it, non exclusive
00050 #define WINDOW_INTRANSITION 0x00000100 // window is in transition
00051 #define WINDOW_FORECOLORSET 0x00000200 // forecolor was explicitly set ( used to color alpha images or not )
00052 #define WINDOW_HORIZONTAL 0x00000400 // for list boxes and sliders, vertical is default this is set of horizontal
00053 #define WINDOW_LB_LEFTARROW 0x00000800 // mouse is over left/up arrow
00054 #define WINDOW_LB_RIGHTARROW 0x00001000 // mouse is over right/down arrow
00055 #define WINDOW_LB_THUMB 0x00002000 // mouse is over thumb
00056 #define WINDOW_LB_PGUP 0x00004000 // mouse is over page up
00057 #define WINDOW_LB_PGDN 0x00008000 // mouse is over page down
00058 #define WINDOW_ORBITING 0x00010000 // item is in orbit
00059 #define WINDOW_OOB_CLICK 0x00020000 // close on out of bounds click
00060 #define WINDOW_WRAPPED 0x00040000 // manually wrap text
00061 #define WINDOW_AUTOWRAPPED 0x00080000 // auto wrap text
00062 #define WINDOW_FORCED 0x00100000 // forced open
00063 #define WINDOW_POPUP 0x00200000 // popup
00064 #define WINDOW_BACKCOLORSET 0x00400000 // backcolor was explicitly set
00065 #define WINDOW_TIMEDVISIBLE 0x00800000 // visibility timing ( NOT implemented )
00066
00067
00068
00069 #define CURSOR_NONE 0x00000001
00070 #define CURSOR_ARROW 0x00000002
00071 #define CURSOR_SIZER 0x00000004
00072
00073 #ifdef CGAME
00074 #define STRING_POOL_SIZE 128*1024
00075 #else
00076 #define STRING_POOL_SIZE 384*1024
00077 #endif
00078 #define MAX_STRING_HANDLES 4096
00079
00080 #define MAX_SCRIPT_ARGS 12
00081 #define MAX_EDITFIELD 256
00082
00083 #define ART_FX_BASE "menu/art/fx_base"
00084 #define ART_FX_BLUE "menu/art/fx_blue"
00085 #define ART_FX_CYAN "menu/art/fx_cyan"
00086 #define ART_FX_GREEN "menu/art/fx_grn"
00087 #define ART_FX_RED "menu/art/fx_red"
00088 #define ART_FX_TEAL "menu/art/fx_teal"
00089 #define ART_FX_WHITE "menu/art/fx_white"
00090 #define ART_FX_YELLOW "menu/art/fx_yel"
00091
00092 #define ASSET_GRADIENTBAR "ui/assets/gradientbar2.tga"
00093 #define ASSET_SCROLLBAR "ui/assets/scrollbar.tga"
00094 #define ASSET_SCROLLBAR_ARROWDOWN "ui/assets/scrollbar_arrow_dwn_a.tga"
00095 #define ASSET_SCROLLBAR_ARROWUP "ui/assets/scrollbar_arrow_up_a.tga"
00096 #define ASSET_SCROLLBAR_ARROWLEFT "ui/assets/scrollbar_arrow_left.tga"
00097 #define ASSET_SCROLLBAR_ARROWRIGHT "ui/assets/scrollbar_arrow_right.tga"
00098 #define ASSET_SCROLL_THUMB "ui/assets/scrollbar_thumb.tga"
00099 #define ASSET_SLIDER_BAR "ui/assets/slider2.tga"
00100 #define ASSET_SLIDER_THUMB "ui/assets/sliderbutt_1.tga"
00101 #define SCROLLBAR_SIZE 16.0
00102 #define SLIDER_WIDTH 96.0
00103 #define SLIDER_HEIGHT 16.0
00104 #define SLIDER_THUMB_WIDTH 12.0
00105 #define SLIDER_THUMB_HEIGHT 20.0
00106 #define NUM_CROSSHAIRS 10
00107
00108 typedef struct {
00109 const char *command;
00110 const char *args[MAX_SCRIPT_ARGS];
00111 } scriptDef_t;
00112
00113
00114 typedef struct {
00115 float x;
00116 float y;
00117 float w;
00118 float h;
00119 } rectDef_t;
00120
00121 typedef rectDef_t Rectangle;
00122
00123
00124 typedef struct {
00125 Rectangle rect;
00126 Rectangle rectClient;
00127 const char *name;
00128 const char *group;
00129 const char *cinematicName;
00130 int cinematic;
00131 int style;
00132 int border;
00133 int ownerDraw;
00134 int ownerDrawFlags;
00135 float borderSize;
00136 int flags;
00137 Rectangle rectEffects;
00138 Rectangle rectEffects2;
00139 int offsetTime;
00140 int nextTime;
00141 vec4_t foreColor;
00142 vec4_t backColor;
00143 vec4_t borderColor;
00144 vec4_t outlineColor;
00145 qhandle_t background;
00146 } windowDef_t;
00147
00148 typedef windowDef_t Window;
00149
00150 typedef struct {
00151 vec4_t color;
00152 float low;
00153 float high;
00154 } colorRangeDef_t;
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 #define MAX_LB_COLUMNS 16
00167
00168 typedef struct columnInfo_s {
00169 int pos;
00170 int width;
00171 int maxChars;
00172 } columnInfo_t;
00173
00174 typedef struct listBoxDef_s {
00175 int startPos;
00176 int endPos;
00177 int drawPadding;
00178 int cursorPos;
00179 float elementWidth;
00180 float elementHeight;
00181 int elementStyle;
00182 int numColumns;
00183 columnInfo_t columnInfo[MAX_LB_COLUMNS];
00184 const char *doubleClick;
00185 qboolean notselectable;
00186 } listBoxDef_t;
00187
00188 typedef struct editFieldDef_s {
00189 float minVal;
00190 float maxVal;
00191 float defVal;
00192 float range;
00193 int maxChars;
00194 int maxPaintChars;
00195 int paintOffset;
00196 } editFieldDef_t;
00197
00198 #define MAX_MULTI_CVARS 32
00199
00200 typedef struct multiDef_s {
00201 const char *cvarList[MAX_MULTI_CVARS];
00202 const char *cvarStr[MAX_MULTI_CVARS];
00203 float cvarValue[MAX_MULTI_CVARS];
00204 int count;
00205 qboolean strDef;
00206 } multiDef_t;
00207
00208 typedef struct modelDef_s {
00209 int angle;
00210 vec3_t origin;
00211 float fov_x;
00212 float fov_y;
00213 int rotationSpeed;
00214 } modelDef_t;
00215
00216 #define CVAR_ENABLE 0x00000001
00217 #define CVAR_DISABLE 0x00000002
00218 #define CVAR_SHOW 0x00000004
00219 #define CVAR_HIDE 0x00000008
00220
00221 typedef struct itemDef_s {
00222 Window window;
00223 Rectangle textRect;
00224 int type;
00225 int alignment;
00226 int textalignment;
00227 float textalignx;
00228 float textaligny;
00229 float textscale;
00230 int textStyle;
00231 const char *text;
00232 void *parent;
00233 qhandle_t asset;
00234 const char *mouseEnterText;
00235 const char *mouseExitText;
00236 const char *mouseEnter;
00237 const char *mouseExit;
00238 const char *action;
00239 const char *onFocus;
00240 const char *leaveFocus;
00241 const char *cvar;
00242 const char *cvarTest;
00243 const char *enableCvar;
00244 int cvarFlags;
00245 sfxHandle_t focusSound;
00246 int numColors;
00247 colorRangeDef_t colorRanges[MAX_COLOR_RANGES];
00248 float special;
00249 int cursorPos;
00250 void *typeData;
00251 } itemDef_t;
00252
00253 typedef struct {
00254 Window window;
00255 const char *font;
00256 qboolean fullScreen;
00257 int itemCount;
00258 int fontIndex;
00259 int cursorItem;
00260 int fadeCycle;
00261 float fadeClamp;
00262 float fadeAmount;
00263 const char *onOpen;
00264 const char *onClose;
00265 const char *onESC;
00266 const char *soundName;
00267
00268 vec4_t focusColor;
00269 vec4_t disableColor;
00270 itemDef_t *items[MAX_MENUITEMS];
00271 } menuDef_t;
00272
00273 typedef struct {
00274 const char *fontStr;
00275 const char *cursorStr;
00276 const char *gradientStr;
00277 fontInfo_t textFont;
00278 fontInfo_t smallFont;
00279 fontInfo_t bigFont;
00280 qhandle_t cursor;
00281 qhandle_t gradientBar;
00282 qhandle_t scrollBarArrowUp;
00283 qhandle_t scrollBarArrowDown;
00284 qhandle_t scrollBarArrowLeft;
00285 qhandle_t scrollBarArrowRight;
00286 qhandle_t scrollBar;
00287 qhandle_t scrollBarThumb;
00288 qhandle_t buttonMiddle;
00289 qhandle_t buttonInside;
00290 qhandle_t solidBox;
00291 qhandle_t sliderBar;
00292 qhandle_t sliderThumb;
00293 sfxHandle_t menuEnterSound;
00294 sfxHandle_t menuExitSound;
00295 sfxHandle_t menuBuzzSound;
00296 sfxHandle_t itemFocusSound;
00297 float fadeClamp;
00298 int fadeCycle;
00299 float fadeAmount;
00300 float shadowX;
00301 float shadowY;
00302 vec4_t shadowColor;
00303 float shadowFadeClamp;
00304 qboolean fontRegistered;
00305
00306
00307 qhandle_t fxBasePic;
00308 qhandle_t fxPic[7];
00309 qhandle_t crosshairShader[NUM_CROSSHAIRS];
00310
00311 } cachedAssets_t;
00312
00313 typedef struct {
00314 const char *name;
00315 void (*handler) (itemDef_t *item, char** args);
00316 } commandDef_t;
00317
00318 typedef struct {
00319 qhandle_t (*registerShaderNoMip) (const char *p);
00320 void (*setColor) (const vec4_t v);
00321 void (*drawHandlePic) (float x, float y, float w, float h, qhandle_t asset);
00322 void (*drawStretchPic) (float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader );
00323 void (*drawText) (float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style );
00324 int (*textWidth) (const char *text, float scale, int limit);
00325 int (*textHeight) (const char *text, float scale, int limit);
00326 qhandle_t (*registerModel) (const char *p);
00327 void (*modelBounds) (qhandle_t model, vec3_t min, vec3_t max);
00328 void (*fillRect) ( float x, float y, float w, float h, const vec4_t color);
00329 void (*drawRect) ( float x, float y, float w, float h, float size, const vec4_t color);
00330 void (*drawSides) (float x, float y, float w, float h, float size);
00331 void (*drawTopBottom) (float x, float y, float w, float h, float size);
00332 void (*clearScene) ();
00333 void (*addRefEntityToScene) (const refEntity_t *re );
00334 void (*renderScene) ( const refdef_t *fd );
00335 void (*registerFont) (const char *pFontname, int pointSize, fontInfo_t *font);
00336 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);
00337 float (*getValue) (int ownerDraw);
00338 qboolean (*ownerDrawVisible) (int flags);
00339 void (*runScript)(char **p);
00340 void (*getTeamColor)(vec4_t *color);
00341 void (*getCVarString)(const char *cvar, char *buffer, int bufsize);
00342 float (*getCVarValue)(const char *cvar);
00343 void (*setCVar)(const char *cvar, const char *value);
00344 void (*drawTextWithCursor)(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style);
00345 void (*setOverstrikeMode)(qboolean b);
00346 qboolean (*getOverstrikeMode)();
00347 void (*startLocalSound)( sfxHandle_t sfx, int channelNum );
00348 qboolean (*ownerDrawHandleKey)(int ownerDraw, int flags, float *special, int key);
00349 int (*feederCount)(float feederID);
00350 const char *(*feederItemText)(float feederID, int index, int column, qhandle_t *handle);
00351 qhandle_t (*feederItemImage)(float feederID, int index);
00352 void (*feederSelection)(float feederID, int index);
00353 void (*keynumToStringBuf)( int keynum, char *buf, int buflen );
00354 void (*getBindingBuf)( int keynum, char *buf, int buflen );
00355 void (*setBinding)( int keynum, const char *binding );
00356 void (*executeText)(int exec_when, const char *text );
00357 void (*Error)(int level, const char *error, ...);
00358 void (*Print)(const char *msg, ...);
00359 void (*Pause)(qboolean b);
00360 int (*ownerDrawWidth)(int ownerDraw, float scale);
00361 sfxHandle_t (*registerSound)(const char *name, qboolean compressed);
00362 void (*startBackgroundTrack)( const char *intro, const char *loop);
00363 void (*stopBackgroundTrack)();
00364 int (*playCinematic)(const char *name, float x, float y, float w, float h);
00365 void (*stopCinematic)(int handle);
00366 void (*drawCinematic)(int handle, float x, float y, float w, float h);
00367 void (*runCinematicFrame)(int handle);
00368
00369 float yscale;
00370 float xscale;
00371 float bias;
00372 int realTime;
00373 int frameTime;
00374 int cursorx;
00375 int cursory;
00376 qboolean debug;
00377
00378 cachedAssets_t Assets;
00379
00380 glconfig_t glconfig;
00381 qhandle_t whiteShader;
00382 qhandle_t gradientImage;
00383 qhandle_t cursor;
00384 float FPS;
00385
00386 } displayContextDef_t;
00387
00388 const char *String_Alloc(const char *p);
00389 void String_Init();
00390 void String_Report();
00391 void Init_Display(displayContextDef_t *dc);
00392 void Display_ExpandMacros(char * buff);
00393 void Menu_Init(menuDef_t *menu);
00394 void Item_Init(itemDef_t *item);
00395 void Menu_PostParse(menuDef_t *menu);
00396 menuDef_t *Menu_GetFocused();
00397 void Menu_HandleKey(menuDef_t *menu, int key, qboolean down);
00398 void Menu_HandleMouseMove(menuDef_t *menu, float x, float y);
00399 void Menu_ScrollFeeder(menuDef_t *menu, int feeder, qboolean down);
00400 qboolean Float_Parse(char **p, float *f);
00401 qboolean Color_Parse(char **p, vec4_t *c);
00402 qboolean Int_Parse(char **p, int *i);
00403 qboolean Rect_Parse(char **p, rectDef_t *r);
00404 qboolean String_Parse(char **p, const char **out);
00405 qboolean Script_Parse(char **p, const char **out);
00406 qboolean PC_Float_Parse(int handle, float *f);
00407 qboolean PC_Color_Parse(int handle, vec4_t *c);
00408 qboolean PC_Int_Parse(int handle, int *i);
00409 qboolean PC_Rect_Parse(int handle, rectDef_t *r);
00410 qboolean PC_String_Parse(int handle, const char **out);
00411 qboolean PC_Script_Parse(int handle, const char **out);
00412 int Menu_Count();
00413 void Menu_New(int handle);
00414 void Menu_PaintAll();
00415 menuDef_t *Menus_ActivateByName(const char *p);
00416 void Menu_Reset();
00417 qboolean Menus_AnyFullScreenVisible();
00418 void Menus_Activate(menuDef_t *menu);
00419
00420 displayContextDef_t *Display_GetContext();
00421 void *Display_CaptureItem(int x, int y);
00422 qboolean Display_MouseMove(void *p, int x, int y);
00423 int Display_CursorType(int x, int y);
00424 qboolean Display_KeyBindPending();
00425 void Menus_OpenByName(const char *p);
00426 menuDef_t *Menus_FindByName(const char *p);
00427 void Menus_ShowByName(const char *p);
00428 void Menus_CloseByName(const char *p);
00429 void Display_HandleKey(int key, qboolean down, int x, int y);
00430 void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t);
00431 void Menus_CloseAll();
00432 void Menu_Paint(menuDef_t *menu, qboolean forcePaint);
00433 void Menu_SetFeederSelection(menuDef_t *menu, int feeder, int index, const char *name);
00434 void Display_CacheAll();
00435
00436 void *UI_Alloc( int size );
00437 void UI_InitMemory( void );
00438 qboolean UI_OutOfMemory();
00439
00440 void Controls_GetConfig( void );
00441 void Controls_SetConfig(qboolean restart);
00442 void Controls_SetDefaults( void );
00443
00444 int trap_PC_AddGlobalDefine( char *define );
00445 int trap_PC_LoadSource( const char *filename );
00446 int trap_PC_FreeSource( int handle );
00447 int trap_PC_ReadToken( int handle, pc_token_t *pc_token );
00448 int trap_PC_SourceFileAndLine( int handle, char *filename, int *line );
00449
00450 #endif