/* ================== MenuField_Draw ================== */ void MenuField_Draw( menufield_s *f ) { int x; int y; int w; int style; qboolean focus; float *color; x = f->generic.x; y = f->generic.y; if (f->generic.flags & QMF_SMALLFONT) { w = SMALLCHAR_WIDTH; style = UI_SMALLFONT; } else { w = BIGCHAR_WIDTH; style = UI_BIGFONT; } if (Menu_ItemAtCursor( f->generic.parent ) == f) { focus = qtrue; style |= UI_PULSE; } else { focus = qfalse; } if (f->generic.flags & QMF_GRAYED) color = text_color_disabled; else if (focus) color = text_color_highlight; else color = text_color_normal; if ( focus ) { // draw cursor CG_FillRect( f->generic.left, f->generic.top, f->generic.right-f->generic.left+1, f->generic.bottom-f->generic.top+1, listbar_color ); UI_DrawChar( x, y, GLYPH_ARROW, UI_CENTER|UI_BLINK|style, color); } if ( f->generic.name ) { UI_DrawString( x - w, y, f->generic.name, style|UI_RIGHT, color ); } MField_Draw( &f->field, x + w, y, style, color, focus ); }
/* ================= UI_CDKeyMenu_DrawKey ================= */ static void UI_CDKeyMenu_DrawKey( void *self ) { menufield_s *f; qboolean focus; int style; char c; float *color; int x, y; int val; f = (menufield_s *)self; focus = (f->generic.parent->cursor == f->generic.menuPosition); style = UI_LEFT; if( focus ) { color = color_yellow; } else { color = color_orange; } x = 320 - 8 * BIGCHAR_WIDTH; y = 240 - BIGCHAR_HEIGHT / 2; UI_FillRect( x, y, 16 * BIGCHAR_WIDTH, BIGCHAR_HEIGHT, listbar_color ); UI_DrawString( x, y, f->field.buffer, style, color ); // draw cursor if we have focus if( focus ) { if ( trap_Key_GetOverstrikeMode() ) { c = 11; } else { c = 10; } style &= ~UI_PULSE; style |= UI_BLINK; UI_DrawChar( x + f->field.cursor * BIGCHAR_WIDTH, y, c, style, color_white ); } val = UI_CDKeyMenu_PreValidateKey( f->field.buffer ); if( val == 1 ) { UI_DrawProportionalString( 320, 376, "Please enter your CD Key", UI_CENTER|UI_SMALLFONT, color_yellow ); } else if ( val == 0 ) { UI_DrawProportionalString( 320, 376, "The CD Key appears to be valid, thank you", UI_CENTER|UI_SMALLFONT, color_white ); } else { UI_DrawProportionalString( 320, 376, "The CD Key is not valid", UI_CENTER|UI_SMALLFONT, color_red ); } }
/* ================= RadioButton_Draw ================= */ static void RadioButton_Draw( menuradiobutton_s *rb ) { int x; int y; float *color; int style; qboolean focus; x = rb->generic.x; y = rb->generic.y; focus = (rb->generic.parent->cursor == rb->generic.menuPosition); if ( rb->generic.flags & QMF_GRAYED ) { color = text_color_disabled; style = UI_LEFT|UI_SMALLFONT; } else if ( focus ) { color = text_color_highlight; style = UI_LEFT|UI_PULSE|UI_SMALLFONT; } else { color = text_color_normal; style = UI_LEFT|UI_SMALLFONT; } if ( focus ) { // draw cursor UI_FillRect( rb->generic.left, rb->generic.top, rb->generic.right-rb->generic.left+1, rb->generic.bottom-rb->generic.top+1, listbar_color ); UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|UI_SMALLFONT, color); } if ( rb->generic.name ) UI_DrawString( x - SMALLCHAR_WIDTH, y, rb->generic.name, UI_RIGHT|UI_SMALLFONT, color ); if ( !rb->curvalue ) { UI_DrawHandlePic( x + SMALLCHAR_WIDTH, y + 2, 16, 16, uis.rb_off); UI_DrawString( x + SMALLCHAR_WIDTH + 16, y, "off", style, color ); } else { UI_DrawHandlePic( x + SMALLCHAR_WIDTH, y + 2, 16, 16, uis.rb_on ); UI_DrawString( x + SMALLCHAR_WIDTH + 16, y, "on", style, color ); } }
static void VQH_DrawCrosshair() { if ( cl.qh_intermission ) { return; } if ( crosshair->value == 2 ) { int x = scr_vrect.x + scr_vrect.width / 2 - 3 + cl_crossx->value; int y = scr_vrect.y + scr_vrect.height / 2 - 3 + cl_crossy->value; unsigned char* pColor = r_palette[ crosshaircolor->integer ]; float colour[ 4 ] = { pColor[ 0 ] / 255.0, pColor[ 1 ] / 255.0, pColor[ 2 ] / 255.0, pColor[ 3 ] / 255.0 }; R_SetColor( colour ); UI_DrawStretchPicShader( x - 4, y - 4, 16, 16, cs_texture ); R_SetColor( NULL ); } else if ( crosshair->value ) { UI_DrawChar( scr_vrect.x + scr_vrect.width / 2 - 4 + cl_crossx->value, scr_vrect.y + scr_vrect.height / 2 - 4 + cl_crossy->value, '+' ); } }
/* ================= Crosshair_Draw ================= */ static void Crosshair_Draw( void *self ) { menulist_s *s; float *color; int x, y; int style; qboolean focus; s = (menulist_s *)self; x = s->generic.x; y = s->generic.y; style = UI_SMALLFONT; focus = (s->generic.parent->cursor == s->generic.menuPosition); if ( s->generic.flags & QMF_GRAYED ) color = text_color_disabled; else if ( focus ) { color = text_color_highlight; style |= UI_PULSE; } else if ( s->generic.flags & QMF_BLINK ) { color = text_color_highlight; style |= UI_BLINK; } else color = text_color_normal; if ( focus ) { // draw cursor CG_FillRect( s->generic.left, s->generic.top, s->generic.right-s->generic.left+1, s->generic.bottom-s->generic.top+1, listbar_color ); UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|UI_SMALLFONT, color); } UI_DrawString( x - SMALLCHAR_WIDTH, y, s->generic.name, style|UI_RIGHT, color ); if( !s->curvalue ) { return; } CG_DrawPic( x + SMALLCHAR_WIDTH, y - 4, 24, 24, s_preferences.crosshairShader[s->curvalue] ); }
void UI_DrawString( int x, int y, const char* str, int mask ) { vec4_t color; Vector4Set( color, 1, 1, 1, 1 ); R_SetColor( color ); while ( *str ) { if ( Q_IsColorString( str ) ) { if ( *( str + 1 ) == COLOR_NULL ) { Vector4Set( color, 1, 1, 1, 1 ); } else { Com_Memcpy( color, g_color_table[ ColorIndex( *( str + 1 ) ) ], sizeof ( color ) ); } str += 2; R_SetColor( color ); continue; } UI_DrawChar( x, y, ( ( byte ) * str ) | mask ); str++; x += 8; } R_SetColor( NULL ); }
/* ================= SpinControl_Draw ================= */ static void SpinControl_Draw( menulist_s *s ) { float *color; int x,y; int style; qboolean focus; x = s->generic.x; y = s->generic.y; style = UI_SMALLFONT; focus = (s->generic.parent->cursor == s->generic.menuPosition); if ( s->generic.flags & QMF_GRAYED ) color = text_color_disabled; else if ( focus ) { color = text_color_highlight; style |= UI_PULSE; } else if ( s->generic.flags & QMF_BLINK ) { color = text_color_highlight; style |= UI_BLINK; } else color = text_color_normal; if ( focus ) { // draw cursor CG_FillRect( s->generic.left, s->generic.top, s->generic.right-s->generic.left+1, s->generic.bottom-s->generic.top+1, listbar_color ); UI_DrawChar( x, y, GLYPH_ARROW, UI_CENTER|UI_BLINK|UI_SMALLFONT, color); } UI_DrawString( x - SMALLCHAR_WIDTH, y, s->generic.name, style|UI_RIGHT, color ); UI_DrawString( x + SMALLCHAR_WIDTH, y, s->itemnames[s->curvalue], style|UI_LEFT, color ); }
/* ================= Action_Draw ================= */ static void Action_Draw( menuaction_s *a ) { int x, y; int style; float* color; style = 0; color = menu_text_color; if ( a->generic.flags & QMF_GRAYED ) { color = text_color_disabled; } else if (( a->generic.flags & QMF_PULSEIFFOCUS ) && ( a->generic.parent->cursor == a->generic.menuPosition )) { color = text_color_highlight; style = UI_PULSE; } else if (( a->generic.flags & QMF_HIGHLIGHT_IF_FOCUS ) && ( a->generic.parent->cursor == a->generic.menuPosition )) { color = text_color_highlight; } else if ( a->generic.flags & QMF_BLINK ) { style = UI_BLINK; color = text_color_highlight; } x = a->generic.x; y = a->generic.y; UI_DrawString( x, y, a->generic.name, UI_LEFT|style, color ); if ( a->generic.parent->cursor == a->generic.menuPosition ) { // draw cursor UI_DrawChar( x - BIGCHAR_WIDTH, y, GLYPH_ARROW, UI_LEFT|UI_BLINK, color); } }
/* ================= Slider_Draw ================= */ static void Slider_Draw( menuslider_s *s ) { float *color; int style; int i; int x; int y; qboolean focus; x = s->generic.x; y = s->generic.y; focus = (s->generic.parent->cursor == s->generic.menuPosition); style = UI_SMALLFONT; if ( s->generic.flags & QMF_GRAYED ) { color = text_color_disabled; } else if (focus) { color = text_color_highlight; style |= UI_PULSE; } else { color = text_color_normal; } if ( focus ) { // draw cursor CG_FillRect( s->generic.left, s->generic.top, s->generic.right-s->generic.left+1, s->generic.bottom-s->generic.top+1, listbar_color ); UI_DrawChar( x, y, GLYPH_ARROW, UI_CENTER|UI_BLINK|UI_SMALLFONT, color); } // draw label UI_DrawString( x - SMALLCHAR_WIDTH, y, s->generic.name, UI_RIGHT|style, color ); // draw slider UI_DrawChar( x + SMALLCHAR_WIDTH, y, 128, UI_LEFT|style, color); for ( i = 0; i < SLIDER_RANGE; i++ ) UI_DrawChar( x + (i+2)*SMALLCHAR_WIDTH, y, 129, UI_LEFT|style, color); UI_DrawChar( x + (i+2)*SMALLCHAR_WIDTH, y, 130, UI_LEFT|style, color); // clamp thumb if (s->maxvalue > s->minvalue) { s->range = ( s->curvalue - s->minvalue ) / ( float ) ( s->maxvalue - s->minvalue ); if ( s->range < 0) s->range = 0; else if ( s->range > 1) s->range = 1; } else s->range = 0; // draw thumb if (style & UI_PULSE) { style &= ~UI_PULSE; style |= UI_BLINK; } UI_DrawChar( (int)( x + 2*SMALLCHAR_WIDTH + (SLIDER_RANGE-1)*SMALLCHAR_WIDTH* s->range ), y, 131, UI_LEFT|style, color); }
/* ================= PlayerSettings_DrawName ================= */ static void PlayerSettings_DrawName(void* self) { menufield_s* f; qboolean focus; int style; char* txt; char c; float* color; int n; int basex, x, y; char name[32]; f = (menufield_s*)self; basex = f->generic.x; y = f->generic.y; focus = (f->generic.parent->cursor == f->generic.menuPosition); style = UI_LEFT | UI_SMALLFONT; color = text_color_normal; if (focus) { style |= UI_PULSE; color = text_color_highlight; } UI_DrawProportionalString(basex, y, "Name", style, color); // draw the actual name basex += 64; y += PROP_HEIGHT; txt = f->field.buffer; color = g_color_table[ColorIndex(COLOR_WHITE)]; x = basex; while ((c = *txt) != 0) { if (!focus && Q_IsColorString(txt)) { n = ColorIndex(*(txt + 1)); if (n == 0) { n = 7; } color = g_color_table[n]; txt += 2; continue; } UI_DrawChar(x, y, c, style, color); txt++; x += SMALLCHAR_WIDTH; } // draw cursor if we have focus if (focus) { if (trap_Key_GetOverstrikeMode()) { c = 11; } else { c = 10; } style &= ~UI_PULSE; style |= UI_BLINK; UI_DrawChar(basex + f->field.cursor * SMALLCHAR_WIDTH, y, c, style, color_white); } // draw at bottom also using proportional font Q_strncpyz(name, f->field.buffer, sizeof(name)); Q_CleanStr(name); UI_DrawProportionalString(320, 440, name, UI_CENTER | UI_BIGFONT, text_color_normal); }
/* =================== UI_Field_Draw Handles horizontal scrolling and cursor blinking x, y, are in pixels =================== */ void UI_Field_Draw( mfield_t *edit, int x, int y, int style, vec4_t color ) { int len; int charw; int drawLen; int prestep; int cursorChar; char str[MAX_STRING_CHARS]; drawLen = edit->widthInChars; len = strlen( edit->buffer ) + 1; // guarantee that cursor will be visible if ( len <= drawLen ) { prestep = 0; } else { if ( edit->scroll + drawLen > len ) { edit->scroll = len - drawLen; if ( edit->scroll < 0 ) { edit->scroll = 0; } } prestep = edit->scroll; } if ( prestep + drawLen > len ) { drawLen = len - prestep; } // extract <drawLen> characters from the field at <prestep> if ( drawLen >= MAX_STRING_CHARS ) { trap_Error( "drawLen >= MAX_STRING_CHARS" ); } memcpy( str, edit->buffer + prestep, drawLen ); str[ drawLen ] = 0; UI_DrawString( x, y, str, style, color ); // draw the cursor if (!(style & UI_PULSE)) { return; } if ( trap_Key_GetOverstrikeMode() ) { cursorChar = 11; } else { cursorChar = 10; } style &= ~UI_PULSE; style |= UI_BLINK; if (style & UI_SMALLFONT) { charw = SMALLCHAR_WIDTH; } else if (style & UI_GIANTFONT) { charw = GIANTCHAR_WIDTH; } else { charw = BIGCHAR_WIDTH; } if (style & UI_CENTER) { len = strlen(str); x = x - len*charw/2; } else if (style & UI_RIGHT) { len = strlen(str); x = x - len*charw; } UI_DrawChar( x + ( edit->cursor - prestep ) * charw, y, cursorChar, style & ~(UI_CENTER|UI_RIGHT), color ); }
/* ================= Controls_DrawKeyBinding ================= */ static void Controls_DrawKeyBinding( void *self ) { menuaction_s* a; int x; int y; int b1; int b2; qboolean c; char name[32]; char name2[32]; a = (menuaction_s*) self; x = a->generic.x; y = a->generic.y; c = (Menu_ItemAtCursor( a->generic.parent ) == a); b1 = g_bindings[a->generic.id].bind1; if (b1 == -1) strcpy(name,"???"); else { trap_Key_KeynumToStringBuf( b1, name, 32 ); Q_strupr(name); b2 = g_bindings[a->generic.id].bind2; if (b2 != -1) { trap_Key_KeynumToStringBuf( b2, name2, 32 ); Q_strupr(name2); strcat( name, " or " ); strcat( name, name2 ); } } if (c) { UI_FillRect( a->generic.left, a->generic.top, a->generic.right-a->generic.left+1, a->generic.bottom-a->generic.top+1, listbar_color ); UI_DrawString( x - SMALLCHAR_WIDTH, y, g_bindings[a->generic.id].label, UI_RIGHT|UI_SMALLFONT, text_color_highlight ); UI_DrawString( x + SMALLCHAR_WIDTH, y, name, UI_LEFT|UI_SMALLFONT|UI_PULSE, text_color_highlight ); if (s_controls.waitingforkey) { UI_DrawChar( x, y, '=', UI_CENTER|UI_BLINK|UI_SMALLFONT, text_color_highlight); UI_DrawString(500, SCREEN_HEIGHT * 0.85, "Waiting for new key ... ESCAPE to cancel", UI_SMALLFONT|UI_CENTER|UI_PULSE, colorWhite ); } else { UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|UI_SMALLFONT, text_color_highlight); UI_DrawString(500, SCREEN_HEIGHT * 0.83, "Press ENTER or CLICK to change", UI_SMALLFONT|UI_CENTER, colorWhite ); UI_DrawString(500, SCREEN_HEIGHT * 0.87, "Press BACKSPACE to clear", UI_SMALLFONT|UI_CENTER, colorWhite ); } } else { if (a->generic.flags & QMF_GRAYED) { UI_DrawString( x - SMALLCHAR_WIDTH, y, g_bindings[a->generic.id].label, UI_RIGHT|UI_SMALLFONT, text_color_disabled ); UI_DrawString( x + SMALLCHAR_WIDTH, y, name, UI_LEFT|UI_SMALLFONT, text_color_disabled ); } else { UI_DrawString( x - SMALLCHAR_WIDTH, y, g_bindings[a->generic.id].label, UI_RIGHT|UI_SMALLFONT, controls_binding_color ); UI_DrawString( x + SMALLCHAR_WIDTH, y, name, UI_LEFT|UI_SMALLFONT, controls_binding_color ); } } }