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.
|
// Callbacks.
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to update all property values.
|
* Action callback.
|
||||||
*/
|
*/
|
||||||
static void
|
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.
|
////////////////////////////////////////////////////////////////////////
|
||||||
*/
|
// Implementation of GUIData.
|
||||||
static void
|
////////////////////////////////////////////////////////////////////////
|
||||||
close_callback (puObject * object)
|
|
||||||
|
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
|
void
|
||||||
GUIWidget::applyProperties ()
|
GUIWidget::applyProperties ()
|
||||||
|
@ -170,8 +165,6 @@ GUIWidget::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight
|
||||||
void
|
void
|
||||||
GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
|
GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
|
||||||
{
|
{
|
||||||
object->setUserData(this);
|
|
||||||
|
|
||||||
if (props->hasValue("legend"))
|
if (props->hasValue("legend"))
|
||||||
object->setLegend(props->getStringValue("legend"));
|
object->setLegend(props->getStringValue("legend"));
|
||||||
|
|
||||||
|
@ -186,17 +179,9 @@ GUIWidget::setupObject (puObject * object, SGPropertyNode * props)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props->hasValue("action")) {
|
if (props->hasValue("action")) {
|
||||||
string action = props->getStringValue("action");
|
_actions.push_back(GUIData(this, props->getStringValue("action")));
|
||||||
if (action == "update")
|
object->setUserData(&_actions[_actions.size()-1]);
|
||||||
object->setCallback(update_callback);
|
object->setCallback(action_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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object->makeReturnDefault(props->getBoolValue("default"));
|
object->makeReturnDefault(props->getBoolValue("default"));
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// new_gui.hxx - XML-configurable GUI subsystem.
|
||||||
|
|
||||||
#ifndef __NEW_GUI_HXX
|
#ifndef __NEW_GUI_HXX
|
||||||
#define __NEW_GUI_HXX 1
|
#define __NEW_GUI_HXX 1
|
||||||
|
|
||||||
|
@ -19,39 +21,50 @@ SG_USING_STD(map);
|
||||||
#include <Main/fgfs.hxx>
|
#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
|
class GUIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GUIWidget (SGPropertyNode_ptr props);
|
GUIWidget (SGPropertyNode_ptr props);
|
||||||
virtual ~GUIWidget ();
|
virtual ~GUIWidget ();
|
||||||
|
|
||||||
virtual void updateProperties ();
|
virtual void action (const string &command);
|
||||||
virtual void applyProperties ();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void display (SGPropertyNode_ptr props);
|
|
||||||
|
|
||||||
GUIWidget (const GUIWidget &); // just for safety
|
GUIWidget (const GUIWidget &); // just for safety
|
||||||
|
void display (SGPropertyNode_ptr props);
|
||||||
|
virtual void updateProperties ();
|
||||||
|
virtual void applyProperties ();
|
||||||
puObject * makeObject (SGPropertyNode * props,
|
puObject * makeObject (SGPropertyNode * props,
|
||||||
int parentWidth, int parentHeight);
|
int parentWidth, int parentHeight);
|
||||||
|
|
||||||
void setupObject (puObject * object, SGPropertyNode * props);
|
void setupObject (puObject * object, SGPropertyNode * props);
|
||||||
|
|
||||||
void setupGroup (puGroup * group, SGPropertyNode * props,
|
void setupGroup (puGroup * group, SGPropertyNode * props,
|
||||||
int width, int height, bool makeFrame = false);
|
int width, int height, bool makeFrame = false);
|
||||||
|
|
||||||
puObject * _object;
|
puObject * _object;
|
||||||
|
vector<GUIData> _actions;
|
||||||
struct PropertyObject {
|
struct PropertyObject {
|
||||||
PropertyObject (puObject * object, SGPropertyNode_ptr node);
|
PropertyObject (puObject * object, SGPropertyNode_ptr node);
|
||||||
puObject * object;
|
puObject * object;
|
||||||
SGPropertyNode_ptr node;
|
SGPropertyNode_ptr node;
|
||||||
};
|
};
|
||||||
|
|
||||||
vector<PropertyObject> _propertyObjects;
|
vector<PropertyObject> _propertyObjects;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,3 +87,5 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __NEW_GUI_HXX
|
#endif // __NEW_GUI_HXX
|
||||||
|
|
||||||
|
// end of new_gui.hxx
|
||||||
|
|
Loading…
Reference in a new issue