| 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 |
// |
| 23 |
// string allocation/managment |
| 24 |
|
| 25 |
#include "ui_shared.h" |
| 26 |
|
| 27 |
#define SCROLL_TIME_START 500 |
| 28 |
#define SCROLL_TIME_ADJUST 150 |
| 29 |
#define SCROLL_TIME_ADJUSTOFFSET 40 |
| 30 |
#define SCROLL_TIME_FLOOR 20 |
| 31 |
|
| 32 |
typedef struct scrollInfo_s { |
| 33 |
int nextScrollTime; |
| 34 |
int nextAdjustTime; |
| 35 |
int adjustValue; |
| 36 |
int scrollKey; |
| 37 |
float xStart; |
| 38 |
float yStart; |
| 39 |
itemDef_t *item; |
| 40 |
qboolean scrollDir; |
| 41 |
} scrollInfo_t; |
| 42 |
|
| 43 |
static scrollInfo_t scrollInfo; |
| 44 |
|
| 45 |
static void (*captureFunc) (void *p) = 0; |
| 46 |
static void *captureData = NULL; |
| 47 |
static itemDef_t *itemCapture = NULL; // item that has the mouse captured ( if any ) |
| 48 |
|
| 49 |
displayContextDef_t *DC = NULL; |
| 50 |
|
| 51 |
static qboolean g_waitingForKey = qfalse; |
| 52 |
static qboolean g_editingField = qfalse; |
| 53 |
|
| 54 |
static itemDef_t *g_bindItem = NULL; |
| 55 |
static itemDef_t *g_editItem = NULL; |
| 56 |
|
| 57 |
menuDef_t Menus[MAX_MENUS]; // defined menus |
| 58 |
int menuCount = 0; // how many |
| 59 |
|
| 60 |
menuDef_t *menuStack[MAX_OPEN_MENUS]; |
| 61 |
int openMenuCount = 0; |
| 62 |
|
| 63 |
static qboolean debugMode = qfalse; |
| 64 |
|
| 65 |
#define DOUBLE_CLICK_DELAY 300 |
| 66 |
static int lastListBoxClickTime = 0; |
| 67 |
|
| 68 |
void Item_RunScript(itemDef_t *item, const char *s); |
| 69 |
void Item_SetupKeywordHash(void); |
| 70 |
void Menu_SetupKeywordHash(void); |
| 71 |
int BindingIDFromName(const char *name); |
| 72 |
qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down); |
| 73 |
itemDef_t *Menu_SetPrevCursorItem(menuDef_t *menu); |
| 74 |
itemDef_t *Menu_SetNextCursorItem(menuDef_t *menu); |
| 75 |
static qboolean Menu_OverActiveItem(menuDef_t *menu, float x, float y); |
| 76 |
|
| 77 |
#ifdef CGAME |
| 78 |
#define MEM_POOL_SIZE 128 * 1024 |
| 79 |
#else |
| 80 |
#define MEM_POOL_SIZE 1024 * 1024 |
| 81 |
#endif |
| 82 |
|
| 83 |
static char memoryPool[MEM_POOL_SIZE]; |
| 84 |
static int allocPoint, outOfMemory; |
| 85 |
|
| 86 |
|
| 87 |
/* |
| 88 |
=============== |
| 89 |
UI_Alloc |
| 90 |
=============== |
| 91 |
*/ |
| 92 |
void *UI_Alloc( int size ) { |
| 93 |
char *p; |
| 94 |
|
| 95 |
if ( allocPoint + size > MEM_POOL_SIZE ) { |
| 96 |
outOfMemory = qtrue; |
| 97 |
if (DC->Print) { |
| 98 |
DC->Print("UI_Alloc: Failure. Out of memory!\n"); |
| 99 |
} |
| 100 |
//DC->trap_Print(S_COLOR_YELLOW"WARNING: UI Out of Memory!\n"); |
| 101 |
return NULL; |
| 102 |
} |
| 103 |
|
| 104 |
p = &memoryPool[allocPoint]; |
| 105 |
|
| 106 |
allocPoint += ( size + 15 ) & ~15; |
| 107 |
|
| 108 |
return p; |
| 109 |
} |
| 110 |
|
| 111 |
/* |
| 112 |
=============== |
| 113 |
UI_InitMemory |
| 114 |
=============== |
| 115 |
*/ |
| 116 |
void UI_InitMemory( void ) { |
| 117 |
allocPoint = 0; |
| 118 |
outOfMemory = qfalse; |
| 119 |
} |
| 120 |
|
| 121 |
qboolean UI_OutOfMemory( void ) { |
| 122 |
return outOfMemory; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
#define HASH_TABLE_SIZE 2048 |
| 130 |
/* |
| 131 |
================ |
| 132 |
return a hash value for the string |
| 133 |
================ |
| 134 |
*/ |
| 135 |
static unsigned hashForString(const char *str) { |
| 136 |
int i; |
| 137 |
unsigned hash; |
| 138 |
char letter; |
| 139 |
|
| 140 |
hash = 0; |
| 141 |
i = 0; |
| 142 |
while (str[i] != '\0') { |
| 143 |
letter = tolower(str[i]); |
| 144 |
hash+=(unsigned)(letter)*(i+119); |
| 145 |
i++; |
| 146 |
} |
| 147 |
hash &= (HASH_TABLE_SIZE-1); |
| 148 |
return hash; |
| 149 |
} |
| 150 |
|
| 151 |
typedef struct stringDef_s { |
| 152 |
struct stringDef_s *next; |
| 153 |
const char *str; |
| 154 |
} stringDef_t; |
| 155 |
|
| 156 |
static int strPoolIndex = 0; |
| 157 |
static char strPool[STRING_POOL_SIZE]; |
| 158 |
|
| 159 |
static int strHandleCount = 0; |
| 160 |
static stringDef_t *strHandle[HASH_TABLE_SIZE]; |
| 161 |
|
| 162 |
|
| 163 |
const char *String_Alloc(const char *p) { |
| 164 |
int len; |
| 165 |
unsigned hash; |
| 166 |
stringDef_t *str, *last; |
| 167 |
static const char *staticNULL = ""; |
| 168 |
|
| 169 |
if (p == NULL) { |
| 170 |
return NULL; |
| 171 |
} |
| 172 |
|
| 173 |
if (*p == 0) { |
| 174 |
return staticNULL; |
| 175 |
} |
| 176 |
|
| 177 |
hash = hashForString(p); |
| 178 |
|
| 179 |
str = strHandle[hash]; |
| 180 |
while (str) { |
| 181 |
if (strcmp(p, str->str) == 0) { |
| 182 |
return str->str; |
| 183 |
} |
| 184 |
str = str->next; |
| 185 |
} |
| 186 |
|
| 187 |
len = strlen(p); |
| 188 |
if (len + strPoolIndex + 1 < STRING_POOL_SIZE) { |
| 189 |
int ph = strPoolIndex; |
| 190 |
strcpy(&strPool[strPoolIndex], p); |
| 191 |
strPoolIndex += len + 1; |
| 192 |
|
| 193 |
str = strHandle[hash]; |
| 194 |
last = str; |
| 195 |
while (str && str->next) { |
| 196 |
last = str; |
| 197 |
str = str->next; |
| 198 |
} |
| 199 |
|
| 200 |
str = UI_Alloc(sizeof(stringDef_t)); |
| 201 |
str->next = NULL; |
| 202 |
str->str = &strPool[ph]; |
| 203 |
if (last) { |
| 204 |
last->next = str; |
| 205 |
} else { |
| 206 |
strHandle[hash] = str; |
| 207 |
} |
| 208 |
return &strPool[ph]; |
| 209 |
} |
| 210 |
return NULL; |
| 211 |
} |
| 212 |
|
| 213 |
void String_Report(void) { |
| 214 |
float f; |
| 215 |
Com_Printf("Memory/String Pool Info\n"); |
| 216 |
Com_Printf("----------------\n"); |
| 217 |
f = strPoolIndex; |
| 218 |
f /= STRING_POOL_SIZE; |
| 219 |
f *= 100; |
| 220 |
Com_Printf("String Pool is %.1f%% full, %i bytes out of %i used.\n", f, strPoolIndex, STRING_POOL_SIZE); |
| 221 |
f = allocPoint; |
| 222 |
f /= MEM_POOL_SIZE; |
| 223 |
f *= 100; |
| 224 |
Com_Printf("Memory Pool is %.1f%% full, %i bytes out of %i used.\n", f, allocPoint, MEM_POOL_SIZE); |
| 225 |
} |
| 226 |
|
| 227 |
/* |
| 228 |
================= |
| 229 |
String_Init |
| 230 |
================= |
| 231 |
*/ |
| 232 |
void String_Init(void) { |
| 233 |
int i; |
| 234 |
for (i = 0; i < HASH_TABLE_SIZE; i++) { |
| 235 |
strHandle[i] = NULL; |
| 236 |
} |
| 237 |
strHandleCount = 0; |
| 238 |
strPoolIndex = 0; |
| 239 |
menuCount = 0; |
| 240 |
openMenuCount = 0; |
| 241 |
UI_InitMemory(); |
| 242 |
Item_SetupKeywordHash(); |
| 243 |
Menu_SetupKeywordHash(); |
| 244 |
if (DC && DC->getBindingBuf) { |
| 245 |
Controls_GetConfig(); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
/* |
| 250 |
================= |
| 251 |
PC_SourceWarning |
| 252 |
================= |
| 253 |
*/ |
| 254 |
void PC_SourceWarning(int handle, char *format, ...) { |
| 255 |
int line; |
| 256 |
char filename[128]; |
| 257 |
va_list argptr; |
| 258 |
static char string[4096]; |
| 259 |
|
| 260 |
va_start (argptr, format); |
| 261 |
Q_vsnprintf (string, sizeof(string), format, argptr); |
| 262 |
va_end (argptr); |
| 263 |
|
| 264 |
filename[0] = '\0'; |
| 265 |
line = 0; |
| 266 |
trap_PC_SourceFileAndLine(handle, filename, &line); |
| 267 |
|
| 268 |
Com_Printf(S_COLOR_YELLOW "WARNING: %s, line %d: %s\n", filename, line, string); |
| 269 |
} |
| 270 |
|
| 271 |
/* |
| 272 |
================= |
| 273 |
PC_SourceError |
| 274 |
================= |
| 275 |
*/ |
| 276 |
void PC_SourceError(int handle, char *format, ...) { |
| 277 |
int line; |
| 278 |
char filename[128]; |
| 279 |
va_list argptr; |
| 280 |
static char string[4096]; |
| 281 |
|
| 282 |
va_start (argptr, format); |
| 283 |
Q_vsnprintf (string, sizeof(string), format, argptr); |
| 284 |
va_end (argptr); |
| 285 |
|
| 286 |
filename[0] = '\0'; |
| 287 |
line = 0; |
| 288 |
trap_PC_SourceFileAndLine(handle, filename, &line); |
| 289 |
|
| 290 |
Com_Printf(S_COLOR_RED "ERROR: %s, line %d: %s\n", filename, line, string); |
| 291 |
} |
| 292 |
|
| 293 |
/* |
| 294 |
================= |
| 295 |
LerpColor |
| 296 |
================= |
| 297 |
*/ |
| 298 |
void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t) |
| 299 |
{ |
| 300 |
int i; |
| 301 |
|
| 302 |
// lerp and clamp each component |
| 303 |
for (i=0; i<4; i++) |
| 304 |
{ |
| 305 |
c[i] = a[i] + t*(b[i]-a[i]); |
| 306 |
if (c[i] < 0) |
| 307 |
c[i] = 0; |
| 308 |
else if (c[i] > 1.0) |
| 309 |
c[i] = 1.0; |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
/* |
| 314 |
================= |
| 315 |
Float_Parse |
| 316 |
================= |
| 317 |
*/ |
| 318 |
qboolean Float_Parse(char **p, float *f) { |
| 319 |
char *token; |
| 320 |
token = COM_ParseExt(p, qfalse); |
| 321 |
if (token && token[0] != 0) { |
| 322 |
*f = atof(token); |
| 323 |
return qtrue; |
| 324 |
} else { |
| 325 |
return qfalse; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
/* |
| 330 |
================= |
| 331 |
PC_Float_Parse |
| 332 |
================= |
| 333 |
*/ |
| 334 |
qboolean PC_Float_Parse(int handle, float *f) { |
| 335 |
pc_token_t token; |
| 336 |
int negative = qfalse; |
| 337 |
|
| 338 |
if (!trap_PC_ReadToken(handle, &token)) |
| 339 |
return qfalse; |
| 340 |
if (token.string[0] == '-') { |
| 341 |
if (!trap_PC_ReadToken(handle, &token)) |
| 342 |
return qfalse; |
| 343 |
negative = qtrue; |
| 344 |
} |
| 345 |
if (token.type != TT_NUMBER) { |
| 346 |
PC_SourceError(handle, "expected float but found %s\n", token.string); |
| 347 |
return qfalse; |
| 348 |
} |
| 349 |
if (negative) |
| 350 |
*f = -token.floatvalue; |
| 351 |
else |
| 352 |
*f = token.floatvalue; |
| 353 |
return qtrue; |
| 354 |
} |
| 355 |
|
| 356 |
/* |
| 357 |
================= |
| 358 |
Color_Parse |
| 359 |
================= |
| 360 |
*/ |
| 361 |
qboolean Color_Parse(char **p, vec4_t *c) { |
| 362 |
int i; |
| 363 |
float f; |
| 364 |
|
| 365 |
for (i = 0; i < 4; i++) { |
| 366 |
if (!Float_Parse(p, &f)) { |
| 367 |
return qfalse; |
| 368 |
} |
| 369 |
(*c)[i] = f; |
| 370 |
} |
| 371 |
return qtrue; |
| 372 |
} |
| 373 |
|
| 374 |
/* |
| 375 |
================= |
| 376 |
PC_Color_Parse |
| 377 |
================= |
| 378 |
*/ |
| 379 |
qboolean PC_Color_Parse(int handle, vec4_t *c) { |
| 380 |
int i; |
| 381 |
float f; |
| 382 |
|
| 383 |
for (i = 0; i < 4; i++) { |
| 384 |
if (!PC_Float_Parse(handle, &f)) { |
| 385 |
return qfalse; |
| 386 |
} |
| 387 |
(*c)[i] = f; |
| 388 |
} |
| 389 |
return qtrue; |
| 390 |
} |
| 391 |
|
| 392 |
/* |
| 393 |
================= |
| 394 |
Int_Parse |
| 395 |
================= |
| 396 |
*/ |
| 397 |
qboolean Int_Parse(char **p, int *i) { |
| 398 |
char *token; |
| 399 |
token = COM_ParseExt(p, qfalse); |
| 400 |
|
| 401 |
if (token && token[0] != 0) { |
| 402 |
*i = atoi(token); |
| 403 |
return qtrue; |
| 404 |
} else { |
| 405 |
return qfalse; |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
/* |
| 410 |
================= |
| 411 |
PC_Int_Parse |
| 412 |
================= |
| 413 |
*/ |
| 414 |
qboolean PC_Int_Parse(int handle, int *i) { |
| 415 |
pc_token_t token; |
| 416 |
int negative = qfalse; |
| 417 |
|
| 418 |
if (!trap_PC_ReadToken(handle, &token)) |
| 419 |
return qfalse; |
| 420 |
if (token.string[0] == '-') { |
| 421 |
if (!trap_PC_ReadToken(handle, &token)) |
| 422 |
return qfalse; |
| 423 |
negative = qtrue; |
| 424 |
} |
| 425 |
if (token.type != TT_NUMBER) { |
| 426 |
PC_SourceError(handle, "expected integer but found %s\n", token.string); |
| 427 |
return qfalse; |
| 428 |
} |
| 429 |
*i = token.intvalue; |
| 430 |
if (negative) |
| 431 |
*i = - *i; |
| 432 |
return qtrue; |
| 433 |
} |
| 434 |
|
| 435 |
/* |
| 436 |
================= |
| 437 |
Rect_Parse |
| 438 |
================= |
| 439 |
*/ |
| 440 |
qboolean Rect_Parse(char **p, rectDef_t *r) { |
| 441 |
if (Float_Parse(p, &r->x)) { |
| 442 |
if (Float_Parse(p, &r->y)) { |
| 443 |
if (Float_Parse(p, &r->w)) { |
| 444 |
if (Float_Parse(p, &r->h)) { |
| 445 |
return qtrue; |
| 446 |
} |
| 447 |
} |
| 448 |
} |
| 449 |
} |
| 450 |
return qfalse; |
| 451 |
} |
| 452 |
|
| 453 |
/* |
| 454 |
================= |
| 455 |
PC_Rect_Parse |
| 456 |
================= |
| 457 |
*/ |
| 458 |
qboolean PC_Rect_Parse(int handle, rectDef_t *r) { |
| 459 |
if (PC_Float_Parse(handle, &r->x)) { |
| 460 |
if (PC_Float_Parse(handle, &r->y)) { |
| 461 |
if (PC_Float_Parse(handle, &r->w)) { |
| 462 |
if (PC_Float_Parse(handle, &r->h)) { |
| 463 |
return qtrue; |
| 464 |
} |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
return qfalse; |
| 469 |
} |
| 470 |
|
| 471 |
/* |
| 472 |
================= |
| 473 |
String_Parse |
| 474 |
================= |
| 475 |
*/ |
| 476 |
qboolean String_Parse(char **p, const char **out) { |
| 477 |
char *token; |
| 478 |
|
| 479 |
token = COM_ParseExt(p, qfalse); |
| 480 |
if (token && token[0] != 0) { |
| 481 |
*(out) = String_Alloc(token); |
| 482 |
return qtrue; |
| 483 |
} |
| 484 |
return qfalse; |
| 485 |
} |
| 486 |
|
| 487 |
/* |
| 488 |
================= |
| 489 |
PC_String_Parse |
| 490 |
================= |
| 491 |
*/ |
| 492 |
qboolean PC_String_Parse(int handle, const char **out) { |
| 493 |
pc_token_t token; |
| 494 |
|
| 495 |
if (!trap_PC_ReadToken(handle, &token)) |
| 496 |
return qfalse; |
| 497 |
|
| 498 |
*(out) = String_Alloc(token.string); |
| 499 |
return qtrue; |
| 500 |
} |
| 501 |
|
| 502 |
/* |
| 503 |
================= |
| 504 |
PC_Script_Parse |
| 505 |
================= |
| 506 |
*/ |
| 507 |
qboolean PC_Script_Parse(int handle, const char **out) { |
| 508 |
char script[1024]; |
| 509 |
pc_token_t token; |
| 510 |
|
| 511 |
memset(script, 0, sizeof(script)); |
| 512 |
// scripts start with { and have ; separated command lists.. commands are command, arg.. |
| 513 |
// basically we want everything between the { } as it will be interpreted at run time |
| 514 |
|
| 515 |
if (!trap_PC_ReadToken(handle, &token)) |
| 516 |
return qfalse; |
| 517 |
if (Q_stricmp(token.string, "{") != 0) { |
| 518 |
return qfalse; |
| 519 |
} |
| 520 |
|
| 521 |
while ( 1 ) { |
| 522 |
if (!trap_PC_ReadToken(handle, &token)) |
| 523 |
return qfalse; |
| 524 |
|
| 525 |
if (Q_stricmp(token.string, "}") == 0) { |
| 526 |
*out = String_Alloc(script); |
| 527 |
return qtrue; |
| 528 |
} |
| 529 |
|
| 530 |
if (token.string[1] != '\0') { |
| 531 |
Q_strcat(script, 1024, va("\"%s\"", token.string)); |
| 532 |
} else { |
| 533 |
Q_strcat(script, 1024, token.string); |
| 534 |
} |
| 535 |
Q_strcat(script, 1024, " "); |
| 536 |
} |
| 537 |
return qfalse; // bk001105 - LCC missing return value |
| 538 |
} |
| 539 |
|
| 540 |
// display, window, menu, item code |
| 541 |
// |
| 542 |
|
| 543 |
/* |
| 544 |
================== |
| 545 |
Init_Display |
| 546 |
|
| 547 |
Initializes the display with a structure to all the drawing routines |
| 548 |
================== |
| 549 |
*/ |
| 550 |
void Init_Display(displayContextDef_t *dc) { |
| 551 |
DC = dc; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
// type and style painting |
| 557 |
|
| 558 |
void GradientBar_Paint(rectDef_t *rect, vec4_t color) { |
| 559 |
// gradient bar takes two paints |
| 560 |
DC->setColor( color ); |
| 561 |
DC->drawHandlePic(rect->x, rect->y, rect->w, rect->h, DC->Assets.gradientBar); |
| 562 |
DC->setColor( NULL ); |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
/* |
| 567 |
================== |
| 568 |
Window_Init |
| 569 |
|
| 570 |
Initializes a window structure ( windowDef_t ) with defaults |
| 571 |
|
| 572 |
================== |
| 573 |
*/ |
| 574 |
void Window_Init(Window *w) { |
| 575 |
memset(w, 0, sizeof(windowDef_t)); |
| 576 |
w->borderSize = 1; |
| 577 |
w->foreColor[0] = w->foreColor[1] = w->foreColor[2] = w->foreColor[3] = 1.0; |
| 578 |
w->cinematic = -1; |
| 579 |
} |
| 580 |
|
| 581 |
void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboolean bFlags, float fadeAmount) { |
| 582 |
if (*flags & (WINDOW_FADINGOUT | WINDOW_FADINGIN)) { |
| 583 |
if (DC->realTime > *nextTime) { |
| 584 |
*nextTime = DC->realTime + offsetTime; |
| 585 |
if (*flags & WINDOW_FADINGOUT) { |
| 586 |
*f -= fadeAmount; |
| 587 |
if (bFlags && *f <= 0.0) { |
| 588 |
*flags &= ~(WINDOW_FADINGOUT | WINDOW_VISIBLE); |
| 589 |
} |
| 590 |
} else { |
| 591 |
*f += fadeAmount; |
| 592 |
if (*f >= clamp) { |
| 593 |
*f = clamp; |
| 594 |
if (bFlags) { |
| 595 |
*flags &= ~WINDOW_FADINGIN; |
| 596 |
} |
| 597 |
} |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
void Window_Paint(Window *w, float fadeAmount, float fadeClamp, float fadeCycle) { |
| 606 |
//float bordersize = 0; |
| 607 |
vec4_t color; |
| 608 |
rectDef_t fillRect = w->rect; |
| 609 |
|
| 610 |
|
| 611 |
color[0] = color[1] = color[2] = color[3] = 1; |
| 612 |
if (debugMode) { |
| 613 |
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, 1, color); |
| 614 |
} |
| 615 |
|
| 616 |
if (w == NULL || (w->style == 0 && w->border == 0)) { |
| 617 |
return; |
| 618 |
} |
| 619 |
|
| 620 |
if (w->border != 0) { |
| 621 |
fillRect.x += w->borderSize; |
| 622 |
fillRect.y += w->borderSize; |
| 623 |
fillRect.w -= w->borderSize + 1; |
| 624 |
fillRect.h -= w->borderSize + 1; |
| 625 |
} |
| 626 |
|
| 627 |
if (w->style == WINDOW_STYLE_FILLED) { |
| 628 |
// box, but possible a shader that needs filled |
| 629 |
if (w->background) { |
| 630 |
Fade(&w->flags, &w->backColor[3], fadeClamp, &w->nextTime, fadeCycle, qtrue, fadeAmount); |
| 631 |
DC->setColor(w->backColor); |
| 632 |
DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background); |
| 633 |
DC->setColor(NULL); |
| 634 |
} else { |
| 635 |
DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->backColor); |
| 636 |
} |
| 637 |
} else if (w->style == WINDOW_STYLE_GRADIENT) { |
| 638 |
GradientBar_Paint(&fillRect, w->backColor); |
| 639 |
// gradient bar |
| 640 |
} else if (w->style == WINDOW_STYLE_SHADER) { |
| 641 |
if (w->flags & WINDOW_FORECOLORSET) { |
| 642 |
DC->setColor(w->foreColor); |
| 643 |
} |
| 644 |
DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background); |
| 645 |
DC->setColor(NULL); |
| 646 |
} else if (w->style == WINDOW_STYLE_TEAMCOLOR) { |
| 647 |
if (DC->getTeamColor) { |
| 648 |
DC->getTeamColor(&color); |
| 649 |
DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, color); |
| 650 |
} |
| 651 |
} else if (w->style == WINDOW_STYLE_CINEMATIC) { |
| 652 |
if (w->cinematic == -1) { |
| 653 |
w->cinematic = DC->playCinematic(w->cinematicName, fillRect.x, fillRect.y, fillRect.w, fillRect.h); |
| 654 |
if (w->cinematic == -1) { |
| 655 |
w->cinematic = -2; |
| 656 |
} |
| 657 |
} |
| 658 |
if (w->cinematic >= 0) { |
| 659 |
DC->runCinematicFrame(w->cinematic); |
| 660 |
DC->drawCinematic(w->cinematic, fillRect.x, fillRect.y, fillRect.w, fillRect.h); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
if (w->border == WINDOW_BORDER_FULL) { |
| 665 |
// full |
| 666 |
// HACK HACK HACK |
| 667 |
if (w->style == WINDOW_STYLE_TEAMCOLOR) { |
| 668 |
if (color[0] > 0) { |
| 669 |
// red |
| 670 |
color[0] = 1; |
| 671 |
color[1] = color[2] = .5; |
| 672 |
|
| 673 |
} else { |
| 674 |
color[2] = 1; |
| 675 |
color[0] = color[1] = .5; |
| 676 |
} |
| 677 |
color[3] = 1; |
| 678 |
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, color); |
| 679 |
} else { |
| 680 |
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, w->borderColor); |
| 681 |
} |
| 682 |
} else if (w->border == WINDOW_BORDER_HORZ) { |
| 683 |
// top/bottom |
| 684 |
DC->setColor(w->borderColor); |
| 685 |
DC->drawTopBottom(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize); |
| 686 |
DC->setColor( NULL ); |
| 687 |
} else if (w->border == WINDOW_BORDER_VERT) { |
| 688 |
// left right |
| 689 |
DC->setColor(w->borderColor); |
| 690 |
DC->drawSides(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize); |
| 691 |
DC->setColor( NULL ); |
| 692 |
} else if (w->border == WINDOW_BORDER_KCGRADIENT) { |
| 693 |
// this is just two gradient bars along each horz edge |
| 694 |
rectDef_t r = w->rect; |
| 695 |
r.h = w->borderSize; |
| 696 |
GradientBar_Paint(&r, w->borderColor); |
| 697 |
r.y = w->rect.y + w->rect.h - 1; |
| 698 |
GradientBar_Paint(&r, w->borderColor); |
| 699 |
} |
| 700 |
|
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
void Item_SetScreenCoords(itemDef_t *item, float x, float y) { |
| 705 |
|
| 706 |
if (item == NULL) { |
| 707 |
return; |
| 708 |
} |
| 709 |
|
| 710 |
if (item->window.border != 0) { |
| 711 |
x += item->window.borderSize; |
| 712 |
y += item->window.borderSize; |
| 713 |
} |
| 714 |
|
| 715 |
item->window.rect.x = x + item->window.rectClient.x; |
| 716 |
item->window.rect.y = y + item->window.rectClient.y; |
| 717 |
item->window.rect.w = item->window.rectClient.w; |
| 718 |
item->window.rect.h = item->window.rectClient.h; |
| 719 |
|
| 720 |
// force the text rects to recompute |
| 721 |
item->textRect.w = 0; |
| 722 |
item->textRect.h = 0; |
| 723 |
} |
| 724 |
|
| 725 |
// FIXME: consolidate this with nearby stuff |
| 726 |
void Item_UpdatePosition(itemDef_t *item) { |
| 727 |
float x, y; |
| 728 |
menuDef_t *menu; |
| 729 |
|
| 730 |
if (item == NULL || item->parent == NULL) { |
| 731 |
return; |
| 732 |
} |
| 733 |
|
| 734 |
menu = item->parent; |
| 735 |
|
| 736 |
x = menu->window.rect.x; |
| 737 |
y = menu->window.rect.y; |
| 738 |
|
| 739 |
if (menu->window.border != 0) { |
| 740 |
x += menu->window.borderSize; |
| 741 |
y += menu->window.borderSize; |
| 742 |
} |
| 743 |
|
| 744 |
Item_SetScreenCoords(item, x, y); |
| 745 |
|
| 746 |
} |
| 747 |
|
| 748 |
// menus |
| 749 |
void Menu_UpdatePosition(menuDef_t *menu) { |
| 750 |
int i; |
| 751 |
float x, y; |
| 752 |
|
| 753 |
if (menu == NULL) { |
| 754 |
return; |
| 755 |
} |
| 756 |
|
| 757 |
x = menu->window.rect.x; |
| 758 |
y = menu->window.rect.y; |
| 759 |
if (menu->window.border != 0) { |
| 760 |
x += menu->window.borderSize; |
| 761 |
y += menu->window.borderSize; |
| 762 |
} |
| 763 |
|
| 764 |
for (i = 0; i < menu->itemCount; i++) { |
| 765 |
Item_SetScreenCoords(menu->items[i], x, y); |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
void Menu_PostParse(menuDef_t *menu) { |
| 770 |
if (menu == NULL) { |
| 771 |
return; |
| 772 |
} |
| 773 |
if (menu->fullScreen) { |
| 774 |
menu->window.rect.x = 0; |
| 775 |
menu->window.rect.y = 0; |
| 776 |
menu->window.rect.w = 640; |
| 777 |
menu->window.rect.h = 480; |
| 778 |
} |
| 779 |
Menu_UpdatePosition(menu); |
| 780 |
} |
| 781 |
|
| 782 |
itemDef_t *Menu_ClearFocus(menuDef_t *menu) { |
| 783 |
int i; |
| 784 |
itemDef_t *ret = NULL; |
| 785 |
|
| 786 |
if (menu == NULL) { |
| 787 |
return NULL; |
| 788 |
} |
| 789 |
|
| 790 |
for (i = 0; i < menu->itemCount; i++) { |
| 791 |
if (menu->items[i]->window.flags & WINDOW_HASFOCUS) { |
| 792 |
ret = menu->items[i]; |
| 793 |
} |
| 794 |
menu->items[i]->window.flags &= ~WINDOW_HASFOCUS; |
| 795 |
if (menu->items[i]->leaveFocus) { |
| 796 |
Item_RunScript(menu->items[i], menu->items[i]->leaveFocus); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
return ret; |
| 801 |
} |
| 802 |
|
| 803 |
qboolean IsVisible(int flags) { |
| 804 |
return (flags & WINDOW_VISIBLE && !(flags & WINDOW_FADINGOUT)); |
| 805 |
} |
| 806 |
|
| 807 |
qboolean Rect_ContainsPoint(rectDef_t *rect, float x, float y) { |
| 808 |
if (rect) { |
| 809 |
if (x > rect->x && x < rect->x + rect->w && y > rect->y && y < rect->y + rect->h) { |
| 810 |
return qtrue; |
| 811 |
} |
| 812 |
} |
| 813 |
return qfalse; |
| 814 |
} |
| 815 |
|
| 816 |
int Menu_ItemsMatchingGroup(menuDef_t *menu, const char *name) { |
| 817 |
int i; |
| 818 |
int count = 0; |
| 819 |
for (i = 0; i < menu->itemCount; i++) { |
| 820 |
if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0)) { |
| 821 |
count++; |
| 822 |
} |
| 823 |
} |
| 824 |
return count; |
| 825 |
} |
| 826 |
|
| 827 |
itemDef_t *Menu_GetMatchingItemByNumber(menuDef_t *menu, int index, const char *name) { |
| 828 |
int i; |
| 829 |
int count = 0; |
| 830 |
for (i = 0; i < menu->itemCount; i++) { |
| 831 |
if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0)) { |
| 832 |
if (count == index) { |
| 833 |
return menu->items[i]; |
| 834 |
} |
| 835 |
count++; |
| 836 |
} |
| 837 |
} |
| 838 |
return NULL; |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
void Script_SetColor(itemDef_t *item, char **args) { |
| 844 |
const char *name; |
| 845 |
int i; |
| 846 |
float f; |
| 847 |
vec4_t *out; |
| 848 |
// expecting type of color to set and 4 args for the color |
| 849 |
if (String_Parse(args, &name)) { |
| 850 |
out = NULL; |
| 851 |
if (Q_stricmp(name, "backcolor") == 0) { |
| 852 |
out = &item->window.backColor; |
| 853 |
item->window.flags |= WINDOW_BACKCOLORSET; |
| 854 |
} else if (Q_stricmp(name, "forecolor") == 0) { |
| 855 |
out = &item->window.foreColor; |
| 856 |
item->window.flags |= WINDOW_FORECOLORSET; |
| 857 |
} else if (Q_stricmp(name, "bordercolor") == 0) { |
| 858 |
out = &item->window.borderColor; |
| 859 |
} |
| 860 |
|
| 861 |
if (out) { |
| 862 |
for (i = 0; i < 4; i++) { |
| 863 |
if (!Float_Parse(args, &f)) { |
| 864 |
return; |
| 865 |
} |
| 866 |
(*out)[i] = f; |
| 867 |
} |
| 868 |
} |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
void Script_SetAsset(itemDef_t *item, char **args) { |
| 873 |
const char *name; |
| 874 |
// expecting name to set asset to |
| 875 |
if (String_Parse(args, &name)) { |
| 876 |
// check for a model |
| 877 |
if (item->type == ITEM_TYPE_MODEL) { |
| 878 |
} |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
void Script_SetBackground(itemDef_t *item, char **args) { |
| 883 |
const char *name; |
| 884 |
// expecting name to set asset to |
| 885 |
if (String_Parse(args, &name)) { |
| 886 |
item->window.background = DC->registerShaderNoMip(name); |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
itemDef_t *Menu_FindItemByName(menuDef_t *menu, const char *p) { |
| 894 |
int i; |
| 895 |
if (menu == NULL || p == NULL) { |
| 896 |
return NULL; |
| 897 |
} |
| 898 |
|
| 899 |
for (i = 0; i < menu->itemCount; i++) { |
| 900 |
if (Q_stricmp(p, menu->items[i]->window.name) == 0) { |
| 901 |
return menu->items[i]; |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
return NULL; |
| 906 |
} |
| 907 |
|
| 908 |
void Script_SetTeamColor(itemDef_t *item, char **args) { |
| 909 |
if (DC->getTeamColor) { |
| 910 |
int i; |
| 911 |
vec4_t color; |
| 912 |
DC->getTeamColor(&color); |
| 913 |
for (i = 0; i < 4; i++) { |
| 914 |
item->window.backColor[i] = color[i]; |
| 915 |
} |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
void Script_SetItemColor(itemDef_t *item, char **args) { |
| 920 |
const char *itemname; |
| 921 |
const char *name; |
| 922 |
vec4_t color; |
| 923 |
int i; |
| 924 |
vec4_t *out; |
| 925 |
// expecting type of color to set and 4 args for the color |
| 926 |
if (String_Parse(args, &itemname) && String_Parse(args, &name)) { |
| 927 |
itemDef_t *item2; |
| 928 |
int j; |
| 929 |
int count = Menu_ItemsMatchingGroup(item->parent, itemname); |
| 930 |
|
| 931 |
if (!Color_Parse(args, &color)) { |
| 932 |
return; |
| 933 |
} |
| 934 |
|
| 935 |
for (j = 0; j < count; j++) { |
| 936 |
item2 = Menu_GetMatchingItemByNumber(item->parent, j, itemname); |
| 937 |
if (item2 != NULL) { |
| 938 |
out = NULL; |
| 939 |
if (Q_stricmp(name, "backcolor") == 0) { |
| 940 |
out = &item2->window.backColor; |
| 941 |
} else if (Q_stricmp(name, "forecolor") == 0) { |
| 942 |
out = &item2->window.foreColor; |
| 943 |
item2->window.flags |= WINDOW_FORECOLORSET; |
| 944 |
} else if (Q_stricmp(name, "bordercolor") == 0) { |
| 945 |
out = &item2->window.borderColor; |
| 946 |
} |
| 947 |
|
| 948 |
if (out) { |
| 949 |
for (i = 0; i < 4; i++) { |
| 950 |
(*out)[i] = color[i]; |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
} |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
|
| 959 |
void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow) { |
| 960 |
itemDef_t *item; |
| 961 |
int i; |
| 962 |
int count = Menu_ItemsMatchingGroup(menu, p); |
| 963 |
for (i = 0; i < count; i++) { |
| 964 |
item = Menu_GetMatchingItemByNumber(menu, i, p); |
| 965 |
if (item != NULL) { |
| 966 |
if (bShow) { |
| 967 |
item->window.flags |= WINDOW_VISIBLE; |
| 968 |
} else { |
| 969 |
item->window.flags &= ~WINDOW_VISIBLE; |
| 970 |
// stop cinematics playing in the window |
| 971 |
if (item->window.cinematic >= 0) { |
| 972 |
DC->stopCinematic(item->window.cinematic); |
| 973 |
item->window.cinematic = -1; |
| 974 |
} |
| 975 |
} |
| 976 |
} |
| 977 |
} |
| 978 |
} |
| 979 |
|
| 980 |
void Menu_FadeItemByName(menuDef_t *menu, const char *p, qboolean fadeOut) { |
| 981 |
itemDef_t *item; |
| 982 |
int i; |
| 983 |
int count = Menu_ItemsMatchingGroup(menu, p); |
| 984 |
for (i = 0; i < count; i++) { |
| 985 |
item = Menu_GetMatchingItemByNumber(menu, i, p); |
| 986 |
if (item != NULL) { |
| 987 |
if (fadeOut) { |
| 988 |
item->window.flags |= (WINDOW_FADINGOUT | WINDOW_VISIBLE); |
| 989 |
item->window.flags &= ~WINDOW_FADINGIN; |
| 990 |
} else { |
| 991 |
item->window.flags |= (WINDOW_VISIBLE | WINDOW_FADINGIN); |
| 992 |
item->window.flags &= ~WINDOW_FADINGOUT; |
| 993 |
} |
| 994 |
} |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
menuDef_t *Menus_FindByName(const char *p) { |
| 999 |
int i; |
| 1000 |
for (i = 0; i < menuCount; i++) { |
| 1001 |
if (Q_stricmp(Menus[i].window.name, p) == 0) { |
| 1002 |
return &Menus[i]; |
| 1003 |
} |
| 1004 |
} |
| 1005 |
return NULL; |
| 1006 |
} |
| 1007 |
|
| 1008 |
void Menus_ShowByName(const char *p) { |
| 1009 |
menuDef_t *menu = Menus_FindByName(p); |
| 1010 |
if (menu) { |
| 1011 |
Menus_Activate(menu); |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
void Menus_OpenByName(const char *p) { |
| 1016 |
Menus_ActivateByName(p); |
| 1017 |
} |
| 1018 |
|
| 1019 |
static void Menu_RunCloseScript(menuDef_t *menu) { |
| 1020 |
if (menu && menu->window.flags & WINDOW_VISIBLE && menu->onClose) { |
| 1021 |
itemDef_t item; |
| 1022 |
item.parent = menu; |
| 1023 |
Item_RunScript(&item, menu->onClose); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
|
| 1027 |
void Menus_CloseByName(const char *p) { |
| 1028 |
menuDef_t *menu = Menus_FindByName(p); |
| 1029 |
if (menu != NULL) { |
| 1030 |
Menu_RunCloseScript(menu); |
| 1031 |
menu->window.flags &= ~(WINDOW_VISIBLE | WINDOW_HASFOCUS); |
| 1032 |
} |
| 1033 |
} |
| 1034 |
|
| 1035 |
void Menus_CloseAll(void) { |
| 1036 |
int i; |
| 1037 |
for (i = 0; i < menuCount; i++) { |
| 1038 |
Menu_RunCloseScript(&Menus[i]); |
| 1039 |
Menus[i].window.flags &= ~(WINDOW_HASFOCUS | WINDOW_VISIBLE); |
| 1040 |
} |
| 1041 |
} |
| 1042 |
|
| 1043 |
|
| 1044 |
void Script_Show(itemDef_t *item, char **args) { |
| 1045 |
const char *name; |
| 1046 |
if (String_Parse(args, &name)) { |
| 1047 |
Menu_ShowItemByName(item->parent, name, qtrue); |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
void Script_Hide(itemDef_t *item, char **args) { |
| 1052 |
const char *name; |
| 1053 |
if (String_Parse(args, &name)) { |
| 1054 |
Menu_ShowItemByName(item->parent, name, qfalse); |
| 1055 |
} |
| 1056 |
} |
| 1057 |
|
| 1058 |
void Script_FadeIn(itemDef_t *item, char **args) { |
| 1059 |
const char *name; |
| 1060 |
if (String_Parse(args, &name)) { |
| 1061 |
Menu_FadeItemByName(item->parent, name, qfalse); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
void Script_FadeOut(itemDef_t *item, char **args) { |
| 1066 |
const char *name; |
| 1067 |
if (String_Parse(args, &name)) { |
| 1068 |
Menu_FadeItemByName(item->parent, name, qtrue); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
void Script_Open(itemDef_t *item, char **args) { |
| 1075 |
const char *name; |
| 1076 |
if (String_Parse(args, &name)) { |
| 1077 |
Menus_OpenByName(name); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
void Script_ConditionalOpen(itemDef_t *item, char **args) { |
| 1082 |
const char *cvar; |
| 1083 |
const char *name1; |
| 1084 |
const char *name2; |
| 1085 |
float val; |
| 1086 |
|
| 1087 |
if ( String_Parse(args, &cvar) && String_Parse(args, &name1) && String_Parse(args, &name2) ) { |
| 1088 |
val = DC->getCVarValue( cvar ); |
| 1089 |
if ( val == 0.f ) { |
| 1090 |
Menus_OpenByName(name2); |
| 1091 |
} else { |
| 1092 |
Menus_OpenByName(name1); |
| 1093 |
} |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
void Script_Close(itemDef_t *item, char **args) { |
| 1098 |
const char *name; |
| 1099 |
if (String_Parse(args, &name)) { |
| 1100 |
Menus_CloseByName(name); |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
void Menu_TransitionItemByName(menuDef_t *menu, const char *p, rectDef_t rectFrom, rectDef_t rectTo, int time, float amt) { |
| 1105 |
itemDef_t *item; |
| 1106 |
int i; |
| 1107 |
int count = Menu_ItemsMatchingGroup(menu, p); |
| 1108 |
for (i = 0; i < count; i++) { |
| 1109 |
item = Menu_GetMatchingItemByNumber(menu, i, p); |
| 1110 |
if (item != NULL) { |
| 1111 |
item->window.flags |= (WINDOW_INTRANSITION | WINDOW_VISIBLE); |
| 1112 |
item->window.offsetTime = time; |
| 1113 |
memcpy(&item->window.rectClient, &rectFrom, sizeof(rectDef_t)); |
| 1114 |
memcpy(&item->window.rectEffects, &rectTo, sizeof(rectDef_t)); |
| 1115 |
item->window.rectEffects2.x = abs(rectTo.x - rectFrom.x) / amt; |
| 1116 |
item->window.rectEffects2.y = abs(rectTo.y - rectFrom.y) / amt; |
| 1117 |
item->window.rectEffects2.w = abs(rectTo.w - rectFrom.w) / amt; |
| 1118 |
item->window.rectEffects2.h = abs(rectTo.h - rectFrom.h) / amt; |
| 1119 |
Item_UpdatePosition(item); |
| 1120 |
} |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
void Script_Transition(itemDef_t *item, char **args) { |
| 1126 |
const char *name; |
| 1127 |
rectDef_t rectFrom, rectTo; |
| 1128 |
int time; |
| 1129 |
float amt; |
| 1130 |
|
| 1131 |
if (String_Parse(args, &name)) { |
| 1132 |
if ( Rect_Parse(args, &rectFrom) && Rect_Parse(args, &rectTo) && Int_Parse(args, &time) && Float_Parse(args, &amt)) { |
| 1133 |
Menu_TransitionItemByName(item->parent, name, rectFrom, rectTo, time, amt); |
| 1134 |
} |
| 1135 |
} |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
void Menu_OrbitItemByName(menuDef_t *menu, const char *p, float x, float y, float cx, float cy, int time) { |
| 1140 |
itemDef_t *item; |
| 1141 |
int i; |
| 1142 |
int count = Menu_ItemsMatchingGroup(menu, p); |
| 1143 |
for (i = 0; i < count; i++) { |
| 1144 |
item = Menu_GetMatchingItemByNumber(menu, i, p); |
| 1145 |
if (item != NULL) { |
| 1146 |
item->window.flags |= (WINDOW_ORBITING | WINDOW_VISIBLE); |
| 1147 |
item->window.offsetTime = time; |
| 1148 |
item->window.rectEffects.x = cx; |
| 1149 |
item->window.rectEffects.y = cy; |
| 1150 |
item->window.rectClient.x = x; |
| 1151 |
item->window.rectClient.y = y; |
| 1152 |
Item_UpdatePosition(item); |
| 1153 |
} |
| 1154 |
} |
| 1155 |
} |
| 1156 |
|
| 1157 |
|
| 1158 |
void Script_Orbit(itemDef_t *item, char **args) { |
| 1159 |
const char *name; |
| 1160 |
float cx, cy, x, y; |
| 1161 |
int time; |
| 1162 |
|
| 1163 |
if (String_Parse(args, &name)) { |
| 1164 |
if ( Float_Parse(args, &x) && Float_Parse(args, &y) && Float_Parse(args, &cx) && Float_Parse(args, &cy) && Int_Parse(args, &time) ) { |
| 1165 |
Menu_OrbitItemByName(item->parent, name, x, y, cx, cy, time); |
| 1166 |
} |
| 1167 |
} |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
void Script_SetFocus(itemDef_t *item, char **args) { |
| 1173 |
const char *name; |
| 1174 |
itemDef_t *focusItem; |
| 1175 |
|
| 1176 |
if (String_Parse(args, &name)) { |
| 1177 |
focusItem = Menu_FindItemByName(item->parent, name); |
| 1178 |
if (focusItem && !(focusItem->window.flags & WINDOW_DECORATION) && !(focusItem->window.flags & WINDOW_HASFOCUS)) { |
| 1179 |
Menu_ClearFocus(item->parent); |
| 1180 |
focusItem->window.flags |= WINDOW_HASFOCUS; |
| 1181 |
if (focusItem->onFocus) { |
| 1182 |
Item_RunScript(focusItem, focusItem->onFocus); |
| 1183 |
} |
| 1184 |
if (DC->Assets.itemFocusSound) { |
| 1185 |
DC->startLocalSound( DC->Assets.itemFocusSound, CHAN_LOCAL_SOUND ); |
| 1186 |
} |
| 1187 |
} |
| 1188 |
} |
| 1189 |
} |
| 1190 |
|
| 1191 |
void Script_SetPlayerModel(itemDef_t *item, char **args) { |
| 1192 |
const char *name; |
| 1193 |
if (String_Parse(args, &name)) { |
| 1194 |
DC->setCVar("team_model", name); |
| 1195 |
} |
| 1196 |
} |
| 1197 |
|
| 1198 |
void Script_SetPlayerHead(itemDef_t *item, char **args) { |
| 1199 |
const char *name; |
| 1200 |
if (String_Parse(args, &name)) { |
| 1201 |
DC->setCVar("team_headmodel", name); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
void Script_SetCvar(itemDef_t *item, char **args) { |
| 1206 |
const char *cvar, *val; |
| 1207 |
if (String_Parse(args, &cvar) && String_Parse(args, &val)) { |
| 1208 |
DC->setCVar(cvar, val); |
| 1209 |
} |
| 1210 |
|
| 1211 |
} |
| 1212 |
|
| 1213 |
void Script_Exec(itemDef_t *item, char **args) { |
| 1214 |
const char *val; |
| 1215 |
if (String_Parse(args, &val)) { |
| 1216 |
DC->executeText(EXEC_APPEND, va("%s ; ", val)); |
| 1217 |
} |
| 1218 |
} |
| 1219 |
|
| 1220 |
void Script_Play(itemDef_t *item, char **args) { |
| 1221 |
const char *val; |
| 1222 |
if (String_Parse(args, &val)) { |
| 1223 |
DC->startLocalSound(DC->registerSound(val, qfalse), CHAN_LOCAL_SOUND); |
| 1224 |
} |
| 1225 |
} |
| 1226 |
|
| 1227 |
void Script_playLooped(itemDef_t *item, char **args) { |
| 1228 |
const char *val; |
| 1229 |
if (String_Parse(args, &val)) { |
| 1230 |
DC->stopBackgroundTrack(); |
| 1231 |
DC->startBackgroundTrack(val, val); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
|
| 1235 |
|
| 1236 |
commandDef_t commandList[] = |
| 1237 |
{ |
| 1238 |
{"fadein", &Script_FadeIn}, // group/name |
| 1239 |
{"fadeout", &Script_FadeOut}, // group/name |
| 1240 |
{"show", &Script_Show}, // group/name |
| 1241 |
{"hide", &Script_Hide}, // group/name |
| 1242 |
{"setcolor", &Script_SetColor}, // works on this |
| 1243 |
{"open", &Script_Open}, // menu |
| 1244 |
{"conditionalopen", &Script_ConditionalOpen}, // menu |
| 1245 |
{"close", &Script_Close}, // menu |
| 1246 |
{"setasset", &Script_SetAsset}, // works on this |
| 1247 |
{"setbackground", &Script_SetBackground}, // works on this |
| 1248 |
{"setitemcolor", &Script_SetItemColor}, // group/name |
| 1249 |
{"setteamcolor", &Script_SetTeamColor}, // sets this background color to team color |
| 1250 |
{"setfocus", &Script_SetFocus}, // sets this background color to team color |
| 1251 |
{"setplayermodel", &Script_SetPlayerModel}, // sets this background color to team color |
| 1252 |
{"setplayerhead", &Script_SetPlayerHead}, // sets this background color to team color |
| 1253 |
{"transition", &Script_Transition}, // group/name |
| 1254 |
{"setcvar", &Script_SetCvar}, // group/name |
| 1255 |
{"exec", &Script_Exec}, // group/name |
| 1256 |
{"play", &Script_Play}, // group/name |
| 1257 |
{"playlooped", &Script_playLooped}, // group/name |
| 1258 |
{"orbit", &Script_Orbit} // group/name |
| 1259 |
}; |
| 1260 |
|
| 1261 |
int scriptCommandCount = sizeof(commandList) / sizeof(commandDef_t); |
| 1262 |
|
| 1263 |
|
| 1264 |
void Item_RunScript(itemDef_t *item, const char *s) { |
| 1265 |
char script[1024], *p; |
| 1266 |
int i; |
| 1267 |
qboolean bRan; |
| 1268 |
memset(script, 0, sizeof(script)); |
| 1269 |
if (item && s && s[0]) { |
| 1270 |
Q_strcat(script, 1024, s); |
| 1271 |
p = script; |
| 1272 |
while (1) { |
| 1273 |
const char *command; |
| 1274 |
// expect command then arguments, ; ends command, NULL ends script |
| 1275 |
if (!String_Parse(&p, &command)) { |
| 1276 |
return; |
| 1277 |
} |
| 1278 |
|
| 1279 |
if (command[0] == ';' && command[1] == '\0') { |
| 1280 |
continue; |
| 1281 |
} |
| 1282 |
|
| 1283 |
bRan = qfalse; |
| 1284 |
for (i = 0; i < scriptCommandCount; i++) { |
| 1285 |
if (Q_stricmp(command, commandList[i].name) == 0) { |
| 1286 |
(commandList[i].handler(item, &p)); |
| 1287 |
bRan = qtrue; |
| 1288 |
break; |
| 1289 |
} |
| 1290 |
} |
| 1291 |
// not in our auto list, pass to handler |
| 1292 |
if (!bRan) { |
| 1293 |
DC->runScript(&p); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
} |
| 1297 |
} |
| 1298 |
|
| 1299 |
|
| 1300 |
qboolean Item_EnableShowViaCvar(itemDef_t *item, int flag) { |
| 1301 |
char script[1024], *p; |
| 1302 |
memset(script, 0, sizeof(script)); |
| 1303 |
if (item && item->enableCvar && *item->enableCvar && item->cvarTest && *item->cvarTest) { |
| 1304 |
char buff[1024]; |
| 1305 |
DC->getCVarString(item->cvarTest, buff, sizeof(buff)); |
| 1306 |
|
| 1307 |
Q_strcat(script, 1024, item->enableCvar); |
| 1308 |
p = script; |
| 1309 |
while (1) { |
| 1310 |
const char *val; |
| 1311 |
// expect value then ; or NULL, NULL ends list |
| 1312 |
if (!String_Parse(&p, &val)) { |
| 1313 |
return (item->cvarFlags & flag) ? qfalse : qtrue; |
| 1314 |
} |
| 1315 |
|
| 1316 |
if (val[0] == ';' && val[1] == '\0') { |
| 1317 |
continue; |
| 1318 |
} |
| 1319 |
|
| 1320 |
// enable it if any of the values are true |
| 1321 |
if (item->cvarFlags & flag) { |
| 1322 |
if (Q_stricmp(buff, val) == 0) { |
| 1323 |
return qtrue; |
| 1324 |
} |
| 1325 |
} else { |
| 1326 |
// disable it if any of the values are true |
| 1327 |
if (Q_stricmp(buff, val) == 0) { |
| 1328 |
return qfalse; |
| 1329 |
} |
| 1330 |
} |
| 1331 |
|
| 1332 |
} |
| 1333 |
return (item->cvarFlags & flag) ? qfalse : qtrue; |
| 1334 |
} |
| 1335 |
return qtrue; |
| 1336 |
} |
| 1337 |
|
| 1338 |
|
| 1339 |
// will optionaly set focus to this item |
| 1340 |
qboolean Item_SetFocus(itemDef_t *item, float x, float y) { |
| 1341 |
int i; |
| 1342 |
itemDef_t *oldFocus; |
| 1343 |
sfxHandle_t *sfx = &DC->Assets.itemFocusSound; |
| 1344 |
qboolean playSound = qfalse; |
| 1345 |
menuDef_t *parent; // bk001206: = (menuDef_t*)item->parent; |
| 1346 |
// sanity check, non-null, not a decoration and does not already have the focus |
| 1347 |
if (item == NULL || item->window.flags & WINDOW_DECORATION || item->window.flags & WINDOW_HASFOCUS || !(item->window.flags & WINDOW_VISIBLE)) { |
| 1348 |
return qfalse; |
| 1349 |
} |
| 1350 |
|
| 1351 |
// bk001206 - this can be NULL. |
| 1352 |
parent = (menuDef_t*)item->parent; |
| 1353 |
|
| 1354 |
// items can be enabled and disabled based on cvars |
| 1355 |
if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { |
| 1356 |
return qfalse; |
| 1357 |
} |
| 1358 |
|
| 1359 |
if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW)) { |
| 1360 |
return qfalse; |
| 1361 |
} |
| 1362 |
|
| 1363 |
oldFocus = Menu_ClearFocus(item->parent); |
| 1364 |
|
| 1365 |
if (item->type == ITEM_TYPE_TEXT) { |
| 1366 |
rectDef_t r; |
| 1367 |
r = item->textRect; |
| 1368 |
r.y -= r.h; |
| 1369 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1370 |
item->window.flags |= WINDOW_HASFOCUS; |
| 1371 |
if (item->focusSound) { |
| 1372 |
sfx = &item->focusSound; |
| 1373 |
} |
| 1374 |
playSound = qtrue; |
| 1375 |
} else { |
| 1376 |
if (oldFocus) { |
| 1377 |
oldFocus->window.flags |= WINDOW_HASFOCUS; |
| 1378 |
if (oldFocus->onFocus) { |
| 1379 |
Item_RunScript(oldFocus, oldFocus->onFocus); |
| 1380 |
} |
| 1381 |
} |
| 1382 |
} |
| 1383 |
} else { |
| 1384 |
item->window.flags |= WINDOW_HASFOCUS; |
| 1385 |
if (item->onFocus) { |
| 1386 |
Item_RunScript(item, item->onFocus); |
| 1387 |
} |
| 1388 |
if (item->focusSound) { |
| 1389 |
sfx = &item->focusSound; |
| 1390 |
} |
| 1391 |
playSound = qtrue; |
| 1392 |
} |
| 1393 |
|
| 1394 |
if (playSound && sfx) { |
| 1395 |
DC->startLocalSound( *sfx, CHAN_LOCAL_SOUND ); |
| 1396 |
} |
| 1397 |
|
| 1398 |
for (i = 0; i < parent->itemCount; i++) { |
| 1399 |
if (parent->items[i] == item) { |
| 1400 |
parent->cursorItem = i; |
| 1401 |
break; |
| 1402 |
} |
| 1403 |
} |
| 1404 |
|
| 1405 |
return qtrue; |
| 1406 |
} |
| 1407 |
|
| 1408 |
int Item_ListBox_MaxScroll(itemDef_t *item) { |
| 1409 |
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; |
| 1410 |
int count = DC->feederCount(item->special); |
| 1411 |
int max; |
| 1412 |
|
| 1413 |
if (item->window.flags & WINDOW_HORIZONTAL) { |
| 1414 |
max = count - (item->window.rect.w / listPtr->elementWidth) + 1; |
| 1415 |
} |
| 1416 |
else { |
| 1417 |
max = count - (item->window.rect.h / listPtr->elementHeight) + 1; |
| 1418 |
} |
| 1419 |
if (max < 0) { |
| 1420 |
return 0; |
| 1421 |
} |
| 1422 |
return max; |
| 1423 |
} |
| 1424 |
|
| 1425 |
int Item_ListBox_ThumbPosition(itemDef_t *item) { |
| 1426 |
float max, pos, size; |
| 1427 |
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; |
| 1428 |
|
| 1429 |
max = Item_ListBox_MaxScroll(item); |
| 1430 |
if (item->window.flags & WINDOW_HORIZONTAL) { |
| 1431 |
size = item->window.rect.w - (SCROLLBAR_SIZE * 2) - 2; |
| 1432 |
if (max > 0) { |
| 1433 |
pos = (size-SCROLLBAR_SIZE) / (float) max; |
| 1434 |
} else { |
| 1435 |
pos = 0; |
| 1436 |
} |
| 1437 |
pos *= listPtr->startPos; |
| 1438 |
return item->window.rect.x + 1 + SCROLLBAR_SIZE + pos; |
| 1439 |
} |
| 1440 |
else { |
| 1441 |
size = item->window.rect.h - (SCROLLBAR_SIZE * 2) - 2; |
| 1442 |
if (max > 0) { |
| 1443 |
pos = (size-SCROLLBAR_SIZE) / (float) max; |
| 1444 |
} else { |
| 1445 |
pos = 0; |
| 1446 |
} |
| 1447 |
pos *= listPtr->startPos; |
| 1448 |
return item->window.rect.y + 1 + SCROLLBAR_SIZE + pos; |
| 1449 |
} |
| 1450 |
} |
| 1451 |
|
| 1452 |
int Item_ListBox_ThumbDrawPosition(itemDef_t *item) { |
| 1453 |
int min, max; |
| 1454 |
|
| 1455 |
if (itemCapture == item) { |
| 1456 |
if (item->window.flags & WINDOW_HORIZONTAL) { |
| 1457 |
min = item->window.rect.x + SCROLLBAR_SIZE + 1; |
| 1458 |
max = item->window.rect.x + item->window.rect.w - 2*SCROLLBAR_SIZE - 1; |
| 1459 |
if (DC->cursorx >= min + SCROLLBAR_SIZE/2 && DC->cursorx <= max + SCROLLBAR_SIZE/2) { |
| 1460 |
return DC->cursorx - SCROLLBAR_SIZE/2; |
| 1461 |
} |
| 1462 |
else { |
| 1463 |
return Item_ListBox_ThumbPosition(item); |
| 1464 |
} |
| 1465 |
} |
| 1466 |
else { |
| 1467 |
min = item->window.rect.y + SCROLLBAR_SIZE + 1; |
| 1468 |
max = item->window.rect.y + item->window.rect.h - 2*SCROLLBAR_SIZE - 1; |
| 1469 |
if (DC->cursory >= min + SCROLLBAR_SIZE/2 && DC->cursory <= max + SCROLLBAR_SIZE/2) { |
| 1470 |
return DC->cursory - SCROLLBAR_SIZE/2; |
| 1471 |
} |
| 1472 |
else { |
| 1473 |
return Item_ListBox_ThumbPosition(item); |
| 1474 |
} |
| 1475 |
} |
| 1476 |
} |
| 1477 |
else { |
| 1478 |
return Item_ListBox_ThumbPosition(item); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
float Item_Slider_ThumbPosition(itemDef_t *item) { |
| 1483 |
float value, range, x; |
| 1484 |
editFieldDef_t *editDef = item->typeData; |
| 1485 |
|
| 1486 |
if (item->text) { |
| 1487 |
x = item->textRect.x + item->textRect.w + 8; |
| 1488 |
} else { |
| 1489 |
x = item->window.rect.x; |
| 1490 |
} |
| 1491 |
|
| 1492 |
if (editDef == NULL && item->cvar) { |
| 1493 |
return x; |
| 1494 |
} |
| 1495 |
|
| 1496 |
value = DC->getCVarValue(item->cvar); |
| 1497 |
|
| 1498 |
if (value < editDef->minVal) { |
| 1499 |
value = editDef->minVal; |
| 1500 |
} else if (value > editDef->maxVal) { |
| 1501 |
value = editDef->maxVal; |
| 1502 |
} |
| 1503 |
|
| 1504 |
range = editDef->maxVal - editDef->minVal; |
| 1505 |
value -= editDef->minVal; |
| 1506 |
value /= range; |
| 1507 |
//value /= (editDef->maxVal - editDef->minVal); |
| 1508 |
value *= SLIDER_WIDTH; |
| 1509 |
x += value; |
| 1510 |
// vm fuckage |
| 1511 |
//x = x + (((float)value / editDef->maxVal) * SLIDER_WIDTH); |
| 1512 |
return x; |
| 1513 |
} |
| 1514 |
|
| 1515 |
int Item_Slider_OverSlider(itemDef_t *item, float x, float y) { |
| 1516 |
rectDef_t r; |
| 1517 |
|
| 1518 |
r.x = Item_Slider_ThumbPosition(item) - (SLIDER_THUMB_WIDTH / 2); |
| 1519 |
r.y = item->window.rect.y - 2; |
| 1520 |
r.w = SLIDER_THUMB_WIDTH; |
| 1521 |
r.h = SLIDER_THUMB_HEIGHT; |
| 1522 |
|
| 1523 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1524 |
return WINDOW_LB_THUMB; |
| 1525 |
} |
| 1526 |
return 0; |
| 1527 |
} |
| 1528 |
|
| 1529 |
int Item_ListBox_OverLB(itemDef_t *item, float x, float y) { |
| 1530 |
rectDef_t r; |
| 1531 |
listBoxDef_t *listPtr; |
| 1532 |
int thumbstart; |
| 1533 |
int count; |
| 1534 |
|
| 1535 |
count = DC->feederCount(item->special); |
| 1536 |
listPtr = (listBoxDef_t*)item->typeData; |
| 1537 |
if (item->window.flags & WINDOW_HORIZONTAL) { |
| 1538 |
// check if on left arrow |
| 1539 |
r.x = item->window.rect.x; |
| 1540 |
r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE; |
| 1541 |
r.h = r.w = SCROLLBAR_SIZE; |
| 1542 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1543 |
return WINDOW_LB_LEFTARROW; |
| 1544 |
} |
| 1545 |
// check if on right arrow |
| 1546 |
r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE; |
| 1547 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1548 |
return WINDOW_LB_RIGHTARROW; |
| 1549 |
} |
| 1550 |
// check if on thumb |
| 1551 |
thumbstart = Item_ListBox_ThumbPosition(item); |
| 1552 |
r.x = thumbstart; |
| 1553 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1554 |
return WINDOW_LB_THUMB; |
| 1555 |
} |
| 1556 |
r.x = item->window.rect.x + SCROLLBAR_SIZE; |
| 1557 |
r.w = thumbstart - r.x; |
| 1558 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1559 |
return WINDOW_LB_PGUP; |
| 1560 |
} |
| 1561 |
r.x = thumbstart + SCROLLBAR_SIZE; |
| 1562 |
r.w = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE; |
| 1563 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1564 |
return WINDOW_LB_PGDN; |
| 1565 |
} |
| 1566 |
} else { |
| 1567 |
r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE; |
| 1568 |
r.y = item->window.rect.y; |
| 1569 |
r.h = r.w = SCROLLBAR_SIZE; |
| 1570 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1571 |
return WINDOW_LB_LEFTARROW; |
| 1572 |
} |
| 1573 |
r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE; |
| 1574 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1575 |
return WINDOW_LB_RIGHTARROW; |
| 1576 |
} |
| 1577 |
thumbstart = Item_ListBox_ThumbPosition(item); |
| 1578 |
r.y = thumbstart; |
| 1579 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1580 |
return WINDOW_LB_THUMB; |
| 1581 |
} |
| 1582 |
r.y = item->window.rect.y + SCROLLBAR_SIZE; |
| 1583 |
r.h = thumbstart - r.y; |
| 1584 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1585 |
return WINDOW_LB_PGUP; |
| 1586 |
} |
| 1587 |
r.y = thumbstart + SCROLLBAR_SIZE; |
| 1588 |
r.h = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE; |
| 1589 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1590 |
return WINDOW_LB_PGDN; |
| 1591 |
} |
| 1592 |
} |
| 1593 |
return 0; |
| 1594 |
} |
| 1595 |
|
| 1596 |
|
| 1597 |
void Item_ListBox_MouseEnter(itemDef_t *item, float x, float y) |
| 1598 |
{ |
| 1599 |
rectDef_t r; |
| 1600 |
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; |
| 1601 |
|
| 1602 |
item->window.flags &= ~(WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN); |
| 1603 |
item->window.flags |= Item_ListBox_OverLB(item, x, y); |
| 1604 |
|
| 1605 |
if (item->window.flags & WINDOW_HORIZONTAL) { |
| 1606 |
if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN))) { |
| 1607 |
// check for selection hit as we have exausted buttons and thumb |
| 1608 |
if (listPtr->elementStyle == LISTBOX_IMAGE) { |
| 1609 |
r.x = item->window.rect.x; |
| 1610 |
r.y = item->window.rect.y; |
| 1611 |
r.h = item->window.rect.h - SCROLLBAR_SIZE; |
| 1612 |
r.w = item->window.rect.w - listPtr->drawPadding; |
| 1613 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1614 |
listPtr->cursorPos = (int)((x - r.x) / listPtr->elementWidth) + listPtr->startPos; |
| 1615 |
if (listPtr->cursorPos >= listPtr->endPos) { |
| 1616 |
listPtr->cursorPos = listPtr->endPos; |
| 1617 |
} |
| 1618 |
} |
| 1619 |
} else { |
| 1620 |
// text hit.. |
| 1621 |
} |
| 1622 |
} |
| 1623 |
} else if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN))) { |
| 1624 |
r.x = item->window.rect.x; |
| 1625 |
r.y = item->window.rect.y; |
| 1626 |
r.w = item->window.rect.w - SCROLLBAR_SIZE; |
| 1627 |
r.h = item->window.rect.h - listPtr->drawPadding; |
| 1628 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1629 |
listPtr->cursorPos = (int)((y - 2 - r.y) / listPtr->elementHeight) + listPtr->startPos; |
| 1630 |
if (listPtr->cursorPos > listPtr->endPos) { |
| 1631 |
listPtr->cursorPos = listPtr->endPos; |
| 1632 |
} |
| 1633 |
} |
| 1634 |
} |
| 1635 |
} |
| 1636 |
|
| 1637 |
void Item_MouseEnter(itemDef_t *item, float x, float y) { |
| 1638 |
rectDef_t r; |
| 1639 |
if (item) { |
| 1640 |
r = item->textRect; |
| 1641 |
r.y -= r.h; |
| 1642 |
// in the text rect? |
| 1643 |
|
| 1644 |
// items can be enabled and disabled based on cvars |
| 1645 |
if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { |
| 1646 |
return; |
| 1647 |
} |
| 1648 |
|
| 1649 |
if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW)) { |
| 1650 |
return; |
| 1651 |
} |
| 1652 |
|
| 1653 |
if (Rect_ContainsPoint(&r, x, y)) { |
| 1654 |
if (!(item->window.flags & WINDOW_MOUSEOVERTEXT)) { |
| 1655 |
Item_RunScript(item, item->mouseEnterText); |
| 1656 |
item->window.flags |= WINDOW_MOUSEOVERTEXT; |
| 1657 |
} |
| 1658 |
if (!(item->window.flags & WINDOW_MOUSEOVER)) { |
| 1659 |
Item_RunScript(item, item->mouseEnter); |
| 1660 |
item->window.flags |= WINDOW_MOUSEOVER; |
| 1661 |
} |
| 1662 |
|
| 1663 |
} else { |
| 1664 |
// not in the text rect |
| 1665 |
if (item->window.flags & WINDOW_MOUSEOVERTEXT) { |
| 1666 |
// if we were |
| 1667 |
Item_RunScript(item, item->mouseExitText); |
| 1668 |
item->window.flags &= ~WINDOW_MOUSEOVERTEXT; |
| 1669 |
} |
| 1670 |
if (!(item->window.flags & WINDOW_MOUSEOVER)) { |
| 1671 |
Item_RunScript(item, item->mouseEnter); |
| 1672 |
item->window.flags |= WINDOW_MOUSEOVER; |
| 1673 |
} |
| 1674 |
|
| 1675 |
if (item->type == ITEM_TYPE_LISTBOX) { |
| 1676 |
Item_ListBox_MouseEnter(item, x, y); |
| 1677 |
} |
| 1678 |
} |
| 1679 |
} |
| 1680 |
} |
| 1681 |
|
| 1682 |
void Item_MouseLeave(itemDef_t *item) { |
| 1683 |
if (item) { |
| 1684 |
if (item->window.flags & WINDOW_MOUSEOVERTEXT) { |
| 1685 |
Item_RunScript(item, item->mouseExitText); |
| 1686 |
item->window.flags &= ~WINDOW_MOUSEOVERTEXT; |
| 1687 |
} |
| 1688 |
Item_RunScript(item, item->mouseExit); |
| 1689 |
item->window.flags &= ~(WINDOW_LB_RIGHTARROW | WINDOW_LB_LEFTARROW); |
| 1690 |
} |
| 1691 |
} |
| 1692 |
|
| 1693 |
itemDef_t *Menu_HitTest(menuDef_t *menu, float x, float y) { |
| 1694 |
int i; |
| 1695 |
for (i = 0; i < menu->itemCount; i++) { |
| 1696 |
if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y)) { |
| 1697 |
return menu->items[i]; |
| 1698 |
} |
| 1699 |
} |
| 1700 |
return NULL; |
| 1701 |
} |
| 1702 |
|
| 1703 |
void Item_SetMouseOver(itemDef_t *item, qboolean focus) { |
| 1704 |
if (item) { |
| 1705 |
if (focus) { |
| 1706 |
item->window.flags |= WINDOW_MOUSEOVER; |
| 1707 |
} else { |
| 1708 |
item->window.flags &= ~WINDOW_MOUSEOVER; |
| 1709 |
} |
| 1710 |
} |
| 1711 |
} |
| 1712 |
|
| 1713 |
|
| 1714 |
qboolean Item_OwnerDraw_HandleKey(itemDef_t *item, int key) { |
| 1715 |
if (item && DC->ownerDrawHandleKey) { |
| 1716 |
return DC->ownerDrawHandleKey(item->window.ownerDraw, item->window.ownerDrawFlags, &item->special, key); |
| 1717 |
} |
| 1718 |
return qfalse; |
| 1719 |
} |
| 1720 |
|
| 1721 |
qboolean Item_ListBox_HandleKey(itemDef_t *item, int key, qboolean down, qboolean force) { |
| 1722 |
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; |
| 1723 |
int count = DC->feederCount(item->special); |
| 1724 |
int max, viewmax; |
| 1725 |
|
| 1726 |
if (force || (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS)) { |
| 1727 |
max = Item_ListBox_MaxScroll(item); |
| 1728 |
if (item->window.flags & WINDOW_HORIZONTAL) { |
| 1729 |
viewmax = (item->window.rect.w / listPtr->elementWidth); |
| 1730 |
if ( key == K_LEFTARROW ) |
| 1731 |
{ |
| 1732 |
if (!listPtr->notselectable) { |
| 1733 |
listPtr->cursorPos--; |
| 1734 |
if (listPtr->cursorPos < 0) { |
| 1735 |
listPtr->cursorPos = 0; |
| 1736 |
} |
| 1737 |
if (listPtr->cursorPos < listPtr->startPos) { |
| 1738 |
listPtr->startPos = listPtr->cursorPos; |
| 1739 |
} |
| 1740 |
if (listPtr->cursorPos >= listPtr->startPos + viewmax) { |
| 1741 |
listPtr->startPos = listPtr->cursorPos - viewmax + 1; |
| 1742 |
} |
| 1743 |
item->cursorPos = listPtr->cursorPos; |
| 1744 |
DC->feederSelection(item->special, item->cursorPos); |
| 1745 |
} |
| 1746 |
else { |
| 1747 |
listPtr->startPos--; |
| 1748 |
if (listPtr->startPos < 0) |
| 1749 |
listPtr->startPos = 0; |
| 1750 |
} |
| 1751 |
return qtrue; |
| 1752 |
} |
| 1753 |
if ( key == K_RIGHTARROW ) |
| 1754 |
{ |
| 1755 |
if (!listPtr->notselectable) { |
| 1756 |
listPtr->cursorPos++; |
| 1757 |
if (listPtr->cursorPos < listPtr->startPos) { |
| 1758 |
listPtr->startPos = listPtr->cursorPos; |
| 1759 |
} |
| 1760 |
if (listPtr->cursorPos >= count) { |
| 1761 |
listPtr->cursorPos = count-1; |
| 1762 |
} |
| 1763 |
if (listPtr->cursorPos >= listPtr->startPos + viewmax) { |
| 1764 |
listPtr->startPos = listPtr->cursorPos - viewmax + 1; |
| 1765 |
} |
| 1766 |
item->cursorPos = listPtr->cursorPos; |
| 1767 |
DC->feederSelection(item->special, item->cursorPos); |
| 1768 |
} |
| 1769 |
else { |
| 1770 |
listPtr->startPos++; |
| 1771 |
if (listPtr->startPos >= count) |
| 1772 |
listPtr->startPos = count-1; |
| 1773 |
} |
| 1774 |
return qtrue; |
| 1775 |
} |
| 1776 |
} |
| 1777 |
else { |
| 1778 |
viewmax = (item->window.rect.h / listPtr->elementHeight); |
| 1779 |
if ( key == K_UPARROW ) |
| 1780 |
{ |
| 1781 |
if (!listPtr->notselectable) { |
| 1782 |
listPtr->cursorPos--; |
| 1783 |
if (listPtr->cursorPos < 0) { |
| 1784 |
listPtr->cursorPos = 0; |
| 1785 |
} |
| 1786 |
if (listPtr->cursorPos < listPtr->startPos) { |
| 1787 |
listPtr->startPos = listPtr->cursorPos; |
| 1788 |
} |
| 1789 |
if (listPtr->cursorPos >= listPtr->startPos + viewmax) { |
| 1790 |
listPtr->startPos = listPtr->cursorPos - viewmax + 1; |
| 1791 |
} |
| 1792 |
item->cursorPos = listPtr->cursorPos; |
| 1793 |
DC->feederSelection(item->special, item->cursorPos); |
| 1794 |
} |
| 1795 |
else { |
| 1796 |
listPtr->startPos--; |
| 1797 |
if (listPtr->startPos < 0) |
| 1798 |
listPtr->startPos = 0; |
| 1799 |
} |
| 1800 |
return qtrue; |
| 1801 |
} |
| 1802 |
if ( key == K_DOWNARROW ) |
| 1803 |
{ |
| 1804 |
if (!listPtr->notselectable) { |
| 1805 |
listPtr->cursorPos++; |
| 1806 |
if (listPtr->cursorPos < listPtr->startPos) { |
| 1807 |
listPtr->startPos = listPtr->cursorPos; |
| 1808 |
} |
| 1809 |
if (listPtr->cursorPos >= count) { |
| 1810 |
listPtr->cursorPos = count-1; |
| 1811 |
} |
| 1812 |
if (listPtr->cursorPos >= listPtr->startPos + viewmax) { |
| 1813 |
listPtr->startPos = listPtr->cursorPos - viewmax + 1; |
| 1814 |
} |
| 1815 |
item->cursorPos = listPtr->cursorPos; |
| 1816 |
DC->feederSelection(item->special, item->cursorPos); |
| 1817 |
} |
| 1818 |
else { |
| 1819 |
listPtr->startPos++; |
| 1820 |
if (listPtr->startPos > max) |
| 1821 |
listPtr->startPos = max; |
| 1822 |
} |
| 1823 |
return qtrue; |
| 1824 |
} |
| 1825 |
} |
| 1826 |
// mouse hit |
| 1827 |
if (key == K_MOUSE1 || key == K_MOUSE2) { |
| 1828 |
if (item->window.flags & WINDOW_LB_LEFTARROW) { |
| 1829 |
listPtr->startPos--; |
| 1830 |
if (listPtr->startPos < 0) { |
| 1831 |
listPtr->startPos = 0; |
| 1832 |
} |
| 1833 |
} else if (item->window.flags & WINDOW_LB_RIGHTARROW) { |
| 1834 |
// one down |
| 1835 |
listPtr->startPos++; |
| 1836 |
if (listPtr->startPos > max) { |
| 1837 |
listPtr->startPos = max; |
| 1838 |
} |
| 1839 |
} else if (item->window.flags & WINDOW_LB_PGUP) { |
| 1840 |
// page up |
| 1841 |
listPtr->startPos -= viewmax; |
| 1842 |
if (listPtr->startPos < 0) { |
| 1843 |
listPtr->startPos = 0; |
| 1844 |
} |
| 1845 |
} else if (item->window.flags & WINDOW_LB_PGDN) { |
| 1846 |
// page down |
| 1847 |
listPtr->startPos += viewmax; |
| 1848 |
if (listPtr->startPos > max) { |
| 1849 |
listPtr->startPos = max; |
| 1850 |
} |
| 1851 |
} else if (item->window.flags & WINDOW_LB_THUMB) { |
| 1852 |
// Display_SetCaptureItem(item); |
| 1853 |
} else { |
| 1854 |
// select an item |
| 1855 |
if (DC->realTime < lastListBoxClickTime && listPtr->doubleClick) { |
| 1856 |
Item_RunScript(item, listPtr->doubleClick); |
| 1857 |
} |
| 1858 |
lastListBoxClickTime = DC->realTime + DOUBLE_CLICK_DELAY; |
| 1859 |
if (item->cursorPos != listPtr->cursorPos) { |
| 1860 |
item->cursorPos = listPtr->cursorPos; |
| 1861 |
DC->feederSelection(item->special, item->cursorPos); |
| 1862 |
} |
| 1863 |
} |
| 1864 |
return qtrue; |
| 1865 |
} |
| 1866 |
if ( key == K_HOME ) { |
| 1867 |
// home |
| 1868 |
listPtr->startPos = 0; |
| 1869 |
return qtrue; |
| 1870 |
} |
| 1871 |
if ( key == K_END ) { |
| 1872 |
// end |
| 1873 |
listPtr->startPos = max; |
| 1874 |
return qtrue; |
| 1875 |
} |
| 1876 |
if (key == K_PGUP ) { |
| 1877 |
// page up |
| 1878 |
if (!listPtr->notselectable) { |
| 1879 |
listPtr->cursorPos -= viewmax; |
| 1880 |
if (listPtr->cursorPos < 0) { |
| 1881 |
listPtr->cursorPos = 0; |
| 1882 |
} |
| 1883 |
if (listPtr->cursorPos < listPtr->startPos) { |
| 1884 |
listPtr->startPos = listPtr->cursorPos; |
| 1885 |
} |
| 1886 |
if (listPtr->cursorPos >= listPtr->startPos + viewmax) { |
| 1887 |
listPtr->startPos = listPtr->cursorPos - viewmax + 1; |
| 1888 |
} |
| 1889 |
item->cursorPos = listPtr->cursorPos; |
| 1890 |
DC->feederSelection(item->special, item->cursorPos); |
| 1891 |
} |
| 1892 |
else { |
| 1893 |
listPtr->startPos -= viewmax; |
| 1894 |
if (listPtr->startPos < 0) { |
| 1895 |
listPtr->startPos = 0; |
| 1896 |
} |
| 1897 |
} |
| 1898 |
return qtrue; |
| 1899 |
} |
| 1900 |
if ( key == K_PGDN ) { |
| 1901 |
// page down |
| 1902 |
if (!listPtr->notselectable) { |
| 1903 |
listPtr->cursorPos += viewmax; |
| 1904 |
if (listPtr->cursorPos < listPtr->startPos) { |
| 1905 |
listPtr->startPos = listPtr->cursorPos; |
| 1906 |
} |
| 1907 |
if (listPtr->cursorPos >= count) { |
| 1908 |
listPtr->cursorPos = count-1; |
| 1909 |
} |
| 1910 |
if (listPtr->cursorPos >= listPtr->startPos + viewmax) { |
| 1911 |
listPtr->startPos = listPtr->cursorPos - viewmax + 1; |
| 1912 |
} |
| 1913 |
item->cursorPos = listPtr->cursorPos; |
| 1914 |
DC->feederSelection(item->special, item->cursorPos); |
| 1915 |
} |
| 1916 |
else { |
| 1917 |
listPtr->startPos += viewmax; |
| 1918 |
if (listPtr->startPos > max) { |
| 1919 |
listPtr->startPos = max; |
| 1920 |
} |
| 1921 |
} |
| 1922 |
return qtrue; |
| 1923 |
} |
| 1924 |
} |
| 1925 |
return qfalse; |
| 1926 |
} |
| 1927 |
|
| 1928 |
qboolean Item_YesNo_HandleKey(itemDef_t *item, int key) { |
| 1929 |
|
| 1930 |
if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS && item->cvar) { |
| 1931 |
if (key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3) { |
| 1932 |
DC->setCVar(item->cvar, va("%i", !DC->getCVarValue(item->cvar))); |
| 1933 |
return qtrue; |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 1937 |
return qfalse; |
| 1938 |
|
| 1939 |
} |
| 1940 |
|
| 1941 |
int Item_Multi_CountSettings(itemDef_t *item) { |
| 1942 |
multiDef_t *multiPtr = (multiDef_t*)item->typeData; |
| 1943 |
if (multiPtr == NULL) { |
| 1944 |
return 0; |
| 1945 |
} |
| 1946 |
return multiPtr->count; |
| 1947 |
} |
| 1948 |
|
| 1949 |
int Item_Multi_FindCvarByValue(itemDef_t *item) { |
| 1950 |
char buff[1024]; |
| 1951 |
float value = 0; |
| 1952 |
int i; |
| 1953 |
multiDef_t *multiPtr = (multiDef_t*)item->typeData; |
| 1954 |
if (multiPtr) { |
| 1955 |
if (multiPtr->strDef) { |
| 1956 |
DC->getCVarString(item->cvar, buff, sizeof(buff)); |
| 1957 |
} else { |
| 1958 |
value = DC->getCVarValue(item->cvar); |
| 1959 |
} |
| 1960 |
for (i = 0; i < multiPtr->count; i++) { |
| 1961 |
if (multiPtr->strDef) { |
| 1962 |
if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0) { |
| 1963 |
return i; |
| 1964 |
} |
| 1965 |
} else { |
| 1966 |
if (multiPtr->cvarValue[i] == value) { |
| 1967 |
return i; |
| 1968 |
} |
| 1969 |
} |
| 1970 |
} |
| 1971 |
} |
| 1972 |
return 0; |
| 1973 |
} |
| 1974 |
|
| 1975 |
const char *Item_Multi_Setting(itemDef_t *item) { |
| 1976 |
char buff[1024]; |
| 1977 |
float value = 0; |
| 1978 |
int i; |
| 1979 |
multiDef_t *multiPtr = (multiDef_t*)item->typeData; |
| 1980 |
if (multiPtr) { |
| 1981 |
if (multiPtr->strDef) { |
| 1982 |
DC->getCVarString(item->cvar, buff, sizeof(buff)); |
| 1983 |
} else { |
| 1984 |
value = DC->getCVarValue(item->cvar); |
| 1985 |
} |
| 1986 |
for (i = 0; i < multiPtr->count; i++) { |
| 1987 |
if (multiPtr->strDef) { |
| 1988 |
if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0) { |
| 1989 |
return multiPtr->cvarList[i]; |
| 1990 |
} |
| 1991 |
} else { |
| 1992 |
if (multiPtr->cvarValue[i] == value) { |
| 1993 |
return multiPtr->cvarList[i]; |
| 1994 |
} |
| 1995 |
} |
| 1996 |
} |
| 1997 |
} |
| 1998 |
return ""; |
| 1999 |
} |
| 2000 |
|
| 2001 |
qboolean Item_Multi_HandleKey(itemDef_t *item, int key) { |
| 2002 |
multiDef_t *multiPtr = (multiDef_t*)item->typeData; |
| 2003 |
if (multiPtr) { |
| 2004 |
if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS && item->cvar) { |
| 2005 |
if (key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3) { |
| 2006 |
int current = Item_Multi_FindCvarByValue(item) + 1; |
| 2007 |
int max = Item_Multi_CountSettings(item); |
| 2008 |
if ( current < 0 || current >= max ) { |
| 2009 |
current = 0; |
| 2010 |
} |
| 2011 |
if (multiPtr->strDef) { |
| 2012 |
DC->setCVar(item->cvar, multiPtr->cvarStr[current]); |
| 2013 |
} else { |
| 2014 |
float value = multiPtr->cvarValue[current]; |
| 2015 |
if (((float)((int) value)) == value) { |
| 2016 |
DC->setCVar(item->cvar, va("%i", (int) value )); |
| 2017 |
} |
| 2018 |
else { |
| 2019 |
DC->setCVar(item->cvar, va("%f", value )); |
| 2020 |
} |
| 2021 |
} |
| 2022 |
return qtrue; |
| 2023 |
} |
| 2024 |
} |
| 2025 |
} |
| 2026 |
return qfalse; |
| 2027 |
} |
| 2028 |
|
| 2029 |
qboolean Item_TextField_HandleKey(itemDef_t *item, int key) { |
| 2030 |
char buff[1024]; |
| 2031 |
int len; |
| 2032 |
itemDef_t *newItem = NULL; |
| 2033 |
editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData; |
| 2034 |
|
| 2035 |
if (item->cvar) { |
| 2036 |
|
| 2037 |
memset(buff, 0, sizeof(buff)); |
| 2038 |
DC->getCVarString(item->cvar, buff, sizeof(buff)); |
| 2039 |
len = strlen(buff); |
| 2040 |
if (editPtr->maxChars && len > editPtr->maxChars) { |
| 2041 |
len = editPtr->maxChars; |
| 2042 |
} |
| 2043 |
if ( key & K_CHAR_FLAG ) { |
| 2044 |
key &= ~K_CHAR_FLAG; |
| 2045 |
|
| 2046 |
|
| 2047 |
if (key == 'h' - 'a' + 1 ) { // ctrl-h is backspace |
| 2048 |
if ( item->cursorPos > 0 ) { |
| 2049 |
memmove( &buff[item->cursorPos - 1], &buff[item->cursorPos], len + 1 - item->cursorPos); |
| 2050 |
item->cursorPos--; |
| 2051 |
if (item->cursorPos < editPtr->paintOffset) { |
| 2052 |
editPtr->paintOffset--; |
| 2053 |
} |
| 2054 |
} |
| 2055 |
DC->setCVar(item->cvar, buff); |
| 2056 |
return qtrue; |
| 2057 |
} |
| 2058 |
|
| 2059 |
|
| 2060 |
// |
| 2061 |
// ignore any non printable chars |
| 2062 |
// |
| 2063 |
if ( key < 32 || !item->cvar) { |
| 2064 |
return qtrue; |
| 2065 |
} |
| 2066 |
|
| 2067 |
if (item->type == ITEM_TYPE_NUMERICFIELD) { |
| 2068 |
if (key < '0' || key > '9') { |
| 2069 |
return qfalse; |
| 2070 |
} |
| 2071 |
} |
| 2072 |
|
| 2073 |
if (!DC->getOverstrikeMode()) { |
| 2074 |
if (( len == MAX_EDITFIELD - 1 ) || (editPtr->maxChars && len >= editPtr->maxChars)) { |
| 2075 |
return qtrue; |
| 2076 |
} |
| 2077 |
memmove( &buff[item->cursorPos + 1], &buff[item->cursorPos], len + 1 - item->cursorPos ); |
| 2078 |
} else { |
| 2079 |
if (editPtr->maxChars && item->cursorPos >= editPtr->maxChars) { |
| 2080 |
return qtrue; |
| 2081 |
} |
| 2082 |
} |
| 2083 |
|
| 2084 |
buff[item->cursorPos] = key; |
| 2085 |
|
| 2086 |
DC->setCVar(item->cvar, buff); |
| 2087 |
|
| 2088 |
if (item->cursorPos < len + 1) { |
| 2089 |
item->cursorPos++; |
| 2090 |
if (editPtr->maxPaintChars && item->cursorPos > editPtr->maxPaintChars) { |
| 2091 |
editPtr->paintOffset++; |
| 2092 |
} |
| 2093 |
} |
| 2094 |
|
| 2095 |
} else { |
| 2096 |
|
| 2097 |
if ( key == K_DEL ) { |
| 2098 |
if ( item->cursorPos < len ) { |
| 2099 |
memmove( buff + item->cursorPos, buff + item->cursorPos + 1, len - item->cursorPos); |
| 2100 |
DC->setCVar(item->cvar, buff); |
| 2101 |
} |
| 2102 |
return qtrue; |
| 2103 |
} |
| 2104 |
|
| 2105 |
if ( key == K_RIGHTARROW ) |
| 2106 |
{ |
| 2107 |
if (editPtr->maxPaintChars && item->cursorPos >= editPtr->maxPaintChars && item->cursorPos < len) { |
| 2108 |
item->cursorPos++; |
| 2109 |
editPtr->paintOffset++; |
| 2110 |
return qtrue; |
| 2111 |
} |
| 2112 |
if (item->cursorPos < len) { |
| 2113 |
item->cursorPos++; |
| 2114 |
} |
| 2115 |
return qtrue; |
| 2116 |
} |
| 2117 |
|
| 2118 |
if ( key == K_LEFTARROW ) |
| 2119 |
{ |
| 2120 |
if ( item->cursorPos > 0 ) { |
| 2121 |
item->cursorPos--; |
| 2122 |
} |
| 2123 |
if (item->cursorPos < editPtr->paintOffset) { |
| 2124 |
editPtr->paintOffset--; |
| 2125 |
} |
| 2126 |
return qtrue; |
| 2127 |
} |
| 2128 |
|
| 2129 |
if ( key == K_HOME ) {// || ( tolower(key) == 'a' && trap_Key_IsDown( K_CTRL ) ) ) { |
| 2130 |
item->cursorPos = 0; |
| 2131 |
editPtr->paintOffset = 0; |
| 2132 |
return qtrue; |
| 2133 |
} |
| 2134 |
|
| 2135 |
if ( key == K_END ) {// ( tolower(key) == 'e' && trap_Key_IsDown( K_CTRL ) ) ) { |
| 2136 |
item->cursorPos = len; |
| 2137 |
if(item->cursorPos > editPtr->maxPaintChars) { |
| 2138 |
editPtr->paintOffset = len - editPtr->maxPaintChars; |
| 2139 |
} |
| 2140 |
return qtrue; |
| 2141 |
} |
| 2142 |
|
| 2143 |
if ( key == K_INS ) { |
| 2144 |
DC->setOverstrikeMode(!DC->getOverstrikeMode()); |
| 2145 |
return qtrue; |
| 2146 |
} |
| 2147 |
} |
| 2148 |
|
| 2149 |
if (key == K_TAB || key == K_DOWNARROW ) { |
| 2150 |
newItem = Menu_SetNextCursorItem(item->parent); |
| 2151 |
if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD)) { |
| 2152 |
g_editItem = newItem; |
| 2153 |
} |
| 2154 |
} |
| 2155 |
|
| 2156 |
if (key == K_UPARROW ) { |
| 2157 |
newItem = Menu_SetPrevCursorItem(item->parent); |
| 2158 |
if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD)) { |
| 2159 |
g_editItem = newItem; |
| 2160 |
} |
| 2161 |
} |
| 2162 |
|
| 2163 |
if ( key == K_ENTER || key == K_KP_ENTER || key == K_ESCAPE) { |
| 2164 |
return qfalse; |
| 2165 |
} |
| 2166 |
|
| 2167 |
return qtrue; |
| 2168 |
} |
| 2169 |
return qfalse; |
| 2170 |
|
| 2171 |
} |
| 2172 |
|
| 2173 |
static void Scroll_ListBox_AutoFunc(void *p) { |
| 2174 |
scrollInfo_t *si = (scrollInfo_t*)p; |
| 2175 |
if (DC->realTime > si->nextScrollTime) { |
| 2176 |
// need to scroll which is done by simulating a click to the item |
| 2177 |
// this is done a bit sideways as the autoscroll "knows" that the item is a listbox |
| 2178 |
// so it calls it directly |
| 2179 |
Item_ListBox_HandleKey(si->item, si->scrollKey, qtrue, qfalse); |
| 2180 |
si->nextScrollTime = DC->realTime + si->adjustValue; |
| 2181 |
} |
| 2182 |
|
| 2183 |
if (DC->realTime > si->nextAdjustTime) { |
| 2184 |
si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST; |
| 2185 |
if (si->adjustValue > SCROLL_TIME_FLOOR) { |
| 2186 |
si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET; |
| 2187 |
} |
| 2188 |
} |
| 2189 |
} |
| 2190 |
|
| 2191 |
static void Scroll_ListBox_ThumbFunc(void *p) { |
| 2192 |
scrollInfo_t *si = (scrollInfo_t*)p; |
| 2193 |
rectDef_t r; |
| 2194 |
int pos, max; |
| 2195 |
|
| 2196 |
listBoxDef_t *listPtr = (listBoxDef_t*)si->item->typeData; |
| 2197 |
if (si->item->window.flags & WINDOW_HORIZONTAL) { |
| 2198 |
if (DC->cursorx == si->xStart) { |
| 2199 |
return; |
| 2200 |
} |
| 2201 |
r.x = si->item->window.rect.x + SCROLLBAR_SIZE + 1; |
| 2202 |
r.y = si->item->window.rect.y + si->item->window.rect.h - SCROLLBAR_SIZE - 1; |
| 2203 |
r.h = SCROLLBAR_SIZE; |
| 2204 |
r.w = si->item->window.rect.w - (SCROLLBAR_SIZE*2) - 2; |
| 2205 |
max = Item_ListBox_MaxScroll(si->item); |
| 2206 |
// |
| 2207 |
pos = (DC->cursorx - r.x - SCROLLBAR_SIZE/2) * max / (r.w - SCROLLBAR_SIZE); |
| 2208 |
if (pos < 0) { |
| 2209 |
pos = 0; |
| 2210 |
} |
| 2211 |
else if (pos > max) { |
| 2212 |
pos = max; |
| 2213 |
} |
| 2214 |
listPtr->startPos = pos; |
| 2215 |
si->xStart = DC->cursorx; |
| 2216 |
} |
| 2217 |
else if (DC->cursory != si->yStart) { |
| 2218 |
|
| 2219 |
r.x = si->item->window.rect.x + si->item->window.rect.w - SCROLLBAR_SIZE - 1; |
| 2220 |
r.y = si->item->window.rect.y + SCROLLBAR_SIZE + 1; |
| 2221 |
r.h = si->item->window.rect.h - (SCROLLBAR_SIZE*2) - 2; |
| 2222 |
r.w = SCROLLBAR_SIZE; |
| 2223 |
max = Item_ListBox_MaxScroll(si->item); |
| 2224 |
// |
| 2225 |
pos = (DC->cursory - r.y - SCROLLBAR_SIZE/2) * max / (r.h - SCROLLBAR_SIZE); |
| 2226 |
if (pos < 0) { |
| 2227 |
pos = 0; |
| 2228 |
} |
| 2229 |
else if (pos > max) { |
| 2230 |
pos = max; |
| 2231 |
} |
| 2232 |
listPtr->startPos = pos; |
| 2233 |
si->yStart = DC->cursory; |
| 2234 |
} |
| 2235 |
|
| 2236 |
if (DC->realTime > si->nextScrollTime) { |
| 2237 |
// need to scroll which is done by simulating a click to the item |
| 2238 |
// this is done a bit sideways as the autoscroll "knows" that the item is a listbox |
| 2239 |
// so it calls it directly |
| 2240 |
Item_ListBox_HandleKey(si->item, si->scrollKey, qtrue, qfalse); |
| 2241 |
si->nextScrollTime = DC->realTime + si->adjustValue; |
| 2242 |
} |
| 2243 |
|
| 2244 |
if (DC->realTime > si->nextAdjustTime) { |
| 2245 |
si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST; |
| 2246 |
if (si->adjustValue > SCROLL_TIME_FLOOR) { |
| 2247 |
si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET; |
| 2248 |
} |
| 2249 |
} |
| 2250 |
} |
| 2251 |
|
| 2252 |
static void Scroll_Slider_ThumbFunc(void *p) { |
| 2253 |
float x, value, cursorx; |
| 2254 |
scrollInfo_t *si = (scrollInfo_t*)p; |
| 2255 |
editFieldDef_t *editDef = si->item->typeData; |
| 2256 |
|
| 2257 |
if (si->item->text) { |
| 2258 |
x = si->item->textRect.x + si->item->textRect.w + 8; |
| 2259 |
} else { |
| 2260 |
x = si->item->window.rect.x; |
| 2261 |
} |
| 2262 |
|
| 2263 |
cursorx = DC->cursorx; |
| 2264 |
|
| 2265 |
if (cursorx < x) { |
| 2266 |
cursorx = x; |
| 2267 |
} else if (cursorx > x + SLIDER_WIDTH) { |
| 2268 |
cursorx = x + SLIDER_WIDTH; |
| 2269 |
} |
| 2270 |
value = cursorx - x; |
| 2271 |
value /= SLIDER_WIDTH; |
| 2272 |
value *= (editDef->maxVal - editDef->minVal); |
| 2273 |
value += editDef->minVal; |
| 2274 |
DC->setCVar(si->item->cvar, va("%f", value)); |
| 2275 |
} |
| 2276 |
|
| 2277 |
void Item_StartCapture(itemDef_t *item, int key) { |
| 2278 |
int flags; |
| 2279 |
switch (item->type) { |
| 2280 |
case ITEM_TYPE_EDITFIELD: |
| 2281 |
case ITEM_TYPE_NUMERICFIELD: |
| 2282 |
|
| 2283 |
case ITEM_TYPE_LISTBOX: |
| 2284 |
{ |
| 2285 |
flags = Item_ListBox_OverLB(item, DC->cursorx, DC->cursory); |
| 2286 |
if (flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW)) { |
| 2287 |
scrollInfo.nextScrollTime = DC->realTime + SCROLL_TIME_START; |
| 2288 |
scrollInfo.nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST; |
| 2289 |
scrollInfo.adjustValue = SCROLL_TIME_START; |
| 2290 |
scrollInfo.scrollKey = key; |
| 2291 |
scrollInfo.scrollDir = (flags & WINDOW_LB_LEFTARROW) ? qtrue : qfalse; |
| 2292 |
scrollInfo.item = item; |
| 2293 |
captureData = &scrollInfo; |
| 2294 |
captureFunc = &Scroll_ListBox_AutoFunc; |
| 2295 |
itemCapture = item; |
| 2296 |
} else if (flags & WINDOW_LB_THUMB) { |
| 2297 |
scrollInfo.scrollKey = key; |
| 2298 |
scrollInfo.item = item; |
| 2299 |
scrollInfo.xStart = DC->cursorx; |
| 2300 |
scrollInfo.yStart = DC->cursory; |
| 2301 |
captureData = &scrollInfo; |
| 2302 |
captureFunc = &Scroll_ListBox_ThumbFunc; |
| 2303 |
itemCapture = item; |
| 2304 |
} |
| 2305 |
break; |
| 2306 |
} |
| 2307 |
case ITEM_TYPE_SLIDER: |
| 2308 |
{ |
| 2309 |
flags = Item_Slider_OverSlider(item, DC->cursorx, DC->cursory); |
| 2310 |
if (flags & WINDOW_LB_THUMB) { |
| 2311 |
scrollInfo.scrollKey = key; |
| 2312 |
scrollInfo.item = item; |
| 2313 |
scrollInfo.xStart = DC->cursorx; |
| 2314 |
scrollInfo.yStart = DC->cursory; |
| 2315 |
captureData = &scrollInfo; |
| 2316 |
captureFunc = &Scroll_Slider_ThumbFunc; |
| 2317 |
itemCapture = item; |
| 2318 |
} |
| 2319 |
break; |
| 2320 |
} |
| 2321 |
} |
| 2322 |
} |
| 2323 |
|
| 2324 |
void Item_StopCapture(itemDef_t *item) { |
| 2325 |
|
| 2326 |
} |
| 2327 |
|
| 2328 |
qboolean Item_Slider_HandleKey(itemDef_t *item, int key, qboolean down) { |
| 2329 |
float x, value, width, work; |
| 2330 |
|
| 2331 |
//DC->Print("slider handle key\n"); |
| 2332 |
if (item->window.flags & WINDOW_HASFOCUS && item->cvar && Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory)) { |
| 2333 |
if (key == K_MOUSE1 || key == K_ENTER || key == K_MOUSE2 || key == K_MOUSE3) { |
| 2334 |
editFieldDef_t *editDef = item->typeData; |
| 2335 |
if (editDef) { |
| 2336 |
rectDef_t testRect; |
| 2337 |
width = SLIDER_WIDTH; |
| 2338 |
if (item->text) { |
| 2339 |
x = item->textRect.x + item->textRect.w + 8; |
| 2340 |
} else { |
| 2341 |
x = item->window.rect.x; |
| 2342 |
} |
| 2343 |
|
| 2344 |
testRect = item->window.rect; |
| 2345 |
testRect.x = x; |
| 2346 |
value = (float)SLIDER_THUMB_WIDTH / 2; |
| 2347 |
testRect.x -= value; |
| 2348 |
//DC->Print("slider x: %f\n", testRect.x); |
| 2349 |
testRect.w = (SLIDER_WIDTH + (float)SLIDER_THUMB_WIDTH / 2); |
| 2350 |
//DC->Print("slider w: %f\n", testRect.w); |
| 2351 |
if (Rect_ContainsPoint(&testRect, DC->cursorx, DC->cursory)) { |
| 2352 |
work = DC->cursorx - x; |
| 2353 |
value = work / width; |
| 2354 |
value *= (editDef->maxVal - editDef->minVal); |
| 2355 |
// vm fuckage |
| 2356 |
// value = (((float)(DC->cursorx - x)/ SLIDER_WIDTH) * (editDef->maxVal - editDef->minVal)); |
| 2357 |
value += editDef->minVal; |
| 2358 |
DC->setCVar(item->cvar, va("%f", value)); |
| 2359 |
return qtrue; |
| 2360 |
} |
| 2361 |
} |
| 2362 |
} |
| 2363 |
} |
| 2364 |
DC->Print("slider handle key exit\n"); |
| 2365 |
return qfalse; |
| 2366 |
} |
| 2367 |
|
| 2368 |
|
| 2369 |
qboolean Item_HandleKey(itemDef_t *item, int key, qboolean down) { |
| 2370 |
|
| 2371 |
if (itemCapture) { |
| 2372 |
Item_StopCapture(itemCapture); |
| 2373 |
itemCapture = NULL; |
| 2374 |
captureFunc = 0; |
| 2375 |
captureData = NULL; |
| 2376 |
} else { |
| 2377 |
// bk001206 - parentheses |
| 2378 |
if ( down && ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) ) { |
| 2379 |
Item_StartCapture(item, key); |
| 2380 |
} |
| 2381 |
} |
| 2382 |
|
| 2383 |
if (!down) { |
| 2384 |
return qfalse; |
| 2385 |
} |
| 2386 |
|
| 2387 |
switch (item->type) { |
| 2388 |
case ITEM_TYPE_BUTTON: |
| 2389 |
return qfalse; |
| 2390 |
break; |
| 2391 |
case ITEM_TYPE_RADIOBUTTON: |
| 2392 |
return qfalse; |
| 2393 |
break; |
| 2394 |
case ITEM_TYPE_CHECKBOX: |
| 2395 |
return qfalse; |
| 2396 |
break; |
| 2397 |
case ITEM_TYPE_EDITFIELD: |
| 2398 |
case ITEM_TYPE_NUMERICFIELD: |
| 2399 |
//return Item_TextField_HandleKey(item, key); |
| 2400 |
return qfalse; |
| 2401 |
break; |
| 2402 |
case ITEM_TYPE_COMBO: |
| 2403 |
return qfalse; |
| 2404 |
break; |
| 2405 |
case ITEM_TYPE_LISTBOX: |
| 2406 |
return Item_ListBox_HandleKey(item, key, down, qfalse); |
| 2407 |
break; |
| 2408 |
case ITEM_TYPE_YESNO: |
| 2409 |
return Item_YesNo_HandleKey(item, key); |
| 2410 |
break; |
| 2411 |
case ITEM_TYPE_MULTI: |
| 2412 |
return Item_Multi_HandleKey(item, key); |
| 2413 |
break; |
| 2414 |
case ITEM_TYPE_OWNERDRAW: |
| 2415 |
return Item_OwnerDraw_HandleKey(item, key); |
| 2416 |
break; |
| 2417 |
case ITEM_TYPE_BIND: |
| 2418 |
return Item_Bind_HandleKey(item, key, down); |
| 2419 |
break; |
| 2420 |
case ITEM_TYPE_SLIDER: |
| 2421 |
return Item_Slider_HandleKey(item, key, down); |
| 2422 |
break; |
| 2423 |
//case ITEM_TYPE_IMAGE: |
| 2424 |
// Item_Image_Paint(item); |
| 2425 |
// break; |
| 2426 |
default: |
| 2427 |
return qfalse; |
| 2428 |
break; |
| 2429 |
} |
| 2430 |
|
| 2431 |
//return qfalse; |
| 2432 |
} |
| 2433 |
|
| 2434 |
void Item_Action(itemDef_t *item) { |
| 2435 |
if (item) { |
| 2436 |
Item_RunScript(item, item->action); |
| 2437 |
} |
| 2438 |
} |
| 2439 |
|
| 2440 |
itemDef_t *Menu_SetPrevCursorItem(menuDef_t *menu) { |
| 2441 |
qboolean wrapped = qfalse; |
| 2442 |
int oldCursor = menu->cursorItem; |
| 2443 |
|
| 2444 |
if (menu->cursorItem < 0) { |
| 2445 |
menu->cursorItem = menu->itemCount-1; |
| 2446 |
wrapped = qtrue; |
| 2447 |
} |
| 2448 |
|
| 2449 |
while (menu->cursorItem > -1) { |
| 2450 |
|
| 2451 |
menu->cursorItem--; |
| 2452 |
if (menu->cursorItem < 0 && !wrapped) { |
| 2453 |
wrapped = qtrue; |
| 2454 |
menu->cursorItem = menu->itemCount -1; |
| 2455 |
} |
| 2456 |
|
| 2457 |
if (Item_SetFocus(menu->items[menu->cursorItem], DC->cursorx, DC->cursory)) { |
| 2458 |
Menu_HandleMouseMove(menu, menu->items[menu->cursorItem]->window.rect.x + 1, menu->items[menu->cursorItem]->window.rect.y + 1); |
| 2459 |
return menu->items[menu->cursorItem]; |
| 2460 |
} |
| 2461 |
} |
| 2462 |
menu->cursorItem = oldCursor; |
| 2463 |
return NULL; |
| 2464 |
|
| 2465 |
} |
| 2466 |
|
| 2467 |
itemDef_t *Menu_SetNextCursorItem(menuDef_t *menu) { |
| 2468 |
|
| 2469 |
qboolean wrapped = qfalse; |
| 2470 |
int oldCursor = menu->cursorItem; |
| 2471 |
|
| 2472 |
|
| 2473 |
if (menu->cursorItem == -1) { |
| 2474 |
menu->cursorItem = 0; |
| 2475 |
wrapped = qtrue; |
| 2476 |
} |
| 2477 |
|
| 2478 |
while (menu->cursorItem < menu->itemCount) { |
| 2479 |
|
| 2480 |
menu->cursorItem++; |
| 2481 |
if (menu->cursorItem >= menu->itemCount && !wrapped) { |
| 2482 |
wrapped = qtrue; |
| 2483 |
menu->cursorItem = 0; |
| 2484 |
} |
| 2485 |
if (Item_SetFocus(menu->items[menu->cursorItem], DC->cursorx, DC->cursory)) { |
| 2486 |
Menu_HandleMouseMove(menu, menu->items[menu->cursorItem]->window.rect.x + 1, menu->items[menu->cursorItem]->window.rect.y + 1); |
| 2487 |
return menu->items[menu->cursorItem]; |
| 2488 |
} |
| 2489 |
|
| 2490 |
} |
| 2491 |
|
| 2492 |
menu->cursorItem = oldCursor; |
| 2493 |
return NULL; |
| 2494 |
} |
| 2495 |
|
| 2496 |
static void Window_CloseCinematic(windowDef_t *window) { |
| 2497 |
if (window->style == WINDOW_STYLE_CINEMATIC && window->cinematic >= 0) { |
| 2498 |
DC->stopCinematic(window->cinematic); |
| 2499 |
window->cinematic = -1; |
| 2500 |
} |
| 2501 |
} |
| 2502 |
|
| 2503 |
static void Menu_CloseCinematics(menuDef_t *menu) { |
| 2504 |
if (menu) { |
| 2505 |
int i; |
| 2506 |
Window_CloseCinematic(&menu->window); |
| 2507 |
for (i = 0; i < menu->itemCount; i++) { |
| 2508 |
Window_CloseCinematic(&menu->items[i]->window); |
| 2509 |
if (menu->items[i]->type == ITEM_TYPE_OWNERDRAW) { |
| 2510 |
DC->stopCinematic(0-menu->items[i]->window.ownerDraw); |
| 2511 |
} |
| 2512 |
} |
| 2513 |
} |
| 2514 |
} |
| 2515 |
|
| 2516 |
static void Display_CloseCinematics( void ) { |
| 2517 |
int i; |
| 2518 |
for (i = 0; i < menuCount; i++) { |
| 2519 |
Menu_CloseCinematics(&Menus[i]); |
| 2520 |
} |
| 2521 |
} |
| 2522 |
|
| 2523 |
void Menus_Activate(menuDef_t *menu) { |
| 2524 |
menu->window.flags |= (WINDOW_HASFOCUS | WINDOW_VISIBLE); |
| 2525 |
if (menu->onOpen) { |
| 2526 |
itemDef_t item; |
| 2527 |
item.parent = menu; |
| 2528 |
Item_RunScript(&item, menu->onOpen); |
| 2529 |
} |
| 2530 |
|
| 2531 |
if (menu->soundName && *menu->soundName) { |
| 2532 |
// DC->stopBackgroundTrack(); // you don't want to do this since it will reset s_rawend |
| 2533 |
DC->startBackgroundTrack(menu->soundName, menu->soundName); |
| 2534 |
} |
| 2535 |
|
| 2536 |
Display_CloseCinematics(); |
| 2537 |
|
| 2538 |
} |
| 2539 |
|
| 2540 |
int Display_VisibleMenuCount( void ) { |
| 2541 |
int i, count; |
| 2542 |
count = 0; |
| 2543 |
for (i = 0; i < menuCount; i++) { |
| 2544 |
if (Menus[i].window.flags & (WINDOW_FORCED | WINDOW_VISIBLE)) { |
| 2545 |
count++; |
| 2546 |
} |
| 2547 |
} |
| 2548 |
return count; |
| 2549 |
} |
| 2550 |
|
| 2551 |
void Menus_HandleOOBClick(menuDef_t *menu, int key, qboolean down) { |
| 2552 |
if (menu) { |
| 2553 |
int i; |
| 2554 |
// basically the behaviour we are looking for is if there are windows in the stack.. see if |
| 2555 |
// the cursor is within any of them.. if not close them otherwise activate them and pass the |
| 2556 |
// key on.. force a mouse move to activate focus and script stuff |
| 2557 |
if (down && menu->window.flags & WINDOW_OOB_CLICK) { |
| 2558 |
Menu_RunCloseScript(menu); |
| 2559 |
menu->window.flags &= ~(WINDOW_HASFOCUS | WINDOW_VISIBLE); |
| 2560 |
} |
| 2561 |
|
| 2562 |
for (i = 0; i < menuCount; i++) { |
| 2563 |
if (Menu_OverActiveItem(&Menus[i], DC->cursorx, DC->cursory)) { |
| 2564 |
Menu_RunCloseScript(menu); |
| 2565 |
menu->window.flags &= ~(WINDOW_HASFOCUS | WINDOW_VISIBLE); |
| 2566 |
Menus_Activate(&Menus[i]); |
| 2567 |
Menu_HandleMouseMove(&Menus[i], DC->cursorx, DC->cursory); |
| 2568 |
Menu_HandleKey(&Menus[i], key, down); |
| 2569 |
} |
| 2570 |
} |
| 2571 |
|
| 2572 |
if (Display_VisibleMenuCount() == 0) { |
| 2573 |
if (DC->Pause) { |
| 2574 |
DC->Pause(qfalse); |
| 2575 |
} |
| 2576 |
} |
| 2577 |
Display_CloseCinematics(); |
| 2578 |
} |
| 2579 |
} |
| 2580 |
|
| 2581 |
static rectDef_t *Item_CorrectedTextRect(itemDef_t *item) { |
| 2582 |
static rectDef_t rect; |
| 2583 |
memset(&rect, 0, sizeof(rectDef_t)); |
| 2584 |
if (item) { |
| 2585 |
rect = item->textRect; |
| 2586 |
if (rect.w) { |
| 2587 |
rect.y -= rect.h; |
| 2588 |
} |
| 2589 |
} |
| 2590 |
return ▭ |
| 2591 |
} |
| 2592 |
|
| 2593 |
void Menu_HandleKey(menuDef_t *menu, int key, qboolean down) { |
| 2594 |
int i; |
| 2595 |
itemDef_t *item = NULL; |
| 2596 |
qboolean inHandler = qfalse; |
| 2597 |
|
| 2598 |
if (inHandler) { |
| 2599 |
return; |
| 2600 |
} |
| 2601 |
|
| 2602 |
inHandler = qtrue; |
| 2603 |
if (g_waitingForKey && down) { |
| 2604 |
Item_Bind_HandleKey(g_bindItem, key, down); |
| 2605 |
inHandler = qfalse; |
| 2606 |
return; |
| 2607 |
} |
| 2608 |
|
| 2609 |
if (g_editingField && down) { |
| 2610 |
if (!Item_TextField_HandleKey(g_editItem, key)) { |
| 2611 |
g_editingField = qfalse; |
| 2612 |
g_editItem = NULL; |
| 2613 |
inHandler = qfalse; |
| 2614 |
return; |
| 2615 |
} else if (key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3) { |
| 2616 |
g_editingField = qfalse; |
| 2617 |
g_editItem = NULL; |
| 2618 |
Display_MouseMove(NULL, DC->cursorx, DC->cursory); |
| 2619 |
} else if (key == K_TAB || key == K_UPARROW || key == K_DOWNARROW) { |
| 2620 |
return; |
| 2621 |
} |
| 2622 |
} |
| 2623 |
|
| 2624 |
if (menu == NULL) { |
| 2625 |
inHandler = qfalse; |
| 2626 |
return; |
| 2627 |
} |
| 2628 |
|
| 2629 |
// see if the mouse is within the window bounds and if so is this a mouse click |
| 2630 |
if (down && !(menu->window.flags & WINDOW_POPUP) && !Rect_ContainsPoint(&menu->window.rect, DC->cursorx, DC->cursory)) { |
| 2631 |
static qboolean inHandleKey = qfalse; |
| 2632 |
// bk001206 - parentheses |
| 2633 |
if (!inHandleKey && ( key == K_MOUSE1 || key == K_MOUSE2 || key == K_MOUSE3 ) ) { |
| 2634 |
inHandleKey = qtrue; |
| 2635 |
Menus_HandleOOBClick(menu, key, down); |
| 2636 |
inHandleKey = qfalse; |
| 2637 |
inHandler = qfalse; |
| 2638 |
return; |
| 2639 |
} |
| 2640 |
} |
| 2641 |
|
| 2642 |
// get the item with focus |
| 2643 |
for (i = 0; i < menu->itemCount; i++) { |
| 2644 |
if (menu->items[i]->window.flags & WINDOW_HASFOCUS) { |
| 2645 |
item = menu->items[i]; |
| 2646 |
} |
| 2647 |
} |
| 2648 |
|
| 2649 |
if (item != NULL) { |
| 2650 |
if (Item_HandleKey(item, key, down)) { |
| 2651 |
Item_Action(item); |
| 2652 |
inHandler = qfalse; |
| 2653 |
return; |
| 2654 |
} |
| 2655 |
} |
| 2656 |
|
| 2657 |
if (!down) { |
| 2658 |
inHandler = qfalse; |
| 2659 |
return; |
| 2660 |
} |
| 2661 |
|
| 2662 |
// default handling |
| 2663 |
switch ( key ) { |
| 2664 |
|
| 2665 |
case K_F11: |
| 2666 |
if (DC->getCVarValue("developer")) { |
| 2667 |
debugMode ^= 1; |
| 2668 |
} |
| 2669 |
break; |
| 2670 |
|
| 2671 |
case K_F12: |
| 2672 |
if (DC->getCVarValue("developer")) { |
| 2673 |
DC->executeText(EXEC_APPEND, "screenshot\n"); |
| 2674 |
} |
| 2675 |
break; |
| 2676 |
case K_UPARROW: |
| 2677 |
Menu_SetPrevCursorItem(menu); |
| 2678 |
break; |
| 2679 |
|
| 2680 |
case K_ESCAPE: |
| 2681 |
if (!g_waitingForKey && menu->onESC) { |
| 2682 |
itemDef_t it; |
| 2683 |
it.parent = menu; |
| 2684 |
Item_RunScript(&it, menu->onESC); |
| 2685 |
} |
| 2686 |
break; |
| 2687 |
case K_TAB: |
| 2688 |
case K_DOWNARROW: |
| 2689 |
Menu_SetNextCursorItem(menu); |
| 2690 |
break; |
| 2691 |
|
| 2692 |
case K_MOUSE1: |
| 2693 |
case K_MOUSE2: |
| 2694 |
if (item) { |
| 2695 |
if (item->type == ITEM_TYPE_TEXT) { |
| 2696 |
if (Rect_ContainsPoint(Item_CorrectedTextRect(item), DC->cursorx, DC->cursory)) { |
| 2697 |
Item_Action(item); |
| 2698 |
} |
| 2699 |
} else if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD) { |
| 2700 |
if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory)) { |
| 2701 |
item->cursorPos = 0; |
| 2702 |
g_editingField = qtrue; |
| 2703 |
g_editItem = item; |
| 2704 |
} |
| 2705 |
} else { |
| 2706 |
if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory)) { |
| 2707 |
Item_Action(item); |
| 2708 |
} |
| 2709 |
} |
| 2710 |
} |
| 2711 |
break; |
| 2712 |
|
| 2713 |
case K_JOY1: |
| 2714 |
case K_JOY2: |
| 2715 |
case K_JOY3: |
| 2716 |
case K_JOY4: |
| 2717 |
case K_AUX1: |
| 2718 |
case K_AUX2: |
| 2719 |
case K_AUX3: |
| 2720 |
case K_AUX4: |
| 2721 |
case K_AUX5: |
| 2722 |
case K_AUX6: |
| 2723 |
case K_AUX7: |
| 2724 |
case K_AUX8: |
| 2725 |
case K_AUX9: |
| 2726 |
case K_AUX10: |
| 2727 |
case K_AUX11: |
| 2728 |
case K_AUX12: |
| 2729 |
case K_AUX13: |
| 2730 |
case K_AUX14: |
| 2731 |
case K_AUX15: |
| 2732 |
case K_AUX16: |
| 2733 |
break; |
| 2734 |
case K_KP_ENTER: |
| 2735 |
case K_ENTER: |
| 2736 |
if (item) { |
| 2737 |
if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD) { |
| 2738 |
item->cursorPos = 0; |
| 2739 |
g_editingField = qtrue; |
| 2740 |
g_editItem = item; |
| 2741 |
} else { |
| 2742 |
Item_Action(item); |
| 2743 |
} |
| 2744 |
} |
| 2745 |
break; |
| 2746 |
} |
| 2747 |
inHandler = qfalse; |
| 2748 |
} |
| 2749 |
|
| 2750 |
void ToWindowCoords(float *x, float *y, windowDef_t *window) { |
| 2751 |
if (window->border != 0) { |
| 2752 |
*x += window->borderSize; |
| 2753 |
*y += window->borderSize; |
| 2754 |
} |
| 2755 |
*x += window->rect.x; |
| 2756 |
*y += window->rect.y; |
| 2757 |
} |
| 2758 |
|
| 2759 |
void Rect_ToWindowCoords(rectDef_t *rect, windowDef_t *window) { |
| 2760 |
ToWindowCoords(&rect->x, &rect->y, window); |
| 2761 |
} |
| 2762 |
|
| 2763 |
void Item_SetTextExtents(itemDef_t *item, int *width, int *height, const char *text) { |
| 2764 |
const char *textPtr = (text) ? text : item->text; |
| 2765 |
|
| 2766 |
if (textPtr == NULL ) { |
| 2767 |
return; |
| 2768 |
} |
| 2769 |
|
| 2770 |
*width = item->textRect.w; |
| 2771 |
*height = item->textRect.h; |
| 2772 |
|
| 2773 |
// keeps us from computing the widths and heights more than once |
| 2774 |
if (*width == 0 || (item->type == ITEM_TYPE_OWNERDRAW && item->textalignment == ITEM_ALIGN_CENTER)) { |
| 2775 |
int originalWidth = DC->textWidth(item->text, item->textscale, 0); |
| 2776 |
|
| 2777 |
if (item->type == ITEM_TYPE_OWNERDRAW && (item->textalignment == ITEM_ALIGN_CENTER || item->textalignment == ITEM_ALIGN_RIGHT)) { |
| 2778 |
originalWidth += DC->ownerDrawWidth(item->window.ownerDraw, item->textscale); |
| 2779 |
} else if (item->type == ITEM_TYPE_EDITFIELD && item->textalignment == ITEM_ALIGN_CENTER && item->cvar) { |
| 2780 |
char buff[256]; |
| 2781 |
DC->getCVarString(item->cvar, buff, 256); |
| 2782 |
originalWidth += DC->textWidth(buff, item->textscale, 0); |
| 2783 |
} |
| 2784 |
|
| 2785 |
*width = DC->textWidth(textPtr, item->textscale, 0); |
| 2786 |
*height = DC->textHeight(textPtr, item->textscale, 0); |
| 2787 |
item->textRect.w = *width; |
| 2788 |
item->textRect.h = *height; |
| 2789 |
item->textRect.x = item->textalignx; |
| 2790 |
item->textRect.y = item->textaligny; |
| 2791 |
if (item->textalignment == ITEM_ALIGN_RIGHT) { |
| 2792 |
item->textRect.x = item->textalignx - originalWidth; |
| 2793 |
} else if (item->textalignment == ITEM_ALIGN_CENTER) { |
| 2794 |
item->textRect.x = item->textalignx - originalWidth / 2; |
| 2795 |
} |
| 2796 |
|
| 2797 |
ToWindowCoords(&item->textRect.x, &item->textRect.y, &item->window); |
| 2798 |
} |
| 2799 |
} |
| 2800 |
|
| 2801 |
void Item_TextColor(itemDef_t *item, vec4_t *newColor) { |
| 2802 |
vec4_t lowLight; |
| 2803 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 2804 |
|
| 2805 |
Fade(&item->window.flags, &item->window.foreColor[3], parent->fadeClamp, &item->window.nextTime, parent->fadeCycle, qtrue, parent->fadeAmount); |
| 2806 |
|
| 2807 |
if (item->window.flags & WINDOW_HASFOCUS) { |
| 2808 |
lowLight[0] = 0.8 * parent->focusColor[0]; |
| 2809 |
lowLight[1] = 0.8 * parent->focusColor[1]; |
| 2810 |
lowLight[2] = 0.8 * parent->focusColor[2]; |
| 2811 |
lowLight[3] = 0.8 * parent->focusColor[3]; |
| 2812 |
LerpColor(parent->focusColor,lowLight,*newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 2813 |
} else if (item->textStyle == ITEM_TEXTSTYLE_BLINK && !((DC->realTime/BLINK_DIVISOR) & 1)) { |
| 2814 |
lowLight[0] = 0.8 * item->window.foreColor[0]; |
| 2815 |
lowLight[1] = 0.8 * item->window.foreColor[1]; |
| 2816 |
lowLight[2] = 0.8 * item->window.foreColor[2]; |
| 2817 |
lowLight[3] = 0.8 * item->window.foreColor[3]; |
| 2818 |
LerpColor(item->window.foreColor,lowLight,*newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 2819 |
} else { |
| 2820 |
memcpy(newColor, &item->window.foreColor, sizeof(vec4_t)); |
| 2821 |
// items can be enabled and disabled based on cvars |
| 2822 |
} |
| 2823 |
|
| 2824 |
if (item->enableCvar && *item->enableCvar && item->cvarTest && *item->cvarTest) { |
| 2825 |
if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { |
| 2826 |
memcpy(newColor, &parent->disableColor, sizeof(vec4_t)); |
| 2827 |
} |
| 2828 |
} |
| 2829 |
} |
| 2830 |
|
| 2831 |
void Item_Text_AutoWrapped_Paint(itemDef_t *item) { |
| 2832 |
char text[1024]; |
| 2833 |
const char *p, *textPtr, *newLinePtr; |
| 2834 |
char buff[1024]; |
| 2835 |
int width, height, len, textWidth, newLine, newLineWidth; |
| 2836 |
float y; |
| 2837 |
vec4_t color; |
| 2838 |
|
| 2839 |
textWidth = 0; |
| 2840 |
newLinePtr = NULL; |
| 2841 |
|
| 2842 |
if (item->text == NULL) { |
| 2843 |
if (item->cvar == NULL) { |
| 2844 |
return; |
| 2845 |
} |
| 2846 |
else { |
| 2847 |
DC->getCVarString(item->cvar, text, sizeof(text)); |
| 2848 |
textPtr = text; |
| 2849 |
} |
| 2850 |
} |
| 2851 |
else { |
| 2852 |
textPtr = item->text; |
| 2853 |
} |
| 2854 |
if (*textPtr == '\0') { |
| 2855 |
return; |
| 2856 |
} |
| 2857 |
Item_TextColor(item, &color); |
| 2858 |
Item_SetTextExtents(item, &width, &height, textPtr); |
| 2859 |
|
| 2860 |
y = item->textaligny; |
| 2861 |
len = 0; |
| 2862 |
buff[0] = '\0'; |
| 2863 |
newLine = 0; |
| 2864 |
newLineWidth = 0; |
| 2865 |
p = textPtr; |
| 2866 |
while (p) { |
| 2867 |
if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\0') { |
| 2868 |
newLine = len; |
| 2869 |
newLinePtr = p+1; |
| 2870 |
newLineWidth = textWidth; |
| 2871 |
} |
| 2872 |
textWidth = DC->textWidth(buff, item->textscale, 0); |
| 2873 |
if ( (newLine && textWidth > item->window.rect.w) || *p == '\n' || *p == '\0') { |
| 2874 |
if (len) { |
| 2875 |
if (item->textalignment == ITEM_ALIGN_LEFT) { |
| 2876 |
item->textRect.x = item->textalignx; |
| 2877 |
} else if (item->textalignment == ITEM_ALIGN_RIGHT) { |
| 2878 |
item->textRect.x = item->textalignx - newLineWidth; |
| 2879 |
} else if (item->textalignment == ITEM_ALIGN_CENTER) { |
| 2880 |
item->textRect.x = item->textalignx - newLineWidth / 2; |
| 2881 |
} |
| 2882 |
item->textRect.y = y; |
| 2883 |
ToWindowCoords(&item->textRect.x, &item->textRect.y, &item->window); |
| 2884 |
// |
| 2885 |
buff[newLine] = '\0'; |
| 2886 |
DC->drawText(item->textRect.x, item->textRect.y, item->textscale, color, buff, 0, 0, item->textStyle); |
| 2887 |
} |
| 2888 |
if (*p == '\0') { |
| 2889 |
break; |
| 2890 |
} |
| 2891 |
// |
| 2892 |
y += height + 5; |
| 2893 |
p = newLinePtr; |
| 2894 |
len = 0; |
| 2895 |
newLine = 0; |
| 2896 |
newLineWidth = 0; |
| 2897 |
continue; |
| 2898 |
} |
| 2899 |
buff[len++] = *p++; |
| 2900 |
buff[len] = '\0'; |
| 2901 |
} |
| 2902 |
} |
| 2903 |
|
| 2904 |
void Item_Text_Wrapped_Paint(itemDef_t *item) { |
| 2905 |
char text[1024]; |
| 2906 |
const char *p, *start, *textPtr; |
| 2907 |
char buff[1024]; |
| 2908 |
int width, height; |
| 2909 |
float x, y; |
| 2910 |
vec4_t color; |
| 2911 |
|
| 2912 |
// now paint the text and/or any optional images |
| 2913 |
// default to left |
| 2914 |
|
| 2915 |
if (item->text == NULL) { |
| 2916 |
if (item->cvar == NULL) { |
| 2917 |
return; |
| 2918 |
} |
| 2919 |
else { |
| 2920 |
DC->getCVarString(item->cvar, text, sizeof(text)); |
| 2921 |
textPtr = text; |
| 2922 |
} |
| 2923 |
} |
| 2924 |
else { |
| 2925 |
textPtr = item->text; |
| 2926 |
} |
| 2927 |
if (*textPtr == '\0') { |
| 2928 |
return; |
| 2929 |
} |
| 2930 |
|
| 2931 |
Item_TextColor(item, &color); |
| 2932 |
Item_SetTextExtents(item, &width, &height, textPtr); |
| 2933 |
|
| 2934 |
x = item->textRect.x; |
| 2935 |
y = item->textRect.y; |
| 2936 |
start = textPtr; |
| 2937 |
p = strchr(textPtr, '\r'); |
| 2938 |
while (p && *p) { |
| •2939 |
Q_strncpyz(buff, start, p - start + 1); |
| 2940 |
DC->drawText(x, y, item->textscale, color, buff, 0, 0, item->textStyle); |
| 2941 |
y += height + 5; |
| 2942 |
start += p - start + 1; |
| 2943 |
p = strchr(p+1, '\r'); |
| 2944 |
} |
| 2945 |
DC->drawText(x, y, item->textscale, color, start, 0, 0, item->textStyle); |
| 2946 |
} |
| 2947 |
|
| 2948 |
void Item_Text_Paint(itemDef_t *item) { |
| 2949 |
char text[1024]; |
| 2950 |
const char *textPtr; |
| 2951 |
int height, width; |
| 2952 |
vec4_t color; |
| 2953 |
|
| 2954 |
if (item->window.flags & WINDOW_WRAPPED) { |
| 2955 |
Item_Text_Wrapped_Paint(item); |
| 2956 |
return; |
| 2957 |
} |
| 2958 |
if (item->window.flags & WINDOW_AUTOWRAPPED) { |
| 2959 |
Item_Text_AutoWrapped_Paint(item); |
| 2960 |
return; |
| 2961 |
} |
| 2962 |
|
| 2963 |
if (item->text == NULL) { |
| 2964 |
if (item->cvar == NULL) { |
| 2965 |
return; |
| 2966 |
} |
| 2967 |
else { |
| 2968 |
DC->getCVarString(item->cvar, text, sizeof(text)); |
| 2969 |
textPtr = text; |
| 2970 |
} |
| 2971 |
} |
| 2972 |
else { |
| 2973 |
textPtr = item->text; |
| 2974 |
} |
| 2975 |
|
| 2976 |
// this needs to go here as it sets extents for cvar types as well |
| 2977 |
Item_SetTextExtents(item, &width, &height, textPtr); |
| 2978 |
|
| 2979 |
if (*textPtr == '\0') { |
| 2980 |
return; |
| 2981 |
} |
| 2982 |
|
| 2983 |
|
| 2984 |
Item_TextColor(item, &color); |
| 2985 |
|
| 2986 |
//FIXME: this is a fucking mess |
| 2987 |
/* |
| 2988 |
adjust = 0; |
| 2989 |
if (item->textStyle == ITEM_TEXTSTYLE_OUTLINED || item->textStyle == ITEM_TEXTSTYLE_OUTLINESHADOWED) { |
| 2990 |
adjust = 0.5; |
| 2991 |
} |
| 2992 |
|
| 2993 |
if (item->textStyle == ITEM_TEXTSTYLE_SHADOWED || item->textStyle == ITEM_TEXTSTYLE_OUTLINESHADOWED) { |
| 2994 |
Fade(&item->window.flags, &DC->Assets.shadowColor[3], DC->Assets.fadeClamp, &item->window.nextTime, DC->Assets.fadeCycle, qfalse); |
| 2995 |
DC->drawText(item->textRect.x + DC->Assets.shadowX, item->textRect.y + DC->Assets.shadowY, item->textscale, DC->Assets.shadowColor, textPtr, adjust); |
| 2996 |
} |
| 2997 |
*/ |
| 2998 |
|
| 2999 |
|
| 3000 |
// if (item->textStyle == ITEM_TEXTSTYLE_OUTLINED || item->textStyle == ITEM_TEXTSTYLE_OUTLINESHADOWED) { |
| 3001 |
// Fade(&item->window.flags, &item->window.outlineColor[3], DC->Assets.fadeClamp, &item->window.nextTime, DC->Assets.fadeCycle, qfalse); |
| 3002 |
// /* |
| 3003 |
// Text_Paint(item->textRect.x-1, item->textRect.y-1, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3004 |
// Text_Paint(item->textRect.x, item->textRect.y-1, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3005 |
// Text_Paint(item->textRect.x+1, item->textRect.y-1, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3006 |
// Text_Paint(item->textRect.x-1, item->textRect.y, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3007 |
// Text_Paint(item->textRect.x+1, item->textRect.y, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3008 |
// Text_Paint(item->textRect.x-1, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3009 |
// Text_Paint(item->textRect.x, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3010 |
// Text_Paint(item->textRect.x+1, item->textRect.y+1, item->textscale, item->window.foreColor, textPtr, adjust); |
| 3011 |
// */ |
| 3012 |
// DC->drawText(item->textRect.x - 1, item->textRect.y + 1, item->textscale * 1.02, item->window.outlineColor, textPtr, adjust); |
| 3013 |
// } |
| 3014 |
|
| 3015 |
DC->drawText(item->textRect.x, item->textRect.y, item->textscale, color, textPtr, 0, 0, item->textStyle); |
| 3016 |
} |
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
//float trap_Cvar_VariableValue( const char *var_name ); |
| 3021 |
//void trap_Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ); |
| 3022 |
|
| 3023 |
void Item_TextField_Paint(itemDef_t *item) { |
| 3024 |
char buff[1024]; |
| 3025 |
vec4_t newColor, lowLight; |
| 3026 |
int offset; |
| 3027 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 3028 |
editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData; |
| 3029 |
|
| 3030 |
Item_Text_Paint(item); |
| 3031 |
|
| 3032 |
buff[0] = '\0'; |
| 3033 |
|
| 3034 |
if (item->cvar) { |
| 3035 |
DC->getCVarString(item->cvar, buff, sizeof(buff)); |
| 3036 |
} |
| 3037 |
|
| 3038 |
parent = (menuDef_t*)item->parent; |
| 3039 |
|
| 3040 |
if (item->window.flags & WINDOW_HASFOCUS) { |
| 3041 |
lowLight[0] = 0.8 * parent->focusColor[0]; |
| 3042 |
lowLight[1] = 0.8 * parent->focusColor[1]; |
| 3043 |
lowLight[2] = 0.8 * parent->focusColor[2]; |
| 3044 |
lowLight[3] = 0.8 * parent->focusColor[3]; |
| 3045 |
LerpColor(parent->focusColor,lowLight,newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 3046 |
} else { |
| 3047 |
memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); |
| 3048 |
} |
| 3049 |
|
| 3050 |
offset = (item->text && *item->text) ? 8 : 0; |
| 3051 |
if (item->window.flags & WINDOW_HASFOCUS && g_editingField) { |
| 3052 |
char cursor = DC->getOverstrikeMode() ? '_' : '|'; |
| 3053 |
DC->drawTextWithCursor(item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, buff + editPtr->paintOffset, item->cursorPos - editPtr->paintOffset , cursor, editPtr->maxPaintChars, item->textStyle); |
| 3054 |
} else { |
| 3055 |
DC->drawText(item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, buff + editPtr->paintOffset, 0, editPtr->maxPaintChars, item->textStyle); |
| 3056 |
} |
| 3057 |
|
| 3058 |
} |
| 3059 |
|
| 3060 |
void Item_YesNo_Paint(itemDef_t *item) { |
| 3061 |
vec4_t newColor, lowLight; |
| 3062 |
float value; |
| 3063 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 3064 |
|
| 3065 |
value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0; |
| 3066 |
|
| 3067 |
if (item->window.flags & WINDOW_HASFOCUS) { |
| 3068 |
lowLight[0] = 0.8 * parent->focusColor[0]; |
| 3069 |
lowLight[1] = 0.8 * parent->focusColor[1]; |
| 3070 |
lowLight[2] = 0.8 * parent->focusColor[2]; |
| 3071 |
lowLight[3] = 0.8 * parent->focusColor[3]; |
| 3072 |
LerpColor(parent->focusColor,lowLight,newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 3073 |
} else { |
| 3074 |
memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); |
| 3075 |
} |
| 3076 |
|
| 3077 |
if (item->text) { |
| 3078 |
Item_Text_Paint(item); |
| 3079 |
DC->drawText(item->textRect.x + item->textRect.w + 8, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); |
| 3080 |
} else { |
| 3081 |
DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "Yes" : "No", 0, 0, item->textStyle); |
| 3082 |
} |
| 3083 |
} |
| 3084 |
|
| 3085 |
void Item_Multi_Paint(itemDef_t *item) { |
| 3086 |
vec4_t newColor, lowLight; |
| 3087 |
const char *text = ""; |
| 3088 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 3089 |
|
| 3090 |
if (item->window.flags & WINDOW_HASFOCUS) { |
| 3091 |
lowLight[0] = 0.8 * parent->focusColor[0]; |
| 3092 |
lowLight[1] = 0.8 * parent->focusColor[1]; |
| 3093 |
lowLight[2] = 0.8 * parent->focusColor[2]; |
| 3094 |
lowLight[3] = 0.8 * parent->focusColor[3]; |
| 3095 |
LerpColor(parent->focusColor,lowLight,newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 3096 |
} else { |
| 3097 |
memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); |
| 3098 |
} |
| 3099 |
|
| 3100 |
text = Item_Multi_Setting(item); |
| 3101 |
|
| 3102 |
if (item->text) { |
| 3103 |
Item_Text_Paint(item); |
| 3104 |
DC->drawText(item->textRect.x + item->textRect.w + 8, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); |
| 3105 |
} else { |
| 3106 |
DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, text, 0, 0, item->textStyle); |
| 3107 |
} |
| 3108 |
} |
| 3109 |
|
| 3110 |
|
| 3111 |
typedef struct { |
| 3112 |
char *command; |
| 3113 |
int id; |
| 3114 |
int defaultbind1; |
| 3115 |
int defaultbind2; |
| 3116 |
int bind1; |
| 3117 |
int bind2; |
| 3118 |
} bind_t; |
| 3119 |
|
| 3120 |
typedef struct |
| 3121 |
{ |
| 3122 |
char* name; |
| 3123 |
float defaultvalue; |
| 3124 |
float value; |
| 3125 |
} configcvar_t; |
| 3126 |
|
| 3127 |
|
| 3128 |
static bind_t g_bindings[] = |
| 3129 |
{ |
| 3130 |
{"+scores", K_TAB, -1, -1, -1}, |
| 3131 |
{"+button2", K_ENTER, -1, -1, -1}, |
| 3132 |
{"+speed", K_SHIFT, -1, -1, -1}, |
| 3133 |
{"+forward", K_UPARROW, -1, -1, -1}, |
| 3134 |
{"+back", K_DOWNARROW, -1, -1, -1}, |
| 3135 |
{"+moveleft", ',', -1, -1, -1}, |
| 3136 |
{"+moveright", '.', -1, -1, -1}, |
| 3137 |
{"+moveup", K_SPACE, -1, -1, -1}, |
| 3138 |
{"+movedown", 'c', -1, -1, -1}, |
| 3139 |
{"+left", K_LEFTARROW, -1, -1, -1}, |
| 3140 |
{"+right", K_RIGHTARROW, -1, -1, -1}, |
| 3141 |
{"+strafe", K_ALT, -1, -1, -1}, |
| 3142 |
{"+lookup", K_PGDN, -1, -1, -1}, |
| 3143 |
{"+lookdown", K_DEL, -1, -1, -1}, |
| 3144 |
{"+mlook", '/', -1, -1, -1}, |
| 3145 |
{"centerview", K_END, -1, -1, -1}, |
| 3146 |
{"+zoom", -1, -1, -1, -1}, |
| 3147 |
{"weapon 1", '1', -1, -1, -1}, |
| 3148 |
{"weapon 2", '2', -1, -1, -1}, |
| 3149 |
{"weapon 3", '3', -1, -1, -1}, |
| 3150 |
{"weapon 4", '4', -1, -1, -1}, |
| 3151 |
{"weapon 5", '5', -1, -1, -1}, |
| 3152 |
{"weapon 6", '6', -1, -1, -1}, |
| 3153 |
{"weapon 7", '7', -1, -1, -1}, |
| 3154 |
{"weapon 8", '8', -1, -1, -1}, |
| 3155 |
{"weapon 9", '9', -1, -1, -1}, |
| 3156 |
{"weapon 10", '0', -1, -1, -1}, |
| 3157 |
{"weapon 11", -1, -1, -1, -1}, |
| 3158 |
{"weapon 12", -1, -1, -1, -1}, |
| 3159 |
{"weapon 13", -1, -1, -1, -1}, |
| 3160 |
{"+attack", K_CTRL, -1, -1, -1}, |
| 3161 |
{"weapprev", '[', -1, -1, -1}, |
| 3162 |
{"weapnext", ']', -1, -1, -1}, |
| 3163 |
{"+button3", K_MOUSE3, -1, -1, -1}, |
| 3164 |
{"+button4", K_MOUSE4, -1, -1, -1}, |
| 3165 |
{"prevTeamMember", 'w', -1, -1, -1}, |
| 3166 |
{"nextTeamMember", 'r', -1, -1, -1}, |
| 3167 |
{"nextOrder", 't', -1, -1, -1}, |
| 3168 |
{"confirmOrder", 'y', -1, -1, -1}, |
| 3169 |
{"denyOrder", 'n', -1, -1, -1}, |
| 3170 |
{"taskOffense", 'o', -1, -1, -1}, |
| 3171 |
{"taskDefense", 'd', -1, -1, -1}, |
| 3172 |
{"taskPatrol", 'p', -1, -1, -1}, |
| 3173 |
{"taskCamp", 'c', -1, -1, -1}, |
| 3174 |
{"taskFollow", 'f', -1, -1, -1}, |
| 3175 |
{"taskRetrieve", 'v', -1, -1, -1}, |
| 3176 |
{"taskEscort", 'e', -1, -1, -1}, |
| 3177 |
{"taskOwnFlag", 'i', -1, -1, -1}, |
| 3178 |
{"taskSuicide", 'k', -1, -1, -1}, |
| 3179 |
{"tauntKillInsult", K_F1, -1, -1, -1}, |
| 3180 |
{"tauntPraise", K_F2, -1, -1, -1}, |
| 3181 |
{"tauntTaunt", K_F3, -1, -1, -1}, |
| 3182 |
{"tauntDeathInsult", K_F4, -1, -1, -1}, |
| 3183 |
{"tauntGauntlet", K_F5, -1, -1, -1}, |
| 3184 |
{"scoresUp", K_KP_PGUP, -1, -1, -1}, |
| 3185 |
{"scoresDown", K_KP_PGDN, -1, -1, -1}, |
| 3186 |
// bk001205 - this one below was: '-1' |
| 3187 |
{"messagemode", -1, -1, -1, -1}, |
| 3188 |
{"messagemode2", -1, -1, -1, -1}, |
| 3189 |
{"messagemode3", -1, -1, -1, -1}, |
| 3190 |
{"messagemode4", -1, -1, -1, -1} |
| 3191 |
}; |
| 3192 |
|
| 3193 |
|
| 3194 |
static const int g_bindCount = sizeof(g_bindings) / sizeof(bind_t); |
| 3195 |
|
| 3196 |
#ifndef MISSIONPACK // bk001206 |
| 3197 |
static configcvar_t g_configcvars[] = |
| 3198 |
{ |
| 3199 |
{"cl_run", 0, 0}, |
| 3200 |
{"m_pitch", 0, 0}, |
| 3201 |
{"cg_autoswitch", 0, 0}, |
| 3202 |
{"sensitivity", 0, 0}, |
| 3203 |
{"in_joystick", 0, 0}, |
| 3204 |
{"joy_threshold", 0, 0}, |
| 3205 |
{"m_filter", 0, 0}, |
| 3206 |
{"cl_freelook", 0, 0}, |
| 3207 |
{NULL, 0, 0} |
| 3208 |
}; |
| 3209 |
#endif |
| 3210 |
|
| 3211 |
/* |
| 3212 |
================= |
| 3213 |
Controls_GetKeyAssignment |
| 3214 |
================= |
| 3215 |
*/ |
| 3216 |
static void Controls_GetKeyAssignment (char *command, int *twokeys) |
| 3217 |
{ |
| 3218 |
int count; |
| 3219 |
int j; |
| 3220 |
char b[256]; |
| 3221 |
|
| 3222 |
twokeys[0] = twokeys[1] = -1; |
| 3223 |
count = 0; |
| 3224 |
|
| 3225 |
for ( j = 0; j < 256; j++ ) |
| 3226 |
{ |
| 3227 |
DC->getBindingBuf( j, b, 256 ); |
| 3228 |
if ( *b == 0 ) { |
| 3229 |
continue; |
| 3230 |
} |
| 3231 |
if ( !Q_stricmp( b, command ) ) { |
| 3232 |
twokeys[count] = j; |
| 3233 |
count++; |
| 3234 |
if (count == 2) { |
| 3235 |
break; |
| 3236 |
} |
| 3237 |
} |
| 3238 |
} |
| 3239 |
} |
| 3240 |
|
| 3241 |
/* |
| 3242 |
================= |
| 3243 |
Controls_GetConfig |
| 3244 |
================= |
| 3245 |
*/ |
| 3246 |
void Controls_GetConfig( void ) |
| 3247 |
{ |
| 3248 |
int i; |
| 3249 |
int twokeys[2]; |
| 3250 |
|
| 3251 |
// iterate each command, get its numeric binding |
| 3252 |
for (i=0; i < g_bindCount; i++) |
| 3253 |
{ |
| 3254 |
|
| 3255 |
Controls_GetKeyAssignment(g_bindings[i].command, twokeys); |
| 3256 |
|
| 3257 |
g_bindings[i].bind1 = twokeys[0]; |
| 3258 |
g_bindings[i].bind2 = twokeys[1]; |
| 3259 |
} |
| 3260 |
|
| 3261 |
//s_controls.invertmouse.curvalue = DC->getCVarValue( "m_pitch" ) < 0; |
| 3262 |
//s_controls.smoothmouse.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "m_filter" ) ); |
| 3263 |
//s_controls.alwaysrun.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_run" ) ); |
| 3264 |
//s_controls.autoswitch.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cg_autoswitch" ) ); |
| 3265 |
//s_controls.sensitivity.curvalue = UI_ClampCvar( 2, 30, Controls_GetCvarValue( "sensitivity" ) ); |
| 3266 |
//s_controls.joyenable.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "in_joystick" ) ); |
| 3267 |
//s_controls.joythreshold.curvalue = UI_ClampCvar( 0.05, 0.75, Controls_GetCvarValue( "joy_threshold" ) ); |
| 3268 |
//s_controls.freelook.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_freelook" ) ); |
| 3269 |
} |
| 3270 |
|
| 3271 |
/* |
| 3272 |
================= |
| 3273 |
Controls_SetConfig |
| 3274 |
================= |
| 3275 |
*/ |
| 3276 |
void Controls_SetConfig(qboolean restart) |
| 3277 |
{ |
| 3278 |
int i; |
| 3279 |
|
| 3280 |
// iterate each command, get its numeric binding |
| 3281 |
for (i=0; i < g_bindCount; i++) |
| 3282 |
{ |
| 3283 |
|
| 3284 |
if (g_bindings[i].bind1 != -1) |
| 3285 |
{ |
| 3286 |
DC->setBinding( g_bindings[i].bind1, g_bindings[i].command ); |
| 3287 |
|
| 3288 |
if (g_bindings[i].bind2 != -1) |
| 3289 |
DC->setBinding( g_bindings[i].bind2, g_bindings[i].command ); |
| 3290 |
} |
| 3291 |
} |
| 3292 |
|
| 3293 |
//if ( s_controls.invertmouse.curvalue ) |
| 3294 |
// DC->setCVar("m_pitch", va("%f),-fabs( DC->getCVarValue( "m_pitch" ) ) ); |
| 3295 |
//else |
| 3296 |
// trap_Cvar_SetValue( "m_pitch", fabs( trap_Cvar_VariableValue( "m_pitch" ) ) ); |
| 3297 |
|
| 3298 |
//trap_Cvar_SetValue( "m_filter", s_controls.smoothmouse.curvalue ); |
| 3299 |
//trap_Cvar_SetValue( "cl_run", s_controls.alwaysrun.curvalue ); |
| 3300 |
//trap_Cvar_SetValue( "cg_autoswitch", s_controls.autoswitch.curvalue ); |
| 3301 |
//trap_Cvar_SetValue( "sensitivity", s_controls.sensitivity.curvalue ); |
| 3302 |
//trap_Cvar_SetValue( "in_joystick", s_controls.joyenable.curvalue ); |
| 3303 |
//trap_Cvar_SetValue( "joy_threshold", s_controls.joythreshold.curvalue ); |
| 3304 |
//trap_Cvar_SetValue( "cl_freelook", s_controls.freelook.curvalue ); |
| 3305 |
DC->executeText(EXEC_APPEND, "in_restart\n"); |
| 3306 |
//trap_Cmd_ExecuteText( EXEC_APPEND, "in_restart\n" ); |
| 3307 |
} |
| 3308 |
|
| 3309 |
/* |
| 3310 |
================= |
| 3311 |
Controls_SetDefaults |
| 3312 |
================= |
| 3313 |
*/ |
| 3314 |
void Controls_SetDefaults( void ) |
| 3315 |
{ |
| 3316 |
int i; |
| 3317 |
|
| 3318 |
// iterate each command, set its default binding |
| 3319 |
for (i=0; i < g_bindCount; i++) |
| 3320 |
{ |
| 3321 |
g_bindings[i].bind1 = g_bindings[i].defaultbind1; |
| 3322 |
g_bindings[i].bind2 = g_bindings[i].defaultbind2; |
| 3323 |
} |
| 3324 |
|
| 3325 |
//s_controls.invertmouse.curvalue = Controls_GetCvarDefault( "m_pitch" ) < 0; |
| 3326 |
//s_controls.smoothmouse.curvalue = Controls_GetCvarDefault( "m_filter" ); |
| 3327 |
//s_controls.alwaysrun.curvalue = Controls_GetCvarDefault( "cl_run" ); |
| 3328 |
//s_controls.autoswitch.curvalue = Controls_GetCvarDefault( "cg_autoswitch" ); |
| 3329 |
//s_controls.sensitivity.curvalue = Controls_GetCvarDefault( "sensitivity" ); |
| 3330 |
//s_controls.joyenable.curvalue = Controls_GetCvarDefault( "in_joystick" ); |
| 3331 |
//s_controls.joythreshold.curvalue = Controls_GetCvarDefault( "joy_threshold" ); |
| 3332 |
//s_controls.freelook.curvalue = Controls_GetCvarDefault( "cl_freelook" ); |
| 3333 |
} |
| 3334 |
|
| 3335 |
int BindingIDFromName(const char *name) { |
| 3336 |
int i; |
| 3337 |
for (i=0; i < g_bindCount; i++) |
| 3338 |
{ |
| 3339 |
if (Q_stricmp(name, g_bindings[i].command) == 0) { |
| 3340 |
return i; |
| 3341 |
} |
| 3342 |
} |
| 3343 |
return -1; |
| 3344 |
} |
| 3345 |
|
| 3346 |
char g_nameBind1[32]; |
| 3347 |
char g_nameBind2[32]; |
| 3348 |
|
| 3349 |
void BindingFromName(const char *cvar) { |
| 3350 |
int i, b1, b2; |
| 3351 |
|
| 3352 |
// iterate each command, set its default binding |
| 3353 |
for (i=0; i < g_bindCount; i++) |
| 3354 |
{ |
| 3355 |
if (Q_stricmp(cvar, g_bindings[i].command) == 0) { |
| 3356 |
b1 = g_bindings[i].bind1; |
| 3357 |
if (b1 == -1) { |
| 3358 |
break; |
| 3359 |
} |
| 3360 |
DC->keynumToStringBuf( b1, g_nameBind1, 32 ); |
| 3361 |
Q_strupr(g_nameBind1); |
| 3362 |
|
| 3363 |
b2 = g_bindings[i].bind2; |
| 3364 |
if (b2 != -1) |
| 3365 |
{ |
| 3366 |
DC->keynumToStringBuf( b2, g_nameBind2, 32 ); |
| 3367 |
Q_strupr(g_nameBind2); |
| 3368 |
strcat( g_nameBind1, " or " ); |
| 3369 |
strcat( g_nameBind1, g_nameBind2 ); |
| 3370 |
} |
| 3371 |
return; |
| 3372 |
} |
| 3373 |
} |
| 3374 |
strcpy(g_nameBind1, "???"); |
| 3375 |
} |
| 3376 |
|
| 3377 |
void Item_Slider_Paint(itemDef_t *item) { |
| 3378 |
vec4_t newColor, lowLight; |
| 3379 |
float x, y, value; |
| 3380 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 3381 |
|
| 3382 |
value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0; |
| 3383 |
|
| 3384 |
if (item->window.flags & WINDOW_HASFOCUS) { |
| 3385 |
lowLight[0] = 0.8 * parent->focusColor[0]; |
| 3386 |
lowLight[1] = 0.8 * parent->focusColor[1]; |
| 3387 |
lowLight[2] = 0.8 * parent->focusColor[2]; |
| 3388 |
lowLight[3] = 0.8 * parent->focusColor[3]; |
| 3389 |
LerpColor(parent->focusColor,lowLight,newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 3390 |
} else { |
| 3391 |
memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); |
| 3392 |
} |
| 3393 |
|
| 3394 |
y = item->window.rect.y; |
| 3395 |
if (item->text) { |
| 3396 |
Item_Text_Paint(item); |
| 3397 |
x = item->textRect.x + item->textRect.w + 8; |
| 3398 |
} else { |
| 3399 |
x = item->window.rect.x; |
| 3400 |
} |
| 3401 |
DC->setColor(newColor); |
| 3402 |
DC->drawHandlePic( x, y, SLIDER_WIDTH, SLIDER_HEIGHT, DC->Assets.sliderBar ); |
| 3403 |
|
| 3404 |
x = Item_Slider_ThumbPosition(item); |
| 3405 |
DC->drawHandlePic( x - (SLIDER_THUMB_WIDTH / 2), y - 2, SLIDER_THUMB_WIDTH, SLIDER_THUMB_HEIGHT, DC->Assets.sliderThumb ); |
| 3406 |
|
| 3407 |
} |
| 3408 |
|
| 3409 |
void Item_Bind_Paint(itemDef_t *item) { |
| 3410 |
vec4_t newColor, lowLight; |
| 3411 |
float value; |
| 3412 |
int maxChars = 0; |
| 3413 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 3414 |
editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData; |
| 3415 |
if (editPtr) { |
| 3416 |
maxChars = editPtr->maxPaintChars; |
| 3417 |
} |
| 3418 |
|
| 3419 |
value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0; |
| 3420 |
|
| 3421 |
if (item->window.flags & WINDOW_HASFOCUS) { |
| 3422 |
if (g_bindItem == item) { |
| 3423 |
lowLight[0] = 0.8f * 1.0f; |
| 3424 |
lowLight[1] = 0.8f * 0.0f; |
| 3425 |
lowLight[2] = 0.8f * 0.0f; |
| 3426 |
lowLight[3] = 0.8f * 1.0f; |
| 3427 |
} else { |
| 3428 |
lowLight[0] = 0.8f * parent->focusColor[0]; |
| 3429 |
lowLight[1] = 0.8f * parent->focusColor[1]; |
| 3430 |
lowLight[2] = 0.8f * parent->focusColor[2]; |
| 3431 |
lowLight[3] = 0.8f * parent->focusColor[3]; |
| 3432 |
} |
| 3433 |
LerpColor(parent->focusColor,lowLight,newColor,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 3434 |
} else { |
| 3435 |
memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t)); |
| 3436 |
} |
| 3437 |
|
| 3438 |
if (item->text) { |
| 3439 |
Item_Text_Paint(item); |
| 3440 |
BindingFromName(item->cvar); |
| 3441 |
DC->drawText(item->textRect.x + item->textRect.w + 8, item->textRect.y, item->textscale, newColor, g_nameBind1, 0, maxChars, item->textStyle); |
| 3442 |
} else { |
| 3443 |
DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "FIXME" : "FIXME", 0, maxChars, item->textStyle); |
| 3444 |
} |
| 3445 |
} |
| 3446 |
|
| 3447 |
qboolean Display_KeyBindPending(void) { |
| 3448 |
return g_waitingForKey; |
| 3449 |
} |
| 3450 |
|
| 3451 |
qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down) { |
| 3452 |
int id; |
| 3453 |
int i; |
| 3454 |
|
| 3455 |
if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && !g_waitingForKey) |
| 3456 |
{ |
| 3457 |
if (down && (key == K_MOUSE1 || key == K_ENTER)) { |
| 3458 |
g_waitingForKey = qtrue; |
| 3459 |
g_bindItem = item; |
| 3460 |
} |
| 3461 |
return qtrue; |
| 3462 |
} |
| 3463 |
else |
| 3464 |
{ |
| 3465 |
if (!g_waitingForKey || g_bindItem == NULL) { |
| 3466 |
return qtrue; |
| 3467 |
} |
| 3468 |
|
| 3469 |
if (key & K_CHAR_FLAG) { |
| 3470 |
return qtrue; |
| 3471 |
} |
| 3472 |
|
| 3473 |
switch (key) |
| 3474 |
{ |
| 3475 |
case K_ESCAPE: |
| 3476 |
g_waitingForKey = qfalse; |
| 3477 |
return qtrue; |
| 3478 |
|
| 3479 |
case K_BACKSPACE: |
| 3480 |
id = BindingIDFromName(item->cvar); |
| 3481 |
if (id != -1) { |
| 3482 |
g_bindings[id].bind1 = -1; |
| 3483 |
g_bindings[id].bind2 = -1; |
| 3484 |
} |
| 3485 |
Controls_SetConfig(qtrue); |
| 3486 |
g_waitingForKey = qfalse; |
| 3487 |
g_bindItem = NULL; |
| 3488 |
return qtrue; |
| 3489 |
|
| 3490 |
case '`': |
| 3491 |
return qtrue; |
| 3492 |
} |
| 3493 |
} |
| 3494 |
|
| 3495 |
if (key != -1) |
| 3496 |
{ |
| 3497 |
|
| 3498 |
for (i=0; i < g_bindCount; i++) |
| 3499 |
{ |
| 3500 |
|
| 3501 |
if (g_bindings[i].bind2 == key) { |
| 3502 |
g_bindings[i].bind2 = -1; |
| 3503 |
} |
| 3504 |
|
| 3505 |
if (g_bindings[i].bind1 == key) |
| 3506 |
{ |
| 3507 |
g_bindings[i].bind1 = g_bindings[i].bind2; |
| 3508 |
g_bindings[i].bind2 = -1; |
| 3509 |
} |
| 3510 |
} |
| 3511 |
} |
| 3512 |
|
| 3513 |
|
| 3514 |
id = BindingIDFromName(item->cvar); |
| 3515 |
|
| 3516 |
if (id != -1) { |
| 3517 |
if (key == -1) { |
| 3518 |
if( g_bindings[id].bind1 != -1 ) { |
| 3519 |
DC->setBinding( g_bindings[id].bind1, "" ); |
| 3520 |
g_bindings[id].bind1 = -1; |
| 3521 |
} |
| 3522 |
if( g_bindings[id].bind2 != -1 ) { |
| 3523 |
DC->setBinding( g_bindings[id].bind2, "" ); |
| 3524 |
g_bindings[id].bind2 = -1; |
| 3525 |
} |
| 3526 |
} |
| 3527 |
else if (g_bindings[id].bind1 == -1) { |
| 3528 |
g_bindings[id].bind1 = key; |
| 3529 |
} |
| 3530 |
else if (g_bindings[id].bind1 != key && g_bindings[id].bind2 == -1) { |
| 3531 |
g_bindings[id].bind2 = key; |
| 3532 |
} |
| 3533 |
else { |
| 3534 |
DC->setBinding( g_bindings[id].bind1, "" ); |
| 3535 |
DC->setBinding( g_bindings[id].bind2, "" ); |
| 3536 |
g_bindings[id].bind1 = key; |
| 3537 |
g_bindings[id].bind2 = -1; |
| 3538 |
} |
| 3539 |
} |
| 3540 |
|
| 3541 |
Controls_SetConfig(qtrue); |
| 3542 |
g_waitingForKey = qfalse; |
| 3543 |
|
| 3544 |
return qtrue; |
| 3545 |
} |
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
void AdjustFrom640(float *x, float *y, float *w, float *h) { |
| 3550 |
//*x = *x * DC->scale + DC->bias; |
| 3551 |
*x *= DC->xscale; |
| 3552 |
*y *= DC->yscale; |
| 3553 |
*w *= DC->xscale; |
| 3554 |
*h *= DC->yscale; |
| 3555 |
} |
| 3556 |
|
| 3557 |
void Item_Model_Paint(itemDef_t *item) { |
| 3558 |
float x, y, w, h; |
| 3559 |
refdef_t refdef; |
| 3560 |
refEntity_t ent; |
| 3561 |
vec3_t mins, maxs, origin; |
| 3562 |
vec3_t angles; |
| 3563 |
modelDef_t *modelPtr = (modelDef_t*)item->typeData; |
| 3564 |
|
| 3565 |
if (modelPtr == NULL) { |
| 3566 |
return; |
| 3567 |
} |
| 3568 |
|
| 3569 |
// setup the refdef |
| 3570 |
memset( &refdef, 0, sizeof( refdef ) ); |
| 3571 |
refdef.rdflags = RDF_NOWORLDMODEL; |
| 3572 |
AxisClear( refdef.viewaxis ); |
| 3573 |
x = item->window.rect.x+1; |
| 3574 |
y = item->window.rect.y+1; |
| 3575 |
w = item->window.rect.w-2; |
| 3576 |
h = item->window.rect.h-2; |
| 3577 |
|
| 3578 |
AdjustFrom640( &x, &y, &w, &h ); |
| 3579 |
|
| 3580 |
refdef.x = x; |
| 3581 |
refdef.y = y; |
| 3582 |
refdef.width = w; |
| 3583 |
refdef.height = h; |
| 3584 |
|
| 3585 |
DC->modelBounds( item->asset, mins, maxs ); |
| 3586 |
|
| 3587 |
origin[2] = -0.5 * ( mins[2] + maxs[2] ); |
| 3588 |
origin[1] = 0.5 * ( mins[1] + maxs[1] ); |
| 3589 |
|
| 3590 |
// calculate distance so the model nearly fills the box |
| 3591 |
if (qtrue) { |
| 3592 |
float len = 0.5 * ( maxs[2] - mins[2] ); |
| 3593 |
origin[0] = len / 0.268; // len / tan( fov/2 ) |
| 3594 |
//origin[0] = len / tan(w/2); |
| 3595 |
} else { |
| 3596 |
origin[0] = item->textscale; |
| 3597 |
} |
| 3598 |
refdef.fov_x = (modelPtr->fov_x) ? modelPtr->fov_x : w; |
| 3599 |
refdef.fov_y = (modelPtr->fov_y) ? modelPtr->fov_y : h; |
| 3600 |
|
| 3601 |
//refdef.fov_x = (int)((float)refdef.width / 640.0f * 90.0f); |
| 3602 |
//xx = refdef.width / tan( refdef.fov_x / 360 * M_PI ); |
| 3603 |
//refdef.fov_y = atan2( refdef.height, xx ); |
| 3604 |
//refdef.fov_y *= ( 360 / M_PI ); |
| 3605 |
|
| 3606 |
DC->clearScene(); |
| 3607 |
|
| 3608 |
refdef.time = DC->realTime; |
| 3609 |
|
| 3610 |
// add the model |
| 3611 |
|
| 3612 |
memset( &ent, 0, sizeof(ent) ); |
| 3613 |
|
| 3614 |
//adjust = 5.0 * sin( (float)uis.realtime / 500 ); |
| 3615 |
//adjust = 360 % (int)((float)uis.realtime / 1000); |
| 3616 |
//VectorSet( angles, 0, 0, 1 ); |
| 3617 |
|
| 3618 |
// use item storage to track |
| 3619 |
if (modelPtr->rotationSpeed) { |
| 3620 |
if (DC->realTime > item->window.nextTime) { |
| 3621 |
item->window.nextTime = DC->realTime + modelPtr->rotationSpeed; |
| 3622 |
modelPtr->angle = (int)(modelPtr->angle + 1) % 360; |
| 3623 |
} |
| 3624 |
} |
| 3625 |
VectorSet( angles, 0, modelPtr->angle, 0 ); |
| 3626 |
AnglesToAxis( angles, ent.axis ); |
| 3627 |
|
| 3628 |
ent.hModel = item->asset; |
| 3629 |
VectorCopy( origin, ent.origin ); |
| 3630 |
VectorCopy( origin, ent.lightingOrigin ); |
| 3631 |
ent.renderfx = RF_LIGHTING_ORIGIN | RF_NOSHADOW; |
| 3632 |
VectorCopy( ent.origin, ent.oldorigin ); |
| 3633 |
|
| 3634 |
DC->addRefEntityToScene( &ent ); |
| 3635 |
DC->renderScene( &refdef ); |
| 3636 |
|
| 3637 |
} |
| 3638 |
|
| 3639 |
|
| 3640 |
void Item_Image_Paint(itemDef_t *item) { |
| 3641 |
if (item == NULL) { |
| 3642 |
return; |
| 3643 |
} |
| 3644 |
DC->drawHandlePic(item->window.rect.x+1, item->window.rect.y+1, item->window.rect.w-2, item->window.rect.h-2, item->asset); |
| 3645 |
} |
| 3646 |
|
| 3647 |
void Item_ListBox_Paint(itemDef_t *item) { |
| 3648 |
float x, y, size, thumb; |
| 3649 |
int count, i; |
| 3650 |
qhandle_t image; |
| 3651 |
qhandle_t optionalImage; |
| 3652 |
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; |
| 3653 |
|
| 3654 |
// the listbox is horizontal or vertical and has a fixed size scroll bar going either direction |
| 3655 |
// elements are enumerated from the DC and either text or image handles are acquired from the DC as well |
| 3656 |
// textscale is used to size the text, textalignx and textaligny are used to size image elements |
| 3657 |
// there is no clipping available so only the last completely visible item is painted |
| 3658 |
count = DC->feederCount(item->special); |
| 3659 |
// default is vertical if horizontal flag is not here |
| 3660 |
if (item->window.flags & WINDOW_HORIZONTAL) { |
| 3661 |
// draw scrollbar in bottom of the window |
| 3662 |
// bar |
| 3663 |
x = item->window.rect.x + 1; |
| 3664 |
y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE - 1; |
| 3665 |
DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowLeft); |
| 3666 |
x += SCROLLBAR_SIZE - 1; |
| 3667 |
size = item->window.rect.w - (SCROLLBAR_SIZE * 2); |
| 3668 |
DC->drawHandlePic(x, y, size+1, SCROLLBAR_SIZE, DC->Assets.scrollBar); |
| 3669 |
x += size - 1; |
| 3670 |
DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowRight); |
| 3671 |
// thumb |
| 3672 |
thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item); |
| 3673 |
if (thumb > x - SCROLLBAR_SIZE - 1) { |
| 3674 |
thumb = x - SCROLLBAR_SIZE - 1; |
| 3675 |
} |
| 3676 |
DC->drawHandlePic(thumb, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarThumb); |
| 3677 |
// |
| 3678 |
listPtr->endPos = listPtr->startPos; |
| 3679 |
size = item->window.rect.w - 2; |
| 3680 |
// items |
| 3681 |
// size contains max available space |
| 3682 |
if (listPtr->elementStyle == LISTBOX_IMAGE) { |
| 3683 |
// fit = 0; |
| 3684 |
x = item->window.rect.x + 1; |
| 3685 |
y = item->window.rect.y + 1; |
| 3686 |
for (i = listPtr->startPos; i < count; i++) { |
| 3687 |
// always draw at least one |
| 3688 |
// which may overdraw the box if it is too small for the element |
| 3689 |
image = DC->feederItemImage(item->special, i); |
| 3690 |
if (image) { |
| 3691 |
DC->drawHandlePic(x+1, y+1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image); |
| 3692 |
} |
| 3693 |
|
| 3694 |
if (i == item->cursorPos) { |
| 3695 |
DC->drawRect(x, y, listPtr->elementWidth-1, listPtr->elementHeight-1, item->window.borderSize, item->window.borderColor); |
| 3696 |
} |
| 3697 |
|
| 3698 |
size -= listPtr->elementWidth; |
| 3699 |
if (size < listPtr->elementWidth) { |
| 3700 |
listPtr->drawPadding = size; //listPtr->elementWidth - size; |
| 3701 |
break; |
| 3702 |
} |
| 3703 |
x += listPtr->elementWidth; |
| 3704 |
listPtr->endPos++; |
| 3705 |
// fit++; |
| 3706 |
} |
| 3707 |
} else { |
| 3708 |
// |
| 3709 |
} |
| 3710 |
} else { |
| 3711 |
// draw scrollbar to right side of the window |
| 3712 |
x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE - 1; |
| 3713 |
y = item->window.rect.y + 1; |
| 3714 |
DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowUp); |
| 3715 |
y += SCROLLBAR_SIZE - 1; |
| 3716 |
|
| 3717 |
listPtr->endPos = listPtr->startPos; |
| 3718 |
size = item->window.rect.h - (SCROLLBAR_SIZE * 2); |
| 3719 |
DC->drawHandlePic(x, y, SCROLLBAR_SIZE, size+1, DC->Assets.scrollBar); |
| 3720 |
y += size - 1; |
| 3721 |
DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowDown); |
| 3722 |
// thumb |
| 3723 |
thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item); |
| 3724 |
if (thumb > y - SCROLLBAR_SIZE - 1) { |
| 3725 |
thumb = y - SCROLLBAR_SIZE - 1; |
| 3726 |
} |
| 3727 |
DC->drawHandlePic(x, thumb, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarThumb); |
| 3728 |
|
| 3729 |
// adjust size for item painting |
| 3730 |
size = item->window.rect.h - 2; |
| 3731 |
if (listPtr->elementStyle == LISTBOX_IMAGE) { |
| 3732 |
// fit = 0; |
| 3733 |
x = item->window.rect.x + 1; |
| 3734 |
y = item->window.rect.y + 1; |
| 3735 |
for (i = listPtr->startPos; i < count; i++) { |
| 3736 |
// always draw at least one |
| 3737 |
// which may overdraw the box if it is too small for the element |
| 3738 |
image = DC->feederItemImage(item->special, i); |
| 3739 |
if (image) { |
| 3740 |
DC->drawHandlePic(x+1, y+1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image); |
| 3741 |
} |
| 3742 |
|
| 3743 |
if (i == item->cursorPos) { |
| 3744 |
DC->drawRect(x, y, listPtr->elementWidth - 1, listPtr->elementHeight - 1, item->window.borderSize, item->window.borderColor); |
| 3745 |
} |
| 3746 |
|
| 3747 |
listPtr->endPos++; |
| 3748 |
size -= listPtr->elementWidth; |
| 3749 |
if (size < listPtr->elementHeight) { |
| 3750 |
listPtr->drawPadding = listPtr->elementHeight - size; |
| 3751 |
break; |
| 3752 |
} |
| 3753 |
y += listPtr->elementHeight; |
| 3754 |
// fit++; |
| 3755 |
} |
| 3756 |
} else { |
| 3757 |
x = item->window.rect.x + 1; |
| 3758 |
y = item->window.rect.y + 1; |
| 3759 |
for (i = listPtr->startPos; i < count; i++) { |
| 3760 |
const char *text; |
| 3761 |
// always draw at least one |
| 3762 |
// which may overdraw the box if it is too small for the element |
| 3763 |
|
| 3764 |
if (listPtr->numColumns > 0) { |
| 3765 |
int j; |
| 3766 |
for (j = 0; j < listPtr->numColumns; j++) { |
| 3767 |
text = DC->feederItemText(item->special, i, j, &optionalImage); |
| 3768 |
if (optionalImage >= 0) { |
| 3769 |
DC->drawHandlePic(x + 4 + listPtr->columnInfo[j].pos, y - 1 + listPtr->elementHeight / 2, listPtr->columnInfo[j].width, listPtr->columnInfo[j].width, optionalImage); |
| 3770 |
} else if (text) { |
| 3771 |
DC->drawText(x + 4 + listPtr->columnInfo[j].pos, y + listPtr->elementHeight, item->textscale, item->window.foreColor, text, 0, listPtr->columnInfo[j].maxChars, item->textStyle); |
| 3772 |
} |
| 3773 |
} |
| 3774 |
} else { |
| 3775 |
text = DC->feederItemText(item->special, i, 0, &optionalImage); |
| 3776 |
if (optionalImage >= 0) { |
| 3777 |
//DC->drawHandlePic(x + 4 + listPtr->elementHeight, y, listPtr->columnInfo[j].width, listPtr->columnInfo[j].width, optionalImage); |
| 3778 |
} else if (text) { |
| 3779 |
DC->drawText(x + 4, y + listPtr->elementHeight, item->textscale, item->window.foreColor, text, 0, 0, item->textStyle); |
| 3780 |
} |
| 3781 |
} |
| 3782 |
|
| 3783 |
if (i == item->cursorPos) { |
| 3784 |
DC->fillRect(x + 2, y + 2, item->window.rect.w - SCROLLBAR_SIZE - 4, listPtr->elementHeight, item->window.outlineColor); |
| 3785 |
} |
| 3786 |
|
| 3787 |
size -= listPtr->elementHeight; |
| 3788 |
if (size < listPtr->elementHeight) { |
| 3789 |
listPtr->drawPadding = listPtr->elementHeight - size; |
| 3790 |
break; |
| 3791 |
} |
| 3792 |
listPtr->endPos++; |
| 3793 |
y += listPtr->elementHeight; |
| 3794 |
// fit++; |
| 3795 |
} |
| 3796 |
} |
| 3797 |
} |
| 3798 |
} |
| 3799 |
|
| 3800 |
|
| 3801 |
void Item_OwnerDraw_Paint(itemDef_t *item) { |
| 3802 |
menuDef_t *parent; |
| 3803 |
|
| 3804 |
if (item == NULL) { |
| 3805 |
return; |
| 3806 |
} |
| 3807 |
parent = (menuDef_t*)item->parent; |
| 3808 |
|
| 3809 |
if (DC->ownerDrawItem) { |
| 3810 |
vec4_t color, lowLight; |
| 3811 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 3812 |
Fade(&item->window.flags, &item->window.foreColor[3], parent->fadeClamp, &item->window.nextTime, parent->fadeCycle, qtrue, parent->fadeAmount); |
| 3813 |
memcpy(&color, &item->window.foreColor, sizeof(color)); |
| 3814 |
if (item->numColors > 0 && DC->getValue) { |
| 3815 |
// if the value is within one of the ranges then set color to that, otherwise leave at default |
| 3816 |
int i; |
| 3817 |
float f = DC->getValue(item->window.ownerDraw); |
| 3818 |
for (i = 0; i < item->numColors; i++) { |
| 3819 |
if (f >= item->colorRanges[i].low && f <= item->colorRanges[i].high) { |
| 3820 |
memcpy(&color, &item->colorRanges[i].color, sizeof(color)); |
| 3821 |
break; |
| 3822 |
} |
| 3823 |
} |
| 3824 |
} |
| 3825 |
|
| 3826 |
if (item->window.flags & WINDOW_HASFOCUS) { |
| 3827 |
lowLight[0] = 0.8 * parent->focusColor[0]; |
| 3828 |
lowLight[1] = 0.8 * parent->focusColor[1]; |
| 3829 |
lowLight[2] = 0.8 * parent->focusColor[2]; |
| 3830 |
lowLight[3] = 0.8 * parent->focusColor[3]; |
| 3831 |
LerpColor(parent->focusColor,lowLight,color,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 3832 |
} else if (item->textStyle == ITEM_TEXTSTYLE_BLINK && !((DC->realTime/BLINK_DIVISOR) & 1)) { |
| 3833 |
lowLight[0] = 0.8 * item->window.foreColor[0]; |
| 3834 |
lowLight[1] = 0.8 * item->window.foreColor[1]; |
| 3835 |
lowLight[2] = 0.8 * item->window.foreColor[2]; |
| 3836 |
lowLight[3] = 0.8 * item->window.foreColor[3]; |
| 3837 |
LerpColor(item->window.foreColor,lowLight,color,0.5+0.5*sin(DC->realTime / PULSE_DIVISOR)); |
| 3838 |
} |
| 3839 |
|
| 3840 |
if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) { |
| 3841 |
Com_Memcpy(color, parent->disableColor, sizeof(vec4_t)); |
| 3842 |
} |
| 3843 |
|
| 3844 |
if (item->text) { |
| 3845 |
Item_Text_Paint(item); |
| 3846 |
if (item->text[0]) { |
| 3847 |
// +8 is an offset kludge to properly align owner draw items that have text combined with them |
| 3848 |
DC->ownerDrawItem(item->textRect.x + item->textRect.w + 8, item->window.rect.y, item->window.rect.w, item->window.rect.h, 0, item->textaligny, item->window.ownerDraw, item->window.ownerDrawFlags, item->alignment, item->special, item->textscale, color, item->window.background, item->textStyle ); |
| 3849 |
} else { |
| 3850 |
DC->ownerDrawItem(item->textRect.x + item->textRect.w, item->window.rect.y, item->window.rect.w, item->window.rect.h, 0, item->textaligny, item->window.ownerDraw, item->window.ownerDrawFlags, item->alignment, item->special, item->textscale, color, item->window.background, item->textStyle ); |
| 3851 |
} |
| 3852 |
} else { |
| 3853 |
DC->ownerDrawItem(item->window.rect.x, item->window.rect.y, item->window.rect.w, item->window.rect.h, item->textalignx, item->textaligny, item->window.ownerDraw, item->window.ownerDrawFlags, item->alignment, item->special, item->textscale, color, item->window.background, item->textStyle ); |
| 3854 |
} |
| 3855 |
} |
| 3856 |
} |
| 3857 |
|
| 3858 |
|
| 3859 |
void Item_Paint(itemDef_t *item) { |
| 3860 |
vec4_t red; |
| 3861 |
menuDef_t *parent = (menuDef_t*)item->parent; |
| 3862 |
red[0] = red[3] = 1; |
| 3863 |
red[1] = red[2] = 0; |
| 3864 |
|
| 3865 |
if (item == NULL) { |
| 3866 |
return; |
| 3867 |
} |
| 3868 |
|
| 3869 |
if (item->window.flags & WINDOW_ORBITING) { |
| 3870 |
if (DC->realTime > item->window.nextTime) { |
| 3871 |
float rx, ry, a, c, s, w, h; |
| 3872 |
|
| 3873 |
item->window.nextTime = DC->realTime + item->window.offsetTime; |
| 3874 |
// translate |
| 3875 |
w = item->window.rectClient.w / 2; |
| 3876 |
h = item->window.rectClient.h / 2; |
| 3877 |
rx = item->window.rectClient.x + w - item->window.rectEffects.x; |
| 3878 |
ry = item->window.rectClient.y + h - item->window.rectEffects.y; |
| 3879 |
a = 3 * M_PI / 180; |
| 3880 |
c = cos(a); |
| 3881 |
s = sin(a); |
| 3882 |
item->window.rectClient.x = (rx * c - ry * s) + item->window.rectEffects.x - w; |
| 3883 |
item->window.rectClient.y = (rx * s + ry * c) + item->window.rectEffects.y - h; |
| 3884 |
Item_UpdatePosition(item); |
| 3885 |
|
| 3886 |
} |
| 3887 |
} |
| 3888 |
|
| 3889 |
|
| 3890 |
if (item->window.flags & WINDOW_INTRANSITION) { |
| 3891 |
if (DC->realTime > item->window.nextTime) { |
| 3892 |
int done = 0; |
| 3893 |
item->window.nextTime = DC->realTime + item->window.offsetTime; |
| 3894 |
// transition the x,y |
| 3895 |
if (item->window.rectClient.x == item->window.rectEffects.x) { |
| 3896 |
done++; |
| 3897 |
} else { |
| 3898 |
if (item->window.rectClient.x < item->window.rectEffects.x) { |
| 3899 |
item->window.rectClient.x += item->window.rectEffects2.x; |
| 3900 |
if (item->window.rectClient.x > item->window.rectEffects.x) { |
| 3901 |
item->window.rectClient.x = item->window.rectEffects.x; |
| 3902 |
done++; |
| 3903 |
} |
| 3904 |
} else { |
| 3905 |
item->window.rectClient.x -= item->window.rectEffects2.x; |
| 3906 |
if (item->window.rectClient.x < item->window.rectEffects.x) { |
| 3907 |
item->window.rectClient.x = item->window.rectEffects.x; |
| 3908 |
done++; |
| 3909 |
} |
| 3910 |
} |
| 3911 |
} |
| 3912 |
if (item->window.rectClient.y == item->window.rectEffects.y) { |
| 3913 |
done++; |
| 3914 |
} else { |
| 3915 |
if (item->window.rectClient.y < item->window.rectEffects.y) { |
| 3916 |
item->window.rectClient.y += item->window.rectEffects2.y; |
| 3917 |
if (item->window.rectClient.y > item->window.rectEffects.y) { |
| 3918 |
item->window.rectClient.y = item->window.rectEffects.y; |
| 3919 |
done++; |
| 3920 |
} |
| 3921 |
} else { |
| 3922 |
item->window.rectClient.y -= item->window.rectEffects2.y; |
| 3923 |
if (item->window.rectClient.y < item->window.rectEffects.y) { |
| 3924 |
item->window.rectClient.y = item->window.rectEffects.y; |
| 3925 |
done++; |
| 3926 |
} |
| 3927 |
} |
| 3928 |
} |
| 3929 |
if (item->window.rectClient.w == item->window.rectEffects.w) { |
| 3930 |
done++; |
| 3931 |
} else { |
| 3932 |
if (item->window.rectClient.w < item->window.rectEffects.w) { |
| 3933 |
item->window.rectClient.w += item->window.rectEffects2.w; |
| 3934 |
if (item->window.rectClient.w > item->window.rectEffects.w) { |
| 3935 |
item->window.rectClient.w = item->window.rectEffects.w; |
| 3936 |
done++; |
| 3937 |
} |
| 3938 |
} else { |
| 3939 |
item->window.rectClient.w -= item->window.rectEffects2.w; |
| 3940 |
if (item->window.rectClient.w < item->window.rectEffects.w) { |
| 3941 |
item->window.rectClient.w = item->window.rectEffects.w; |
| 3942 |
done++; |
| 3943 |
} |
| 3944 |
} |
| 3945 |
} |
| 3946 |
if (item->window.rectClient.h == item->window.rectEffects.h) { |
| 3947 |
done++; |
| 3948 |
} else { |
| 3949 |
if (item->window.rectClient.h < item->window.rectEffects.h) { |
| 3950 |
item->window.rectClient.h += item->window.rectEffects2.h; |
| 3951 |
if (item->window.rectClient.h > item->window.rectEffects.h) { |
| 3952 |
item->window.rectClient.h = item->window.rectEffects.h; |
| 3953 |
done++; |
| 3954 |
} |
| 3955 |
} else { |
| 3956 |
item->window.rectClient.h -= item->window.rectEffects2.h; |
| 3957 |
if (item->window.rectClient.h < item->window.rectEffects.h) { |
| 3958 |
item->window.rectClient.h = item->window.rectEffects.h; |
| 3959 |
done++; |
| 3960 |
} |
| 3961 |
} |
| 3962 |
} |
| 3963 |
|
| 3964 |
Item_UpdatePosition(item); |
| 3965 |
|
| 3966 |
if (done == 4) { |
| 3967 |
item->window.flags &= ~WINDOW_INTRANSITION; |
| 3968 |
} |
| 3969 |
|
| 3970 |
} |
| 3971 |
} |
| 3972 |
|
| 3973 |
if (item->window.ownerDrawFlags && DC->ownerDrawVisible) { |
| 3974 |
if (!DC->ownerDrawVisible(item->window.ownerDrawFlags)) { |
| 3975 |
item->window.flags &= ~WINDOW_VISIBLE; |
| 3976 |
} else { |
| 3977 |
item->window.flags |= WINDOW_VISIBLE; |
| 3978 |
} |
| 3979 |
} |
| 3980 |
|
| 3981 |
if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE)) { |
| 3982 |
if (!Item_EnableShowViaCvar(item, CVAR_SHOW)) { |
| 3983 |
return; |
| 3984 |
} |
| 3985 |
} |
| 3986 |
|
| 3987 |
if (item->window.flags & WINDOW_TIMEDVISIBLE) { |
| 3988 |
|
| 3989 |
} |
| 3990 |
|
| 3991 |
if (!(item->window.flags & WINDOW_VISIBLE)) { |
| 3992 |
return; |
| 3993 |
} |
| 3994 |
|
| 3995 |
// paint the rect first.. |
| 3996 |
Window_Paint(&item->window, parent->fadeAmount , parent->fadeClamp, parent->fadeCycle); |
| 3997 |
|
| 3998 |
if (debugMode) { |
| 3999 |
vec4_t color; |
| 4000 |
rectDef_t *r = Item_CorrectedTextRect(item); |
| 4001 |
color[1] = color[3] = 1; |
| 4002 |
color[0] = color[2] = 0; |
| 4003 |
DC->drawRect(r->x, r->y, r->w, r->h, 1, color); |
| 4004 |
} |
| 4005 |
|
| 4006 |
//DC->drawRect(item->window.rect.x, item->window.rect.y, item->window.rect.w, item->window.rect.h, 1, red); |
| 4007 |
|
| 4008 |
switch (item->type) { |
| 4009 |
case ITEM_TYPE_OWNERDRAW: |
| 4010 |
Item_OwnerDraw_Paint(item); |
| 4011 |
break; |
| 4012 |
case ITEM_TYPE_TEXT: |
| 4013 |
case ITEM_TYPE_BUTTON: |
| 4014 |
Item_Text_Paint(item); |
| 4015 |
break; |
| 4016 |
case ITEM_TYPE_RADIOBUTTON: |
| 4017 |
break; |
| 4018 |
case ITEM_TYPE_CHECKBOX: |
| 4019 |
break; |
| 4020 |
case ITEM_TYPE_EDITFIELD: |
| 4021 |
case ITEM_TYPE_NUMERICFIELD: |
| 4022 |
Item_TextField_Paint(item); |
| 4023 |
break; |
| 4024 |
case ITEM_TYPE_COMBO: |
| 4025 |
break; |
| 4026 |
case ITEM_TYPE_LISTBOX: |
| 4027 |
Item_ListBox_Paint(item); |
| 4028 |
break; |
| 4029 |
//case ITEM_TYPE_IMAGE: |
| 4030 |
// Item_Image_Paint(item); |
| 4031 |
// break; |
| 4032 |
case ITEM_TYPE_MODEL: |
| 4033 |
Item_Model_Paint(item); |
| 4034 |
break; |
| 4035 |
case ITEM_TYPE_YESNO: |
| 4036 |
Item_YesNo_Paint(item); |
| 4037 |
break; |
| 4038 |
case ITEM_TYPE_MULTI: |
| 4039 |
Item_Multi_Paint(item); |
| 4040 |
break; |
| 4041 |
case ITEM_TYPE_BIND: |
| 4042 |
Item_Bind_Paint(item); |
| 4043 |
break; |
| 4044 |
case ITEM_TYPE_SLIDER: |
| 4045 |
Item_Slider_Paint(item); |
| 4046 |
break; |
| 4047 |
default: |
| 4048 |
break; |
| 4049 |
} |
| 4050 |
|
| 4051 |
} |
| 4052 |
|
| 4053 |
void Menu_Init(menuDef_t *menu) { |
| 4054 |
memset(menu, 0, sizeof(menuDef_t)); |
| 4055 |
menu->cursorItem = -1; |
| 4056 |
menu->fadeAmount = DC->Assets.fadeAmount; |
| 4057 |
menu->fadeClamp = DC->Assets.fadeClamp; |
| 4058 |
menu->fadeCycle = DC->Assets.fadeCycle; |
| 4059 |
Window_Init(&menu->window); |
| 4060 |
} |
| 4061 |
|
| 4062 |
itemDef_t *Menu_GetFocusedItem(menuDef_t *menu) { |
| 4063 |
int i; |
| 4064 |
if (menu) { |
| 4065 |
for (i = 0; i < menu->itemCount; i++) { |
| 4066 |
if (menu->items[i]->window.flags & WINDOW_HASFOCUS) { |
| 4067 |
return menu->items[i]; |
| 4068 |
} |
| 4069 |
} |
| 4070 |
} |
| 4071 |
return NULL; |
| 4072 |
} |
| 4073 |
|
| 4074 |
menuDef_t *Menu_GetFocused(void) { |
| 4075 |
int i; |
| 4076 |
for (i = 0; i < menuCount; i++) { |
| 4077 |
if (Menus[i].window.flags & WINDOW_HASFOCUS && Menus[i].window.flags & WINDOW_VISIBLE) { |
| 4078 |
return &Menus[i]; |
| 4079 |
} |
| 4080 |
} |
| 4081 |
return NULL; |
| 4082 |
} |
| 4083 |
|
| 4084 |
void Menu_ScrollFeeder(menuDef_t *menu, int feeder, qboolean down) { |
| 4085 |
if (menu) { |
| 4086 |
int i; |
| 4087 |
for (i = 0; i < menu->itemCount; i++) { |
| 4088 |
if (menu->items[i]->special == feeder) { |
| 4089 |
Item_ListBox_HandleKey(menu->items[i], (down) ? K_DOWNARROW : K_UPARROW, qtrue, qtrue); |
| 4090 |
return; |
| 4091 |
} |
| 4092 |
} |
| 4093 |
} |
| 4094 |
} |
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
void Menu_SetFeederSelection(menuDef_t *menu, int feeder, int index, const char *name) { |
| 4099 |
if (menu == NULL) { |
| 4100 |
if (name == NULL) { |
| 4101 |
menu = Menu_GetFocused(); |
| 4102 |
} else { |
| 4103 |
menu = Menus_FindByName(name); |
| 4104 |
} |
| 4105 |
} |
| 4106 |
|
| 4107 |
if (menu) { |
| 4108 |
int i; |
| 4109 |
for (i = 0; i < menu->itemCount; i++) { |
| 4110 |
if (menu->items[i]->special == feeder) { |
| 4111 |
if (index == 0) { |
| 4112 |
listBoxDef_t *listPtr = (listBoxDef_t*)menu->items[i]->typeData; |
| 4113 |
listPtr->cursorPos = 0; |
| 4114 |
listPtr->startPos = 0; |
| 4115 |
} |
| 4116 |
menu->items[i]->cursorPos = index; |
| 4117 |
DC->feederSelection(menu->items[i]->special, menu->items[i]->cursorPos); |
| 4118 |
return; |
| 4119 |
} |
| 4120 |
} |
| 4121 |
} |
| 4122 |
} |
| 4123 |
|
| 4124 |
qboolean Menus_AnyFullScreenVisible(void) { |
| 4125 |
int i; |
| 4126 |
for (i = 0; i < menuCount; i++) { |
| 4127 |
if (Menus[i].window.flags & WINDOW_VISIBLE && Menus[i].fullScreen) { |
| 4128 |
return qtrue; |
| 4129 |
} |
| 4130 |
} |
| 4131 |
return qfalse; |
| 4132 |
} |
| 4133 |
|
| 4134 |
menuDef_t *Menus_ActivateByName(const char *p) { |
| 4135 |
int i; |
| 4136 |
menuDef_t *m = NULL; |
| 4137 |
menuDef_t *focus = Menu_GetFocused(); |
| 4138 |
for (i = 0; i < menuCount; i++) { |
| 4139 |
if (Q_stricmp(Menus[i].window.name, p) == 0) { |
| 4140 |
m = &Menus[i]; |
| 4141 |
Menus_Activate(m); |
| 4142 |
if (openMenuCount < MAX_OPEN_MENUS && focus != NULL) { |
| 4143 |
menuStack[openMenuCount++] = focus; |
| 4144 |
} |
| 4145 |
} else { |
| 4146 |
Menus[i].window.flags &= ~WINDOW_HASFOCUS; |
| 4147 |
} |
| 4148 |
} |
| 4149 |
Display_CloseCinematics(); |
| 4150 |
return m; |
| 4151 |
} |
| 4152 |
|
| 4153 |
|
| 4154 |
void Item_Init(itemDef_t *item) { |
| 4155 |
memset(item, 0, sizeof(itemDef_t)); |
| 4156 |
item->textscale = 0.55f; |
| 4157 |
Window_Init(&item->window); |
| 4158 |
} |
| 4159 |
|
| 4160 |
void Menu_HandleMouseMove(menuDef_t *menu, float x, float y) { |
| 4161 |
int i, pass; |
| 4162 |
qboolean focusSet = qfalse; |
| 4163 |
|
| 4164 |
itemDef_t *overItem; |
| 4165 |
if (menu == NULL) { |
| 4166 |
return; |
| 4167 |
} |
| 4168 |
|
| 4169 |
if (!(menu->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED))) { |
| 4170 |
return; |
| 4171 |
} |
| 4172 |
|
| 4173 |
if (itemCapture) { |
| 4174 |
//Item_MouseMove(itemCapture, x, y); |
| 4175 |
return; |
| 4176 |
} |
| 4177 |
|
| 4178 |
if (g_waitingForKey || g_editingField) { |
| 4179 |
return; |
| 4180 |
} |
| 4181 |
|
| 4182 |
// FIXME: this is the whole issue of focus vs. mouse over.. |
| 4183 |
// need a better overall solution as i don't like going through everything twice |
| 4184 |
for (pass = 0; pass < 2; pass++) { |
| 4185 |
for (i = 0; i < menu->itemCount; i++) { |
| 4186 |
// turn off focus each item |
| 4187 |
// menu->items[i].window.flags &= ~WINDOW_HASFOCUS; |
| 4188 |
|
| 4189 |
if (!(menu->items[i]->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED))) { |
| 4190 |
continue; |
| 4191 |
} |
| 4192 |
|
| 4193 |
// items can be enabled and disabled based on cvars |
| 4194 |
if (menu->items[i]->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(menu->items[i], CVAR_ENABLE)) { |
| 4195 |
continue; |
| 4196 |
} |
| 4197 |
|
| 4198 |
if (menu->items[i]->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(menu->items[i], CVAR_SHOW)) { |
| 4199 |
continue; |
| 4200 |
} |
| 4201 |
|
| 4202 |
|
| 4203 |
|
| 4204 |
if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y)) { |
| 4205 |
if (pass == 1) { |
| 4206 |
overItem = menu->items[i]; |
| 4207 |
if (overItem->type == ITEM_TYPE_TEXT && overItem->text) { |
| 4208 |
if (!Rect_ContainsPoint(Item_CorrectedTextRect(overItem), x, y)) { |
| 4209 |
continue; |
| 4210 |
} |
| 4211 |
} |
| 4212 |
// if we are over an item |
| 4213 |
if (IsVisible(overItem->window.flags)) { |
| 4214 |
// different one |
| 4215 |
Item_MouseEnter(overItem, x, y); |
| 4216 |
// Item_SetMouseOver(overItem, qtrue); |
| 4217 |
|
| 4218 |
// if item is not a decoration see if it can take focus |
| 4219 |
if (!focusSet) { |
| 4220 |
focusSet = Item_SetFocus(overItem, x, y); |
| 4221 |
} |
| 4222 |
} |
| 4223 |
} |
| 4224 |
} else if (menu->items[i]->window.flags & WINDOW_MOUSEOVER) { |
| 4225 |
Item_MouseLeave(menu->items[i]); |
| 4226 |
Item_SetMouseOver(menu->items[i], qfalse); |
| 4227 |
} |
| 4228 |
} |
| 4229 |
} |
| 4230 |
|
| 4231 |
} |
| 4232 |
|
| 4233 |
void Menu_Paint(menuDef_t *menu, qboolean forcePaint) { |
| 4234 |
int i; |
| 4235 |
|
| 4236 |
if (menu == NULL) { |
| 4237 |
return; |
| 4238 |
} |
| 4239 |
|
| 4240 |
if (!(menu->window.flags & WINDOW_VISIBLE) && !forcePaint) { |
| 4241 |
return; |
| 4242 |
} |
| 4243 |
|
| 4244 |
if (menu->window.ownerDrawFlags && DC->ownerDrawVisible && !DC->ownerDrawVisible(menu->window.ownerDrawFlags)) { |
| 4245 |
return; |
| 4246 |
} |
| 4247 |
|
| 4248 |
if (forcePaint) { |
| 4249 |
menu->window.flags |= WINDOW_FORCED; |
| 4250 |
} |
| 4251 |
|
| 4252 |
// draw the background if necessary |
| 4253 |
if (menu->fullScreen) { |
| 4254 |
// implies a background shader |
| 4255 |
// FIXME: make sure we have a default shader if fullscreen is set with no background |
| 4256 |
DC->drawHandlePic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, menu->window.background ); |
| 4257 |
} else if (menu->window.background) { |
| 4258 |
// this allows a background shader without being full screen |
| 4259 |
//UI_DrawHandlePic(menu->window.rect.x, menu->window.rect.y, menu->window.rect.w, menu->window.rect.h, menu->backgroundShader); |
| 4260 |
} |
| 4261 |
|
| 4262 |
// paint the background and or border |
| 4263 |
Window_Paint(&menu->window, menu->fadeAmount, menu->fadeClamp, menu->fadeCycle ); |
| 4264 |
|
| 4265 |
for (i = 0; i < menu->itemCount; i++) { |
| 4266 |
Item_Paint(menu->items[i]); |
| 4267 |
} |
| 4268 |
|
| 4269 |
if (debugMode) { |
| 4270 |
vec4_t color; |
| 4271 |
color[0] = color[2] = color[3] = 1; |
| 4272 |
color[1] = 0; |
| 4273 |
DC->drawRect(menu->window.rect.x, menu->window.rect.y, menu->window.rect.w, menu->window.rect.h, 1, color); |
| 4274 |
} |
| 4275 |
} |
| 4276 |
|
| 4277 |
/* |
| 4278 |
=============== |
| 4279 |
Item_ValidateTypeData |
| 4280 |
=============== |
| 4281 |
*/ |
| 4282 |
void Item_ValidateTypeData(itemDef_t *item) { |
| 4283 |
if (item->typeData) { |
| 4284 |
return; |
| 4285 |
} |
| 4286 |
|
| 4287 |
if (item->type == ITEM_TYPE_LISTBOX) { |
| 4288 |
item->typeData = UI_Alloc(sizeof(listBoxDef_t)); |
| 4289 |
memset(item->typeData, 0, sizeof(listBoxDef_t)); |
| 4290 |
} else if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD || item->type == ITEM_TYPE_YESNO || item->type == ITEM_TYPE_BIND || item->type == ITEM_TYPE_SLIDER || item->type == ITEM_TYPE_TEXT) { |
| 4291 |
item->typeData = UI_Alloc(sizeof(editFieldDef_t)); |
| 4292 |
memset(item->typeData, 0, sizeof(editFieldDef_t)); |
| 4293 |
if (item->type == ITEM_TYPE_EDITFIELD) { |
| 4294 |
if (!((editFieldDef_t *) item->typeData)->maxPaintChars) { |
| 4295 |
((editFieldDef_t *) item->typeData)->maxPaintChars = MAX_EDITFIELD; |
| 4296 |
} |
| 4297 |
} |
| 4298 |
} else if (item->type == ITEM_TYPE_MULTI) { |
| 4299 |
item->typeData = UI_Alloc(sizeof(multiDef_t)); |
| 4300 |
} else if (item->type == ITEM_TYPE_MODEL) { |
| 4301 |
item->typeData = UI_Alloc(sizeof(modelDef_t)); |
| 4302 |
} |
| 4303 |
} |
| 4304 |
|
| 4305 |
/* |
| 4306 |
=============== |
| 4307 |
Keyword Hash |
| 4308 |
=============== |
| 4309 |
*/ |
| 4310 |
|
| 4311 |
#define KEYWORDHASH_SIZE 512 |
| 4312 |
|
| 4313 |
typedef struct keywordHash_s |
| 4314 |
{ |
| 4315 |
char *keyword; |
| 4316 |
qboolean (*func)(itemDef_t *item, int handle); |
| 4317 |
struct keywordHash_s *next; |
| 4318 |
} keywordHash_t; |
| 4319 |
|
| 4320 |
int KeywordHash_Key(char *keyword) { |
| 4321 |
int register hash, i; |
| 4322 |
|
| 4323 |
hash = 0; |
| 4324 |
for (i = 0; keyword[i] != '\0'; i++) { |
| 4325 |
if (keyword[i] >= 'A' && keyword[i] <= 'Z') |
| 4326 |
hash += (keyword[i] + ('a' - 'A')) * (119 + i); |
| 4327 |
else |
| 4328 |
hash += keyword[i] * (119 + i); |
| 4329 |
} |
| 4330 |
hash = (hash ^ (hash >> 10) ^ (hash >> 20)) & (KEYWORDHASH_SIZE-1); |
| 4331 |
return hash; |
| 4332 |
} |
| 4333 |
|
| 4334 |
void KeywordHash_Add(keywordHash_t *table[], keywordHash_t *key) { |
| 4335 |
int hash; |
| 4336 |
|
| 4337 |
hash = KeywordHash_Key(key->keyword); |
| 4338 |
/* |
| 4339 |
if (table[hash]) { |
| 4340 |
int collision = qtrue; |
| 4341 |
} |
| 4342 |
*/ |
| 4343 |
key->next = table[hash]; |
| 4344 |
table[hash] = key; |
| 4345 |
} |
| 4346 |
|
| 4347 |
keywordHash_t *KeywordHash_Find(keywordHash_t *table[], char *keyword) |
| 4348 |
{ |
| 4349 |
keywordHash_t *key; |
| 4350 |
int hash; |
| 4351 |
|
| 4352 |
hash = KeywordHash_Key(keyword); |
| 4353 |
for (key = table[hash]; key; key = key->next) { |
| 4354 |
if (!Q_stricmp(key->keyword, keyword)) |
| 4355 |
return key; |
| 4356 |
} |
| 4357 |
return NULL; |
| 4358 |
} |
| 4359 |
|
| 4360 |
/* |
| 4361 |
=============== |
| 4362 |
Item Keyword Parse functions |
| 4363 |
=============== |
| 4364 |
*/ |
| 4365 |
|
| 4366 |
// name <string> |
| 4367 |
qboolean ItemParse_name( itemDef_t *item, int handle ) { |
| 4368 |
if (!PC_String_Parse(handle, &item->window.name)) { |
| 4369 |
return qfalse; |
| 4370 |
} |
| 4371 |
return qtrue; |
| 4372 |
} |
| 4373 |
|
| 4374 |
// name <string> |
| 4375 |
qboolean ItemParse_focusSound( itemDef_t *item, int handle ) { |
| 4376 |
const char *temp; |
| 4377 |
if (!PC_String_Parse(handle, &temp)) { |
| 4378 |
return qfalse; |
| 4379 |
} |
| 4380 |
item->focusSound = DC->registerSound(temp, qfalse); |
| 4381 |
return qtrue; |
| 4382 |
} |
| 4383 |
|
| 4384 |
|
| 4385 |
// text <string> |
| 4386 |
qboolean ItemParse_text( itemDef_t *item, int handle ) { |
| 4387 |
if (!PC_String_Parse(handle, &item->text)) { |
| 4388 |
return qfalse; |
| 4389 |
} |
| 4390 |
return qtrue; |
| 4391 |
} |
| 4392 |
|
| 4393 |
// group <string> |
| 4394 |
qboolean ItemParse_group( itemDef_t *item, int handle ) { |
| 4395 |
if (!PC_String_Parse(handle, &item->window.group)) { |
| 4396 |
return qfalse; |
| 4397 |
} |
| 4398 |
return qtrue; |
| 4399 |
} |
| 4400 |
|
| 4401 |
// asset_model <string> |
| 4402 |
qboolean ItemParse_asset_model( itemDef_t *item, int handle ) { |
| 4403 |
const char *temp; |
| 4404 |
modelDef_t *modelPtr; |
| 4405 |
Item_ValidateTypeData(item); |
| 4406 |
modelPtr = (modelDef_t*)item->typeData; |
| 4407 |
|
| 4408 |
if (!PC_String_Parse(handle, &temp)) { |
| 4409 |
return qfalse; |
| 4410 |
} |
| 4411 |
item->asset = DC->registerModel(temp); |
| 4412 |
modelPtr->angle = rand() % 360; |
| 4413 |
return qtrue; |
| 4414 |
} |
| 4415 |
|
| 4416 |
// asset_shader <string> |
| 4417 |
qboolean ItemParse_asset_shader( itemDef_t *item, int handle ) { |
| 4418 |
const char *temp; |
| 4419 |
|
| 4420 |
if (!PC_String_Parse(handle, &temp)) { |
| 4421 |
return qfalse; |
| 4422 |
} |
| 4423 |
item->asset = DC->registerShaderNoMip(temp); |
| 4424 |
return qtrue; |
| 4425 |
} |
| 4426 |
|
| 4427 |
// model_origin <number> <number> <number> |
| 4428 |
qboolean ItemParse_model_origin( itemDef_t *item, int handle ) { |
| 4429 |
modelDef_t *modelPtr; |
| 4430 |
Item_ValidateTypeData(item); |
| 4431 |
modelPtr = (modelDef_t*)item->typeData; |
| 4432 |
|
| 4433 |
if (PC_Float_Parse(handle, &modelPtr->origin[0])) { |
| 4434 |
if (PC_Float_Parse(handle, &modelPtr->origin[1])) { |
| 4435 |
if (PC_Float_Parse(handle, &modelPtr->origin[2])) { |
| 4436 |
return qtrue; |
| 4437 |
} |
| 4438 |
} |
| 4439 |
} |
| 4440 |
return qfalse; |
| 4441 |
} |
| 4442 |
|
| 4443 |
// model_fovx <number> |
| 4444 |
qboolean ItemParse_model_fovx( itemDef_t *item, int handle ) { |
| 4445 |
modelDef_t *modelPtr; |
| 4446 |
Item_ValidateTypeData(item); |
| 4447 |
modelPtr = (modelDef_t*)item->typeData; |
| 4448 |
|
| 4449 |
if (!PC_Float_Parse(handle, &modelPtr->fov_x)) { |
| 4450 |
return qfalse; |
| 4451 |
} |
| 4452 |
return qtrue; |
| 4453 |
} |
| 4454 |
|
| 4455 |
// model_fovy <number> |
| 4456 |
qboolean ItemParse_model_fovy( itemDef_t *item, int handle ) { |
| 4457 |
modelDef_t *modelPtr; |
| 4458 |
Item_ValidateTypeData(item); |
| 4459 |
modelPtr = (modelDef_t*)item->typeData; |
| 4460 |
|
| 4461 |
if (!PC_Float_Parse(handle, &modelPtr->fov_y)) { |
| 4462 |
return qfalse; |
| 4463 |
} |
| 4464 |
return qtrue; |
| 4465 |
} |
| 4466 |
|
| 4467 |
// model_rotation <integer> |
| 4468 |
qboolean ItemParse_model_rotation( itemDef_t *item, int handle ) { |
| 4469 |
modelDef_t *modelPtr; |
| 4470 |
Item_ValidateTypeData(item); |
| 4471 |
modelPtr = (modelDef_t*)item->typeData; |
| 4472 |
|
| 4473 |
if (!PC_Int_Parse(handle, &modelPtr->rotationSpeed)) { |
| 4474 |
return qfalse; |
| 4475 |
} |
| 4476 |
return qtrue; |
| 4477 |
} |
| 4478 |
|
| 4479 |
// model_angle <integer> |
| 4480 |
qboolean ItemParse_model_angle( itemDef_t *item, int handle ) { |
| 4481 |
modelDef_t *modelPtr; |
| 4482 |
Item_ValidateTypeData(item); |
| 4483 |
modelPtr = (modelDef_t*)item->typeData; |
| 4484 |
|
| 4485 |
if (!PC_Int_Parse(handle, &modelPtr->angle)) { |
| 4486 |
return qfalse; |
| 4487 |
} |
| 4488 |
return qtrue; |
| 4489 |
} |
| 4490 |
|
| 4491 |
// rect <rectangle> |
| 4492 |
qboolean ItemParse_rect( itemDef_t *item, int handle ) { |
| 4493 |
if (!PC_Rect_Parse(handle, &item->window.rectClient)) { |
| 4494 |
return qfalse; |
| 4495 |
} |
| 4496 |
return qtrue; |
| 4497 |
} |
| 4498 |
|
| 4499 |
// style <integer> |
| 4500 |
qboolean ItemParse_style( itemDef_t *item, int handle ) { |
| 4501 |
if (!PC_Int_Parse(handle, &item->window.style)) { |
| 4502 |
return qfalse; |
| 4503 |
} |
| 4504 |
return qtrue; |
| 4505 |
} |
| 4506 |
|
| 4507 |
// decoration |
| 4508 |
qboolean ItemParse_decoration( itemDef_t *item, int handle ) { |
| 4509 |
item->window.flags |= WINDOW_DECORATION; |
| 4510 |
return qtrue; |
| 4511 |
} |
| 4512 |
|
| 4513 |
// notselectable |
| 4514 |
qboolean ItemParse_notselectable( itemDef_t *item, int handle ) { |
| 4515 |
listBoxDef_t *listPtr; |
| 4516 |
Item_ValidateTypeData(item); |
| 4517 |
listPtr = (listBoxDef_t*)item->typeData; |
| 4518 |
if (item->type == ITEM_TYPE_LISTBOX && listPtr) { |
| 4519 |
listPtr->notselectable = qtrue; |
| 4520 |
} |
| 4521 |
return qtrue; |
| 4522 |
} |
| 4523 |
|
| 4524 |
// manually wrapped |
| 4525 |
qboolean ItemParse_wrapped( itemDef_t *item, int handle ) { |
| 4526 |
item->window.flags |= WINDOW_WRAPPED; |
| 4527 |
return qtrue; |
| 4528 |
} |
| 4529 |
|
| 4530 |
// auto wrapped |
| 4531 |
qboolean ItemParse_autowrapped( itemDef_t *item, int handle ) { |
| 4532 |
item->window.flags |= WINDOW_AUTOWRAPPED; |
| 4533 |
return qtrue; |
| 4534 |
} |
| 4535 |
|
| 4536 |
|
| 4537 |
// horizontalscroll |
| 4538 |
qboolean ItemParse_horizontalscroll( itemDef_t *item, int handle ) { |
| 4539 |
item->window.flags |= WINDOW_HORIZONTAL; |
| 4540 |
return qtrue; |
| 4541 |
} |
| 4542 |
|
| 4543 |
// type <integer> |
| 4544 |
qboolean ItemParse_type( itemDef_t *item, int handle ) { |
| 4545 |
if (!PC_Int_Parse(handle, &item->type)) { |
| 4546 |
return qfalse; |
| 4547 |
} |
| 4548 |
Item_ValidateTypeData(item); |
| 4549 |
return qtrue; |
| 4550 |
} |
| 4551 |
|
| 4552 |
// elementwidth, used for listbox image elements |
| 4553 |
// uses textalignx for storage |
| 4554 |
qboolean ItemParse_elementwidth( itemDef_t *item, int handle ) { |
| 4555 |
listBoxDef_t *listPtr; |
| 4556 |
|
| 4557 |
Item_ValidateTypeData(item); |
| 4558 |
listPtr = (listBoxDef_t*)item->typeData; |
| 4559 |
if (!PC_Float_Parse(handle, &listPtr->elementWidth)) { |
| 4560 |
return qfalse; |
| 4561 |
} |
| 4562 |
return qtrue; |
| 4563 |
} |
| 4564 |
|
| 4565 |
// elementheight, used for listbox image elements |
| 4566 |
// uses textaligny for storage |
| 4567 |
qboolean ItemParse_elementheight( itemDef_t *item, int handle ) { |
| 4568 |
listBoxDef_t *listPtr; |
| 4569 |
|
| 4570 |
Item_ValidateTypeData(item); |
| 4571 |
listPtr = (listBoxDef_t*)item->typeData; |
| 4572 |
if (!PC_Float_Parse(handle, &listPtr->elementHeight)) { |
| 4573 |
return qfalse; |
| 4574 |
} |
| 4575 |
return qtrue; |
| 4576 |
} |
| 4577 |
|
| 4578 |
// feeder <float> |
| 4579 |
qboolean ItemParse_feeder( itemDef_t *item, int handle ) { |
| 4580 |
if (!PC_Float_Parse(handle, &item->special)) { |
| 4581 |
return qfalse; |
| 4582 |
} |
| 4583 |
return qtrue; |
| 4584 |
} |
| 4585 |
|
| 4586 |
// elementtype, used to specify what type of elements a listbox contains |
| 4587 |
// uses textstyle for storage |
| 4588 |
qboolean ItemParse_elementtype( itemDef_t *item, int handle ) { |
| 4589 |
listBoxDef_t *listPtr; |
| 4590 |
|
| 4591 |
Item_ValidateTypeData(item); |
| 4592 |
if (!item->typeData) |
| 4593 |
return qfalse; |
| 4594 |
listPtr = (listBoxDef_t*)item->typeData; |
| 4595 |
if (!PC_Int_Parse(handle, &listPtr->elementStyle)) { |
| 4596 |
return qfalse; |
| 4597 |
} |
| 4598 |
return qtrue; |
| 4599 |
} |
| 4600 |
|
| 4601 |
// columns sets a number of columns and an x pos and width per.. |
| 4602 |
qboolean ItemParse_columns( itemDef_t *item, int handle ) { |
| 4603 |
int num, i; |
| 4604 |
listBoxDef_t *listPtr; |
| 4605 |
|
| 4606 |
Item_ValidateTypeData(item); |
| 4607 |
if (!item->typeData) |
| 4608 |
return qfalse; |
| 4609 |
listPtr = (listBoxDef_t*)item->typeData; |
| 4610 |
if (PC_Int_Parse(handle, &num)) { |
| 4611 |
if (num > MAX_LB_COLUMNS) { |
| 4612 |
num = MAX_LB_COLUMNS; |
| 4613 |
} |
| 4614 |
listPtr->numColumns = num; |
| 4615 |
for (i = 0; i < num; i++) { |
| 4616 |
int pos, width, maxChars; |
| 4617 |
|
| 4618 |
if (PC_Int_Parse(handle, &pos) && PC_Int_Parse(handle, &width) && PC_Int_Parse(handle, &maxChars)) { |
| 4619 |
listPtr->columnInfo[i].pos = pos; |
| 4620 |
listPtr->columnInfo[i].width = width; |
| 4621 |
listPtr->columnInfo[i].maxChars = maxChars; |
| 4622 |
} else { |
| 4623 |
return qfalse; |
| 4624 |
} |
| 4625 |
} |
| 4626 |
} else { |
| 4627 |
return qfalse; |
| 4628 |
} |
| 4629 |
return qtrue; |
| 4630 |
} |
| 4631 |
|
| 4632 |
qboolean ItemParse_border( itemDef_t *item, int handle ) { |
| 4633 |
if (!PC_Int_Parse(handle, &item->window.border)) { |
| 4634 |
return qfalse; |
| 4635 |
} |
| 4636 |
return qtrue; |
| 4637 |
} |
| 4638 |
|
| 4639 |
qboolean ItemParse_bordersize( itemDef_t *item, int handle ) { |
| 4640 |
if (!PC_Float_Parse(handle, &item->window.borderSize)) { |
| 4641 |
return qfalse; |
| 4642 |
} |
| 4643 |
return qtrue; |
| 4644 |
} |
| 4645 |
|
| 4646 |
qboolean ItemParse_visible( itemDef_t *item, int handle ) { |
| 4647 |
int i; |
| 4648 |
|
| 4649 |
if (!PC_Int_Parse(handle, &i)) { |
| 4650 |
return qfalse; |
| 4651 |
} |
| 4652 |
if (i) { |
| 4653 |
item->window.flags |= WINDOW_VISIBLE; |
| 4654 |
} |
| 4655 |
return qtrue; |
| 4656 |
} |
| 4657 |
|
| 4658 |
qboolean ItemParse_ownerdraw( itemDef_t *item, int handle ) { |
| 4659 |
if (!PC_Int_Parse(handle, &item->window.ownerDraw)) { |
| 4660 |
return qfalse; |
| 4661 |
} |
| 4662 |
item->type = ITEM_TYPE_OWNERDRAW; |
| 4663 |
return qtrue; |
| 4664 |
} |
| 4665 |
|
| 4666 |
qboolean ItemParse_align( itemDef_t *item, int handle ) { |
| 4667 |
if (!PC_Int_Parse(handle, &item->alignment)) { |
| 4668 |
return qfalse; |
| 4669 |
} |
| 4670 |
return qtrue; |
| 4671 |
} |
| 4672 |
|
| 4673 |
qboolean ItemParse_textalign( itemDef_t *item, int handle ) { |
| 4674 |
if (!PC_Int_Parse(handle, &item->textalignment)) { |
| 4675 |
return qfalse; |
| 4676 |
} |
| 4677 |
return qtrue; |
| 4678 |
} |
| 4679 |
|
| 4680 |
qboolean ItemParse_textalignx( itemDef_t *item, int handle ) { |
| 4681 |
if (!PC_Float_Parse(handle, &item->textalignx)) { |
| 4682 |
return qfalse; |
| 4683 |
} |
| 4684 |
return qtrue; |
| 4685 |
} |
| 4686 |
|
| 4687 |
qboolean ItemParse_textaligny( itemDef_t *item, int handle ) { |
| 4688 |
if (!PC_Float_Parse(handle, &item->textaligny)) { |
| 4689 |
return qfalse; |
| 4690 |
} |
| 4691 |
return qtrue; |
| 4692 |
} |
| 4693 |
|
| 4694 |
qboolean ItemParse_textscale( itemDef_t *item, int handle ) { |
| 4695 |
if (!PC_Float_Parse(handle, &item->textscale)) { |
| 4696 |
return qfalse; |
| 4697 |
} |
| 4698 |
return qtrue; |
| 4699 |
} |
| 4700 |
|
| 4701 |
qboolean ItemParse_textstyle( itemDef_t *item, int handle ) { |
| 4702 |
if (!PC_Int_Parse(handle, &item->textStyle)) { |
| 4703 |
return qfalse; |
| 4704 |
} |
| 4705 |
return qtrue; |
| 4706 |
} |
| 4707 |
|
| 4708 |
qboolean ItemParse_backcolor( itemDef_t *item, int handle ) { |
| 4709 |
int i; |
| 4710 |
float f; |
| 4711 |
|
| 4712 |
for (i = 0; i < 4; i++) { |
| 4713 |
if (!PC_Float_Parse(handle, &f)) { |
| 4714 |
return qfalse; |
| 4715 |
} |
| 4716 |
item->window.backColor[i] = f; |
| 4717 |
} |
| 4718 |
return qtrue; |
| 4719 |
} |
| 4720 |
|
| 4721 |
qboolean ItemParse_forecolor( itemDef_t *item, int handle ) { |
| 4722 |
int i; |
| 4723 |
float f; |
| 4724 |
|
| 4725 |
for (i = 0; i < 4; i++) { |
| 4726 |
if (!PC_Float_Parse(handle, &f)) { |
| 4727 |
return qfalse; |
| 4728 |
} |
| 4729 |
item->window.foreColor[i] = f; |
| 4730 |
item->window.flags |= WINDOW_FORECOLORSET; |
| 4731 |
} |
| 4732 |
return qtrue; |
| 4733 |
} |
| 4734 |
|
| 4735 |
qboolean ItemParse_bordercolor( itemDef_t *item, int handle ) { |
| 4736 |
int i; |
| 4737 |
float f; |
| 4738 |
|
| 4739 |
for (i = 0; i < 4; i++) { |
| 4740 |
if (!PC_Float_Parse(handle, &f)) { |
| 4741 |
return qfalse; |
| 4742 |
} |
| 4743 |
item->window.borderColor[i] = f; |
| 4744 |
} |
| 4745 |
return qtrue; |
| 4746 |
} |
| 4747 |
|
| 4748 |
qboolean ItemParse_outlinecolor( itemDef_t *item, int handle ) { |
| 4749 |
if (!PC_Color_Parse(handle, &item->window.outlineColor)){ |
| 4750 |
return qfalse; |
| 4751 |
} |
| 4752 |
return qtrue; |
| 4753 |
} |
| 4754 |
|
| 4755 |
qboolean ItemParse_background( itemDef_t *item, int handle ) { |
| 4756 |
const char *temp; |
| 4757 |
|
| 4758 |
if (!PC_String_Parse(handle, &temp)) { |
| 4759 |
return qfalse; |
| 4760 |
} |
| 4761 |
item->window.background = DC->registerShaderNoMip(temp); |
| 4762 |
return qtrue; |
| 4763 |
} |
| 4764 |
|
| 4765 |
qboolean ItemParse_cinematic( itemDef_t *item, int handle ) { |
| 4766 |
if (!PC_String_Parse(handle, &item->window.cinematicName)) { |
| 4767 |
return qfalse; |
| 4768 |
} |
| 4769 |
return qtrue; |
| 4770 |
} |
| 4771 |
|
| 4772 |
qboolean ItemParse_doubleClick( itemDef_t *item, int handle ) { |
| 4773 |
listBoxDef_t *listPtr; |
| 4774 |
|
| 4775 |
Item_ValidateTypeData(item); |
| 4776 |
if (!item->typeData) { |
| 4777 |
return qfalse; |
| 4778 |
} |
| 4779 |
|
| 4780 |
listPtr = (listBoxDef_t*)item->typeData; |
| 4781 |
|
| 4782 |
if (!PC_Script_Parse(handle, &listPtr->doubleClick)) { |
| 4783 |
return qfalse; |
| 4784 |
} |
| 4785 |
return qtrue; |
| 4786 |
} |
| 4787 |
|
| 4788 |
qboolean ItemParse_onFocus( itemDef_t *item, int handle ) { |
| 4789 |
if (!PC_Script_Parse(handle, &item->onFocus)) { |
| 4790 |
return qfalse; |
| 4791 |
} |
| 4792 |
return qtrue; |
| 4793 |
} |
| 4794 |
|
| 4795 |
qboolean ItemParse_leaveFocus( itemDef_t *item, int handle ) { |
| 4796 |
if (!PC_Script_Parse(handle, &item->leaveFocus)) { |
| 4797 |
return qfalse; |
| 4798 |
} |
| 4799 |
return qtrue; |
| 4800 |
} |
| 4801 |
|
| 4802 |
qboolean ItemParse_mouseEnter( itemDef_t *item, int handle ) { |
| 4803 |
if (!PC_Script_Parse(handle, &item->mouseEnter)) { |
| 4804 |
return qfalse; |
| 4805 |
} |
| 4806 |
return qtrue; |
| 4807 |
} |
| 4808 |
|
| 4809 |
qboolean ItemParse_mouseExit( itemDef_t *item, int handle ) { |
| 4810 |
if (!PC_Script_Parse(handle, &item->mouseExit)) { |
| 4811 |
return qfalse; |
| 4812 |
} |
| 4813 |
return qtrue; |
| 4814 |
} |
| 4815 |
|
| 4816 |
qboolean ItemParse_mouseEnterText( itemDef_t *item, int handle ) { |
| 4817 |
if (!PC_Script_Parse(handle, &item->mouseEnterText)) { |
| 4818 |
return qfalse; |
| 4819 |
} |
| 4820 |
return qtrue; |
| 4821 |
} |
| 4822 |
|
| 4823 |
qboolean ItemParse_mouseExitText( itemDef_t *item, int handle ) { |
| 4824 |
if (!PC_Script_Parse(handle, &item->mouseExitText)) { |
| 4825 |
return qfalse; |
| 4826 |
} |
| 4827 |
return qtrue; |
| 4828 |
} |
| 4829 |
|
| 4830 |
qboolean ItemParse_action( itemDef_t *item, int handle ) { |
| 4831 |
if (!PC_Script_Parse(handle, &item->action)) { |
| 4832 |
return qfalse; |
| 4833 |
} |
| 4834 |
return qtrue; |
| 4835 |
} |
| 4836 |
|
| 4837 |
qboolean ItemParse_special( itemDef_t *item, int handle ) { |
| 4838 |
if (!PC_Float_Parse(handle, &item->special)) { |
| 4839 |
return qfalse; |
| 4840 |
} |
| 4841 |
return qtrue; |
| 4842 |
} |
| 4843 |
|
| 4844 |
qboolean ItemParse_cvarTest( itemDef_t *item, int handle ) { |
| 4845 |
if (!PC_String_Parse(handle, &item->cvarTest)) { |
| 4846 |
return qfalse; |
| 4847 |
} |
| 4848 |
return qtrue; |
| 4849 |
} |
| 4850 |
|
| 4851 |
qboolean ItemParse_cvar( itemDef_t *item, int handle ) { |
| 4852 |
editFieldDef_t *editPtr; |
| 4853 |
|
| 4854 |
Item_ValidateTypeData(item); |
| 4855 |
if (!PC_String_Parse(handle, &item->cvar)) { |
| 4856 |
return qfalse; |
| 4857 |
} |
| 4858 |
if (item->typeData) { |
| 4859 |
editPtr = (editFieldDef_t*)item->typeData; |
| 4860 |
editPtr->minVal = -1; |
| 4861 |
editPtr->maxVal = -1; |
| 4862 |
editPtr->defVal = -1; |
| 4863 |
} |
| 4864 |
return qtrue; |
| 4865 |
} |
| 4866 |
|
| 4867 |
qboolean ItemParse_maxChars( itemDef_t *item, int handle ) { |
| 4868 |
editFieldDef_t *editPtr; |
| 4869 |
int maxChars; |
| 4870 |
|
| 4871 |
Item_ValidateTypeData(item); |
| 4872 |
if (!item->typeData) |
| 4873 |
return qfalse; |
| 4874 |
|
| 4875 |
if (!PC_Int_Parse(handle, &maxChars)) { |
| 4876 |
return qfalse; |
| 4877 |
} |
| 4878 |
editPtr = (editFieldDef_t*)item->typeData; |
| 4879 |
editPtr->maxChars = maxChars; |
| 4880 |
return qtrue; |
| 4881 |
} |
| 4882 |
|
| 4883 |
qboolean ItemParse_maxPaintChars( itemDef_t *item, int handle ) { |
| 4884 |
editFieldDef_t *editPtr; |
| 4885 |
int maxChars; |
| 4886 |
|
| 4887 |
Item_ValidateTypeData(item); |
| 4888 |
if (!item->typeData) |
| 4889 |
return qfalse; |
| 4890 |
|
| 4891 |
if (!PC_Int_Parse(handle, &maxChars)) { |
| 4892 |
return qfalse; |
| 4893 |
} |
| 4894 |
editPtr = (editFieldDef_t*)item->typeData; |
| 4895 |
editPtr->maxPaintChars = maxChars; |
| 4896 |
return qtrue; |
| 4897 |
} |
| 4898 |
|
| 4899 |
|
| 4900 |
|
| 4901 |
qboolean ItemParse_cvarFloat( itemDef_t *item, int handle ) { |
| 4902 |
editFieldDef_t *editPtr; |
| 4903 |
|
| 4904 |
Item_ValidateTypeData(item); |
| 4905 |
if (!item->typeData) |
| 4906 |
return qfalse; |
| 4907 |
editPtr = (editFieldDef_t*)item->typeData; |
| 4908 |
if (PC_String_Parse(handle, &item->cvar) && |
| 4909 |
PC_Float_Parse(handle, &editPtr->defVal) && |
| 4910 |
PC_Float_Parse(handle, &editPtr->minVal) && |
| 4911 |
PC_Float_Parse(handle, &editPtr->maxVal)) { |
| 4912 |
return qtrue; |
| 4913 |
} |
| 4914 |
return qfalse; |
| 4915 |
} |
| 4916 |
|
| 4917 |
qboolean ItemParse_cvarStrList( itemDef_t *item, int handle ) { |
| 4918 |
pc_token_t token; |
| 4919 |
multiDef_t *multiPtr; |
| 4920 |
int pass; |
| 4921 |
|
| 4922 |
Item_ValidateTypeData(item); |
| 4923 |
if (!item->typeData) |
| 4924 |
return qfalse; |
| 4925 |
multiPtr = (multiDef_t*)item->typeData; |
| 4926 |
multiPtr->count = 0; |
| 4927 |
multiPtr->strDef = qtrue; |
| 4928 |
|
| 4929 |
if (!trap_PC_ReadToken(handle, &token)) |
| 4930 |
return qfalse; |
| 4931 |
if (*token.string != '{') { |
| 4932 |
return qfalse; |
| 4933 |
} |
| 4934 |
|
| 4935 |
pass = 0; |
| 4936 |
while ( 1 ) { |
| 4937 |
if (!trap_PC_ReadToken(handle, &token)) { |
| 4938 |
PC_SourceError(handle, "end of file inside menu item\n"); |
| 4939 |
return qfalse; |
| 4940 |
} |
| 4941 |
|
| 4942 |
if (*token.string == '}') { |
| 4943 |
return qtrue; |
| 4944 |
} |
| 4945 |
|
| 4946 |
if (*token.string == ',' || *token.string == ';') { |
| 4947 |
continue; |
| 4948 |
} |
| 4949 |
|
| 4950 |
if (pass == 0) { |
| 4951 |
multiPtr->cvarList[multiPtr->count] = String_Alloc(token.string); |
| 4952 |
pass = 1; |
| 4953 |
} else { |
| 4954 |
multiPtr->cvarStr[multiPtr->count] = String_Alloc(token.string); |
| 4955 |
pass = 0; |
| 4956 |
multiPtr->count++; |
| 4957 |
if (multiPtr->count >= MAX_MULTI_CVARS) { |
| 4958 |
return qfalse; |
| 4959 |
} |
| 4960 |
} |
| 4961 |
|
| 4962 |
} |
| 4963 |
return qfalse; // bk001205 - LCC missing return value |
| 4964 |
} |
| 4965 |
|
| 4966 |
qboolean ItemParse_cvarFloatList( itemDef_t *item, int handle ) { |
| 4967 |
pc_token_t token; |
| 4968 |
multiDef_t *multiPtr; |
| 4969 |
|
| 4970 |
Item_ValidateTypeData(item); |
| 4971 |
if (!item->typeData) |
| 4972 |
return qfalse; |
| 4973 |
multiPtr = (multiDef_t*)item->typeData; |
| 4974 |
multiPtr->count = 0; |
| 4975 |
multiPtr->strDef = qfalse; |
| 4976 |
|
| 4977 |
if (!trap_PC_ReadToken(handle, &token)) |
| 4978 |
return qfalse; |
| 4979 |
if (*token.string != '{') { |
| 4980 |
return qfalse; |
| 4981 |
} |
| 4982 |
|
| 4983 |
while ( 1 ) { |
| 4984 |
if (!trap_PC_ReadToken(handle, &token)) { |
| 4985 |
PC_SourceError(handle, "end of file inside menu item\n"); |
| 4986 |
return qfalse; |
| 4987 |
} |
| 4988 |
|
| 4989 |
if (*token.string == '}') { |
| 4990 |
return qtrue; |
| 4991 |
} |
| 4992 |
|
| 4993 |
if (*token.string == ',' || *token.string == ';') { |
| 4994 |
continue; |
| 4995 |
} |
| 4996 |
|
| 4997 |
multiPtr->cvarList[multiPtr->count] = String_Alloc(token.string); |
| 4998 |
if (!PC_Float_Parse(handle, &multiPtr->cvarValue[multiPtr->count])) { |
| 4999 |
return qfalse; |
| 5000 |
} |
| 5001 |
|
| 5002 |
multiPtr->count++; |
| 5003 |
if (multiPtr->count >= MAX_MULTI_CVARS) { |
| 5004 |
return qfalse; |
| 5005 |
} |
| 5006 |
|
| 5007 |
} |
| 5008 |
return qfalse; // bk001205 - LCC missing return value |
| 5009 |
} |
| 5010 |
|
| 5011 |
|
| 5012 |
|
| 5013 |
qboolean ItemParse_addColorRange( itemDef_t *item, int handle ) { |
| 5014 |
colorRangeDef_t color; |
| 5015 |
|
| 5016 |
if (PC_Float_Parse(handle, &color.low) && |
| 5017 |
PC_Float_Parse(handle, &color.high) && |
| 5018 |
PC_Color_Parse(handle, &color.color) ) { |
| 5019 |
if (item->numColors < MAX_COLOR_RANGES) { |
| 5020 |
memcpy(&item->colorRanges[item->numColors], &color, sizeof(color)); |
| 5021 |
item->numColors++; |
| 5022 |
} |
| 5023 |
return qtrue; |
| 5024 |
} |
| 5025 |
return qfalse; |
| 5026 |
} |
| 5027 |
|
| 5028 |
qboolean ItemParse_ownerdrawFlag( itemDef_t *item, int handle ) { |
| 5029 |
int i; |
| 5030 |
if (!PC_Int_Parse(handle, &i)) { |
| 5031 |
return qfalse; |
| 5032 |
} |
| 5033 |
item->window.ownerDrawFlags |= i; |
| 5034 |
return qtrue; |
| 5035 |
} |
| 5036 |
|
| 5037 |
qboolean ItemParse_enableCvar( itemDef_t *item, int handle ) { |
| 5038 |
if (PC_Script_Parse(handle, &item->enableCvar)) { |
| 5039 |
item->cvarFlags = CVAR_ENABLE; |
| 5040 |
return qtrue; |
| 5041 |
} |
| 5042 |
return qfalse; |
| 5043 |
} |
| 5044 |
|
| 5045 |
qboolean ItemParse_disableCvar( itemDef_t *item, int handle ) { |
| 5046 |
if (PC_Script_Parse(handle, &item->enableCvar)) { |
| 5047 |
item->cvarFlags = CVAR_DISABLE; |
| 5048 |
return qtrue; |
| 5049 |
} |
| 5050 |
return qfalse; |
| 5051 |
} |
| 5052 |
|
| 5053 |
qboolean ItemParse_showCvar( itemDef_t *item, int handle ) { |
| 5054 |
if (PC_Script_Parse(handle, &item->enableCvar)) { |
| 5055 |
item->cvarFlags = CVAR_SHOW; |
| 5056 |
return qtrue; |
| 5057 |
} |
| 5058 |
return qfalse; |
| 5059 |
} |
| 5060 |
|
| 5061 |
qboolean ItemParse_hideCvar( itemDef_t *item, int handle ) { |
| 5062 |
if (PC_Script_Parse(handle, &item->enableCvar)) { |
| 5063 |
item->cvarFlags = CVAR_HIDE; |
| 5064 |
return qtrue; |
| 5065 |
} |
| 5066 |
return qfalse; |
| 5067 |
} |
| 5068 |
|
| 5069 |
|
| 5070 |
keywordHash_t itemParseKeywords[] = { |
| 5071 |
{"name", ItemParse_name, NULL}, |
| 5072 |
{"text", ItemParse_text, NULL}, |
| 5073 |
{"group", ItemParse_group, NULL}, |
| 5074 |
{"asset_model", ItemParse_asset_model, NULL}, |
| 5075 |
{"asset_shader", ItemParse_asset_shader, NULL}, |
| 5076 |
{"model_origin", ItemParse_model_origin, NULL}, |
| 5077 |
{"model_fovx", ItemParse_model_fovx, NULL}, |
| 5078 |
{"model_fovy", ItemParse_model_fovy, NULL}, |
| 5079 |
{"model_rotation", ItemParse_model_rotation, NULL}, |
| 5080 |
{"model_angle", ItemParse_model_angle, NULL}, |
| 5081 |
{"rect", ItemParse_rect, NULL}, |
| 5082 |
{"style", ItemParse_style, NULL}, |
| 5083 |
{"decoration", ItemParse_decoration, NULL}, |
| 5084 |
{"notselectable", ItemParse_notselectable, NULL}, |
| 5085 |
{"wrapped", ItemParse_wrapped, NULL}, |
| 5086 |
{"autowrapped", ItemParse_autowrapped, NULL}, |
| 5087 |
{"horizontalscroll", ItemParse_horizontalscroll, NULL}, |
| 5088 |
{"type", ItemParse_type, NULL}, |
| 5089 |
{"elementwidth", ItemParse_elementwidth, NULL}, |
| 5090 |
{"elementheight", ItemParse_elementheight, NULL}, |
| 5091 |
{"feeder", ItemParse_feeder, NULL}, |
| 5092 |
{"elementtype", ItemParse_elementtype, NULL}, |
| 5093 |
{"columns", ItemParse_columns, NULL}, |
| 5094 |
{"border", ItemParse_border, NULL}, |
| 5095 |
{"bordersize", ItemParse_bordersize, NULL}, |
| 5096 |
{"visible", ItemParse_visible, NULL}, |
| 5097 |
{"ownerdraw", ItemParse_ownerdraw, NULL}, |
| 5098 |
{"align", ItemParse_align, NULL}, |
| 5099 |
{"textalign", ItemParse_textalign, NULL}, |
| 5100 |
{"textalignx", ItemParse_textalignx, NULL}, |
| 5101 |
{"textaligny", ItemParse_textaligny, NULL}, |
| 5102 |
{"textscale", ItemParse_textscale, NULL}, |
| 5103 |
{"textstyle", ItemParse_textstyle, NULL}, |
| 5104 |
{"backcolor", ItemParse_backcolor, NULL}, |
| 5105 |
{"forecolor", ItemParse_forecolor, NULL}, |
| 5106 |
{"bordercolor", ItemParse_bordercolor, NULL}, |
| 5107 |
{"outlinecolor", ItemParse_outlinecolor, NULL}, |
| 5108 |
{"background", ItemParse_background, NULL}, |
| 5109 |
{"onFocus", ItemParse_onFocus, NULL}, |
| 5110 |
{"leaveFocus", ItemParse_leaveFocus, NULL}, |
| 5111 |
{"mouseEnter", ItemParse_mouseEnter, NULL}, |
| 5112 |
{"mouseExit", ItemParse_mouseExit, NULL}, |
| 5113 |
{"mouseEnterText", ItemParse_mouseEnterText, NULL}, |
| 5114 |
{"mouseExitText", ItemParse_mouseExitText, NULL}, |
| 5115 |
{"action", ItemParse_action, NULL}, |
| 5116 |
{"special", ItemParse_special, NULL}, |
| 5117 |
{"cvar", ItemParse_cvar, NULL}, |
| 5118 |
{"maxChars", ItemParse_maxChars, NULL}, |
| 5119 |
{"maxPaintChars", ItemParse_maxPaintChars, NULL}, |
| 5120 |
{"focusSound", ItemParse_focusSound, NULL}, |
| 5121 |
{"cvarFloat", ItemParse_cvarFloat, NULL}, |
| 5122 |
{"cvarStrList", ItemParse_cvarStrList, NULL}, |
| 5123 |
{"cvarFloatList", ItemParse_cvarFloatList, NULL}, |
| 5124 |
{"addColorRange", ItemParse_addColorRange, NULL}, |
| 5125 |
{"ownerdrawFlag", ItemParse_ownerdrawFlag, NULL}, |
| 5126 |
{"enableCvar", ItemParse_enableCvar, NULL}, |
| 5127 |
{"cvarTest", ItemParse_cvarTest, NULL}, |
| 5128 |
{"disableCvar", ItemParse_disableCvar, NULL}, |
| 5129 |
{"showCvar", ItemParse_showCvar, NULL}, |
| 5130 |
{"hideCvar", ItemParse_hideCvar, NULL}, |
| 5131 |
{"cinematic", ItemParse_cinematic, NULL}, |
| 5132 |
{"doubleclick", ItemParse_doubleClick, NULL}, |
| 5133 |
{NULL, 0, NULL} |
| 5134 |
}; |
| 5135 |
|
| 5136 |
keywordHash_t *itemParseKeywordHash[KEYWORDHASH_SIZE]; |
| 5137 |
|
| 5138 |
/* |
| 5139 |
=============== |
| 5140 |
Item_SetupKeywordHash |
| 5141 |
=============== |
| 5142 |
*/ |
| 5143 |
void Item_SetupKeywordHash(void) { |
| 5144 |
int i; |
| 5145 |
|
| 5146 |
memset(itemParseKeywordHash, 0, sizeof(itemParseKeywordHash)); |
| 5147 |
for (i = 0; itemParseKeywords[i].keyword; i++) { |
| 5148 |
KeywordHash_Add(itemParseKeywordHash, &itemParseKeywords[i]); |
| 5149 |
} |
| 5150 |
} |
| 5151 |
|
| 5152 |
/* |
| 5153 |
=============== |
| 5154 |
Item_Parse |
| 5155 |
=============== |
| 5156 |
*/ |
| 5157 |
qboolean Item_Parse(int handle, itemDef_t *item) { |
| 5158 |
pc_token_t token; |
| 5159 |
keywordHash_t *key; |
| 5160 |
|
| 5161 |
|
| 5162 |
if (!trap_PC_ReadToken(handle, &token)) |
| 5163 |
return qfalse; |
| 5164 |
if (*token.string != '{') { |
| 5165 |
return qfalse; |
| 5166 |
} |
| 5167 |
while ( 1 ) { |
| 5168 |
if (!trap_PC_ReadToken(handle, &token)) { |
| 5169 |
PC_SourceError(handle, "end of file inside menu item\n"); |
| 5170 |
return qfalse; |
| 5171 |
} |
| 5172 |
|
| 5173 |
if (*token.string == '}') { |
| 5174 |
return qtrue; |
| 5175 |
} |
| 5176 |
|
| 5177 |
key = KeywordHash_Find(itemParseKeywordHash, token.string); |
| 5178 |
if (!key) { |
| 5179 |
PC_SourceError(handle, "unknown menu item keyword %s", token.string); |
| 5180 |
continue; |
| 5181 |
} |
| 5182 |
if ( !key->func(item, handle) ) { |
| 5183 |
PC_SourceError(handle, "couldn't parse menu item keyword %s", token.string); |
| 5184 |
return qfalse; |
| 5185 |
} |
| 5186 |
} |
| 5187 |
return qfalse; // bk001205 - LCC missing return value |
| 5188 |
} |
| 5189 |
|
| 5190 |
|
| 5191 |
// Item_InitControls |
| 5192 |
// init's special control types |
| 5193 |
void Item_InitControls(itemDef_t *item) { |
| 5194 |
if (item == NULL) { |
| 5195 |
return; |
| 5196 |
} |
| 5197 |
if (item->type == ITEM_TYPE_LISTBOX) { |
| 5198 |
listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData; |
| 5199 |
item->cursorPos = 0; |
| 5200 |
if (listPtr) { |
| 5201 |
listPtr->cursorPos = 0; |
| 5202 |
listPtr->startPos = 0; |
| 5203 |
listPtr->endPos = 0; |
| 5204 |
listPtr->cursorPos = 0; |
| 5205 |
} |
| 5206 |
} |
| 5207 |
} |
| 5208 |
|
| 5209 |
/* |
| 5210 |
=============== |
| 5211 |
Menu Keyword Parse functions |
| 5212 |
=============== |
| 5213 |
*/ |
| 5214 |
|
| 5215 |
qboolean MenuParse_font( itemDef_t *item, int handle ) { |
| 5216 |
menuDef_t *menu = (menuDef_t*)item; |
| 5217 |
if (!PC_String_Parse(handle, &menu->font)) { |
| 5218 |
return qfalse; |
| 5219 |
} |
| 5220 |
if (!DC->Assets.fontRegistered) { |
| 5221 |
DC->registerFont(menu->font, 48, &DC->Assets.textFont); |
| 5222 |
DC->Assets.fontRegistered = qtrue; |
| 5223 |
} |
| 5224 |
return qtrue; |
| 5225 |
} |
| 5226 |
|
| 5227 |
qboolean MenuParse_name( itemDef_t *item, int handle ) { |
| 5228 |
menuDef_t *menu = (menuDef_t*)item; |
| 5229 |
if (!PC_String_Parse(handle, &menu->window.name)) { |
| 5230 |
return qfalse; |
| 5231 |
} |
| 5232 |
if (Q_stricmp(menu->window.name, "main") == 0) { |
| 5233 |
// default main as having focus |
| 5234 |
//menu->window.flags |= WINDOW_HASFOCUS; |
| 5235 |
} |
| 5236 |
return qtrue; |
| 5237 |
} |
| 5238 |
|
| 5239 |
qboolean MenuParse_fullscreen( itemDef_t *item, int handle ) { |
| 5240 |
menuDef_t *menu = (menuDef_t*)item; |
| 5241 |
if (!PC_Int_Parse(handle, (int*) &menu->fullScreen)) { // bk001206 - cast qboolean |
| 5242 |
return qfalse; |
| 5243 |
} |
| 5244 |
return qtrue; |
| 5245 |
} |
| 5246 |
|
| 5247 |
qboolean MenuParse_rect( itemDef_t *item, int handle ) { |
| 5248 |
menuDef_t *menu = (menuDef_t*)item; |
| 5249 |
if (!PC_Rect_Parse(handle, &menu->window.rect)) { |
| 5250 |
return qfalse; |
| 5251 |
} |
| 5252 |
return qtrue; |
| 5253 |
} |
| 5254 |
|
| 5255 |
qboolean MenuParse_style( itemDef_t *item, int handle ) { |
| 5256 |
menuDef_t *menu = (menuDef_t*)item; |
| 5257 |
if (!PC_Int_Parse(handle, &menu->window.style)) { |
| 5258 |
return qfalse; |
| 5259 |
} |
| 5260 |
return qtrue; |
| 5261 |
} |
| 5262 |
|
| 5263 |
qboolean MenuParse_visible( itemDef_t *item, int handle ) { |
| 5264 |
int i; |
| 5265 |
menuDef_t *menu = (menuDef_t*)item; |
| 5266 |
|
| 5267 |
if (!PC_Int_Parse(handle, &i)) { |
| 5268 |
return qfalse; |
| 5269 |
} |
| 5270 |
if (i) { |
| 5271 |
menu->window.flags |= WINDOW_VISIBLE; |
| 5272 |
} |
| 5273 |
return qtrue; |
| 5274 |
} |
| 5275 |
|
| 5276 |
qboolean MenuParse_onOpen( itemDef_t *item, int handle ) { |
| 5277 |
menuDef_t *menu = (menuDef_t*)item; |
| 5278 |
if (!PC_Script_Parse(handle, &menu->onOpen)) { |
| 5279 |
return qfalse; |
| 5280 |
} |
| 5281 |
return qtrue; |
| 5282 |
} |
| 5283 |
|
| 5284 |
qboolean MenuParse_onClose( itemDef_t *item, int handle ) { |
| 5285 |
menuDef_t *menu = (menuDef_t*)item; |
| 5286 |
if (!PC_Script_Parse(handle, &menu->onClose)) { |
| 5287 |
return qfalse; |
| 5288 |
} |
| 5289 |
return qtrue; |
| 5290 |
} |
| 5291 |
|
| 5292 |
qboolean MenuParse_onESC( itemDef_t *item, int handle ) { |
| 5293 |
menuDef_t *menu = (menuDef_t*)item; |
| 5294 |
if (!PC_Script_Parse(handle, &menu->onESC)) { |
| 5295 |
return qfalse; |
| 5296 |
} |
| 5297 |
return qtrue; |
| 5298 |
} |
| 5299 |
|
| 5300 |
|
| 5301 |
|
| 5302 |
qboolean MenuParse_border( itemDef_t *item, int handle ) { |
| 5303 |
menuDef_t *menu = (menuDef_t*)item; |
| 5304 |
if (!PC_Int_Parse(handle, &menu->window.border)) { |
| 5305 |
return qfalse; |
| 5306 |
} |
| 5307 |
return qtrue; |
| 5308 |
} |
| 5309 |
|
| 5310 |
qboolean MenuParse_borderSize( itemDef_t *item, int handle ) { |
| 5311 |
menuDef_t *menu = (menuDef_t*)item; |
| 5312 |
if (!PC_Float_Parse(handle, &menu->window.borderSize)) { |
| 5313 |
return qfalse; |
| 5314 |
} |
| 5315 |
return qtrue; |
| 5316 |
} |
| 5317 |
|
| 5318 |
qboolean MenuParse_backcolor( itemDef_t *item, int handle ) { |
| 5319 |
int i; |
| 5320 |
float f; |
| 5321 |
menuDef_t *menu = (menuDef_t*)item; |
| 5322 |
|
| 5323 |
for (i = 0; i < 4; i++) { |
| 5324 |
if (!PC_Float_Parse(handle, &f)) { |
| 5325 |
return qfalse; |
| 5326 |
} |
| 5327 |
menu->window.backColor[i] = f; |
| 5328 |
} |
| 5329 |
return qtrue; |
| 5330 |
} |
| 5331 |
|
| 5332 |
qboolean MenuParse_forecolor( itemDef_t *item, int handle ) { |
| 5333 |
int i; |
| 5334 |
float f; |
| 5335 |
menuDef_t *menu = (menuDef_t*)item; |
| 5336 |
|
| 5337 |
for (i = 0; i < 4; i++) { |
| 5338 |
if (!PC_Float_Parse(handle, &f)) { |
| 5339 |
return qfalse; |
| 5340 |
} |
| 5341 |
menu->window.foreColor[i] = f; |
| 5342 |
menu->window.flags |= WINDOW_FORECOLORSET; |
| 5343 |
} |
| 5344 |
return qtrue; |
| 5345 |
} |
| 5346 |
|
| 5347 |
qboolean MenuParse_bordercolor( itemDef_t *item, int handle ) { |
| 5348 |
int i; |
| 5349 |
float f; |
| 5350 |
menuDef_t *menu = (menuDef_t*)item; |
| 5351 |
|
| 5352 |
for (i = 0; i < 4; i++) { |
| 5353 |
if (!PC_Float_Parse(handle, &f)) { |
| 5354 |
return qfalse; |
| 5355 |
} |
| 5356 |
menu->window.borderColor[i] = f; |
| 5357 |
} |
| 5358 |
return qtrue; |
| 5359 |
} |
| 5360 |
|
| 5361 |
qboolean MenuParse_focuscolor( itemDef_t *item, int handle ) { |
| 5362 |
int i; |
| 5363 |
float f; |
| 5364 |
menuDef_t *menu = (menuDef_t*)item; |
| 5365 |
|
| 5366 |
for (i = 0; i < 4; i++) { |
| 5367 |
if (!PC_Float_Parse(handle, &f)) { |
| 5368 |
return qfalse; |
| 5369 |
} |
| 5370 |
menu->focusColor[i] = f; |
| 5371 |
} |
| 5372 |
return qtrue; |
| 5373 |
} |
| 5374 |
|
| 5375 |
qboolean MenuParse_disablecolor( itemDef_t *item, int handle ) { |
| 5376 |
int i; |
| 5377 |
float f; |
| 5378 |
menuDef_t *menu = (menuDef_t*)item; |
| 5379 |
for (i = 0; i < 4; i++) { |
| 5380 |
if (!PC_Float_Parse(handle, &f)) { |
| 5381 |
return qfalse; |
| 5382 |
} |
| 5383 |
menu->disableColor[i] = f; |
| 5384 |
} |
| 5385 |
return qtrue; |
| 5386 |
} |
| 5387 |
|
| 5388 |
|
| 5389 |
qboolean MenuParse_outlinecolor( itemDef_t *item, int handle ) { |
| 5390 |
menuDef_t *menu = (menuDef_t*)item; |
| 5391 |
if (!PC_Color_Parse(handle, &menu->window.outlineColor)){ |
| 5392 |
return qfalse; |
| 5393 |
} |
| 5394 |
return qtrue; |
| 5395 |
} |
| 5396 |
|
| 5397 |
qboolean MenuParse_background( itemDef_t *item, int handle ) { |
| 5398 |
const char *buff; |
| 5399 |
menuDef_t *menu = (menuDef_t*)item; |
| 5400 |
|
| 5401 |
if (!PC_String_Parse(handle, &buff)) { |
| 5402 |
return qfalse; |
| 5403 |
} |
| 5404 |
menu->window.background = DC->registerShaderNoMip(buff); |
| 5405 |
return qtrue; |
| 5406 |
} |
| 5407 |
|
| 5408 |
qboolean MenuParse_cinematic( itemDef_t *item, int handle ) { |
| 5409 |
menuDef_t *menu = (menuDef_t*)item; |
| 5410 |
|
| 5411 |
if (!PC_String_Parse(handle, &menu->window.cinematicName)) { |
| 5412 |
return qfalse; |
| 5413 |
} |
| 5414 |
return qtrue; |
| 5415 |
} |
| 5416 |
|
| 5417 |
qboolean MenuParse_ownerdrawFlag( itemDef_t *item, int handle ) { |
| 5418 |
int i; |
| 5419 |
menuDef_t *menu = (menuDef_t*)item; |
| 5420 |
|
| 5421 |
if (!PC_Int_Parse(handle, &i)) { |
| 5422 |
return qfalse; |
| 5423 |
} |
| 5424 |
menu->window.ownerDrawFlags |= i; |
| 5425 |
return qtrue; |
| 5426 |
} |
| 5427 |
|
| 5428 |
qboolean MenuParse_ownerdraw( itemDef_t *item, int handle ) { |
| 5429 |
menuDef_t *menu = (menuDef_t*)item; |
| 5430 |
|
| 5431 |
if (!PC_Int_Parse(handle, &menu->window.ownerDraw)) { |
| 5432 |
return qfalse; |
| 5433 |
} |
| 5434 |
return qtrue; |
| 5435 |
} |
| 5436 |
|
| 5437 |
|
| 5438 |
// decoration |
| 5439 |
qboolean MenuParse_popup( itemDef_t *item, int handle ) { |
| 5440 |
menuDef_t *menu = (menuDef_t*)item; |
| 5441 |
menu->window.flags |= WINDOW_POPUP; |
| 5442 |
return qtrue; |
| 5443 |
} |
| 5444 |
|
| 5445 |
|
| 5446 |
qboolean MenuParse_outOfBounds( itemDef_t *item, int handle ) { |
| 5447 |
menuDef_t *menu = (menuDef_t*)item; |
| 5448 |
|
| 5449 |
menu->window.flags |= WINDOW_OOB_CLICK; |
| 5450 |
return qtrue; |
| 5451 |
} |
| 5452 |
|
| 5453 |
qboolean MenuParse_soundLoop( itemDef_t *item, int handle ) { |
| 5454 |
menuDef_t *menu = (menuDef_t*)item; |
| 5455 |
|
| 5456 |
if (!PC_String_Parse(handle, &menu->soundName)) { |
| 5457 |
return qfalse; |
| 5458 |
} |
| 5459 |
return qtrue; |
| 5460 |
} |
| 5461 |
|
| 5462 |
qboolean MenuParse_fadeClamp( itemDef_t *item, int handle ) { |
| 5463 |
menuDef_t *menu = (menuDef_t*)item; |
| 5464 |
|
| 5465 |
if (!PC_Float_Parse(handle, &menu->fadeClamp)) { |
| 5466 |
return qfalse; |
| 5467 |
} |
| 5468 |
return qtrue; |
| 5469 |
} |
| 5470 |
|
| 5471 |
qboolean MenuParse_fadeAmount( itemDef_t *item, int handle ) { |
| 5472 |
menuDef_t *menu = (menuDef_t*)item; |
| 5473 |
|
| 5474 |
if (!PC_Float_Parse(handle, &menu->fadeAmount)) { |
| 5475 |
return qfalse; |
| 5476 |
} |
| 5477 |
return qtrue; |
| 5478 |
} |
| 5479 |
|
| 5480 |
|
| 5481 |
qboolean MenuParse_fadeCycle( itemDef_t *item, int handle ) { |
| 5482 |
menuDef_t *menu = (menuDef_t*)item; |
| 5483 |
|
| 5484 |
if (!PC_Int_Parse(handle, &menu->fadeCycle)) { |
| 5485 |
return qfalse; |
| 5486 |
} |
| 5487 |
return qtrue; |
| 5488 |
} |
| 5489 |
|
| 5490 |
|
| 5491 |
qboolean MenuParse_itemDef( itemDef_t *item, int handle ) { |
| 5492 |
menuDef_t *menu = (menuDef_t*)item; |
| 5493 |
if (menu->itemCount < MAX_MENUITEMS) { |
| 5494 |
menu->items[menu->itemCount] = UI_Alloc(sizeof(itemDef_t)); |
| 5495 |
Item_Init(menu->items[menu->itemCount]); |
| 5496 |
if (!Item_Parse(handle, menu->items[menu->itemCount])) { |
| 5497 |
return qfalse; |
| 5498 |
} |
| 5499 |
Item_InitControls(menu->items[menu->itemCount]); |
| 5500 |
menu->items[menu->itemCount++]->parent = menu; |
| 5501 |
} |
| 5502 |
return qtrue; |
| 5503 |
} |
| 5504 |
|
| 5505 |
keywordHash_t menuParseKeywords[] = { |
| 5506 |
{"font", MenuParse_font, NULL}, |
| 5507 |
{"name", MenuParse_name, NULL}, |
| 5508 |
{"fullscreen", MenuParse_fullscreen, NULL}, |
| 5509 |
{"rect", MenuParse_rect, NULL}, |
| 5510 |
{"style", MenuParse_style, NULL}, |
| 5511 |
{"visible", MenuParse_visible, NULL}, |
| 5512 |
{"onOpen", MenuParse_onOpen, NULL}, |
| 5513 |
{"onClose", MenuParse_onClose, NULL}, |
| 5514 |
{"onESC", MenuParse_onESC, NULL}, |
| 5515 |
{"border", MenuParse_border, NULL}, |
| 5516 |
{"borderSize", MenuParse_borderSize, NULL}, |
| 5517 |
{"backcolor", MenuParse_backcolor, NULL}, |
| 5518 |
{"forecolor", MenuParse_forecolor, NULL}, |
| 5519 |
{"bordercolor", MenuParse_bordercolor, NULL}, |
| 5520 |
{"focuscolor", MenuParse_focuscolor, NULL}, |
| 5521 |
{"disablecolor", MenuParse_disablecolor, NULL}, |
| 5522 |
{"outlinecolor", MenuParse_outlinecolor, NULL}, |
| 5523 |
{"background", MenuParse_background, NULL}, |
| 5524 |
{"ownerdraw", MenuParse_ownerdraw, NULL}, |
| 5525 |
{"ownerdrawFlag", MenuParse_ownerdrawFlag, NULL}, |
| 5526 |
{"outOfBoundsClick", MenuParse_outOfBounds, NULL}, |
| 5527 |
{"soundLoop", MenuParse_soundLoop, NULL}, |
| 5528 |
{"itemDef", MenuParse_itemDef, NULL}, |
| 5529 |
{"cinematic", MenuParse_cinematic, NULL}, |
| 5530 |
{"popup", MenuParse_popup, NULL}, |
| 5531 |
{"fadeClamp", MenuParse_fadeClamp, NULL}, |
| 5532 |
{"fadeCycle", MenuParse_fadeCycle, NULL}, |
| 5533 |
{"fadeAmount", MenuParse_fadeAmount, NULL}, |
| 5534 |
{NULL, 0, NULL} |
| 5535 |
}; |
| 5536 |
|
| 5537 |
keywordHash_t *menuParseKeywordHash[KEYWORDHASH_SIZE]; |
| 5538 |
|
| 5539 |
/* |
| 5540 |
=============== |
| 5541 |
Menu_SetupKeywordHash |
| 5542 |
=============== |
| 5543 |
*/ |
| 5544 |
void Menu_SetupKeywordHash(void) { |
| 5545 |
int i; |
| 5546 |
|
| 5547 |
memset(menuParseKeywordHash, 0, sizeof(menuParseKeywordHash)); |
| 5548 |
for (i = 0; menuParseKeywords[i].keyword; i++) { |
| 5549 |
KeywordHash_Add(menuParseKeywordHash, &menuParseKeywords[i]); |
| 5550 |
} |
| 5551 |
} |
| 5552 |
|
| 5553 |
/* |
| 5554 |
=============== |
| 5555 |
Menu_Parse |
| 5556 |
=============== |
| 5557 |
*/ |
| 5558 |
qboolean Menu_Parse(int handle, menuDef_t *menu) { |
| 5559 |
pc_token_t token; |
| 5560 |
keywordHash_t *key; |
| 5561 |
|
| 5562 |
if (!trap_PC_ReadToken(handle, &token)) |
| 5563 |
return qfalse; |
| 5564 |
if (*token.string != '{') { |
| 5565 |
return qfalse; |
| 5566 |
} |
| 5567 |
|
| 5568 |
while ( 1 ) { |
| 5569 |
|
| 5570 |
memset(&token, 0, sizeof(pc_token_t)); |
| 5571 |
if (!trap_PC_ReadToken(handle, &token)) { |
| 5572 |
PC_SourceError(handle, "end of file inside menu\n"); |
| 5573 |
return qfalse; |
| 5574 |
} |
| 5575 |
|
| 5576 |
if (*token.string == '}') { |
| 5577 |
return qtrue; |
| 5578 |
} |
| 5579 |
|
| 5580 |
key = KeywordHash_Find(menuParseKeywordHash, token.string); |
| 5581 |
if (!key) { |
| 5582 |
PC_SourceError(handle, "unknown menu keyword %s", token.string); |
| 5583 |
continue; |
| 5584 |
} |
| 5585 |
if ( !key->func((itemDef_t*)menu, handle) ) { |
| 5586 |
PC_SourceError(handle, "couldn't parse menu keyword %s", token.string); |
| 5587 |
return qfalse; |
| 5588 |
} |
| 5589 |
} |
| 5590 |
return qfalse; // bk001205 - LCC missing return value |
| 5591 |
} |
| 5592 |
|
| 5593 |
/* |
| 5594 |
=============== |
| 5595 |
Menu_New |
| 5596 |
=============== |
| 5597 |
*/ |
| 5598 |
void Menu_New(int handle) { |
| 5599 |
menuDef_t *menu = &Menus[menuCount]; |
| 5600 |
|
| 5601 |
if (menuCount < MAX_MENUS) { |
| 5602 |
Menu_Init(menu); |
| 5603 |
if (Menu_Parse(handle, menu)) { |
| 5604 |
Menu_PostParse(menu); |
| 5605 |
menuCount++; |
| 5606 |
} |
| 5607 |
} |
| 5608 |
} |
| 5609 |
|
| 5610 |
int Menu_Count(void) { |
| 5611 |
return menuCount; |
| 5612 |
} |
| 5613 |
|
| 5614 |
void Menu_PaintAll(void) { |
| 5615 |
int i; |
| 5616 |
if (captureFunc) { |
| 5617 |
captureFunc(captureData); |
| 5618 |
} |
| 5619 |
|
| 5620 |
for (i = 0; i < Menu_Count(); i++) { |
| 5621 |
Menu_Paint(&Menus[i], qfalse); |
| 5622 |
} |
| 5623 |
|
| 5624 |
if (debugMode) { |
| 5625 |
vec4_t v = {1, 1, 1, 1}; |
| 5626 |
DC->drawText(5, 25, .5, v, va("fps: %f", DC->FPS), 0, 0, 0); |
| 5627 |
} |
| 5628 |
} |
| 5629 |
|
| 5630 |
void Menu_Reset(void) { |
| 5631 |
menuCount = 0; |
| 5632 |
} |
| 5633 |
|
| 5634 |
displayContextDef_t *Display_GetContext(void) { |
| 5635 |
return DC; |
| 5636 |
} |
| 5637 |
|
| 5638 |
#ifndef MISSIONPACK // bk001206 |
| 5639 |
static float captureX; |
| 5640 |
static float captureY; |
| 5641 |
#endif |
| 5642 |
|
| 5643 |
void *Display_CaptureItem(int x, int y) { |
| 5644 |
int i; |
| 5645 |
|
| 5646 |
for (i = 0; i < menuCount; i++) { |
| 5647 |
// turn off focus each item |
| 5648 |
// menu->items[i].window.flags &= ~WINDOW_HASFOCUS; |
| 5649 |
if (Rect_ContainsPoint(&Menus[i].window.rect, x, y)) { |
| 5650 |
return &Menus[i]; |
| 5651 |
} |
| 5652 |
} |
| 5653 |
return NULL; |
| 5654 |
} |
| 5655 |
|
| 5656 |
|
| 5657 |
// FIXME: |
| 5658 |
qboolean Display_MouseMove(void *p, int x, int y) { |
| 5659 |
int i; |
| 5660 |
menuDef_t *menu = p; |
| 5661 |
|
| 5662 |
if (menu == NULL) { |
| 5663 |
menu = Menu_GetFocused(); |
| 5664 |
if (menu) { |
| 5665 |
if (menu->window.flags & WINDOW_POPUP) { |
| 5666 |
Menu_HandleMouseMove(menu, x, y); |
| 5667 |
return qtrue; |
| 5668 |
} |
| 5669 |
} |
| 5670 |
for (i = 0; i < menuCount; i++) { |
| 5671 |
Menu_HandleMouseMove(&Menus[i], x, y); |
| 5672 |
} |
| 5673 |
} else { |
| 5674 |
menu->window.rect.x += x; |
| 5675 |
menu->window.rect.y += y; |
| 5676 |
Menu_UpdatePosition(menu); |
| 5677 |
} |
| 5678 |
return qtrue; |
| 5679 |
|
| 5680 |
} |
| 5681 |
|
| 5682 |
int Display_CursorType(int x, int y) { |
| 5683 |
int i; |
| 5684 |
for (i = 0; i < menuCount; i++) { |
| 5685 |
rectDef_t r2; |
| 5686 |
r2.x = Menus[i].window.rect.x - 3; |
| 5687 |
r2.y = Menus[i].window.rect.y - 3; |
| 5688 |
r2.w = r2.h = 7; |
| 5689 |
if (Rect_ContainsPoint(&r2, x, y)) { |
| 5690 |
return CURSOR_SIZER; |
| 5691 |
} |
| 5692 |
} |
| 5693 |
return CURSOR_ARROW; |
| 5694 |
} |
| 5695 |
|
| 5696 |
|
| 5697 |
void Display_HandleKey(int key, qboolean down, int x, int y) { |
| 5698 |
menuDef_t *menu = Display_CaptureItem(x, y); |
| 5699 |
if (menu == NULL) { |
| 5700 |
menu = Menu_GetFocused(); |
| 5701 |
} |
| 5702 |
if (menu) { |
| 5703 |
Menu_HandleKey(menu, key, down ); |
| 5704 |
} |
| 5705 |
} |
| 5706 |
|
| 5707 |
static void Window_CacheContents(windowDef_t *window) { |
| 5708 |
if (window) { |
| 5709 |
if (window->cinematicName) { |
| 5710 |
int cin = DC->playCinematic(window->cinematicName, 0, 0, 0, 0); |
| 5711 |
DC->stopCinematic(cin); |
| 5712 |
} |
| 5713 |
} |
| 5714 |
} |
| 5715 |
|
| 5716 |
|
| 5717 |
static void Item_CacheContents(itemDef_t *item) { |
| 5718 |
if (item) { |
| 5719 |
Window_CacheContents(&item->window); |
| 5720 |
} |
| 5721 |
|
| 5722 |
} |
| 5723 |
|
| 5724 |
static void Menu_CacheContents(menuDef_t *menu) { |
| 5725 |
if (menu) { |
| 5726 |
int i; |
| 5727 |
Window_CacheContents(&menu->window); |
| 5728 |
for (i = 0; i < menu->itemCount; i++) { |
| 5729 |
Item_CacheContents(menu->items[i]); |
| 5730 |
} |
| 5731 |
|
| 5732 |
if (menu->soundName && *menu->soundName) { |
| 5733 |
DC->registerSound(menu->soundName, qfalse); |
| 5734 |
} |
| 5735 |
} |
| 5736 |
|
| 5737 |
} |
| 5738 |
|
| 5739 |
void Display_CacheAll(void) { |
| 5740 |
int i; |
| 5741 |
for (i = 0; i < menuCount; i++) { |
| 5742 |
Menu_CacheContents(&Menus[i]); |
| 5743 |
} |
| 5744 |
} |
| 5745 |
|
| 5746 |
|
| 5747 |
static qboolean Menu_OverActiveItem(menuDef_t *menu, float x, float y) { |
| 5748 |
if (menu && menu->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED)) { |
| 5749 |
if (Rect_ContainsPoint(&menu->window.rect, x, y)) { |
| 5750 |
int i; |
| 5751 |
for (i = 0; i < menu->itemCount; i++) { |
| 5752 |
// turn off focus each item |
| 5753 |
// menu->items[i].window.flags &= ~WINDOW_HASFOCUS; |
| 5754 |
|
| 5755 |
if (!(menu->items[i]->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED))) { |
| 5756 |
continue; |
| 5757 |
} |
| 5758 |
|
| 5759 |
if (menu->items[i]->window.flags & WINDOW_DECORATION) { |
| 5760 |
continue; |
| 5761 |
} |
| 5762 |
|
| 5763 |
if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y)) { |
| 5764 |
itemDef_t *overItem = menu->items[i]; |
| 5765 |
if (overItem->type == ITEM_TYPE_TEXT && overItem->text) { |
| 5766 |
if (Rect_ContainsPoint(Item_CorrectedTextRect(overItem), x, y)) { |
| 5767 |
return qtrue; |
| 5768 |
} else { |
| 5769 |
continue; |
| 5770 |
} |
| 5771 |
} else { |
| 5772 |
return qtrue; |
| 5773 |
} |
| 5774 |
} |
| 5775 |
} |
| 5776 |
|
| 5777 |
} |
| 5778 |
} |
| 5779 |
return qfalse; |
| 5780 |
} |
| 5781 |
|