Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ui_mfield.c File Reference

#include "ui_local.h"

Include dependency graph for ui_mfield.c:

Include dependency graph

Go to the source code of this file.

Functions

void MenuField_Draw (menufield_s *f)
void MenuField_Init (menufield_s *m)
sfxHandle_t MenuField_Key (menufield_s *m, int *key)
void MField_CharEvent (mfield_t *edit, int ch)
void MField_Clear (mfield_t *edit)
void MField_Draw (mfield_t *edit, int x, int y, int style, vec4_t color)
void MField_KeyDownEvent (mfield_t *edit, int key)
void MField_Paste (mfield_t *edit)


Function Documentation

void MenuField_Draw menufield_s f  ) 
 

Definition at line 332 of file ui_mfield.c.

References menucommon_s::bottom, f, menufield_s::field, menucommon_s::flags, menufield_s::generic, h(), menucommon_s::left, listbar_color, Menu_ItemAtCursor(), MField_Draw(), menucommon_s::name, menucommon_s::parent, qboolean, menucommon_s::right, menucommon_s::top, UI_BLINK, UI_CENTER, UI_DrawChar(), UI_DrawString(), UI_FillRect(), UI_RIGHT, w, x, menucommon_s::x, y, and menucommon_s::y.

Referenced by Menu_Draw().

00333 {
00334     int     x;
00335     int     y;
00336     int     w;
00337     int     h;
00338     int     style;
00339     qboolean focus;
00340     float   *color;
00341 
00342     x = f->generic.x;
00343     y = f->generic.y;
00344 
00345     if (f->generic.flags & QMF_SMALLFONT)
00346     {
00347         w = SMALLCHAR_WIDTH;
00348         h = SMALLCHAR_HEIGHT;
00349         style = UI_SMALLFONT;
00350     }
00351     else
00352     {
00353         w = BIGCHAR_WIDTH;
00354         h = BIGCHAR_HEIGHT;
00355         style = UI_BIGFONT;
00356     }   
00357 
00358     if (Menu_ItemAtCursor( f->generic.parent ) == f) {
00359         focus = qtrue;
00360         style |= UI_PULSE;
00361     }
00362     else {
00363         focus = qfalse;
00364     }
00365 
00366     if (f->generic.flags & QMF_GRAYED)
00367         color = text_color_disabled;
00368     else if (focus)
00369         color = text_color_highlight;
00370     else
00371         color = text_color_normal;
00372 
00373     if ( focus )
00374     {
00375         // draw cursor
00376         UI_FillRect( f->generic.left, f->generic.top, f->generic.right-f->generic.left+1, f->generic.bottom-f->generic.top+1, listbar_color ); 
00377         UI_DrawChar( x, y, 13, UI_CENTER|UI_BLINK|style, color);
00378     }
00379 
00380     if ( f->generic.name ) {
00381         UI_DrawString( x - w, y, f->generic.name, style|UI_RIGHT, color );
00382     }
00383 
00384     MField_Draw( &f->field, x + w, y, style, color );
00385 }

Here is the call graph for this function:

void MenuField_Init menufield_s m  ) 
 

Definition at line 296 of file ui_mfield.c.

References menucommon_s::bottom, menufield_s::field, menucommon_s::flags, menufield_s::generic, h(), l, menucommon_s::left, m, MField_Clear(), menucommon_s::name, menucommon_s::right, strlen(), menucommon_s::top, w, mfield_t::widthInChars, menucommon_s::x, and menucommon_s::y.

Referenced by Menu_AddItem().

00296                                       {
00297     int l;
00298     int w;
00299     int h;
00300 
00301     MField_Clear( &m->field );
00302 
00303     if (m->generic.flags & QMF_SMALLFONT)
00304     {
00305         w = SMALLCHAR_WIDTH;
00306         h = SMALLCHAR_HEIGHT;
00307     }
00308     else
00309     {
00310         w = BIGCHAR_WIDTH;
00311         h = BIGCHAR_HEIGHT;
00312     }   
00313 
00314     if (m->generic.name) {
00315         l = (strlen( m->generic.name )+1) * w;      
00316     }
00317     else {
00318         l = 0;
00319     }
00320 
00321     m->generic.left   = m->generic.x - l;
00322     m->generic.top    = m->generic.y;
00323     m->generic.right  = m->generic.x + w + m->field.widthInChars*w;
00324     m->generic.bottom = m->generic.y + h;
00325 }

