vkQuake2 doxygen  1.0 dev
qmenu.h File Reference

Go to the source code of this file.

Classes

struct  _tag_menuframework
 
struct  menucommon_s
 
struct  menufield_s
 
struct  menuslider_s
 
struct  menulist_s
 
struct  menuaction_s
 
struct  menuseparator_s
 

Macros

#define MAXMENUITEMS   64
 
#define MTYPE_SLIDER   0
 
#define MTYPE_LIST   1
 
#define MTYPE_ACTION   2
 
#define MTYPE_SPINCONTROL   3
 
#define MTYPE_SEPARATOR   4
 
#define MTYPE_FIELD   5
 
#define K_TAB   9
 
#define K_ENTER   13
 
#define K_ESCAPE   27
 
#define K_SPACE   32
 
#define K_BACKSPACE   127
 
#define K_UPARROW   128
 
#define K_DOWNARROW   129
 
#define K_LEFTARROW   130
 
#define K_RIGHTARROW   131
 
#define QMF_LEFT_JUSTIFY   0x00000001
 
#define QMF_GRAYED   0x00000002
 
#define QMF_NUMBERSONLY   0x00000004
 

Typedefs

typedef struct _tag_menuframework menuframework_s
 

Functions

qboolean Field_Key (menufield_s *field, int key)
 
void Menu_AddItem (menuframework_s *menu, void *item)
 
void Menu_AdjustCursor (menuframework_s *menu, int dir)
 
void Menu_Center (menuframework_s *menu)
 
void Menu_Draw (menuframework_s *menu)
 
voidMenu_ItemAtCursor (menuframework_s *m)
 
qboolean Menu_SelectItem (menuframework_s *s)
 
void Menu_SetStatusBar (menuframework_s *s, const char *string)
 
void Menu_SlideItem (menuframework_s *s, int dir)
 
int Menu_TallySlots (menuframework_s *menu)
 
void Menu_DrawString (int, int, const char *)
 
void Menu_DrawStringDark (int, int, const char *)
 
void Menu_DrawStringR2L (int, int, const char *)
 
void Menu_DrawStringR2LDark (int, int, const char *)
 

Macro Definition Documentation

◆ K_BACKSPACE

#define K_BACKSPACE   127

Definition at line 39 of file qmenu.h.

◆ K_DOWNARROW

#define K_DOWNARROW   129

Definition at line 41 of file qmenu.h.

◆ K_ENTER

#define K_ENTER   13

Definition at line 33 of file qmenu.h.

◆ K_ESCAPE

#define K_ESCAPE   27

Definition at line 34 of file qmenu.h.

◆ K_LEFTARROW

#define K_LEFTARROW   130

Definition at line 42 of file qmenu.h.

◆ K_RIGHTARROW

#define K_RIGHTARROW   131

Definition at line 43 of file qmenu.h.

◆ K_SPACE

#define K_SPACE   32

Definition at line 35 of file qmenu.h.

◆ K_TAB

#define K_TAB   9

Definition at line 32 of file qmenu.h.

◆ K_UPARROW

#define K_UPARROW   128

Definition at line 40 of file qmenu.h.

◆ MAXMENUITEMS

#define MAXMENUITEMS   64

Definition at line 23 of file qmenu.h.

◆ MTYPE_ACTION

#define MTYPE_ACTION   2

Definition at line 27 of file qmenu.h.

◆ MTYPE_FIELD

#define MTYPE_FIELD   5

Definition at line 30 of file qmenu.h.

◆ MTYPE_LIST

#define MTYPE_LIST   1

Definition at line 26 of file qmenu.h.

◆ MTYPE_SEPARATOR

#define MTYPE_SEPARATOR   4

Definition at line 29 of file qmenu.h.

◆ MTYPE_SLIDER

#define MTYPE_SLIDER   0

Definition at line 25 of file qmenu.h.

◆ MTYPE_SPINCONTROL

#define MTYPE_SPINCONTROL   3

Definition at line 28 of file qmenu.h.

◆ QMF_GRAYED

#define QMF_GRAYED   0x00000002

Definition at line 46 of file qmenu.h.

◆ QMF_LEFT_JUSTIFY

#define QMF_LEFT_JUSTIFY   0x00000001

