Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
modaldialog.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2003 Mike Byron
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef __MODALDIALOG_H__
23 #define __MODALDIALOG_H__
24 
25 #include "windowcontroller.h"
26 
27 //Callback called when modal dialog closes.
28 //The callback has 3 parameters:
29 //1. The controller. This can be used to interrogate the controller or the
30 //controls in the window for more complex dialogs.
31 //2. The string "id". This is specified by the dialog creator to help handling
32 //code identify which dialog is responding.
33 //3. The integer "result". A simple result from the dialog. More complex
34 //results could be obtained from the window.
35 //The callback returns true if the window is to be closed, false otherwise
36 //(it will then return true on a later callback).
38 {
39 public:
40  virtual void modalDialogResult( const std::string &id, int result, WindowController &controller ) = 0;
41 };
42 
43 //This class controls a modal "dialog" with the user. It puts up a modal
44 //window, gets an answer, and calls a callback function.
45 //Like all WindowController's, by default, this object deletes itself when
46 //the window closes.
47 //Note that this class requires a callback because there is no access to the
48 //GLUT event loop. The common way to implement modal UI is to recursively
49 //call the event loop while the modal UI is showing, so that the UI can
50 //return directly back to the routine that called it. Can't do that in GLUT,
51 //so there is no way to return a value to the caller. The caller must
52 //eventually exit back to the event loop to get the modal UI serviced.
54 {
55 public:
56 //The class that gets called when the window closes.
57  virtual void setCallback( ModalDialogCallback *cb, const std::string &id );
58 
59 //Set up the window and get everything ready.
60  virtual void init( void ) {}
61 
62 //Start everything up.
63  virtual void run( void );
64 
65 //Process a command event from the window.
66  virtual bool processWindowCommand( const EventCommandId &command, Control *control );
67 
68  void modalFinished( void );
69 
70 //CONSTRUCTION
71  ModalDialog();
72  virtual ~ModalDialog( void ) {}
73 
74 protected:
75 
76 //VARIABLES
77  std::string m_callbackId; //"Id" to pass callback function.
78  ModalDialogCallback *m_callback; //The callback class.
79  int m_result; //A simple result for the dialog.
80 };
81 
82 //Display a modal message to the user. The message will be shown until the user
83 //hits the OK button.
84 void showAlert( const std::string &title );
85 
86 //Display a modal yes/no question.
87 //The result is supplied in the callback.
88 void showYesNoQuestion( const std::string &title, ModalDialogCallback *cb, const std::string &id );
89 static const int YES_ANSWER = 1;
90 static const int NO_ANSWER = 0;
91 
92 //Display a modal list of options.
93 //The result is supplied in the callback.
94 void showListQuestion( const std::string &title,
95  const std::vector< std::string > &options,
97  const std::string &id );
98 
99 //This class is used to display predefined alerts and questions.
100 //It creates a Window, loads controls, etc.
102 {
103 public:
104 //Load the controls for this dialog.
105  virtual void initControls( void ) = 0;
106 
107 //Set up the window and get everything ready.
108  virtual void init( const std::string &title );
109 
110 //Start everything up.
111  virtual void run( void );
112 
113 //CONSTRUCTION
115  virtual ~QuestionDialog( void )
116  {
117  if (m_window != NULL && m_deleteWindow) delete m_window;
118  }
119 
120 protected:
121 //VARIABLES
122  bool m_deleteWindow; //True = Delete window when we are deleted.
123 };
124 
125 //Class that supports showListQuestion().
126 //Use this to customize behavior.
127 
128 //Class that will handle List Question dialog correctly.
130 {
131 public:
132 //Load the controls for this dialog into the window.
133  virtual void initControls( void )
134  {
136  }
137 
138 //Process a command event from the window.
139  virtual bool processWindowCommand( const EventCommandId &command, Control *control );
140 
141  class SimplePicker * getPicker();
142 
143 protected:
144  static void CreateControlsForListWindow( Window *w );
145 };
146 
147 #endif //__MODALDIALOG_H__
148