Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

GUI.h

Go to the documentation of this file.
00001 //     $Id: GUI.h,v 1.3 2001/10/06 04:22:14 burnett Exp $
00002 // Project: Atlas top-level prototype
00003 //  Author: Toby Burnett
00004 
00005 #ifndef __GUI_H
00006 #define __GUI_H
00007 
00008 #include "gui/Command.h"
00009 
00010 namespace gui { class SceneControl; }
00011 
00012 #include <iostream>
00013 
00014 namespace gui {
00015 
00016 class GUI 
00017 // Abstract base class which defines a factory method, createGUI for
00018 // the "real" GUI.
00019 // Defines methods to set the window title, to define a menu bar with pull-down command menus,
00020 // (call-backs to Command objects), to use a graphical display (manipulated by an appropriate
00021 // SceneControl object), and to direct printout to a separate window.
00022 {
00023 public:
00024     virtual ~GUI();
00025 
00026     virtual void addToMenu(const char* title, Command* command);
00027     // Add a button to the current menu, either the menu bar, or a pull-down menu
00028 
00029     
00030     class Toggle : public Command 
00031     // Special abstract toggle command that must be implemented by the specific GUI subclass
00032     // set and unset methods allow control of state outside of the windowing system, so that
00033     // a button can control other buttons, setting or unsetting them independent of their 
00034     // current state.
00035     {
00036     public:
00037         void set()  { if(!state()) execute();}
00038         void unset(){ if( state()) execute();}
00039         virtual bool state()const=0;
00040     };
00041     
00042     virtual Toggle* addToggleToMenu(const char* title, bool state, Command* set, Command* unset);
00043     // Add a toggle button to the current menu. state is the initial state (on or off)
00044     // return pointer to command that is created to respond to mouse click
00045 
00046     class Menu; // empty class to tag menu bar or sub menu
00047 
00048     virtual Menu* beginPullDownMenu(const char* title, Menu* m=0);
00049     // start adding commands to a pull-down menu, which may be a submenu of a previous one.
00050     // If zero, add to menubar.
00051     // Return tag
00052 
00053     virtual void restorePullDownMenu(Menu* m);
00054     // Restore a previously-defined pull-down menu
00055 
00056     virtual void endPullDownMenu();
00057     // Stop adding commands to a pull-down menu and revert to the menu bar
00058 
00059     virtual void menuSeparator();
00060     // Insert a separator bar in the current pull-down menu
00061 
00062     virtual gui::SceneControl* graphicsWindow(float size=100, int initial_view=1)=0;
00063     // Create and return a SceneControl object that can create gui graphics in the graphical
00064     // portion of the window.
00065 
00066     virtual std::ostream* textWindow(const char*)=0;
00067     // Create and return an ostream object. (Which may just be cout for unix.)
00068 
00069     virtual void start();
00070     virtual void run(int pause_interval=-1);
00071     // Start the window system. For a real GUI, this is a message loop.
00072 
00073     virtual void quit();
00074     // End the window system. Typically bound to a "Exit" button.
00075 
00076     virtual void setTitle(const char* newtitle);
00077     // Set the window title
00078 
00079     virtual void processMessages();
00080     // Process waiting messages (needed if single thread)
00081 
00082     virtual char * askForFileName(const char* a, const char* b, const char* c);
00083     // File name dialog box.
00084 
00085     virtual char * askUser(const char* promptString,const char* defaultString);
00086     // Simple dialog box that sets a string
00087 
00088     virtual void inform(const char* msg);
00089     // Dialog box with a message.
00090 
00091     static GUI* createGUI(const char* appname=0, const char* title=0);
00092     // Return a GUI. Expect subclass to implement. Prevents more that one GUI implementation
00093     // in an executable
00094 
00095     static GUI* instance(GUI* i=0);
00096     static bool running;  // use to check that GUI has been started
00097 
00098 protected:
00099     GUI(const char* title);  // abstract class
00100     const char* _winTitle;   // window title
00101 private:
00102     static GUI* s_instance;  // public to allow simple setup
00103 
00104 };
00105 
00106 inline GUI::GUI(const char* title):_winTitle(title){}  // abstract class
00107 inline GUI::~GUI(){}
00108 inline void    GUI::addToMenu(const char* , Command* ){}
00109 inline GUI::Toggle*   GUI::addToggleToMenu(const char*, bool, Command*, Command* ){return 0;}
00110 inline GUI::Menu*   GUI::beginPullDownMenu(const char*, GUI::Menu*){return 0;}
00111 inline void    GUI::restorePullDownMenu(GUI::Menu* ){}
00112 inline void    GUI::endPullDownMenu(){}
00113 inline void    GUI::menuSeparator(){}
00114 inline void    GUI::start(){}
00115 inline void    GUI::run(int){}
00116 inline void    GUI::quit(){}
00117 inline void    GUI::setTitle(const char*){}
00118 inline void    GUI::processMessages(){}
00119 inline char *  GUI::askForFileName(const char*, const char*, const char* ){return 0;}
00120 inline char *  GUI::askUser(const char* ,const char* ){return 0;}
00121 inline void    GUI::inform(const char* ){}
00122 
00123 
00124 } // namespace gui
00125 
00126 #endif
00127 

Generated at Wed Nov 21 12:20:55 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000