/* * Con_DrawInput * * The input line scrolls horizontally if typing goes beyond the right edge */ static void Con_DrawInput( int vislines ) { char draw_search_text[MAXCMDLINE*2+4]; const char *text = key_lines[edit_line]; int smallCharHeight = SCR_strHeight( cls.fontSystemSmall ); int text_y = vislines - 14 - smallCharHeight; const int left_margin = 8, right_margin = 8; int promptwidth = SCR_strWidth( "]", cls.fontSystemSmall, 1 ); int cursorwidth = SCR_strWidth( "_", cls.fontSystemSmall, 1 ); int input_width = viddef.width - left_margin - right_margin; int prewidth; // width of input line before cursor if( cls.key_dest != key_console ) return; if( search_text[0] ) { text = draw_search_text; Q_snprintfz( draw_search_text, sizeof( draw_search_text ), "%s : %s", key_lines[edit_line], search_text ); } prewidth = SCR_strWidth( text, cls.fontSystemSmall, key_linepos ); // don't let the cursor go beyond the left screen edge clamp_high( input_prestep, prewidth - promptwidth); // don't let it go beyond the right screen edge clamp_low( input_prestep, prewidth - ( input_width - cursorwidth ) ); SCR_DrawClampString( left_margin - input_prestep, text_y, text, left_margin, text_y, viddef.width - right_margin, viddef.height, cls.fontSystemSmall, colorWhite ); if( (int)( cls.realtime>>8 )&1 ) SCR_DrawRawChar( left_margin + prewidth - input_prestep, text_y, '_', cls.fontSystemSmall, colorWhite ); }
//=============== //SCR_DrawStringWidth - clamp to width in pixels. Returns drawn len //=============== int SCR_DrawStringWidth( int x, int y, int align, const char *str, int maxwidth, struct mufont_s *font, vec4_t color ) { int width; if( !str ) return 0; if( !font ) font = cls.fontSystemSmall; if( maxwidth < 0 ) maxwidth = 0; width = SCR_strWidth( str, font, 0 ); if( width ) { if( maxwidth && width > maxwidth ) width = maxwidth; x = SCR_HorizontalAlignForString( x, align, width ); y = SCR_VerticalAlignForString( y, align, font->fontheight ); return SCR_DrawRawString( x, y, str, maxwidth, font, color ); } return 0; }
//================== // SCR_DrawString //================== void SCR_DrawString( int x, int y, int align, const char *str, struct mufont_s *font, vec4_t color ) { int width; if( !str ) return; if( !font ) font = cls.fontSystemSmall; width = SCR_strWidth( str, font, 0 ); if( width ) { x = SCR_HorizontalAlignForString( x, align, width ); y = SCR_VerticalAlignForString( y, align, font->fontheight ); if( y <= -font->fontheight || y >= (int)viddef.height ) return; // totally off screen if( x <= -width || x >= (int)viddef.width ) return; // totally off screen SCR_DrawRawString( x, y, str, 0, font, color ); } }
/* * Con_DrawNotify * * Draws the last few lines of output transparently over the game top */ void Con_DrawNotify( void ) { int v; char *text; const char *say; const char *translated; int i; int time; char *s; v = 0; if( con_drawNotify->integer ) { for( i = min( NUM_CON_TIMES, con.numlines ) - 1; i >= 0; i-- ) { time = con.times[i]; if( time == 0 ) continue; time = cls.realtime - time; if( time > con_notifytime->value*1000 ) continue; text = con.text[i] ? con.text[i] : ""; SCR_DrawString( 8, v, ALIGN_LEFT_TOP, text, cls.fontSystemSmall, colorWhite ); v += SCR_strHeight( cls.fontSystemSmall ); } } if( cls.key_dest == key_message ) { int x, y; int width, prewidth; int promptwidth, cursorwidth; struct qfontface_s *font = NULL; if( con_chatCGame->integer ) { width = con_chatWidth->integer; if( *con_chatFontFamily->string && con_chatFontSize->integer ) { font = SCR_RegisterFont( con_chatFontFamily->string, con_chatFontStyle->integer, con_chatFontSize->integer ); } if( !font ) font = cls.fontSystemSmall; x = con_chatX->integer; y = con_chatY->integer; } else { width = viddef.width; x = 8; y = v; font = cls.fontSystemSmall; } // 48 is an arbitrary offset for not overlapping the FPS and clock prints width -= 48; cursorwidth = SCR_strWidth( "_", font, 0 ); if( chat_team ) { say = "say_team:"; } else { say = "say:"; } translated = L10n_TranslateString( "common", say ); if( !translated ) { translated = say; } SCR_DrawString( x, y, ALIGN_LEFT_TOP, translated, font, colorWhite ); promptwidth = SCR_strWidth( translated, font, 0 ) + SCR_strWidth( " ", font, 0 ); s = chat_buffer; prewidth = chat_linepos ? SCR_strWidth( s, font, chat_linepos ) : 0; // don't let the cursor go beyond the left screen edge clamp_high( chat_prestep, prewidth ); // don't let it go beyond the right screen edge clamp_low( chat_prestep, prewidth - ( width - promptwidth - cursorwidth ) ); // FIXME: we double the font height to compensate for alignment issues SCR_DrawClampString( x + promptwidth - chat_prestep, y, s, x + promptwidth, y, x + width, y + SCR_strHeight( font ) * 2, font, colorWhite ); if( (int)( cls.realtime>>8 )&1 ) SCR_DrawRawChar( x + promptwidth + prewidth - chat_prestep, y, '_', font, colorWhite ); }