Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

fgx.h

00001 #ifndef fgxH
00002 #define fgxH
00003 
00004 // -----------------------------------------------------------------------------
00005 
00006 #include <list>
00007 
00081 class TiXmlDocument;
00082 class TiXmlElement;
00083 
00084 #ifdef FG_NAMESPACE
00085 namespace fgl {
00086 #endif
00087 
00088 class FGWindow;
00089 class XUIComponent;
00090 
00091 typedef std::list<XUIComponent *> ComponentContainer;
00092 typedef ComponentContainer::iterator ComponentIterator;
00093 typedef ComponentContainer::const_iterator CComponentIterator;
00094 
00098 class XUIComponent
00099 {
00100         friend class XUIBuilder;
00101         void init();
00102 
00103     public:
00104         static const int DEFAULT_VALUE = 0;
00105 
00106     protected:
00107 
00108         const char* id;
00109         const char* label;
00110         char        onclick[FGClosure::name_size];
00111 
00112     public:
00113         FGRect      shape;
00114 
00115         XUIComponent();
00116         XUIComponent(const char* _id, const char* _label, int x, int y, int w, int h);
00117         XUIComponent(const XUIComponent& old);
00118         virtual ~XUIComponent();
00119 
00120         virtual void AddComponent(XUIComponent *) { }
00121         virtual void RemoveComponent(void) { }
00122         virtual ComponentContainer* GetComponents() { return 0; }
00123         virtual int GetComponentCount() { return 0; }
00124 
00125         void SetId(const char* name);
00126         void SetLabel(const char* name);
00127         void SetSignalName(const char* name);
00128 
00129         const char* GetId() const { return id; }
00130         const char* GetLabel() const { return label; }
00131         const char* GetSignalName() const { return onclick; }
00132 
00133         virtual void Save(TiXmlElement* doc);
00134         virtual void Load(TiXmlElement* doc);
00135         bool LoadColor(TiXmlElement* doc, const char* name, FGColor& color);
00136         void SaveColor(TiXmlElement* doc, const char* name, FGColor& color);
00137 
00138         virtual XUIComponent* Clone() = 0;
00139         virtual void Show(XUIComponent* parent = 0) = 0;
00140         virtual bool SetData(const char data[], int size) { return false; }
00141         virtual bool SetData(const int data) { return false; }
00142         virtual bool SetData(const double data) { return false; }
00143         virtual bool Selected() { return false; }
00144         virtual FGWindow* GetParent() { return 0; }
00145 };
00146 
00150 class XUIComposite : public XUIComponent
00151 {
00152         friend class XUIBuilder;
00153     protected:
00154         ComponentContainer  childs;
00155     public:
00156         XUIComposite();
00157         XUIComposite(const char* _id, const char* _label, int x, int y, int w, int h);
00158         XUIComposite(const XUIComposite& old);
00159         virtual ~XUIComposite();
00160 
00161         virtual void Save(TiXmlElement* doc);
00162         virtual void Load(TiXmlElement* doc);
00163 
00164         virtual XUIComponent* Clone();
00165         virtual void Show(XUIComponent* parent = 0);
00166         virtual void AddComponent(XUIComponent *);
00167         virtual void RemoveComponent(void);
00168         virtual ComponentContainer* GetComponents() { return &childs; }
00169         virtual int GetComponentCount();
00170 
00171         XUIComponent* FindObject(const char* name);
00172 };
00173 
00178 class XUIControl : public XUIComponent
00179 {
00180         void init();
00181     protected:
00182         FGControl*  control;
00183     public:
00184         int         selected;
00185         int         hotkey;
00186         int         disable;
00187 
00188         XUIControl();
00189         XUIControl(const char* _id, const char* _label, int key, int x, int y, int w, int h);
00190         XUIControl(const XUIControl& );
00191         virtual ~XUIControl() {}
00192 
00193         virtual void Save(TiXmlElement* doc);
00194         virtual void Load(TiXmlElement* doc);
00195         void FixControl(FGControl* ctrl);
00196         virtual bool Selected() { return selected; }
00197         FGControl* GetControl() { return control; }
00198 
00199 };
00200 
00201 // -----------------------------------------------------------------------------
00202 
00206 class XUIText : public XUIComponent
00207 {
00208         friend class XUIBuilder;
00209     protected:
00210         FGColor ink, paper;
00211     public:
00212         XUIText();
00213         XUIText(const char* _label, int x, int y, FGColor& ink, FGColor& paper);
00214         virtual ~XUIText();
00215 
00216         virtual void Save(TiXmlElement* doc);
00217         virtual void Load(TiXmlElement* doc);
00218 
00219         virtual XUIComponent* Clone();
00220         virtual void Show(XUIComponent* parent);
00221 };
00222 
00223 // -----------------------------------------------------------------------------
00224 
00228 class XUIPushButton : public XUIControl
00229 {
00230         friend class XUIBuilder;
00231 
00232     protected:
00233     public:
00234         XUIPushButton();
00235         XUIPushButton(const char* _id, const char* _label, int key=0,
00236             int x = 0,
00237             int y = 0,
00238             int w = 80,
00239             int h = 23);
00240 
00241         virtual void Save(TiXmlElement* doc);
00242         virtual void Load(TiXmlElement* doc);
00243 
00244         virtual XUIComponent* Clone();
00245         virtual void Show(XUIComponent* parent);
00246 };
00247 
00251 class XUIEditBox : public XUIControl
00252 {
00253         friend class XUIBuilder;
00254         int inputtype;
00255     protected:
00256         void init();
00257 
00258         char        text[FGEditBox::bufsize];
00259         double      high_precision;
00260         int         integer;
00261     public:
00262         int         scrambled;
00263         int         hexadecimal;
00264 
00265         enum { STRING = 1, DOUBLE, INT };
00266 
00267         XUIEditBox();
00268         XUIEditBox(const char* _id, const char* _label, int key = 0,
00269             int x = 8,
00270             int y = 8,
00271             int w = 64,
00272             int h = 0);
00273 
00274         virtual void Save(TiXmlElement* doc);
00275         virtual void Load(TiXmlElement* doc);
00276 
00277         virtual XUIComponent* Clone();
00278         virtual void Show(XUIComponent* parent);
00279         virtual bool SetData(const char data[], int size);
00280         virtual bool SetData(const int data);
00281         virtual bool SetData(const double data);
00282 };
00283 
00287 class XUICheckBox : public XUIControl
00288 {
00289         friend class XUIBuilder;
00290         int         integer;
00291 
00292     public:
00293 
00294         XUICheckBox();
00295         XUICheckBox(const char* _id, const char* _label, int key, int x, int y);
00296 
00297         virtual void Save(TiXmlElement* doc);
00298         virtual void Load(TiXmlElement* doc);
00299 
00300         virtual XUIComponent* Clone();
00301         virtual void Show(XUIComponent* parent);
00302         virtual bool SetData(const int data);
00303 };
00304 
00308 class XUISlideBar : public XUIControl
00309 {
00310         friend class XUIBuilder;
00311         int         minimum;
00312         int         maximum;
00313         int         step;
00314         int         value;
00315         int         horizontal;
00316     public:
00317 
00318         XUISlideBar();
00319         XUISlideBar(const char* _id, int x, int y, int min, int max, int step = 1);
00320 
00321         virtual void Save(TiXmlElement* doc);
00322         virtual void Load(TiXmlElement* doc);
00323 
00324         virtual XUIComponent* Clone();
00325         virtual void Show(XUIComponent* parent);
00326         virtual bool SetData(const int data);
00327 };
00328 
00332 class XUIRadioButton : public XUIControl
00333 {
00334         friend class XUIBuilder;
00335         int         integer;
00336     protected:
00337 
00338     public:
00339 
00340         XUIRadioButton();
00341         virtual ~XUIRadioButton();
00342         XUIRadioButton(const char* _id, const char* _label, int key, int x, int y);
00343 
00344         virtual void Save(TiXmlElement* doc);
00345         virtual void Load(TiXmlElement* doc);
00346 
00347         virtual XUIComponent* Clone();
00348         virtual void Show(XUIComponent* parent);
00349         virtual bool SetData(const int data);
00350 };
00351 
00355 class XUIListBox : public XUIControl
00356 {
00357         friend class XUIBuilder;
00358         int         dropdown;
00359     protected:
00360     public:
00361         XUIListBox();
00362         XUIListBox(const XUIListBox& old);
00363         virtual ~XUIListBox();
00364         XUIListBox(const char* _id, int x, int y, int h, int w, int drop);
00365 
00366         virtual void Save(TiXmlElement* doc);
00367         virtual void Load(TiXmlElement* doc);
00368 
00369         virtual XUIComponent* Clone();
00370         virtual void Show(XUIComponent* parent);
00371         virtual bool SetData(const char data[], int size);
00372         virtual bool SetData(const int data);
00373 };
00374 
00375 // -----------------------------------------------------------------------------
00376 
00380 class XUIRadioGroup : public XUIComposite
00381 {
00382         friend class XUIBuilder;
00383 
00384         char            cbname[16];
00385         FGButtonGroup   group;
00386         int             value;
00387         int             span;
00388         int             horizontal;
00389 
00390         static void callback(CallBack cb, void* data);
00391 
00392     public:
00393         XUIRadioGroup();
00394         XUIRadioGroup(const XUIRadioGroup& old);
00395         XUIRadioGroup(const char* _id, const char* _label[], int key[], int x, int y, int span = 20, bool horizont=false);
00396         virtual ~XUIRadioGroup();
00397 
00398         virtual void Save(TiXmlElement* doc);
00399         virtual void Load(TiXmlElement* doc);
00400 
00401         virtual XUIComponent* Clone();
00402         virtual void Show(XUIComponent* parent);
00403         virtual bool SetData(const int data);
00404 };
00405 
00406 // -----------------------------------------------------------------------------
00407 
00411 class XUIMenuItem : public XUIControl
00412 {
00413         friend class XUIBuilder;
00414     public:
00415         XUIMenuItem();
00416         XUIMenuItem(const XUIMenuItem&);
00417         XUIMenuItem(const char* _id, const char* _label, int key);
00418 
00419         virtual void Save(TiXmlElement* doc);
00420         virtual void Load(TiXmlElement* doc);
00421 
00422         virtual XUIComponent* Clone();
00423         virtual void Show(XUIComponent* parent);
00424 };
00425 
00426 
00432 class XUIPopupMenu : public XUIComposite
00433 {
00434         friend class XUIBuilder;
00435         FGMenuWindow*           parent;
00436     public:
00437 
00438         XUIPopupMenu();
00439         XUIPopupMenu(const XUIPopupMenu& old);
00440         XUIPopupMenu(const char* _id, int x=0, int y=0);
00441         virtual ~XUIPopupMenu();
00442 
00443         virtual void Save(TiXmlElement* doc);
00444         virtual void Load(TiXmlElement* doc);
00445 
00446         virtual XUIComponent* Clone();
00447         virtual void Show(XUIComponent* parent);
00448         FGWindow* GetParent() { return parent; }
00449 };
00450 
00454 class XUIMenu : public XUIControl
00455 {
00456         friend class XUIBuilder;
00457         XUIComponent*   popup;              // if this memeber is valid, then it is concrete submenu
00458     public:
00459         XUIMenu();
00460         XUIMenu(const XUIMenu&);
00461         XUIMenu(const char* _id, const char* _label, int key);
00462         virtual ~XUIMenu();
00463 
00464         virtual void Save(TiXmlElement* doc);
00465         virtual void Load(TiXmlElement* doc);
00466 
00467         virtual void AddComponent(XUIComponent *);
00468         virtual XUIComponent* Clone();
00469         virtual void Show(XUIComponent* parent);
00470 
00471         static void PullDownMenuActivator(CallBack cb, void *);
00472 };
00473 
00477 class XUIMenuBar : public XUIComposite
00478 {
00479         friend class XUIBuilder;
00480 
00481         static void callback(CallBack cb, void* data);
00482 
00483     public:
00484         XUIMenuBar();
00485         XUIMenuBar(const char* _id);
00486         virtual ~XUIMenuBar();
00487 
00488         virtual void Save(TiXmlElement* doc);
00489         virtual void Load(TiXmlElement* doc);
00490 
00491         virtual XUIComponent* Clone();
00492         virtual void Show(XUIComponent* parent);
00493 };
00494 
00498 class XUIWindow : public XUIComposite
00499 {
00500         friend class XUIBuilder;
00501 
00502         FGWindow*           parent;
00503         char                handler[FGClosure::name_size];
00504 
00505         void init();
00506         void LoadChilds(TiXmlElement* doc);
00507         static void GlobalHandler(FGEvent *);
00508 
00509     public:
00510 
00511         FGColor         foreground;
00512         FGColor         background;
00513         int             title;
00514         int             frame;
00515         int             modal;
00516         int             close_on_escape;
00517         int             center;
00518         int             persistent;
00519         int             resize;
00520         int             statusbar;
00521         int             glcontext;
00522         int             sticky;
00523         int             focus;
00524         int             pictograms;
00525         int             selectmode;
00526         int             withmenu;
00527 
00528         XUIWindow(const char* _id, const char* _label, int x, int y, int w, int h);
00529         XUIWindow();
00530         XUIWindow(const XUIWindow& old);
00531         virtual ~XUIWindow();
00532 
00533         virtual void Save(TiXmlElement* doc);
00534         virtual void Load(TiXmlElement* doc);
00535 
00536         virtual XUIComponent* Clone() { return 0; };
00537         virtual void Show(XUIComponent* parent);
00538 
00539         void SetHandlerName(const char* name);
00540         FGWindow* GetParent() { return parent; }
00541 };
00542 
00543 // -----------------------------------------------------------------------------
00544 
00580 class XUIBuilder
00581 {
00582     typedef std::list<XUIWindow> WidgetList;
00583     typedef WidgetList::iterator WidgetIterator;
00584 
00585     protected:
00586         WidgetList  widgets;
00587 
00588         static void CloseApplication(CallBack cb, void*)
00589         {
00590             FGControl::Quit(cb);
00591         }
00592         static void CloseWindow(CallBack cb, void*)
00593         {
00594             FGControl::Close(cb);
00595         }
00596     public:
00597         XUIBuilder();
00598 
00599         bool LoadGUI(const char* fname, const char* widget = 0);
00600         bool SaveGUI(const char* fname);
00601         void Show(const char* widget = 0);
00602         FGWindow* GetWidget(const char* id);
00603         XUIComponent* FindObject(const char* widget_id, const char* component_id);
00604 
00605         void AddWidget(const XUIWindow& widget);
00606         bool DeleteWidget(const char* id);
00607 
00608         bool SetData(const char* widget_id, const char* component_id, const char data[], int size);
00609         bool SetData(const char* widget_id, const char* component_id, const int);
00610         bool SetData(const char* widget_id, const char* component_id, const double);
00611 };
00612 
00613 // $Id: fgx.h,v 1.13 2005/02/09 10:23:45 majo Exp $
00614 //---------------------------------------------------------------------------
00615 
00616 #ifdef FG_NAMESPACE
00617 }
00618 #endif
00619 #endif

Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0