Moved command information into user data.
This commit is contained in:
parent
8205c4e030
commit
49a8c070f3
2 changed files with 56 additions and 56 deletions
|
@ -17,46 +17,26 @@ SG_USING_STD(vector);
|
|||
// Callbacks.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Callback to update all property values.
|
||||
* Action callback.
|
||||
*/
|
||||
static void
|
||||
update_callback (puObject * object)
|
||||
action_callback (puObject * object)
|
||||
{
|
||||
((GUIWidget *)object->getUserData())->updateProperties();
|
||||
GUIData * action = (GUIData *)object->getUserData();
|
||||
action->widget->action(action->command);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback to close the dialog.
|
||||
*/
|
||||
static void
|
||||
close_callback (puObject * object)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of GUIData.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GUIData::GUIData (GUIWidget * w, const char * c)
|
||||
: widget(w),
|
||||
command(c)
|
||||
{
|
||||
delete ((GUIWidget *)object->getUserData());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback to apply the property value for every field.
|
||||
*/
|
||||
static void
|
||||
apply_callback (puObject * object)
|
||||
{
|
||||
((GUIWidget *)object->getUserData())->applyProperties();
|
||||
update_callback(object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback to apply the property values and close the dialog.
|
||||
*/
|
||||
static void
|
||||
close_apply_callback (puObject * object)
|
||||
{
|
||||
apply_callback(object);
|
||||
close_callback(object);
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,6 +75,21 @@ GUIWidget::display (SGPropertyNode_ptr props)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
GUIWidget::action (const string &command)
|
||||
{
|
||||
if (command == "close") {
|
||||
delete this;
|
||||
} else if (command == "apply") {
|
||||
applyProperties();
|
||||
updateProperties();
|
||||
} else if (command == "update") {
|
||||
updateProperties();
|
||||
} else if (command == "close-apply") {
|
||||
applyProperties();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GUIWidget::applyProperties ()
|
||||
|
@ -170,8 +165,6 @@ GUIWidget::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight
|
|||
void
|
||||
GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
|
||||
{
|
||||
object->setUserData(this);
|
||||
|
||||
if (props->hasValue("legend"))
|
||||
object->setLegend(props->getStringValue("legend"));
|
||||
|
||||
|
@ -186,17 +179,9 @@ GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
|
|||
}
|
||||
|
||||
if (props->hasValue("action")) {
|
||||
string action = props->getStringValue("action");
|
||||
if (action == "update")
|
||||
object->setCallback(update_callback);
|
||||
else if (action == "close")
|
||||
object->setCallback(close_callback);
|
||||
else if (action == "apply")
|
||||
object->setCallback(apply_callback);
|
||||
else if (action == "close-apply")
|
||||
object->setCallback(close_apply_callback);
|
||||
else
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Unknown GUI action " + action);
|
||||
_actions.push_back(GUIData(this, props->getStringValue("action")));
|
||||
object->setUserData(&_actions[_actions.size()-1]);
|
||||
object->setCallback(action_callback);
|
||||
}
|
||||
|
||||
object->makeReturnDefault(props->getBoolValue("default"));
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// new_gui.hxx - XML-configurable GUI subsystem.
|
||||
|
||||
#ifndef __NEW_GUI_HXX
|
||||
#define __NEW_GUI_HXX 1
|
||||
|
||||
|
@ -19,39 +21,50 @@ SG_USING_STD(map);
|
|||
#include <Main/fgfs.hxx>
|
||||
|
||||
|
||||
class GUIWidget;
|
||||
|
||||
|
||||
/**
|
||||
* User data attached to a GUI object.
|
||||
*/
|
||||
struct GUIData
|
||||
{
|
||||
GUIData (GUIWidget * w, const char * a);
|
||||
GUIWidget * widget;
|
||||
string command;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Top-level GUI widget.
|
||||
*/
|
||||
class GUIWidget
|
||||
{
|
||||
public:
|
||||
GUIWidget (SGPropertyNode_ptr props);
|
||||
virtual ~GUIWidget ();
|
||||
|
||||
virtual void updateProperties ();
|
||||
virtual void applyProperties ();
|
||||
virtual void action (const string &command);
|
||||
|
||||
private:
|
||||
|
||||
void display (SGPropertyNode_ptr props);
|
||||
|
||||
GUIWidget (const GUIWidget &); // just for safety
|
||||
|
||||
void display (SGPropertyNode_ptr props);
|
||||
virtual void updateProperties ();
|
||||
virtual void applyProperties ();
|
||||
puObject * makeObject (SGPropertyNode * props,
|
||||
int parentWidth, int parentHeight);
|
||||
|
||||
void setupObject (puObject * object, SGPropertyNode * props);
|
||||
|
||||
void setupGroup (puGroup * group, SGPropertyNode * props,
|
||||
int width, int height, bool makeFrame = false);
|
||||
|
||||
puObject * _object;
|
||||
|
||||
vector<GUIData> _actions;
|
||||
struct PropertyObject {
|
||||
PropertyObject (puObject * object, SGPropertyNode_ptr node);
|
||||
puObject * object;
|
||||
SGPropertyNode_ptr node;
|
||||
};
|
||||
|
||||
vector<PropertyObject> _propertyObjects;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,3 +87,5 @@ private:
|
|||
};
|
||||
|
||||
#endif // __NEW_GUI_HXX
|
||||
|
||||
// end of new_gui.hxx
|
||||
|
|
Loading…
Reference in a new issue