From 8e1ae97d3d1f279267aa1efd315442767948fdea Mon Sep 17 00:00:00 2001 From: mfranz Date: Thu, 20 Oct 2005 13:05:02 +0000 Subject: [PATCH] Replace hard-coded message boxes by ones managed by the gui subsystem. Remove obsolete functions. --- src/GUI/gui.cxx | 9 --- src/GUI/gui.h | 2 - src/GUI/gui_funcs.cxx | 144 ++++++------------------------------------ 3 files changed, 19 insertions(+), 136 deletions(-) diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index 571588e9c..fbc5e902a 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -51,10 +51,6 @@ #include "preset_dlg.hxx" #include "layout.hxx" -extern void initDialog (void); -extern void mkDialogInit (void); -extern void ConfirmExitDialogInit(void); - puFont guiFnt = 0; fntTexFont *guiFntHandle = 0; @@ -74,8 +70,6 @@ void guiInit() puSetDefaultStyle ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT puSetDefaultColourScheme (0.8, 0.8, 0.9, 1); - initDialog(); - // Next check home directory SGPath fntpath; char* envp = ::getenv( "FG_FONTS" ); @@ -124,8 +118,5 @@ void guiInit() initMouseQuat(); // Set up our Dialog Boxes - ConfirmExitDialogInit(); fgPresetInit(); - - mkDialogInit(); } diff --git a/src/GUI/gui.h b/src/GUI/gui.h index 2920e48e8..4220b4714 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -45,7 +45,6 @@ extern void guiInit(); extern void mkDialog(const char *txt); extern void guiErrorMessage(const char *txt); extern void guiErrorMessage(const char *txt, const sg_throwable &throwable); -extern void ConfirmExitDialog(void); extern void fgDumpSnapShot(); @@ -65,7 +64,6 @@ extern void fgHiResDump(); #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__) extern void printScreen(puObject *); #endif -extern void MayBeGoodBye(puObject *); extern void guiTogglePanel(puObject *); extern void PilotOffsetAdjust(puObject *); extern void fgHUDalphaAdjust(puObject *); diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index 9eed2d5a1..7073a2887 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -81,6 +81,7 @@ #include
#include
#include
+#include #if defined( WIN32 ) && !defined( __CYGWIN__ ) && !defined(__MINGW32__) # include @@ -107,30 +108,14 @@ extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start, GLfloat x_end, GLfloat y_end ); #endif -puDialogBox *dialogBox = 0; -puFrame *dialogFrame = 0; -puText *dialogBoxMessage = 0; -puOneShot *dialogBoxOkButton = 0; -puDialogBox *YNdialogBox = 0; -puFrame *YNdialogFrame = 0; -puText *YNdialogBoxMessage = 0; -puOneShot *YNdialogBoxOkButton = 0; -puOneShot *YNdialogBoxNoButton = 0; +// TODO: remove after the last hardcoded dialog has died +char *gui_msg_OK = "OK"; +char *gui_msg_NO = "NO"; +char *gui_msg_YES = "YES"; +char *gui_msg_CANCEL = "CANCEL"; +char *gui_msg_RESET = "RESET"; -char *gui_msg_OK; // "OK" -char *gui_msg_NO; // "NO" -char *gui_msg_YES; // "YES" -char *gui_msg_CANCEL; // "CANCEL" -char *gui_msg_RESET; // "RESET" - -char msg_OK[] = "OK"; -char msg_NO[] = "NO"; -char msg_YES[] = "YES"; -char msg_CANCEL[] = "Cancel"; -char msg_RESET[] = "Reset"; - -char global_dialog_string[256]; const __fg_gui_fn_t __fg_gui_fn[] = { @@ -143,7 +128,6 @@ const __fg_gui_fn_t __fg_gui_fn[] = { #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__) {"printScreen", printScreen}, #endif - {"MayBeGoodBye", MayBeGoodBye}, //View {"guiTogglePanel", guiTogglePanel}, @@ -177,29 +161,26 @@ const __fg_gui_fn_t __fg_gui_fn[] = { /* ================ General Purpose Functions ================ */ -void initDialog(void) { - // Initialize our GLOBAL GUI STRINGS - gui_msg_OK = msg_OK; // "OK" - gui_msg_NO = msg_NO; // "NO" - gui_msg_YES = msg_YES; // "YES" - gui_msg_CANCEL = msg_CANCEL; // "CANCEL" - gui_msg_RESET = msg_RESET; // "RESET" -} - // General Purpose Message Box void mkDialog (const char *txt) { - strncpy(global_dialog_string, txt, 256); - dialogBoxMessage->setLabel(global_dialog_string); - FG_PUSH_PUI_DIALOG( dialogBox ); + NewGUI *gui = (NewGUI *)globals->get_subsystem("gui"); + SGPropertyNode_ptr dlg = gui->getDialog("message"); + if (!dlg) { + SG_LOG(SG_GENERAL, SG_ALERT, "'message' dialog missing"); + return; + } + + dlg->setStringValue("text/label", txt); + dlg->setStringValue("button/legend", "OK"); + gui->showDialog("message"); } // Message Box to report an error. void guiErrorMessage (const char *txt) { SG_LOG(SG_GENERAL, SG_ALERT, txt); - if (dialogBox != 0) - mkDialog(txt); + mkDialog(txt); } // Message Box to report a throwable (usually an exception). @@ -214,14 +195,7 @@ void guiErrorMessage (const char *txt, const sg_throwable &throwable) msg += ')'; } SG_LOG(SG_GENERAL, SG_ALERT, msg); - if (dialogBox != 0) - mkDialog(msg.c_str()); -} - -// Intercept the Escape Key -void ConfirmExitDialog(void) -{ - FG_PUSH_PUI_DIALOG( YNdialogBox ); + mkDialog(msg.c_str()); } @@ -248,86 +222,6 @@ void guiTogglePanel(puObject *cb) fgGetInt("/sim/startup/ysize")); } -void goodBye(puObject *) -{ - // SG_LOG( SG_INPUT, SG_ALERT, - // "Program exiting normally at user request." ); - cout << "Program exiting normally at user request." << endl; - - exit(0); -} - - -void goAwayCb (puObject *me) -{ - FG_POP_PUI_DIALOG( dialogBox ); -} - -void mkDialogInit (void) -{ - // printf("mkDialogInit\n"); - int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2); - int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2); - dialogBox = new puDialogBox (x, y); // 150, 50 - { - dialogFrame = new puFrame (0,0,400,100); - dialogBoxMessage = new puText (10, 70); - dialogBoxMessage -> setLabel (""); - dialogBoxOkButton = new puOneShot (180, 10, 240, 50); - dialogBoxOkButton -> setLegend (gui_msg_OK); - dialogBoxOkButton -> makeReturnDefault (TRUE ); - dialogBoxOkButton -> setCallback (goAwayCb); - } - FG_FINALIZE_PUI_DIALOG( dialogBox ); -} - -void MayBeGoodBye(puObject *) -{ - ConfirmExitDialog(); -} - -void goAwayYesNoCb(puObject *me) -{ - FG_POP_PUI_DIALOG( YNdialogBox); -} - -void ConfirmExitDialogInit(void) -{ - char msg[] = "Really Quit"; - char *s; - - // printf("ConfirmExitDialogInit\n"); - int len = 200 - puGetDefaultLabelFont().getStringWidth ( msg ) / 2; - - int x = (fgGetInt("/sim/startup/xsize")/2 - 400/2); - int y = (fgGetInt("/sim/startup/ysize")/2 - 100/2); - - YNdialogBox = new puDialogBox (x, y); // 150, 50 - { - YNdialogFrame = new puFrame (0,0,400, 100); - - YNdialogBoxMessage = new puText (len, 70); - YNdialogBoxMessage -> setDefaultValue (msg); - YNdialogBoxMessage -> getDefaultValue (&s); - YNdialogBoxMessage -> setLabel (s); - - YNdialogBoxOkButton = new puOneShot (100, 10, 160, 50); - YNdialogBoxOkButton -> setLegend (gui_msg_OK); - YNdialogBoxOkButton -> makeReturnDefault (TRUE ); - YNdialogBoxOkButton -> setCallback (goodBye); - - YNdialogBoxNoButton = new puOneShot (240, 10, 300, 50); - YNdialogBoxNoButton -> setLegend (gui_msg_NO); - YNdialogBoxNoButton -> setCallback (goAwayYesNoCb); - } - FG_FINALIZE_PUI_DIALOG( YNdialogBox ); -} - -void notCb (puObject *) -{ - mkDialog ("This function isn't implemented yet"); -} - void helpCb (puObject *) { string command; -- 2.39.5