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

ui_confirm.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 //
00023 /*
00024 =======================================================================
00025 
00026 CONFIRMATION MENU
00027 
00028 =======================================================================
00029 */
00030 
00031 
00032 #include "ui_local.h"
00033 
00034 
00035 #define ART_CONFIRM_FRAME   "menu/art/cut_frame"
00036 
00037 #define ID_CONFIRM_NO       10
00038 #define ID_CONFIRM_YES      11
00039 
00040 
00041 typedef struct {
00042     menuframework_s menu;
00043 
00044     menutext_s      no;
00045     menutext_s      yes;
00046 
00047     int             slashX;
00048     const char *    question;
00049     void            (*draw)( void );
00050     void            (*action)( qboolean result );
00051     
00052     int style;
00053     const char **lines;
00054 } confirmMenu_t;
00055 
00056 
00057 static confirmMenu_t    s_confirm;
00058 
00059 
00060 /*
00061 =================
00062 ConfirmMenu_Event
00063 =================
00064 */
00065 static void ConfirmMenu_Event( void* ptr, int event ) {
00066     qboolean    result;
00067 
00068     if( event != QM_ACTIVATED ) {
00069         return;
00070     }
00071 
00072     UI_PopMenu();
00073 
00074     if( ((menucommon_s*)ptr)->id == ID_CONFIRM_NO ) {
00075         result = qfalse;
00076     }
00077     else {
00078         result = qtrue;
00079     }
00080 
00081     if( s_confirm.action ) {
00082         s_confirm.action( result );
00083     }
00084 }
00085 
00086 
00087 /*
00088 =================
00089 ConfirmMenu_Key
00090 =================
00091 */
00092 static sfxHandle_t ConfirmMenu_Key( int key ) {
00093     switch ( key ) {
00094     case K_KP_LEFTARROW:
00095     case K_LEFTARROW:
00096     case K_KP_RIGHTARROW:
00097     case K_RIGHTARROW:
00098         key = K_TAB;
00099         break;
00100 
00101     case 'n':
00102     case 'N':
00103         ConfirmMenu_Event( &s_confirm.no, QM_ACTIVATED );
00104         break;
00105 
00106     case 'y':
00107     case 'Y':
00108         ConfirmMenu_Event( &s_confirm.yes, QM_ACTIVATED );
00109         break;
00110     }
00111 
00112     return Menu_DefaultKey( &s_confirm.menu, key );
00113 }
00114 
00115 
00116 /*
00117 =================
00118 MessaheMenu_Draw
00119 =================
00120 */
00121 static void MessageMenu_Draw( void ) {
00122     int i,y;
00123     
00124     UI_DrawNamedPic( 142, 118, 359, 256, ART_CONFIRM_FRAME );
00125     
00126     y = 188;
00127     for(i=0; s_confirm.lines[i]; i++)
00128     {
00129         UI_DrawProportionalString( 320, y, s_confirm.lines[i], s_confirm.style, color_red );
00130         y += 18;
00131     }
00132 
00133     Menu_Draw( &s_confirm.menu );
00134 
00135     if( s_confirm.draw ) {
00136         s_confirm.draw();
00137     }
00138 }
00139 
00140 /*
00141 =================
00142 ConfirmMenu_Draw
00143 =================
00144 */
00145 static void ConfirmMenu_Draw( void ) {
00146     UI_DrawNamedPic( 142, 118, 359, 256, ART_CONFIRM_FRAME );
00147     UI_DrawProportionalString( 320, 204, s_confirm.question, s_confirm.style, color_red );
00148     UI_DrawProportionalString( s_confirm.slashX, 265, "/", UI_LEFT|UI_INVERSE, color_red );
00149 
00150     Menu_Draw( &s_confirm.menu );
00151 
00152     if( s_confirm.draw ) {
00153         s_confirm.draw();
00154     }
00155 }
00156 
00157 
00158 /*
00159 =================
00160 ConfirmMenu_Cache
00161 =================
00162 */
00163 void ConfirmMenu_Cache( void ) {
00164     trap_R_RegisterShaderNoMip( ART_CONFIRM_FRAME );
00165 }
00166 
00167 
00168 /*
00169 =================
00170 UI_ConfirmMenu_Stlye
00171 =================
00172 */
00173 void UI_ConfirmMenu_Style( const char *question, int style, void (*draw)( void ), void (*action)( qboolean result ) ) {
00174     uiClientState_t cstate;
00175     int n1, n2, n3;
00176     int l1, l2, l3;
00177 
00178     // zero set all our globals
00179     memset( &s_confirm, 0, sizeof(s_confirm) );
00180 
00181     ConfirmMenu_Cache();
00182 
00183     n1 = UI_ProportionalStringWidth( "YES/NO" );
00184     n2 = UI_ProportionalStringWidth( "YES" ) + PROP_GAP_WIDTH;
00185     n3 = UI_ProportionalStringWidth( "/" )  + PROP_GAP_WIDTH;
00186     l1 = 320 - ( n1 / 2 );
00187     l2 = l1 + n2;
00188     l3 = l2 + n3;
00189     s_confirm.slashX = l2;
00190 
00191     s_confirm.question = question;
00192     s_confirm.draw = draw;
00193     s_confirm.action = action;
00194     s_confirm.style = style;
00195 
00196     s_confirm.menu.draw       = ConfirmMenu_Draw;
00197     s_confirm.menu.key        = ConfirmMenu_Key;
00198     s_confirm.menu.wrapAround = qtrue;
00199 
00200     trap_GetClientState( &cstate );
00201     if ( cstate.connState >= CA_CONNECTED ) {
00202         s_confirm.menu.fullscreen = qfalse;
00203     }
00204     else {
00205         s_confirm.menu.fullscreen = qtrue;
00206     }
00207 
00208     s_confirm.yes.generic.type      = MTYPE_PTEXT;      
00209     s_confirm.yes.generic.flags     = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; 
00210     s_confirm.yes.generic.callback  = ConfirmMenu_Event;
00211     s_confirm.yes.generic.id        = ID_CONFIRM_YES;
00212     s_confirm.yes.generic.x         = l1;
00213     s_confirm.yes.generic.y         = 264;
00214     s_confirm.yes.string            = "YES";
00215     s_confirm.yes.color             = color_red;
00216     s_confirm.yes.style             = UI_LEFT;
00217 
00218     s_confirm.no.generic.type       = MTYPE_PTEXT;      
00219     s_confirm.no.generic.flags      = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; 
00220     s_confirm.no.generic.callback   = ConfirmMenu_Event;
00221     s_confirm.no.generic.id         = ID_CONFIRM_NO;
00222     s_confirm.no.generic.x          = l3;
00223     s_confirm.no.generic.y          = 264;
00224     s_confirm.no.string             = "NO";
00225     s_confirm.no.color              = color_red;
00226     s_confirm.no.style              = UI_LEFT;
00227 
00228     Menu_AddItem( &s_confirm.menu,  &s_confirm.yes );             
00229     Menu_AddItem( &s_confirm.menu,  &s_confirm.no );
00230 
00231     UI_PushMenu( &s_confirm.menu );
00232 
00233     Menu_SetCursorToItem( &s_confirm.menu, &s_confirm.no );
00234 }
00235 
00236 /*
00237 =================
00238 UI_ConfirmMenu
00239 =================
00240 */
00241 void UI_ConfirmMenu( const char *question, void (*draw)( void ), void (*action)( qboolean result ) ) {
00242     UI_ConfirmMenu_Style(question, UI_CENTER|UI_INVERSE, draw, action);
00243 }
00244 
00245 /*
00246 =================
00247 UI_Message
00248 hacked over from Confirm stuff
00249 =================
00250 */
00251 void UI_Message( const char **lines ) {
00252     uiClientState_t cstate;
00253     int n1, l1;
00254     
00255     // zero set all our globals
00256     memset( &s_confirm, 0, sizeof(s_confirm) );
00257 
00258     ConfirmMenu_Cache();
00259 
00260     n1 = UI_ProportionalStringWidth( "OK" );
00261     l1 = 320 - ( n1 / 2 );
00262     
00263     s_confirm.lines = lines;
00264     s_confirm.style = UI_CENTER|UI_INVERSE|UI_SMALLFONT;
00265 
00266     s_confirm.menu.draw       = MessageMenu_Draw;
00267     s_confirm.menu.key        = ConfirmMenu_Key;
00268     s_confirm.menu.wrapAround = qtrue;
00269     
00270     trap_GetClientState( &cstate );
00271     if ( cstate.connState >= CA_CONNECTED ) {
00272         s_confirm.menu.fullscreen = qfalse;
00273     }
00274     else {
00275         s_confirm.menu.fullscreen = qtrue;
00276     }
00277 
00278     s_confirm.yes.generic.type      = MTYPE_PTEXT;      
00279     s_confirm.yes.generic.flags     = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS; 
00280     s_confirm.yes.generic.callback  = ConfirmMenu_Event;
00281     s_confirm.yes.generic.id        = ID_CONFIRM_YES;
00282     s_confirm.yes.generic.x         = l1;
00283     s_confirm.yes.generic.y         = 280;
00284     s_confirm.yes.string            = "OK";
00285     s_confirm.yes.color             = color_red;
00286     s_confirm.yes.style             = UI_LEFT;
00287 
00288     Menu_AddItem( &s_confirm.menu,  &s_confirm.yes );
00289     
00290     UI_PushMenu( &s_confirm.menu );
00291 
00292     Menu_SetCursorToItem( &s_confirm.menu, &s_confirm.yes );
00293 }

Generated on Thu Aug 25 12:37:39 2005 for Quake III Arena by  doxygen 1.3.9.1