]> git.mxchange.org Git - flightgear.git/blob - src/GUI/dialog.hxx
allow top level <font> definition that applies to text in the whole dialog
[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     // The dialog font. Defaults to the global gui font, but can get
146     // overridden by a top level font definition.
147     puFont * _font;
148
149     // PUI provides no way for userdata to be deleted automatically
150     // with a GUI object, so we have to keep track of all the special
151     // data we allocated and then free it manually when the dialog
152     // closes.
153     vector<void *> _info;
154     struct PropertyObject {
155         PropertyObject (const char * name,
156                         puObject * object,
157                         SGPropertyNode_ptr node);
158         string name;
159         puObject * object;
160         SGPropertyNode_ptr node;
161     };
162     vector<PropertyObject *> _propertyObjects;
163     vector<PropertyObject *> _liveObjects;
164
165     // PUI doesn't copy arrays, so we have to allocate string arrays
166     // and then keep pointers so that we can delete them when the
167     // dialog closes.
168     char ** make_char_array (int size);
169     vector<char **> _char_arrays;
170 };
171
172 //
173 // Custom subclass of puPopup to implement "draggable" windows in the
174 // interface.  Note that this is a subclass of puPopup, not
175 // puDialogBox.  Sadly, PUI (mis)uses subclassing to implement a
176 // boolean property: modality.  That means that we can't implement
177 // dragging of both puPopup windows and puDialogBoxes with the same
178 // code.  Rather than duplicate code, I've chosen to implement only
179 // "non-modal dragability" here.  Modal dialog boxes (like the exit
180 // confirmation) are not draggable.
181 //
182 class fgPopup : public puPopup {
183 public:
184     fgPopup(int x, int y, bool d = true) : puPopup(x, y) { _dragging = false; _draggable = d;}
185     int checkHit(int b, int up, int x, int y);
186     int checkKey(int key, int updown);
187     int getHitObjects(puObject *, int x, int y);
188     puObject *getKeyObject(puObject *, int key);
189     puObject *getActiveInputField(puObject *);
190 private:
191     bool _draggable;
192     bool _dragging;
193     int _dX, _dY;
194 };
195
196 #endif // __DIALOG_HXX