Definition at line 45 of file qmenu.h.

◆ QMF_NUMBERSONLY

#define QMF_NUMBERSONLY   0x00000004

Definition at line 47 of file qmenu.h.

Typedef Documentation

◆ menuframework_s

Function Documentation

◆ Field_Key()

qboolean Field_Key ( menufield_s field,
int  key 
)

Definition at line 135 of file qmenu.c.

136 {
137  extern int keydown[];
138 
139  switch ( key )
140  {
141  case K_KP_SLASH:
142  key = '/';
143  break;
144  case K_KP_MINUS:
145  key = '-';
146  break;
147  case K_KP_PLUS:
148  key = '+';
149  break;
150  case K_KP_HOME:
151  key = '7';
152  break;
153  case K_KP_UPARROW:
154  key = '8';
155  break;
156  case K_KP_PGUP:
157  key = '9';
158  break;
159  case K_KP_LEFTARROW:
160  key = '4';
161  break;
162  case K_KP_5:
163  key = '5';
164  break;
165  case K_KP_RIGHTARROW:
166  key = '6';
167  break;
168  case K_KP_END:
169  key = '1';
170  break;
171  case K_KP_DOWNARROW:
172  key = '2';
173  break;
174  case K_KP_PGDN:
175  key = '3';
176  break;
177  case K_KP_INS:
178  key = '0';
179  break;
180  case K_KP_DEL:
181  key = '.';
182  break;
183  }
184 
185  if ( key > 127 )
186  {
187  switch ( key )
188  {
189  case K_DEL:
190  default:
191  return false;
192  }
193  }
194 
195  /*
196  ** support pasting from the clipboard
197  */
198  if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) ||
199  ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && keydown[K_SHIFT] ) )
200  {
201  char *cbd;
202 
203  if ( ( cbd = Sys_GetClipboardData() ) != 0 )
204  {
205  strtok( cbd, "\n\r\b" );
206 
207  strncpy( f->buffer, cbd, f->length - 1 );
208  f->cursor = (int)strlen( f->buffer );
209  f->visible_offset = f->cursor - f->visible_length;
210  if ( f->visible_offset < 0 )
211  f->visible_offset = 0;
212 
213  free( cbd );
214  }
215  return true;
216  }
217 
218  switch ( key )
219  {
220  case K_KP_LEFTARROW:
221  case K_LEFTARROW:
222  case K_BACKSPACE:
223  if ( f->cursor > 0 )
224  {
225  memmove( &f->buffer[f->cursor-1], &f->buffer[f->cursor], strlen( &f->buffer[f->cursor] ) + 1 );
226  f->cursor--;
227 
228  if ( f->visible_offset )
229  {
230  f->visible_offset--;
231  }
232  }
233  break;
234 
235  case K_KP_DEL:
236  case K_DEL:
237  memmove( &f->buffer[f->cursor], &f->buffer[f->cursor+1], strlen( &f->buffer[f->cursor+1] ) + 1 );
238  break;
239 
240  case K_KP_ENTER:
241  case K_ENTER:
242  case K_ESCAPE:
243  case K_TAB:
244  return false;
245 
246  case K_SPACE:
247  default:
248  if ( !isdigit( key ) && ( f->generic.flags & QMF_NUMBERSONLY ) )
249  return false;
250 
251  if ( f->cursor < f->length )
252  {
253  f->buffer[f->cursor++] = key;
254  f->buffer[f->cursor] = 0;
255 
256  if ( f->cursor > f->visible_length )
257  {
258  f->visible_offset++;
259  }
260  }
261  }
262 
263  return true;
264 }

Referenced by Default_MenuKey().

◆ Menu_AddItem()

void Menu_AddItem ( menuframework_s menu,
void item 
)

Definition at line 266 of file qmenu.c.

267 {
268  if ( menu->nitems == 0 )
269  menu->nslots = 0;
270 
271  if ( menu->nitems < MAXMENUITEMS )
272  {
273  menu->items[menu->nitems] = item;
274  ( ( menucommon_s * ) menu->items[menu->nitems] )->parent = menu;
275  menu->nitems++;
276  }
277 
278  menu->nslots = Menu_TallySlots( menu );
279 }

