icculus quake2 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 139 of file qmenu.c.

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

Referenced by Default_MenuKey().

◆ Menu_AddItem()

void Menu_AddItem ( menuframework_s menu,
void item 
)

Definition at line 270 of file qmenu.c.

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

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 292 of file qmenu.c.

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

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 340 of file qmenu.c.

341 {
342  int height;
343 
344  height = ( ( menucommon_s * ) menu->items[menu->nitems-1])->y;
345  height += 10;
346 
347  menu->y = ( VID_HEIGHT - height ) / 2;
348 }

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 350 of file qmenu.c.

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

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 438 of file qmenu.c.

439 {
440  unsigned i;
441 
442  for ( i = 0; i < strlen( string ); i++ )
443  {
444  Draw_Char( ( x + i*8 ), y, string[i] );
445  }
446 }

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

◆ Menu_DrawStringDark()

void Menu_DrawStringDark ( int  ,
int  ,
const char *   
)

Definition at line 448 of file qmenu.c.

449 {
450  unsigned i;
451 
452  for ( i = 0; i < strlen( string ); i++ )
453  {
454  Draw_Char( ( x + i*8 ), y, string[i] + 128 );
455  }
456 }

Referenced by Action_Draw().

◆ Menu_DrawStringR2L()

void Menu_DrawStringR2L ( int  ,
int  ,
const char *   
)

Definition at line 458 of file qmenu.c.

459 {
460  unsigned i;
461 
462  for ( i = 0; i < strlen( string ); i++ )
463  {
464  Draw_Char( ( x - i*8 ), y, string[strlen(string)-i-1] );
465  }
466 }

Referenced by Action_Draw().

◆ Menu_DrawStringR2LDark()

void Menu_DrawStringR2LDark ( int  ,
int  ,
const char *   
)

Definition at line 468 of file qmenu.c.

469 {
470  unsigned i;
471 
472  for ( i = 0; i < strlen( string ); i++ )
473  {
474  Draw_Char( ( x - i*8 ), y, string[strlen(string)-i-1]+128 );
475  }
476 }

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 478 of file qmenu.c.

479 {
480  if ( m->cursor < 0 || m->cursor >= m->nitems )
481  return 0;
482 
483  return m->items[m->cursor];
484 }

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 486 of file qmenu.c.

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

Referenced by Default_MenuKey(), and VID_MenuKey().

◆ Menu_SetStatusBar()

void Menu_SetStatusBar ( menuframework_s s,
const char *  string 
)

Definition at line 510 of file qmenu.c.

511 {
512  m->statusbar = string;
513 }

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 515 of file qmenu.c.

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

Referenced by Default_MenuKey(), and VID_MenuKey().

◆ Menu_TallySlots()

int Menu_TallySlots ( menuframework_s menu)

Definition at line 533 of file qmenu.c.

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

Referenced by Menu_AddItem().

