1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 // 21 // ui_local.h 22 // UI attributes CGame doesn't need to see 23 // 24 25 #ifndef __UI_LOCAL_H__ 26 #define __UI_LOCAL_H__ 27 28 #include "../cg_local.h" 29 30 /* 31 ============================================================================= 32 33 SCALING 34 35 ============================================================================= 36 */ 37 38 #define UI_HSCALE ((float)(cg.refConfig.vidWidth / 640.0)) 39 #define UI_VSCALE ((float)(cg.refConfig.vidHeight / 480.0)) 40 41 #define UI_SCALE ((float)(cg.refConfig.vidWidth / 640.0)) 42 43 #define UIFT_SCALE (UI_SCALE) 44 #define UIFT_SIZE (8 * UIFT_SCALE) 45 #define UIFT_SIZEINC (UIFT_SIZE) 46 47 #define UIFT_SCALEMED (UI_SCALE*1.25) 48 #define UIFT_SIZEMED (8 * UIFT_SCALEMED) 49 #define UIFT_SIZEINCMED (UIFT_SIZEMED) 50 51 #define UIFT_SCALELG (UI_SCALE*1.5) 52 #define UIFT_SIZELG (8 * UIFT_SCALELG) 53 #define UIFT_SIZEINCLG (UIFT_SIZELG) 54 55 #define UISCALE_TYPE(flags) ((flags&UIF_LARGE) ? UIFT_SCALELG : (flags&UIF_MEDIUM) ? UIFT_SCALEMED : UIFT_SCALE) 56 #define UISIZE_TYPE(flags) ((flags&UIF_LARGE) ? UIFT_SIZELG : (flags&UIF_MEDIUM) ? UIFT_SIZEMED : UIFT_SIZE) 57 #define UISIZEINC_TYPE(flags) ((flags&UIF_LARGE) ? UIFT_SIZEINCLG : (flags&UIF_MEDIUM) ? UIFT_SIZEINCMED : UIFT_SIZEINC) 58 59 /* 60 ============================================================================= 61 62 UI FRAMEWORK 63 64 ============================================================================= 65 */ 66 67 #define MAX_UI_DEPTH 32 68 #define MAX_UI_ITEMS 128 69 70 // Framework flags 71 enum { 72 FWF_CENTERHEIGHT = 1 << 0, 73 FWF_INTERFACE = 1 << 1, 74 }; 75 76 typedef struct uiFrameWork_s { 77 qBool locked; 78 qBool initialized; 79 int flags; 80 81 float x, y; 82 83 int cursor; // Item last selected 84 int numItems; 85 void *items[MAX_UI_ITEMS]; 86 87 char *statusBar; 88 89 void (*cursorDraw) (struct uiFrameWork_s *m); 90 } uiFrameWork_t; 91 92 /* 93 ============================================================================= 94 95 UI ITEMS 96 97 ============================================================================= 98 */ 99 100 // Item types 101 enum { 102 UITYPE_ACTION, 103 UITYPE_FIELD, 104 UITYPE_IMAGE, 105 UITYPE_SLIDER, 106 UITYPE_SPINCONTROL 107 }; 108 109 // Item flags 110 enum { 111 UIF_LEFT_JUSTIFY = 1 << 0, 112 UIF_CENTERED = 1 << 1, 113 114 UIF_NUMBERSONLY = 1 << 2, 115 116 UIF_SHADOW = 1 << 3, 117 118 UIF_MEDIUM = 1 << 4, 119 UIF_LARGE = 1 << 5, 120 UIF_NOTOOLTIP = 1 << 6, 121 122 UIF_NOSELECT = 1 << 7, 123 UIF_DBLCLICK = 1 << 8, 124 UIF_SELONLY = 1 << 9, 125 UIF_NOSELBAR = 1 << 10, 126 UIF_FORCESELBAR = 1 << 11 127 }; 128 129 #define RCOLUMN_OFFSET (UIFT_SIZE*2) 130 #define LCOLUMN_OFFSET (-(RCOLUMN_OFFSET)) 131 132 #define SLIDER_RANGE 10 133 134 typedef struct uiCommon_s { 135 int type; 136 uint32 flags; 137 138 char *name; 139 140 float x; 141 float y; 142 143 uiFrameWork_t *parent; 144 int cursorOffset; 145 int localData[4]; 146 147 char *statusBar; 148 float topLeft[2]; // top left for mouse collision 149 float botRight[2]; // bottom right for mouse collision 150 151 void (*callBack) (void *self); 152 153 void (*statusBarFunc) (void *self); 154 void (*ownerDraw) (void *self); 155 void (*cursorDraw) (void *self); 156 } uiCommon_t; 157 158 typedef struct uiAction_s { 159 uiCommon_t generic; 160 } uiAction_t; 161 162 typedef struct uiField_s { 163 uiCommon_t generic; 164 165 char buffer[80]; 166 int cursor; 167 168 int length; 169 int visibleLength; 170 int visibleOffset; 171 } uiField_t; 172 173 typedef struct uiList_s { 174 uiCommon_t generic; 175 176 int curValue; 177 178 char **itemNames; 179 int numItemNames; 180 } uiList_t; 181 182 typedef struct uiImage_s { 183 uiCommon_t generic; 184 185 struct shader_s *shader; 186 struct shader_s *hoverShader; 187 188 int width; 189 int height; 190 } uiImage_t; 191 192 typedef struct uiSlider_s { 193 uiCommon_t generic; 194 195 float minValue; 196 float maxValue; 197 float curValue; 198 199 float range; 200 } uiSlider_t; 201 202 /* 203 ============================================================================= 204 205 UI STATE 206 207 ============================================================================= 208 */ 209 210 typedef struct uiState_s { 211 // Cursor information 212 float cursorX; 213 float cursorY; 214 215 int cursorW; 216 int cursorH; 217 218 qBool newCursorItem; // Item changed, trigger sounds 219 qBool cursorOverItem; // Mouse over an item? 220 qBool cursorLock; // Locks mouse cursor movement 221 void *cursorItem; // Item mouse is over or keyboard moved to 222 void *mouseItem; // Item mouse is over 223 void *selectedItem; // For SELONLY items 224 225 // Active interface information 226 uiFrameWork_t *activeUI; 227 void (*drawFunc) (void); 228 struct sfx_s *(*closeFunc) (void); 229 struct sfx_s *(*keyFunc) (uiFrameWork_t *fw, keyNum_t keyNum); 230 } uiState_t; 231 232 extern uiState_t uiState; 233 234 /* 235 ============================================================================= 236 237 CURSOR 238 239 ============================================================================= 240 */ 241 242 void UI_DrawMouseCursor (void); 243 void UI_UpdateMousePos (void); 244 void UI_MoveMouse (float x, float y); 245 void UI_SetupBounds (uiFrameWork_t *menu); 246 247 void UI_CursorInit (void); 248 void UI_CursorShutdown (void); 249 250 /* 251 ============================================================================= 252 253 CVARS 254 255 ============================================================================= 256 */ 257 258 extern cVar_t *ui_filtermouse; 259 extern cVar_t *ui_sensitivity; 260 261 /* 262 ============================================================================= 263 264 SUPPORTING FUNCTIONS 265 266 ============================================================================= 267 */ 268 269 // 270 // ui_backend.c 271 // 272 273 void UI_InitMedia (void); 274 void UI_InitSoundMedia (void); 275 276 void UI_Init (void); 277 void UI_Shutdown (void); 278 279 void UI_PushInterface (uiFrameWork_t *fw, void (*drawFunc) (void), struct sfx_s *(*closeFunc) (void), struct sfx_s *(*keyFunc) (uiFrameWork_t *fw, keyNum_t keyNum)); 280 void UI_PopInterface (void); 281 void UI_ForceAllOff (void); 282 283 void UI_StartFramework (uiFrameWork_t *fw, int flags); 284 void UI_FinishFramework (uiFrameWork_t *fw, qBool lock); 285 286 // 287 // ui_draw.c 288 // 289 290 void UI_DrawTextBox (float x, float y, float scale, int width, int lines); 291 void UI_DrawInterface (uiFrameWork_t *fw); 292 void UI_Refresh (qBool fullScreen); 293 294 // 295 // ui_items.c 296 // 297 298 void UI_SetupItem (void *item); 299 void UI_AddItem (uiFrameWork_t *fw, void *item); 300 void UI_RemoveItem (uiFrameWork_t *fw, void *item); 301 302 void UI_AdjustCursor (uiFrameWork_t *fw, int dir); 303 void *UI_ItemAtCursor (uiFrameWork_t *fw); 304 void UI_SelectItem (uiCommon_t *item); 305 qBool UI_SlideItem (uiCommon_t *item, int dir); 306 307 // 308 // ui_keys.c 309 // 310 311 void UI_KeyDown (int keyNum, qBool isDown); 312 struct sfx_s *UI_DefaultKeyFunc (uiFrameWork_t *fw, keyNum_t keyNum); 313 314 #endif // __UI_LOCAL_H__ 315