Here is the call graph for this function:

sfxHandle_t MenuField_Key menufield_s m,
int *  key
 

Definition at line 392 of file ui_mfield.c.

References menufield_s::field, menucommon_s::flags, menufield_s::generic, K_DOWNARROW, K_ENTER, K_JOY1, K_JOY2, K_JOY3, K_JOY4, K_KP_DOWNARROW, K_KP_ENTER, K_KP_UPARROW, K_TAB, K_UPARROW, m, MField_CharEvent(), MField_KeyDownEvent(), Q_isalpha(), Q_islower(), Q_isupper(), and sfxHandle_t.

Referenced by Menu_DefaultKey().

00393 {
00394     int keycode;
00395 
00396     keycode = *key;
00397 
00398     switch ( keycode )
00399     {
00400         case K_KP_ENTER:
00401         case K_ENTER:
00402         case K_JOY1:
00403         case K_JOY2:
00404         case K_JOY3:
00405         case K_JOY4:
00406             // have enter go to next cursor point
00407             *key = K_TAB;
00408             break;
00409 
00410         case K_TAB:
00411         case K_KP_DOWNARROW:
00412         case K_DOWNARROW:
00413         case K_KP_UPARROW:
00414         case K_UPARROW:
00415             break;
00416 
00417         default:
00418             if ( keycode & K_CHAR_FLAG )
00419             {
00420                 keycode &= ~K_CHAR_FLAG;
00421 
00422                 if ((m->generic.flags & QMF_UPPERCASE) && Q_islower( keycode ))
00423                     keycode -= 'a' - 'A';
00424                 else if ((m->generic.flags & QMF_LOWERCASE) && Q_isupper( keycode ))
00425                     keycode -= 'A' - 'a';
00426                 else if ((m->generic.flags & QMF_NUMBERSONLY) && Q_isalpha( keycode ))
00427                     return (menu_buzz_sound);
00428 
00429                 MField_CharEvent( &m->field, keycode);
00430             }
00431             else
00432                 MField_KeyDownEvent( &m->field, keycode );
00433             break;
00434     }
00435 
00436     return (0);
00437 }

Here is the call graph for this function:

void MField_CharEvent mfield_t edit,
int  ch
 

Definition at line 207 of file ui_mfield.c.

References mfield_t::buffer, ch, mfield_t::cursor, MAX_EDIT_LINE, mfield_t::maxchars, memmove(), MField_Clear(), MField_Paste(), mfield_t::scroll, strlen(), trap_Key_GetOverstrikeMode(), and mfield_t::widthInChars.

Referenced by MenuField_Key(), and MField_Paste().

00207                                                 {
00208     int     len;
00209 
00210     if ( ch == 'v' - 'a' + 1 ) {    // ctrl-v is paste
00211         MField_Paste( edit );
00212         return;
00213     }
00214 
00215     if ( ch == 'c' - 'a' + 1 ) {    // ctrl-c clears the field
00216         MField_Clear( edit );
00217         return;
00218     }
00219 
00220     len = strlen( edit->buffer );
00221 
00222     if ( ch == 'h' - 'a' + 1 )  {   // ctrl-h is backspace
00223         if ( edit->cursor > 0 ) {
00224             memmove( edit->buffer + edit->cursor - 1, 
00225                 edit->buffer + edit->cursor, len + 1 - edit->cursor );
00226             edit->cursor--;
00227             if ( edit->cursor < edit->scroll )
00228             {
00229                 edit->scroll--;
00230             }
00231         }
00232         return;
00233     }
00234 
00235     if ( ch == 'a' - 'a' + 1 ) {    // ctrl-a is home
00236         edit->cursor = 0;
00237         edit->scroll = 0;
00238         return;
00239     }
00240 
00241     if ( ch == 'e' - 'a' + 1 ) {    // ctrl-e is end
00242         edit->cursor = len;
00243         edit->scroll = edit->cursor - edit->widthInChars + 1;
00244         if (edit->scroll < 0)
00245             edit->scroll = 0;
00246         return;
00247     }
00248 
00249     //
00250     // ignore any other non printable chars
00251     //
00252     if ( ch < 32 ) {
00253         return;
00254     }
00255 
00256     if ( !trap_Key_GetOverstrikeMode() ) {  
00257         if ((edit->cursor == MAX_EDIT_LINE - 1) || (edit->maxchars && edit->cursor >= edit->maxchars))
00258             return;
00259     } else {
00260         // insert mode
00261         if (( len == MAX_EDIT_LINE - 1 ) || (edit->maxchars && len >= edit->maxchars))
00262             return;
00263         memmove( edit->buffer + edit->cursor + 1, edit->buffer + edit->cursor, len + 1 - edit->cursor );
00264     }
00265 
00266     edit->buffer[edit->cursor] = ch;
00267     if (!edit->maxchars || edit->cursor < edit->maxchars-1)
00268         edit->cursor++;
00269 
00270     if ( edit->cursor >= edit->widthInChars )
00271     {
00272         edit->scroll++;
00273     }
00274 
00275     if ( edit->cursor == len + 1) {
00276         edit->buffer[edit->cursor] = 0;
00277     }
00278 }