K_KP_PLUS
@ K_KP_PLUS
Definition: keys.h:74
edict_s::s
entity_state_t s
Definition: g_local.h:964
keydown
qboolean keydown[K_LAST]
Definition: keys.c:44
menuseparator_s
Definition: qmenu.h:118
height
GLsizei height
Definition: qgl_win.c:69
K_KP_UPARROW
@ K_KP_UPARROW
Definition: keys.h:61
Draw_Char
#define Draw_Char
Definition: qmenu.c:50
Field_DoEnter
qboolean Field_DoEnter(menufield_s *f)
Definition: qmenu.c:81
_tag_menuframework::items
void * items[64]
Definition: qmenu.h:56
K_KP_PGDN
@ K_KP_PGDN
Definition: keys.h:68
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:659
MAXMENUITEMS
#define MAXMENUITEMS
Definition: qmenu.h:23
x
GLint GLenum GLint x
Definition: qgl_win.c:116
i
int i
Definition: q_shared.c:305
K_KP_LEFTARROW
@ K_KP_LEFTARROW
Definition: keys.h:63
MenuList_Draw
static void MenuList_Draw(menulist_s *l)
Definition: qmenu.c:573
QMF_LEFT_JUSTIFY
#define QMF_LEFT_JUSTIFY
Definition: qmenu.h:45
_tag_menuframework::statusbar
const char * statusbar
Definition: qmenu.h:58
K_KP_HOME
@ K_KP_HOME
Definition: keys.h:60
K_ENTER
@ K_ENTER
Definition: keys.h:26
K_KP_INS
@ K_KP_INS
Definition: keys.h:70
K_LEFTARROW
@ K_LEFTARROW
Definition: keys.h:35
K_KP_MINUS
@ K_KP_MINUS
Definition: keys.h:73
K_ESCAPE
@ K_ESCAPE
Definition: keys.h:27
Action_DoEnter
static void Action_DoEnter(menuaction_s *a)
Definition: qmenu.c:55
edict_s::item
gitem_t * item
Definition: g_local.h:1104
menucommon_s
Definition: qmenu.h:64
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:478
K_KP_RIGHTARROW
@ K_KP_RIGHTARROW
Definition: keys.h:65
_tag_menuframework::cursordraw
void(* cursordraw)(struct _tag_menuframework *m)
Definition: qmenu.h:60
_tag_menuframework::cursor
int cursor
Definition: qmenu.h:52
K_INS
@ K_INS
Definition: keys.h:53
K_CTRL
@ K_CTRL
Definition: keys.h:39
VID_HEIGHT
#define VID_HEIGHT
Definition: qmenu.c:45
K_KP_END
@ K_KP_END
Definition: keys.h:66
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:598
K_KP_ENTER
@ K_KP_ENTER
Definition: keys.h:69
_tag_menuframework::nitems
int nitems
Definition: qmenu.h:54
K_KP_DEL
@ K_KP_DEL
Definition: keys.h:71
y
GLint y
Definition: qgl_win.c:115
SpinControl_DoSlide
static void SpinControl_DoSlide(menulist_s *s, int dir)
Definition: qmenu.c:646
MTYPE_SLIDER
#define MTYPE_SLIDER
Definition: qmenu.h:25
Menu_DrawStatusBar
static void Menu_DrawStatusBar(const char *string)
Definition: qmenu.c:421
Field_Draw
void Field_Draw(menufield_s *f)
Definition: qmenu.c:91
_tag_menuframework::x
int x
Definition: qmenu.h:51
menuslider_s
Definition: qmenu.h:93
K_KP_SLASH
@ K_KP_SLASH
Definition: keys.h:72
K_TAB
@ K_TAB
Definition: keys.h:25
menufield_s
Definition: qmenu.h:82
MTYPE_SPINCONTROL
#define MTYPE_SPINCONTROL
Definition: qmenu.h:28
K_SHIFT
@ K_SHIFT
Definition: keys.h:40
K_SPACE
@ K_SPACE
Definition: keys.h:28
K_KP_5
@ K_KP_5
Definition: keys.h:64
K_KP_PGUP
@ K_KP_PGUP
Definition: keys.h:62
_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:592
Sys_Milliseconds
int Sys_Milliseconds(void)
Definition: q_shwin.c:120
K_DEL
@ K_DEL
Definition: keys.h:54
Menu_TallySlots
int Menu_TallySlots(menuframework_s *menu)
Definition: qmenu.c:533
MTYPE_SEPARATOR
#define MTYPE_SEPARATOR
Definition: qmenu.h:29
Sys_GetClipboardData
char * Sys_GetClipboardData(void)
Definition: sys_win.c:401
gitem_s::flags
int flags
Definition: g_local.h:253
K_BACKSPACE
@ K_BACKSPACE
Definition: keys.h:32
K_KP_DOWNARROW
@ K_KP_DOWNARROW
Definition: keys.h:67
QMF_NUMBERSONLY
#define QMF_NUMBERSONLY
Definition: qmenu.h:47
Action_Draw
static void Action_Draw(menuaction_s *a)
Definition: qmenu.c:61
Slider_Draw
static void Slider_Draw(menuslider_s *s)
Definition: qmenu.c:613