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