]> git.mxchange.org Git - flightgear.git/blob - src/GUI/dialog.hxx
Melchior FRANZ:
[flightgear.git] / src / GUI / dialog.hxx
1 // dialog.hxx - XML-configured dialog box.
2
3 #ifndef __DIALOG_HXX
4 #define __DIALOG_HXX 1
5
6 #ifndef __cplusplus
7 # error This library requires C++
8 #endif
9
10 #include <plib/pu.h>
11
12 #include <simgear/compiler.h>   // for SG_USING_STD
13 #include <simgear/props/props.hxx>
14
15 #include <vector>
16 SG_USING_STD(vector);
17
18 class FGDialog;
19 class FGBinding;
20
21
22 /**
23  * An XML-configured dialog box.
24  *
25  * The GUI manager stores only the property tree for the dialog
26  * boxes.  This class creates a PUI dialog box on demand from
27  * the properties in that tree.  The manager recreates the dialog
28  * every time it needs to show it.
29  */
30 class FGDialog
31 {
32 public:
33
34     /**
35      * Construct a new GUI widget configured by a property tree.
36      *
37      * The configuration properties are not part of the main
38      * FlightGear property tree; the GUI manager reads them
39      * from individual configuration files.
40      *
41      * @param props A property tree describing the dialog.
42      */
43     FGDialog (SGPropertyNode * props);
44
45
46     /**
47      * Destructor.
48      */
49     virtual ~FGDialog ();
50
51
52     /**
53      * Update the values of all GUI objects with a specific name.
54      *
55      * This method copies values from the FlightGear property tree to
56      * the GUI object(s).
57      *
58      * @param objectName The name of the GUI object(s) to update.
59      *        Use the empty name for all unnamed objects.
60      */
61     virtual void updateValue (const char * objectName);
62
63
64     /**
65      * Apply the values of all GUI objects with a specific name.
66      *
67      * This method copies values from the GUI object(s) to the
68      * FlightGear property tree.
69      *
70      * @param objectName The name of the GUI object(s) to update.
71      *        Use the empty name for all unnamed objects.
72      */
73     virtual void applyValue (const char * objectName);
74
75
76     /**
77      * Update the values of all GUI objects.
78      *
79      * This method copies values from the FlightGear property tree to
80      * the GUI objects.
81      */
82     virtual void updateValues ();
83
84
85     /**
86      * Apply the values of all GUI objects.
87      *
88      * This method copies from the GUI objects to the FlightGear
89      * property tree properties.
90      */
91     virtual void applyValues ();
92
93
94     /**
95      * Update state.  Called on active dialogs before rendering.
96      */
97     virtual void update ();
98
99 private:
100
101     // Private copy constructor to avoid unpleasant surprises.
102     FGDialog (const FGDialog &);
103
104     // Show the dialog.
105     void display (SGPropertyNode * props);
106
107     // Build the dialog or a subobject of it.
108     puObject * makeObject (SGPropertyNode * props,
109                            int parentWidth, int parentHeight);
110
111     // Common configuration for all GUI objects.
112     void setupObject (puObject * object, SGPropertyNode * props);
113
114     // Common configuration for all GUI group objects.
115     void setupGroup (puGroup * group, SGPropertyNode * props,
116                      int width, int height, bool makeFrame = false);
117
118     // The top-level PUI object.
119     puObject * _object;
120
121     // PUI provides no way for userdata to be deleted automatically
122     // with a GUI object, so we have to keep track of all the special
123     // data we allocated and then free it manually when the dialog
124     // closes.
125     vector<void *> _info;
126     struct PropertyObject {
127         PropertyObject (const char * name,
128                         puObject * object,
129                         SGPropertyNode_ptr node);
130         string name;
131         puObject * object;
132         SGPropertyNode_ptr node;
133     };
134     vector<PropertyObject *> _propertyObjects;
135     vector<PropertyObject *> _liveObjects;
136
137     // PUI doesn't copy arrays, so we have to allocate string arrays
138     // and then keep pointers so that we can delete them when the
139     // dialog closes.
140     char ** make_char_array (int size);
141     vector<char **> _char_arrays;
142 };
143
144 //
145 // Custom subclass of puPopup to implement "draggable" windows in the
146 // interface.  Note that this is a subclass of puPopup, not
147 // puDialogBox.  Sadly, PUI (mis)uses subclassing to implement a
148 // boolean property: modality.  That means that we can't implement
149 // dragging of both puPopup windows and puDialogBoxes with the same
150 // code.  Rather than duplicate code, I've chosen to implement only
151 // "non-modal dragability" here.  Modal dialog boxes (like the exit
152 // confirmation) are not draggable.
153 //
154 class fgPopup : public puPopup {
155 public:
156     fgPopup(int x, int y) : puPopup(x, y) { _dragging = false; }
157     int checkHit(int b, int up, int x, int y);
158     int getHitObjects(puObject *, int x, int y);
159 private:
160     bool _dragging;
161     int _dX, _dY;
162 };
163
164 #endif // __DIALOG_HXX