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