Referenced by AddressBook_MenuInit(), DMOptions_MenuInit(), DownloadOptions_MenuInit(), Game_MenuInit(), JoinServer_MenuInit(), Keys_MenuInit(), LoadGame_MenuInit(), Multiplayer_MenuInit(), Options_MenuInit(), PlayerConfig_MenuInit(), SaveGame_MenuInit(), StartServer_MenuInit(), and VID_MenuInit().

◆ Menu_AdjustCursor()

void Menu_AdjustCursor ( menuframework_s menu,
int  dir 
)

Definition at line 288 of file qmenu.c.

289 {
290  menucommon_s *citem;
291 
292  /*
293  ** see if it's in a valid spot
294  */
295  if ( m->cursor >= 0 && m->cursor < m->nitems )
296  {
297  if ( ( citem = Menu_ItemAtCursor( m ) ) != 0 )
298  {
299  if ( citem->type != MTYPE_SEPARATOR )
300  return;
301  }
302  }
303 
304  /*
305  ** it's not in a valid spot, so crawl in the direction indicated until we
306  ** find a valid spot
307  */
308  if ( dir == 1 )
309  {
310  while ( 1 )
311  {
312  citem = Menu_ItemAtCursor( m );
313  if ( citem )
314  if ( citem->type != MTYPE_SEPARATOR )
315  break;
316  m->cursor += dir;
317  if ( m->cursor >= m->nitems )
318  m->cursor = 0;
319  }
320  }
321  else
322  {
323  while ( 1 )
324  {
325  citem = Menu_ItemAtCursor( m );
326  if ( citem )
327  if ( citem->type != MTYPE_SEPARATOR )
328  break;
329  m->cursor += dir;
330  if ( m->cursor < 0 )
331  m->cursor = m->nitems - 1;
332  }
333  }
334 }

Referenced by Default_MenuKey(), Game_MenuDraw(), Keys_MenuDraw(), Multiplayer_MenuDraw(), Options_MenuDraw(), SaveGame_MenuDraw(), VID_MenuDraw(), and VID_MenuKey().

◆ Menu_Center()

void Menu_Center ( menuframework_s menu)

Definition at line 336 of file qmenu.c.

337 {
338  int height;
339 
340  height = ( ( menucommon_s * ) menu->items[menu->nitems-1])->y;
341  height += 10;
342 
343  menu->y = ( VID_HEIGHT - height ) / 2;
344 }

Referenced by DMOptions_MenuInit(), DownloadOptions_MenuInit(), Game_MenuInit(), JoinServer_MenuInit(), Keys_MenuInit(), Multiplayer_MenuInit(), StartServer_MenuInit(), and VID_MenuInit().

◆ Menu_Draw()

void Menu_Draw ( menuframework_s menu)

Definition at line 346 of file qmenu.c.

347 {
348  int i;
350 
351  /*
352  ** draw contents
353  */
354  for ( i = 0; i < menu->nitems; i++ )
355  {
356  switch ( ( ( menucommon_s * ) menu->items[i] )->type )
357  {
358  case MTYPE_FIELD:
359  Field_Draw( ( menufield_s * ) menu->items[i] );
360  break;
361  case MTYPE_SLIDER:
362  Slider_Draw( ( menuslider_s * ) menu->items[i] );
363  break;
364  case MTYPE_LIST:
365  MenuList_Draw( ( menulist_s * ) menu->items[i] );
366  break;
367  case MTYPE_SPINCONTROL:
368  SpinControl_Draw( ( menulist_s * ) menu->items[i] );
369  break;
370  case MTYPE_ACTION:
371  Action_Draw( ( menuaction_s * ) menu->items[i] );
372  break;
373  case MTYPE_SEPARATOR:
374  Separator_Draw( ( menuseparator_s * ) menu->items[i] );
375  break;
376  }
377  }
378 
379  item = Menu_ItemAtCursor( menu );
380 
381  if ( item && item->cursordraw )
382  {
383  item->cursordraw( item );
384  }
385  else if ( menu->cursordraw )
386  {
387  menu->cursordraw( menu );
388  }
389  else if ( item && item->type != MTYPE_FIELD )
390  {
391  if ( item->flags & QMF_LEFT_JUSTIFY )
392  {
393  Draw_Char( menu->x + item->x - 24*vid_hudscale->value + item->cursor_offset*vid_hudscale->value, menu->y + item->y, 12 + ( ( int ) ( Sys_Milliseconds()/250 ) & 1 ) );
394  }
395  else
396  {
397  Draw_Char( menu->x + item->cursor_offset*vid_hudscale->value, menu->y + item->y, 12 + ( ( int ) ( Sys_Milliseconds()/250 ) & 1 ) );
398  }
399  }
400 
401  if ( item )
402  {
403  if ( item->statusbarfunc )
404  item->statusbarfunc( ( void * ) item );
405  else if ( item->statusbar )
406  Menu_DrawStatusBar( item->statusbar );
407  else
408  Menu_DrawStatusBar( menu->statusbar );
409 
410  }
411  else
412  {
413  Menu_DrawStatusBar( menu->statusbar );
414  }
415 }