Here is the call graph for this function:

void MField_Clear mfield_t edit  ) 
 

Definition at line 285 of file ui_mfield.c.

References mfield_t::buffer, mfield_t::cursor, and mfield_t::scroll.

Referenced by MenuField_Init(), and MField_CharEvent().

00285                                     {
00286     edit->buffer[0] = 0;
00287     edit->cursor = 0;
00288     edit->scroll = 0;
00289 }

void MField_Draw mfield_t edit,
int  x,
int  y,
int  style,
vec4_t  color
 

Definition at line 33 of file ui_mfield.c.

References mfield_t::buffer, mfield_t::cursor, memcpy(), mfield_t::scroll, strlen(), trap_Error(), trap_Key_GetOverstrikeMode(), UI_CENTER, UI_DrawChar(), UI_DrawString(), UI_RIGHT, mfield_t::widthInChars, x, and y.

Referenced by MenuField_Draw(), UI_DrawConnectScreen(), and UI_SaveConfigMenu_SavenameDraw().

00033                                                                           {
00034     int     len;
00035     int     charw;
00036     int     drawLen;
00037     int     prestep;
00038     int     cursorChar;
00039     char    str[MAX_STRING_CHARS];
00040 
00041     drawLen = edit->widthInChars;
00042     len     = strlen( edit->buffer ) + 1;
00043 
00044     // guarantee that cursor will be visible
00045     if ( len <= drawLen ) {
00046         prestep = 0;
00047     } else {
00048         if ( edit->scroll + drawLen > len ) {
00049             edit->scroll = len - drawLen;
00050             if ( edit->scroll < 0 ) {
00051                 edit->scroll = 0;
00052             }
00053         }
00054         prestep = edit->scroll;
00055     }
00056 
00057     if ( prestep + drawLen > len ) {
00058         drawLen = len - prestep;
00059     }
00060 
00061     // extract <drawLen> characters from the field at <prestep>
00062     if ( drawLen >= MAX_STRING_CHARS ) {
00063         trap_Error( "drawLen >= MAX_STRING_CHARS" );
00064     }
00065     memcpy( str, edit->buffer + prestep, drawLen );
00066     str[ drawLen ] = 0;
00067 
00068     UI_DrawString( x, y, str, style, color );
00069 
00070     // draw the cursor
00071     if (!(style & UI_PULSE)) {
00072         return;
00073     }
00074 
00075     if ( trap_Key_GetOverstrikeMode() ) {
00076         cursorChar = 11;
00077     } else {
00078         cursorChar = 10;
00079     }
00080 
00081     style &= ~UI_PULSE;
00082     style |= UI_BLINK;
00083 
00084     if (style & UI_SMALLFONT)
00085     {
00086         charw = SMALLCHAR_WIDTH;
00087     }
00088     else if (style & UI_GIANTFONT)
00089     {
00090         charw = GIANTCHAR_WIDTH;
00091     }
00092     else
00093     {
00094         charw = BIGCHAR_WIDTH;
00095     }
00096 
00097     if (style & UI_CENTER)
00098     {
00099         len = strlen(str);
00100         x = x - len*charw/2;
00101     }
00102     else if (style & UI_RIGHT)
00103     {
00104         len = strlen(str);
00105         x = x - len*charw;
00106     }
00107     
00108     UI_DrawChar( x + ( edit->cursor - prestep ) * charw, y, cursorChar, style & ~(UI_CENTER|UI_RIGHT), color );
00109 }