Referenced by AddressBook_MenuDraw(), DMOptions_MenuDraw(), DownloadOptions_MenuDraw(), Game_MenuDraw(), JoinServer_MenuDraw(), Keys_MenuDraw(), LoadGame_MenuDraw(), Multiplayer_MenuDraw(), Options_MenuDraw(), PlayerConfig_MenuDraw(), SaveGame_MenuDraw(), StartServer_MenuDraw(), and VID_MenuDraw().

◆ Menu_DrawString()

void Menu_DrawString ( int  ,
int  ,
const char *   
)

Definition at line 434 of file qmenu.c.

435 {
436  unsigned i;
437 
438  for ( i = 0; i < strlen( string ); i++ )
439  {
440  Draw_Char( ( x + i*8*vid_hudscale->value ), y, string[i] );
441  }
442 }

Referenced by Action_Draw(), DrawKeyBindingFunc(), Field_Draw(), Menu_DrawStatusBar(), and SpinControl_Draw().

◆ Menu_DrawStringDark()

void Menu_DrawStringDark ( int  ,
int  ,
const char *   
)

Definition at line 444 of file qmenu.c.

445 {
446  unsigned i;
447 
448  for ( i = 0; i < strlen( string ); i++ )
449  {
450  Draw_Char( ( x + i*8*vid_hudscale->value ), y, string[i] + 128 );
451  }
452 }

Referenced by Action_Draw().

◆ Menu_DrawStringR2L()

void Menu_DrawStringR2L ( int  ,
int  ,
const char *   
)

Definition at line 454 of file qmenu.c.

455 {
456  unsigned i;
457 
458  for ( i = 0; i < strlen( string ); i++ )
459  {
460  Draw_Char( ( x - i*8*vid_hudscale->value), y, string[strlen(string)-i-1] );
461  }
462 }

Referenced by Action_Draw().

◆ Menu_DrawStringR2LDark()

void Menu_DrawStringR2LDark ( int  ,
int  ,
const char *   
)

Definition at line 464 of file qmenu.c.

465 {
466  unsigned i;
467 
468  for ( i = 0; i < strlen( string ); i++ )
469  {
470  Draw_Char( ( x - i*8*vid_hudscale->value ), y, string[strlen(string)-i-1]+128 );
471  }
472 }

Referenced by Action_Draw(), Field_Draw(), MenuList_Draw(), Separator_Draw(), Slider_Draw(), and SpinControl_Draw().

◆ Menu_ItemAtCursor()

void* Menu_ItemAtCursor ( menuframework_s m)

Definition at line 474 of file qmenu.c.

475 {
476  if ( m->cursor < 0 || m->cursor >= m->nitems )
477  return 0;
478 
479  return m->items[m->cursor];
480 }

Referenced by Default_MenuKey(), Field_Draw(), Keys_MenuKey(), Menu_AdjustCursor(), Menu_Draw(), Menu_SelectItem(), and Menu_SlideItem().

◆ Menu_SelectItem()

qboolean Menu_SelectItem ( menuframework_s s)

Definition at line 482 of file qmenu.c.