Here is the call graph for this function:

void MField_KeyDownEvent mfield_t edit,
int  key
 

Definition at line 139 of file ui_mfield.c.

References mfield_t::buffer, mfield_t::cursor, K_CTRL, K_DEL, K_END, K_HOME, K_INS, K_KP_END, K_KP_HOME, K_LEFTARROW, K_RIGHTARROW, K_SHIFT, memmove(), MField_Paste(), mfield_t::scroll, strlen(), tolower(), trap_Key_GetOverstrikeMode(), trap_Key_IsDown(), trap_Key_SetOverstrikeMode(), and mfield_t::widthInChars.

Referenced by MenuField_Key().

00139                                                     {
00140     int     len;
00141 
00142     // shift-insert is paste
00143     if ( ( ( key == K_INS ) || ( key == K_KP_INS ) ) && trap_Key_IsDown( K_SHIFT ) ) {
00144         MField_Paste( edit );
00145         return;
00146     }
00147 
00148     len = strlen( edit->buffer );
00149 
00150     if ( key == K_DEL || key == K_KP_DEL ) {
00151         if ( edit->cursor < len ) {
00152             memmove( edit->buffer + edit->cursor, 
00153                 edit->buffer + edit->cursor + 1, len - edit->cursor );
00154         }
00155         return;
00156     }
00157 
00158     if ( key == K_RIGHTARROW || key == K_KP_RIGHTARROW ) 
00159     {
00160         if ( edit->cursor < len ) {
00161             edit->cursor++;
00162         }
00163         if ( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len )
00164         {
00165             edit->scroll++;
00166         }
00167         return;
00168     }
00169 
00170     if ( key == K_LEFTARROW || key == K_KP_LEFTARROW ) 
00171     {
00172         if ( edit->cursor > 0 ) {
00173             edit->cursor--;
00174         }
00175         if ( edit->cursor < edit->scroll )
00176         {
00177             edit->scroll--;
00178         }
00179         return;
00180     }
00181 
00182     if ( key == K_HOME || key == K_KP_HOME || ( tolower(key) == 'a' && trap_Key_IsDown( K_CTRL ) ) ) {
00183         edit->cursor = 0;
00184         edit->scroll = 0;
00185         return;
00186     }
00187 
00188     if ( key == K_END || key == K_KP_END || ( tolower(key) == 'e' && trap_Key_IsDown( K_CTRL ) ) ) {
00189         edit->cursor = len;
00190         edit->scroll = len - edit->widthInChars + 1;
00191         if (edit->scroll < 0)
00192             edit->scroll = 0;
00193         return;
00194     }
00195 
00196     if ( key == K_INS || key == K_KP_INS ) {
00197         trap_Key_SetOverstrikeMode( !trap_Key_GetOverstrikeMode() );
00198         return;
00199     }
00200 }

Here is the call graph for this function:

void MField_Paste mfield_t edit  ) 
 

Definition at line 116 of file ui_mfield.c.

References i, MField_CharEvent(), strlen(), and trap_GetClipboardData().

Referenced by MField_CharEvent(), and MField_KeyDownEvent().

00116                                     {
00117     char    pasteBuffer[64];
00118     int     pasteLen, i;
00119 
00120     trap_GetClipboardData( pasteBuffer, 64 );
00121 
00122     // send as if typed, so insert / overstrike works properly
00123     pasteLen = strlen( pasteBuffer );
00124     for ( i = 0 ; i < pasteLen ; i++ ) {
00125         MField_CharEvent( edit, pasteBuffer[i] );
00126     }
00127 }

Here is the call graph for this function:


Generated on Thu Aug 25 14:32:58 2005 for Quake III Arena by  doxygen 1.3.9.1