483 {
485 
486  if ( item )
487  {
488  switch ( item->type )
489  {
490  case MTYPE_FIELD:
491  return Field_DoEnter( ( menufield_s * ) item ) ;
492  case MTYPE_ACTION:
494  return true;
495  case MTYPE_LIST:
496 // Menulist_DoEnter( ( menulist_s * ) item );
497  return false;
498  case MTYPE_SPINCONTROL:
499 // SpinControl_DoEnter( ( menulist_s * ) item );
500  return false;
501  }
502  }
503  return false;
504 }

Referenced by Default_MenuKey(), and VID_MenuKey().

◆ Menu_SetStatusBar()

void Menu_SetStatusBar ( menuframework_s s,
const char *  string 
)

Definition at line 506 of file qmenu.c.

507 {
508  m->statusbar = string;
509 }

Referenced by DMOptions_MenuInit(), KeyBindingFunc(), Keys_MenuInit(), Keys_MenuKey(), M_Menu_PlayerConfig_f(), and Multiplayer_MenuInit().

◆ Menu_SlideItem()

void Menu_SlideItem ( menuframework_s s,
int  dir 
)

Definition at line 511 of file qmenu.c.

512 {
514 
515  if ( item )
516  {
517  switch ( item->type )
518  {
519  case MTYPE_SLIDER:
520  Slider_DoSlide( ( menuslider_s * ) item, dir );
521  break;
522  case MTYPE_SPINCONTROL:
523  SpinControl_DoSlide( ( menulist_s * ) item, dir );
524  break;
525  }
526  }
527 }

Referenced by Default_MenuKey(), and VID_MenuKey().

◆ Menu_TallySlots()

int Menu_TallySlots ( menuframework_s menu)

Definition at line 529 of file qmenu.c.

530 {
531  int i;
532  int total = 0;
533 
534  for ( i = 0; i < menu->nitems; i++ )
535  {
536  if ( ( ( menucommon_s * ) menu->items[i] )->type == MTYPE_LIST )
537  {
538  int nitems = 0;
539  const char **n = ( ( menulist_s * ) menu->items[i] )->itemnames;
540 
541  while (*n)
542  nitems++, n++;
543 
544  total += nitems;
545  }
546  else
547  {
548  total++;
549  }
550  }
551 
552  return total;
553 }

Referenced by Menu_AddItem().

K_KP_ENTER
#define K_KP_ENTER
Definition: keys.h:70
K_INS
#define K_INS
Definition: keys.h:53
menuseparator_s
Definition: qmenu.h:118
height
GLsizei height
Definition: qgl_win.c:69
K_KP_RIGHTARROW
#define K_KP_RIGHTARROW
Definition: keys.h:66
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
K_SPACE
#define K_SPACE
Definition: keys.h:28
Draw_Char
#define Draw_Char
Definition: qmenu.c:48
Field_DoEnter
qboolean Field_DoEnter(menufield_s *f)
Definition: qmenu.c:77
_tag_menuframework::items
void * items[64]
Definition: qmenu.h:56
keydown
qboolean keydown[256]
Definition: keys.c:45
menucommon_s::type
int type
Definition: qmenu.h:66
_tag_menuframework::y
int y
Definition: qmenu.h:51
SpinControl_Draw
static void SpinControl_Draw(menulist_s *s)
Definition: qmenu.c:651
MAXMENUITEMS
#define MAXMENUITEMS
Definition: qmenu.h:23
K_BACKSPACE
#define K_BACKSPACE
Definition: keys.h:32
K_KP_END
#define K_KP_END
Definition: keys.h:67
x
GLint GLenum GLint x
Definition: qgl_win.c:116
K_ENTER
#define K_ENTER
Definition: keys.h:26
K_KP_MINUS
#define K_KP_MINUS
Definition: keys.h:74
i
int i
Definition: q_shared.c:305
MenuList_Draw
static void MenuList_Draw(menulist_s *l)
Definition: qmenu.c:567
QMF_LEFT_JUSTIFY
#define QMF_LEFT_JUSTIFY
Definition: qmenu.h:45
_tag_menuframework::statusbar
const char * statusbar
Definition: qmenu.h:58
K_KP_PLUS
#define K_KP_PLUS
Definition: keys.h:75
K_CTRL
#define K_CTRL
Definition: keys.h:39
vid_hudscale
cvar_t * vid_hudscale
Definition: vid_dll.c:48
K_KP_5
#define K_KP_5
Definition: keys.h:65
Action_DoEnter
static void Action_DoEnter(menuaction_s *a)
Definition: qmenu.c:51
edict_s::item
gitem_t * item
Definition: g_local.h:1110
K_KP_SLASH
#define K_KP_SLASH
Definition: keys.h:73
menucommon_s
Definition: qmenu.h:64
K_KP_INS
#define K_KP_INS
Definition: keys.h:71
menulist_s
Definition: qmenu.h:104
MTYPE_LIST
#define MTYPE_LIST
Definition: qmenu.h:26
Menu_ItemAtCursor
void * Menu_ItemAtCursor(menuframework_s *m)
Definition: qmenu.c:474
K_LEFTARROW
#define K_LEFTARROW
Definition: keys.h:35
_tag_menuframework::cursordraw
void(* cursordraw)(struct _tag_menuframework *m)
Definition: qmenu.h:60
_tag_menuframework::cursor
int cursor
Definition: qmenu.h:52
cvar_s::value
float value
Definition: q_shared.h:331
K_KP_DEL
#define K_KP_DEL
Definition: keys.h:72
K_KP_UPARROW
#define K_KP_UPARROW
Definition: keys.h:62
K_KP_HOME
#define K_KP_HOME
Definition: keys.h:61
VID_HEIGHT
#define VID_HEIGHT
Definition: qmenu.c:46
MTYPE_ACTION
#define MTYPE_ACTION
Definition: qmenu.h:27
menuaction_s
Definition: qmenu.h:113
Slider_DoSlide
static void Slider_DoSlide(menuslider_s *s, int dir)
Definition: qmenu.c:592
_tag_menuframework::nitems
int nitems
Definition: qmenu.h:54
s
static fixed16_t s
Definition: r_scan.c:30
y
GLint y
Definition: qgl_win.c:115
SpinControl_DoSlide
static void SpinControl_DoSlide(menulist_s *s, int dir)
Definition: qmenu.c:638
MTYPE_SLIDER
#define MTYPE_SLIDER
Definition: qmenu.h:25
Menu_DrawStatusBar
static void Menu_DrawStatusBar(const char *string)
Definition: qmenu.c:417
Field_Draw
void Field_Draw(menufield_s *f)
Definition: qmenu.c:87
_tag_menuframework::x
int x
Definition: qmenu.h:51
menuslider_s
Definition: qmenu.h:93
menufield_s
Definition: qmenu.h:82
MTYPE_SPINCONTROL
#define MTYPE_SPINCONTROL
Definition: qmenu.h:28
K_DEL
#define K_DEL
Definition: keys.h:54
_tag_menuframework::nslots
int nslots
Definition: qmenu.h:55
MTYPE_FIELD
#define MTYPE_FIELD
Definition: qmenu.h:30
Separator_Draw
static void Separator_Draw(menuseparator_s *s)
Definition: qmenu.c:586
K_KP_PGUP
#define K_KP_PGUP
Definition: keys.h:63
K_KP_DOWNARROW
#define K_KP_DOWNARROW
Definition: keys.h:68
K_ESCAPE
#define K_ESCAPE
Definition: keys.h:27
K_TAB
#define K_TAB
Definition: keys.h:25
K_SHIFT
#define K_SHIFT
Definition: keys.h:40
Sys_Milliseconds
int Sys_Milliseconds(void)
Definition: q_shwin.c:120
K_KP_PGDN
#define K_KP_PGDN
Definition: keys.h:69
Menu_TallySlots
int Menu_TallySlots(menuframework_s *menu)
Definition: qmenu.c:529
MTYPE_SEPARATOR
#define MTYPE_SEPARATOR
Definition: qmenu.h:29
Sys_GetClipboardData
char * Sys_GetClipboardData(void)
Definition: sys_win.c:431
gitem_s::flags
int flags
Definition: g_local.h:255
K_KP_LEFTARROW
#define K_KP_LEFTARROW
Definition: keys.h:64
QMF_NUMBERSONLY
#define QMF_NUMBERSONLY
Definition: qmenu.h:47
Action_Draw
static void Action_Draw(menuaction_s *a)
Definition: qmenu.c:57
Slider_Draw
static void Slider_Draw(menuslider_s *s)
Definition: qmenu.c:607