2003-01-18 15:16:34 +00:00
|
|
|
|
// dialog.cxx: implementation of an XML-configurable dialog box.
|
|
|
|
|
|
2006-02-18 13:58:09 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-03-26 10:09:34 +00:00
|
|
|
|
#include <stdlib.h> // atof()
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
#include <Input/input.hxx>
|
2006-03-08 10:44:46 +00:00
|
|
|
|
#include <Scripting/NasalSys.hxx>
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
#include "dialog.hxx"
|
|
|
|
|
#include "new_gui.hxx"
|
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
|
#include "AirportList.hxx"
|
2006-05-22 14:35:39 +00:00
|
|
|
|
#include "property_list.hxx"
|
2004-05-12 15:36:07 +00:00
|
|
|
|
#include "layout.hxx"
|
2003-11-27 23:41:00 +00:00
|
|
|
|
|
2006-05-22 16:14:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-11-02 13:52:01 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of GUIInfo.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-11-02 13:11:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* User data for a GUI object.
|
|
|
|
|
*/
|
|
|
|
|
struct GUIInfo
|
|
|
|
|
{
|
|
|
|
|
GUIInfo (FGDialog * d);
|
|
|
|
|
virtual ~GUIInfo ();
|
|
|
|
|
|
|
|
|
|
FGDialog * dialog;
|
|
|
|
|
vector <FGBinding *> bindings;
|
|
|
|
|
int key;
|
|
|
|
|
};
|
|
|
|
|
|
2005-11-02 13:52:01 +00:00
|
|
|
|
GUIInfo::GUIInfo (FGDialog * d)
|
|
|
|
|
: dialog(d),
|
|
|
|
|
key(-1)
|
|
|
|
|
{
|
|
|
|
|
}
|
2005-11-02 13:11:19 +00:00
|
|
|
|
|
2005-11-02 13:52:01 +00:00
|
|
|
|
GUIInfo::~GUIInfo ()
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int i = 0; i < bindings.size(); i++) {
|
|
|
|
|
delete bindings[i];
|
|
|
|
|
bindings[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
2005-11-02 13:52:01 +00:00
|
|
|
|
|
2005-11-02 13:11:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Key handler.
|
|
|
|
|
*/
|
|
|
|
|
int fgPopup::checkKey(int key, int updown)
|
|
|
|
|
{
|
|
|
|
|
if (updown == PU_UP || !isVisible() || !isActive() || window != puGetWindow())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
puObject *input = getActiveInputField(this);
|
|
|
|
|
if (input)
|
|
|
|
|
return input->checkKey(key, updown);
|
|
|
|
|
|
|
|
|
|
puObject *object = getKeyObject(this, key);
|
|
|
|
|
if (!object)
|
|
|
|
|
return puPopup::checkKey(key, updown);
|
|
|
|
|
|
2005-11-05 18:41:43 +00:00
|
|
|
|
// invokeCallback() isn't enough; we need to simulate a mouse button press
|
|
|
|
|
object->checkHit(PU_LEFT_BUTTON, PU_DOWN,
|
|
|
|
|
(object->getABox()->min[0] + object->getABox()->max[0]) / 2,
|
|
|
|
|
(object->getABox()->min[1] + object->getABox()->max[1]) / 2);
|
|
|
|
|
object->checkHit(PU_LEFT_BUTTON, PU_UP,
|
|
|
|
|
(object->getABox()->min[0] + object->getABox()->max[0]) / 2,
|
|
|
|
|
(object->getABox()->min[1] + object->getABox()->max[1]) / 2);
|
2005-11-02 13:11:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puObject *fgPopup::getKeyObject(puObject *object, int key)
|
|
|
|
|
{
|
|
|
|
|
puObject *ret;
|
|
|
|
|
if(object->getType() & PUCLASS_GROUP)
|
|
|
|
|
for (puObject *obj = ((puGroup *)object)->getFirstChild();
|
|
|
|
|
obj; obj = obj->getNextObject())
|
|
|
|
|
if ((ret = getKeyObject(obj, key)))
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
GUIInfo *info = (GUIInfo *)object->getUserData();
|
|
|
|
|
if (info && info->key == key)
|
2005-11-05 18:41:43 +00:00
|
|
|
|
return object;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puObject *fgPopup::getActiveInputField(puObject *object)
|
|
|
|
|
{
|
2005-11-03 20:15:05 +00:00
|
|
|
|
puObject *ret;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
if(object->getType() & PUCLASS_GROUP)
|
|
|
|
|
for (puObject *obj = ((puGroup *)object)->getFirstChild();
|
|
|
|
|
obj; obj = obj->getNextObject())
|
2005-11-03 20:15:05 +00:00
|
|
|
|
if ((ret = getActiveInputField(obj)))
|
|
|
|
|
return ret;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
|
|
|
|
|
if (object->getType() & PUCLASS_INPUT && ((puInput *)object)->isAcceptingInput())
|
|
|
|
|
return object;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mouse handler.
|
|
|
|
|
*/
|
2004-05-03 00:40:50 +00:00
|
|
|
|
int fgPopup::checkHit(int button, int updown, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
int result = puPopup::checkHit(button, updown, x, y);
|
|
|
|
|
|
2005-05-02 12:14:12 +00:00
|
|
|
|
if ( !_draggable)
|
|
|
|
|
return result;
|
|
|
|
|
|
2004-05-03 00:40:50 +00:00
|
|
|
|
// This is annoying. We would really want a true result from the
|
|
|
|
|
// superclass to indicate "handled by child object", but all it
|
|
|
|
|
// tells us is that the pointer is inside the dialog. So do the
|
|
|
|
|
// intersection test (again) to make sure we don't start a drag
|
2004-05-14 17:16:35 +00:00
|
|
|
|
// when inside controls.
|
2005-03-24 13:41:43 +00:00
|
|
|
|
|
|
|
|
|
if(updown == PU_DOWN && !_dragging) {
|
|
|
|
|
if(!result)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
int hit = getHitObjects(this, x, y);
|
|
|
|
|
if(hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT))
|
2004-05-03 00:40:50 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
int px, py;
|
|
|
|
|
getPosition(&px, &py);
|
|
|
|
|
_dragging = true;
|
|
|
|
|
_dX = px - x;
|
|
|
|
|
_dY = py - y;
|
|
|
|
|
} else if(updown == PU_DRAG && _dragging) {
|
|
|
|
|
setPosition(x + _dX, y + _dY);
|
|
|
|
|
} else {
|
|
|
|
|
_dragging = false;
|
|
|
|
|
}
|
2005-03-24 13:41:43 +00:00
|
|
|
|
return result;
|
2004-05-03 00:40:50 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2005-03-24 13:41:43 +00:00
|
|
|
|
int fgPopup::getHitObjects(puObject *object, int x, int y)
|
|
|
|
|
{
|
2006-07-10 14:56:07 +00:00
|
|
|
|
if (!object->isVisible())
|
|
|
|
|
return 0;
|
|
|
|
|
|
2005-03-24 13:41:43 +00:00
|
|
|
|
int type = 0;
|
|
|
|
|
if(object->getType() & PUCLASS_GROUP)
|
|
|
|
|
for (puObject *obj = ((puGroup *)object)->getFirstChild();
|
|
|
|
|
obj; obj = obj->getNextObject())
|
|
|
|
|
type |= getHitObjects(obj, x, y);
|
|
|
|
|
|
|
|
|
|
int cx, cy, cw, ch;
|
|
|
|
|
object->getAbsolutePosition(&cx, &cy);
|
|
|
|
|
object->getSize(&cw, &ch);
|
|
|
|
|
if(x >= cx && x < cx + cw && y >= cy && y < cy + ch)
|
|
|
|
|
type |= object->getType();
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Callbacks.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Action callback.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
action_callback (puObject * object)
|
|
|
|
|
{
|
|
|
|
|
GUIInfo * info = (GUIInfo *)object->getUserData();
|
2003-01-18 21:10:49 +00:00
|
|
|
|
NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
|
2003-01-20 16:01:16 +00:00
|
|
|
|
gui->setActiveDialog(info->dialog);
|
2003-01-19 23:04:03 +00:00
|
|
|
|
int nBindings = info->bindings.size();
|
|
|
|
|
for (int i = 0; i < nBindings; i++) {
|
2003-01-18 15:16:34 +00:00
|
|
|
|
info->bindings[i]->fire();
|
2003-01-20 16:01:16 +00:00
|
|
|
|
if (gui->getActiveDialog() == 0)
|
2003-01-19 23:04:03 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-01-20 16:01:16 +00:00
|
|
|
|
gui->setActiveDialog(0);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-03-26 10:09:34 +00:00
|
|
|
|
static void
|
|
|
|
|
format_callback(puObject *obj, int dx, int dy, void *n)
|
|
|
|
|
{
|
|
|
|
|
SGPropertyNode *node = (SGPropertyNode *)n;
|
|
|
|
|
const char *format = node->getStringValue("format"), *f = format;
|
2005-03-29 08:35:13 +00:00
|
|
|
|
bool number, l = false;
|
2005-03-26 10:09:34 +00:00
|
|
|
|
// make sure the format matches '[ -+#]?\d*(\.\d*)?l?[fs]'
|
|
|
|
|
for (; *f; f++) {
|
|
|
|
|
if (*f == '%') {
|
|
|
|
|
if (f[1] == '%')
|
|
|
|
|
f++;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (*f++ != '%')
|
|
|
|
|
return;
|
|
|
|
|
if (*f == ' ' || *f == '+' || *f == '-' || *f == '#')
|
|
|
|
|
f++;
|
|
|
|
|
while (*f && isdigit(*f))
|
|
|
|
|
f++;
|
|
|
|
|
if (*f == '.') {
|
|
|
|
|
f++;
|
|
|
|
|
while (*f && isdigit(*f))
|
|
|
|
|
f++;
|
|
|
|
|
}
|
|
|
|
|
if (*f == 'l')
|
2005-03-29 08:35:13 +00:00
|
|
|
|
l = true, f++;
|
2005-03-26 10:09:34 +00:00
|
|
|
|
|
|
|
|
|
if (*f == 'f')
|
|
|
|
|
number = true;
|
2005-03-29 08:35:13 +00:00
|
|
|
|
else if (*f == 's') {
|
|
|
|
|
if (l)
|
|
|
|
|
return;
|
2005-03-26 10:09:34 +00:00
|
|
|
|
number = false;
|
2005-03-29 08:35:13 +00:00
|
|
|
|
} else
|
2005-03-26 10:09:34 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (++f; *f; f++) {
|
|
|
|
|
if (*f == '%') {
|
|
|
|
|
if (f[1] == '%')
|
|
|
|
|
f++;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-26 10:45:00 +00:00
|
|
|
|
char buf[256];
|
2005-03-26 10:09:34 +00:00
|
|
|
|
const char *src = obj->getLabel();
|
|
|
|
|
|
|
|
|
|
if (number) {
|
|
|
|
|
float value = atof(src);
|
|
|
|
|
snprintf(buf, 256, format, value);
|
|
|
|
|
} else {
|
|
|
|
|
snprintf(buf, 256, format, src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buf[255] = '\0';
|
|
|
|
|
|
|
|
|
|
SGPropertyNode *result = node->getNode("formatted", true);
|
|
|
|
|
result->setStringValue(buf);
|
|
|
|
|
obj->setLabel(result->getStringValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Static helper functions.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copy a property value to a PUI object.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
copy_to_pui (SGPropertyNode * node, puObject * object)
|
|
|
|
|
{
|
2004-05-15 21:41:42 +00:00
|
|
|
|
// Treat puText objects specially, so their "values" can be set
|
|
|
|
|
// from properties.
|
|
|
|
|
if(object->getType() & PUCLASS_TEXT) {
|
|
|
|
|
object->setLabel(node->getStringValue());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
switch (node->getType()) {
|
|
|
|
|
case SGPropertyNode::BOOL:
|
|
|
|
|
case SGPropertyNode::INT:
|
|
|
|
|
case SGPropertyNode::LONG:
|
|
|
|
|
object->setValue(node->getIntValue());
|
|
|
|
|
break;
|
|
|
|
|
case SGPropertyNode::FLOAT:
|
|
|
|
|
case SGPropertyNode::DOUBLE:
|
|
|
|
|
object->setValue(node->getFloatValue());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
object->setValue(node->getStringValue());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
copy_from_pui (puObject * object, SGPropertyNode * node)
|
|
|
|
|
{
|
2004-05-15 21:41:42 +00:00
|
|
|
|
// puText objects are immutable, so should not be copied out
|
|
|
|
|
if(object->getType() & PUCLASS_TEXT)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
switch (node->getType()) {
|
|
|
|
|
case SGPropertyNode::BOOL:
|
|
|
|
|
case SGPropertyNode::INT:
|
|
|
|
|
case SGPropertyNode::LONG:
|
|
|
|
|
node->setIntValue(object->getIntegerValue());
|
|
|
|
|
break;
|
|
|
|
|
case SGPropertyNode::FLOAT:
|
|
|
|
|
case SGPropertyNode::DOUBLE:
|
|
|
|
|
node->setFloatValue(object->getFloatValue());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2005-01-31 10:36:59 +00:00
|
|
|
|
// Special case to handle lists, as getStringValue cannot be overridden
|
|
|
|
|
if(object->getType() & PUCLASS_LIST)
|
|
|
|
|
{
|
2006-03-22 10:56:49 +00:00
|
|
|
|
const char *s = ((puList *) object)->getListStringValue();
|
|
|
|
|
if (s)
|
|
|
|
|
node->setStringValue(s);
|
2005-01-31 10:36:59 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
node->setStringValue(object->getStringValue());
|
|
|
|
|
}
|
2003-01-19 17:21:38 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGDialog.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2003-01-21 15:44:21 +00:00
|
|
|
|
FGDialog::FGDialog (SGPropertyNode * props)
|
2005-07-07 21:30:34 +00:00
|
|
|
|
: _object(0),
|
2006-01-29 21:21:56 +00:00
|
|
|
|
_gui((NewGUI *)globals->get_subsystem("gui")),
|
|
|
|
|
_props(props)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-03-08 10:44:46 +00:00
|
|
|
|
_module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
|
|
|
|
|
SGPropertyNode *nasal = props->getNode("nasal");
|
|
|
|
|
if (nasal) {
|
|
|
|
|
_nasal_close = nasal->getNode("close");
|
|
|
|
|
SGPropertyNode *open = nasal->getNode("open");
|
|
|
|
|
if (open) {
|
|
|
|
|
const char *s = open->getStringValue();
|
|
|
|
|
FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
|
2006-04-27 15:56:51 +00:00
|
|
|
|
nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), props);
|
2006-03-08 10:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
display(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGDialog::~FGDialog ()
|
|
|
|
|
{
|
2006-01-29 21:21:56 +00:00
|
|
|
|
int x, y;
|
|
|
|
|
_object->getAbsolutePosition(&x, &y);
|
|
|
|
|
_props->setIntValue("lastx", x);
|
|
|
|
|
_props->setIntValue("lasty", y);
|
2006-03-08 10:44:46 +00:00
|
|
|
|
|
|
|
|
|
FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
|
|
|
|
|
if (_nasal_close) {
|
|
|
|
|
const char *s = _nasal_close->getStringValue();
|
2006-04-27 15:56:51 +00:00
|
|
|
|
nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
|
2006-03-08 10:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
nas->deleteModule(_module.c_str());
|
|
|
|
|
|
2003-01-20 16:01:16 +00:00
|
|
|
|
puDeleteObject(_object);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2003-03-21 20:39:27 +00:00
|
|
|
|
unsigned int i;
|
2003-01-20 16:01:16 +00:00
|
|
|
|
// Delete all the info objects we
|
|
|
|
|
// were forced to keep around because
|
|
|
|
|
// PUI cannot delete its own user data.
|
2003-01-18 15:16:34 +00:00
|
|
|
|
for (i = 0; i < _info.size(); i++) {
|
2003-01-20 16:01:16 +00:00
|
|
|
|
delete (GUIInfo *)_info[i];
|
2003-01-18 15:16:34 +00:00
|
|
|
|
_info[i] = 0;
|
|
|
|
|
}
|
2003-01-20 16:01:16 +00:00
|
|
|
|
// Finally, delete the property links.
|
2003-01-18 15:16:34 +00:00
|
|
|
|
for (i = 0; i < _propertyObjects.size(); i++) {
|
|
|
|
|
delete _propertyObjects[i];
|
|
|
|
|
_propertyObjects[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2006-04-28 11:49:11 +00:00
|
|
|
|
FGDialog::updateValues (const char * objectName)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-04-28 12:56:11 +00:00
|
|
|
|
if (objectName && !objectName[0])
|
|
|
|
|
objectName = 0;
|
|
|
|
|
|
2003-03-21 20:39:27 +00:00
|
|
|
|
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
|
2003-01-19 17:21:38 +00:00
|
|
|
|
const string &name = _propertyObjects[i]->name;
|
2006-04-28 12:14:23 +00:00
|
|
|
|
if (objectName && name != objectName)
|
2006-04-28 11:49:11 +00:00
|
|
|
|
continue;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2006-04-28 11:49:11 +00:00
|
|
|
|
puObject *obj = _propertyObjects[i]->object;
|
2006-05-21 22:14:18 +00:00
|
|
|
|
if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast<GUI_ID *>(obj)->id & FGCLASS_LIST)) {
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgList *pl = static_cast<fgList *>(obj);
|
|
|
|
|
pl->update();
|
|
|
|
|
} else
|
2006-04-28 15:55:41 +00:00
|
|
|
|
copy_to_pui(_propertyObjects[i]->node, obj);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2006-04-28 11:49:11 +00:00
|
|
|
|
FGDialog::applyValues (const char * objectName)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-04-28 12:56:11 +00:00
|
|
|
|
if (objectName && !objectName[0])
|
|
|
|
|
objectName = 0;
|
|
|
|
|
|
2006-04-28 11:49:11 +00:00
|
|
|
|
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
|
|
|
|
|
const string &name = _propertyObjects[i]->name;
|
2006-04-28 12:14:23 +00:00
|
|
|
|
if (objectName && name != objectName)
|
2006-04-28 11:49:11 +00:00
|
|
|
|
continue;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
copy_from_pui(_propertyObjects[i]->object,
|
|
|
|
|
_propertyObjects[i]->node);
|
2006-04-28 11:49:11 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-05-14 17:16:35 +00:00
|
|
|
|
void
|
|
|
|
|
FGDialog::update ()
|
|
|
|
|
{
|
2005-03-24 13:41:43 +00:00
|
|
|
|
for (unsigned int i = 0; i < _liveObjects.size(); i++) {
|
|
|
|
|
puObject *obj = _liveObjects[i]->object;
|
|
|
|
|
if (obj->getType() & PUCLASS_INPUT && ((puInput *)obj)->isAcceptingInput())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
copy_to_pui(_liveObjects[i]->node, obj);
|
|
|
|
|
}
|
2004-05-14 17:16:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
void
|
2003-01-21 15:44:21 +00:00
|
|
|
|
FGDialog::display (SGPropertyNode * props)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (_object != 0) {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
int screenw = globals->get_props()->getIntValue("/sim/startup/xsize");
|
|
|
|
|
int screenh = globals->get_props()->getIntValue("/sim/startup/ysize");
|
|
|
|
|
|
2005-05-17 09:56:52 +00:00
|
|
|
|
bool userx = props->hasValue("x");
|
|
|
|
|
bool usery = props->hasValue("y");
|
2005-05-16 09:05:17 +00:00
|
|
|
|
bool userw = props->hasValue("width");
|
|
|
|
|
bool userh = props->hasValue("height");
|
2004-05-14 17:16:35 +00:00
|
|
|
|
|
2005-07-02 20:49:38 +00:00
|
|
|
|
// Let the layout widget work in the same property subtree.
|
2004-05-12 15:36:07 +00:00
|
|
|
|
LayoutWidget wid(props);
|
2005-05-17 09:56:52 +00:00
|
|
|
|
|
2006-01-27 12:57:13 +00:00
|
|
|
|
SGPropertyNode *fontnode = props->getNode("font");
|
|
|
|
|
if (fontnode) {
|
2006-06-05 20:25:43 +00:00
|
|
|
|
FGFontCache *fc = globals->get_fontcache();
|
2006-01-27 12:57:13 +00:00
|
|
|
|
_font = fc->get(fontnode);
|
|
|
|
|
} else {
|
|
|
|
|
_font = _gui->getDefaultFont();
|
|
|
|
|
}
|
|
|
|
|
wid.setDefaultFont(_font, int(_font->getPointSize()));
|
2005-07-08 20:12:06 +00:00
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
int pw=0, ph=0;
|
2005-11-06 23:53:30 +00:00
|
|
|
|
int px, py, savex, savey;
|
2004-05-14 17:16:35 +00:00
|
|
|
|
if(!userw || !userh)
|
2004-05-12 15:36:07 +00:00
|
|
|
|
wid.calcPrefSize(&pw, &ph);
|
|
|
|
|
pw = props->getIntValue("width", pw);
|
|
|
|
|
ph = props->getIntValue("height", ph);
|
2005-11-06 23:53:30 +00:00
|
|
|
|
px = savex = props->getIntValue("x", (screenw - pw) / 2);
|
|
|
|
|
py = savey = props->getIntValue("y", (screenh - ph) / 2);
|
|
|
|
|
|
|
|
|
|
// Negative x/y coordinates are interpreted as distance from the top/right
|
|
|
|
|
// corner rather than bottom/left.
|
2006-02-12 19:43:53 +00:00
|
|
|
|
if (userx && px < 0)
|
2005-11-06 23:53:30 +00:00
|
|
|
|
px = screenw - pw + px;
|
2006-02-12 19:43:53 +00:00
|
|
|
|
if (usery && py < 0)
|
2005-11-06 23:53:30 +00:00
|
|
|
|
py = screenh - ph + py;
|
2005-05-17 09:56:52 +00:00
|
|
|
|
|
|
|
|
|
// Define "x", "y", "width" and/or "height" in the property tree if they
|
|
|
|
|
// are not specified in the configuration file.
|
2004-05-12 15:36:07 +00:00
|
|
|
|
wid.layout(px, py, pw, ph);
|
|
|
|
|
|
2005-05-17 09:56:52 +00:00
|
|
|
|
// Use the dimension and location properties as specified in the
|
|
|
|
|
// configuration file or from the layout widget.
|
2004-05-12 15:36:07 +00:00
|
|
|
|
_object = makeObject(props, screenw, screenh);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2004-05-14 17:16:35 +00:00
|
|
|
|
// Remove automatically generated properties, so the layout looks
|
2005-11-06 23:53:30 +00:00
|
|
|
|
// the same next time around, or restore x and y to preserve negative coords.
|
|
|
|
|
if(userx)
|
|
|
|
|
props->setIntValue("x", savex);
|
|
|
|
|
else
|
|
|
|
|
props->removeChild("x");
|
|
|
|
|
|
|
|
|
|
if(usery)
|
|
|
|
|
props->setIntValue("y", savey);
|
|
|
|
|
else
|
|
|
|
|
props->removeChild("y");
|
|
|
|
|
|
2005-05-17 09:56:52 +00:00
|
|
|
|
if(!userw) props->removeChild("width");
|
|
|
|
|
if(!userh) props->removeChild("height");
|
2004-05-14 17:16:35 +00:00
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (_object != 0) {
|
|
|
|
|
_object->reveal();
|
|
|
|
|
} else {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
|
|
|
|
|
<< props->getStringValue("name", "[unnamed]")
|
|
|
|
|
<< " does not contain a proper GUI definition");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puObject *
|
|
|
|
|
FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
|
|
|
|
|
{
|
2005-10-21 17:47:48 +00:00
|
|
|
|
if (props->getBoolValue("hide"))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
bool presetSize = props->hasValue("width") && props->hasValue("height");
|
2003-01-18 15:16:34 +00:00
|
|
|
|
int width = props->getIntValue("width", parentWidth);
|
|
|
|
|
int height = props->getIntValue("height", parentHeight);
|
|
|
|
|
int x = props->getIntValue("x", (parentWidth - width) / 2);
|
|
|
|
|
int y = props->getIntValue("y", (parentHeight - height) / 2);
|
2005-07-02 20:49:38 +00:00
|
|
|
|
string type = props->getName();
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (type == "")
|
2003-01-21 02:08:41 +00:00
|
|
|
|
type = "dialog";
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
if (type == "dialog") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puPopup * obj;
|
2005-05-02 12:14:12 +00:00
|
|
|
|
bool draggable = props->getBoolValue("draggable", true);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (props->getBoolValue("modal", false))
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puDialogBox(x, y);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
else
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new fgPopup(x, y, draggable);
|
|
|
|
|
setupGroup(obj, props, width, height, true);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "group") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puGroup * obj = new puGroup(x, y);
|
|
|
|
|
setupGroup(obj, props, width, height, false);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2005-05-06 11:46:52 +00:00
|
|
|
|
} else if (type == "frame") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puGroup * obj = new puGroup(x, y);
|
|
|
|
|
setupGroup(obj, props, width, height, true);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2005-07-02 20:49:38 +00:00
|
|
|
|
} else if (type == "hrule" || type == "vrule") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puFrame * obj = new puFrame(x, y, x + width, y + height);
|
|
|
|
|
obj->setBorderThickness(0);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
|
} else if (type == "list") {
|
2006-03-23 23:02:48 +00:00
|
|
|
|
int slider_width = props->getIntValue("slider", 20);
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgList * obj = new fgList(x, y, x + width, y + height, props, slider_width);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2006-03-23 23:02:48 +00:00
|
|
|
|
obj->setSize(width, height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
|
} else if (type == "airport-list") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
AirportList * obj = new AirportList(x, y, x + width, y + height);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
|
|
|
|
obj->setSize(width, height);
|
2006-05-22 14:35:39 +00:00
|
|
|
|
setupObject(obj, props);
|
|
|
|
|
setColor(obj, props);
|
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
|
|
} else if (type == "property-list") {
|
|
|
|
|
PropertyList * obj = new PropertyList(x, y, x + width, y + height, globals->get_props());
|
|
|
|
|
if (presetSize)
|
|
|
|
|
obj->setSize(width, height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "input") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puInput * obj = new puInput(x, y, x + width, y + height);
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "text") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puText * obj = new puText(x, y);
|
|
|
|
|
setupObject(obj, props);
|
2005-03-26 10:09:34 +00:00
|
|
|
|
|
2005-03-29 08:35:13 +00:00
|
|
|
|
if (props->getNode("format")) {
|
|
|
|
|
SGPropertyNode *live = props->getNode("live");
|
|
|
|
|
if (live && live->getBoolValue())
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setRenderCallback(format_callback, props);
|
2005-03-29 08:35:13 +00:00
|
|
|
|
else
|
2005-07-07 21:30:34 +00:00
|
|
|
|
format_callback(obj, x, y, props);
|
2005-03-29 08:35:13 +00:00
|
|
|
|
}
|
2004-05-12 15:36:07 +00:00
|
|
|
|
// Layed-out objects need their size set, and non-layout ones
|
|
|
|
|
// get a different placement.
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
|
|
|
|
obj->setSize(width, height);
|
|
|
|
|
else
|
|
|
|
|
obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setColor(obj, props, LABEL);
|
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
} else if (type == "checkbox") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puButton * obj;
|
|
|
|
|
obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
} else if (type == "radio") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puButton * obj;
|
|
|
|
|
obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "button") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puButton * obj;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
const char * legend = props->getStringValue("legend", "[none]");
|
|
|
|
|
if (props->getBoolValue("one-shot", true))
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puOneShot(x, y, legend);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
else
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puButton(x, y, legend);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setSize(width, height);
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-19 23:04:03 +00:00
|
|
|
|
} else if (type == "combo") {
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgComboBox * obj = new fgComboBox(x, y, x + width, y + height, props,
|
2003-01-19 23:04:03 +00:00
|
|
|
|
props->getBoolValue("editable", false));
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-11-09 17:59:53 +00:00
|
|
|
|
#ifdef PUCOL_EDITFIELD // plib > 0.8.4
|
|
|
|
|
setColor(obj, props, EDITFIELD);
|
|
|
|
|
#else
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-11-09 17:59:53 +00:00
|
|
|
|
#endif
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-20 16:01:16 +00:00
|
|
|
|
} else if (type == "slider") {
|
|
|
|
|
bool vertical = props->getBoolValue("vertical", false);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puSlider * obj = new puSlider(x, y, (vertical ? height : width));
|
|
|
|
|
obj->setMinValue(props->getFloatValue("min", 0.0));
|
|
|
|
|
obj->setMaxValue(props->getFloatValue("max", 1.0));
|
|
|
|
|
setupObject(obj, props);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setSize(width, height);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-20 16:01:16 +00:00
|
|
|
|
} else if (type == "dial") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puDial * obj = new puDial(x, y, width);
|
|
|
|
|
obj->setMinValue(props->getFloatValue("min", 0.0));
|
|
|
|
|
obj->setMaxValue(props->getFloatValue("max", 1.0));
|
|
|
|
|
obj->setWrap(props->getBoolValue("wrap", true));
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2004-09-27 14:40:31 +00:00
|
|
|
|
} else if (type == "textbox") {
|
2006-03-23 23:02:48 +00:00
|
|
|
|
int slider_width = props->getIntValue("slider", 20);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
int wrap = props->getBoolValue("wrap", true);
|
2006-05-14 09:03:50 +00:00
|
|
|
|
puaLargeInput * obj = new puaLargeInput(x, y,
|
2005-07-07 21:30:34 +00:00
|
|
|
|
x+width, x+height, 2, slider_width, wrap);
|
|
|
|
|
|
2005-07-11 08:01:28 +00:00
|
|
|
|
if (props->hasValue("editable")) {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
if (props->getBoolValue("editable")==false)
|
|
|
|
|
obj->disableInput();
|
|
|
|
|
else
|
|
|
|
|
obj->enableInput();
|
|
|
|
|
}
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2006-03-23 23:02:48 +00:00
|
|
|
|
obj->setSize(width, height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-03-29 15:04:52 +00:00
|
|
|
|
} else if (type == "select") {
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgSelectBox * obj = new fgSelectBox(x, y, x + width, y + height, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-11-09 17:59:53 +00:00
|
|
|
|
#ifdef PUCOL_EDITFIELD // plib > 0.8.4
|
|
|
|
|
setColor(obj, props, EDITFIELD);
|
|
|
|
|
#else
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-11-09 17:59:53 +00:00
|
|
|
|
#endif
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGDialog::setupObject (puObject * object, SGPropertyNode * props)
|
|
|
|
|
{
|
2006-04-03 15:00:33 +00:00
|
|
|
|
string type = props->getName();
|
2004-05-12 15:36:07 +00:00
|
|
|
|
object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (props->hasValue("legend"))
|
|
|
|
|
object->setLegend(props->getStringValue("legend"));
|
|
|
|
|
|
|
|
|
|
if (props->hasValue("label"))
|
|
|
|
|
object->setLabel(props->getStringValue("label"));
|
|
|
|
|
|
2005-05-06 11:46:52 +00:00
|
|
|
|
if (props->hasValue("border"))
|
|
|
|
|
object->setBorderThickness( props->getIntValue("border", 2) );
|
|
|
|
|
|
2005-05-03 11:58:33 +00:00
|
|
|
|
if ( SGPropertyNode *nft = props->getNode("font", false) ) {
|
2006-06-05 20:25:43 +00:00
|
|
|
|
FGFontCache *fc = globals->get_fontcache();
|
2006-01-26 21:40:37 +00:00
|
|
|
|
puFont *lfnt = fc->get(nft);
|
|
|
|
|
object->setLabelFont(*lfnt);
|
2006-01-27 12:57:13 +00:00
|
|
|
|
} else {
|
|
|
|
|
object->setLabelFont(*_font);
|
2005-05-02 14:45:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (props->hasValue("property")) {
|
|
|
|
|
const char * name = props->getStringValue("name");
|
|
|
|
|
if (name == 0)
|
|
|
|
|
name = "";
|
|
|
|
|
const char * propname = props->getStringValue("property");
|
|
|
|
|
SGPropertyNode_ptr node = fgGetNode(propname, true);
|
2003-01-19 17:21:38 +00:00
|
|
|
|
copy_to_pui(node, object);
|
2006-04-28 15:55:41 +00:00
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
PropertyObject* po = new PropertyObject(name, object, node);
|
2004-05-14 17:16:35 +00:00
|
|
|
|
_propertyObjects.push_back(po);
|
|
|
|
|
if(props->getBoolValue("live"))
|
|
|
|
|
_liveObjects.push_back(po);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-24 14:07:15 +00:00
|
|
|
|
SGPropertyNode * dest = fgGetNode("/sim/bindings/gui", true);
|
2005-06-24 13:44:22 +00:00
|
|
|
|
vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
|
|
|
|
|
if (bindings.size() > 0) {
|
2003-01-18 15:16:34 +00:00
|
|
|
|
GUIInfo * info = new GUIInfo(this);
|
2005-11-02 13:11:19 +00:00
|
|
|
|
info->key = props->getIntValue("keynum", -1);
|
2005-11-05 18:41:43 +00:00
|
|
|
|
if (props->hasValue("key"))
|
|
|
|
|
info->key = getKeyCode(props->getStringValue("key", ""));
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2005-06-24 13:44:22 +00:00
|
|
|
|
for (unsigned int i = 0; i < bindings.size(); i++) {
|
|
|
|
|
unsigned int j = 0;
|
|
|
|
|
SGPropertyNode *binding;
|
|
|
|
|
while (dest->getChild("binding", j))
|
|
|
|
|
j++;
|
|
|
|
|
|
2006-03-08 10:44:46 +00:00
|
|
|
|
const char *cmd = bindings[i]->getStringValue("command");
|
2006-03-08 20:23:31 +00:00
|
|
|
|
if (!strcmp(cmd, "nasal"))
|
2006-03-08 10:44:46 +00:00
|
|
|
|
bindings[i]->setStringValue("module", _module.c_str());
|
|
|
|
|
|
2005-06-24 13:44:22 +00:00
|
|
|
|
binding = dest->getChild("binding", j, true);
|
|
|
|
|
copyProperties(bindings[i], binding);
|
|
|
|
|
info->bindings.push_back(new FGBinding(binding));
|
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
object->setCallback(action_callback);
|
2006-04-03 15:00:33 +00:00
|
|
|
|
|
|
|
|
|
if (type == "input" && props->getBoolValue("live"))
|
|
|
|
|
object->setDownCallback(action_callback);
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
object->setUserData(info);
|
|
|
|
|
_info.push_back(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object->makeReturnDefault(props->getBoolValue("default"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
|
2005-07-07 21:30:34 +00:00
|
|
|
|
int width, int height, bool makeFrame)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
|
|
|
|
setupObject(group, props);
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
if (makeFrame) {
|
|
|
|
|
puFrame* f = new puFrame(0, 0, width, height);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(f, props);
|
2004-05-12 15:36:07 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
int nChildren = props->nChildren();
|
|
|
|
|
for (int i = 0; i < nChildren; i++)
|
|
|
|
|
makeObject(props->getChild(i), width, height);
|
|
|
|
|
group->close();
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-04 07:27:17 +00:00
|
|
|
|
void
|
2005-07-07 21:30:34 +00:00
|
|
|
|
FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
|
2005-07-04 07:27:17 +00:00
|
|
|
|
{
|
2005-07-07 21:30:34 +00:00
|
|
|
|
string type = props->getName();
|
2005-07-13 07:05:50 +00:00
|
|
|
|
if (type == "")
|
|
|
|
|
type = "dialog";
|
2005-11-09 18:23:55 +00:00
|
|
|
|
if (type == "textbox" && props->getBoolValue("editable"))
|
|
|
|
|
type += "-editable";
|
2005-07-13 07:05:50 +00:00
|
|
|
|
|
2005-07-18 10:00:02 +00:00
|
|
|
|
FGColor *c = new FGColor(_gui->getColor("background"));
|
|
|
|
|
c->merge(_gui->getColor(type));
|
|
|
|
|
c->merge(props->getNode("color"));
|
|
|
|
|
if (c->isValid())
|
|
|
|
|
object->setColourScheme(c->red(), c->green(), c->blue(), c->alpha());
|
2005-07-07 21:30:34 +00:00
|
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
|
int mask;
|
|
|
|
|
int id;
|
|
|
|
|
const char *name;
|
2005-07-11 08:01:28 +00:00
|
|
|
|
const char *cname;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
} pucol[] = {
|
2005-07-13 11:43:00 +00:00
|
|
|
|
{ BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
|
|
|
|
|
{ FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
|
|
|
|
|
{ HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
|
|
|
|
|
{ LABEL, PUCOL_LABEL, "label", "color-label" },
|
|
|
|
|
{ LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
|
2005-11-09 17:59:53 +00:00
|
|
|
|
{ MISC, PUCOL_MISC, "misc", "color-misc" },
|
|
|
|
|
#ifdef PUCOL_EDITFIELD // plib > 0.8.4
|
|
|
|
|
{ EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
|
|
|
|
|
#endif
|
2005-07-07 21:30:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-11-02 13:11:19 +00:00
|
|
|
|
const int numcol = sizeof(pucol) / sizeof(pucol[0]);
|
|
|
|
|
|
2005-07-07 21:30:34 +00:00
|
|
|
|
for (int i = 0; i < numcol; i++) {
|
2005-07-11 08:01:28 +00:00
|
|
|
|
bool dirty = false;
|
2005-07-18 10:00:02 +00:00
|
|
|
|
c->clear();
|
|
|
|
|
c->setAlpha(1.0);
|
2005-07-12 16:48:16 +00:00
|
|
|
|
|
2005-07-18 10:00:02 +00:00
|
|
|
|
dirty |= c->merge(_gui->getColor(type + '-' + pucol[i].name));
|
2005-07-11 08:01:28 +00:00
|
|
|
|
if (which & pucol[i].mask)
|
2005-07-18 10:00:02 +00:00
|
|
|
|
dirty |= c->merge(props->getNode("color"));
|
2005-07-11 08:01:28 +00:00
|
|
|
|
|
2005-07-18 10:00:02 +00:00
|
|
|
|
if ((pucol[i].mask == LABEL) && !c->isValid())
|
|
|
|
|
dirty |= c->merge(_gui->getColor("label"));
|
2005-07-11 08:01:28 +00:00
|
|
|
|
|
allow to not only set a general widget <color>, but also specific element
colors: <color-{{back,fore}ground,highlight,label,legend,misc,editfield}>
<input-misc>, for example, sets the input field cursor color, <input-legend>
the input field text color. (This feature was always planned as part of the
'theming' capabilities, and most code is already in place. Only this line
was apparently fogotten. :-)
2006-04-14 10:17:09 +00:00
|
|
|
|
dirty |= c->merge(props->getNode(pucol[i].cname));
|
|
|
|
|
|
2005-07-18 10:00:02 +00:00
|
|
|
|
if (c->isValid() && dirty)
|
|
|
|
|
object->setColor(pucol[i].id, c->red(), c->green(), c->blue(), c->alpha());
|
2005-07-07 21:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-04 07:27:17 +00:00
|
|
|
|
|
2005-11-05 18:41:43 +00:00
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
int key;
|
|
|
|
|
} keymap[] = {
|
2006-03-01 14:26:17 +00:00
|
|
|
|
{"backspace", 8},
|
2005-11-05 18:41:43 +00:00
|
|
|
|
{"tab", 9},
|
|
|
|
|
{"return", 13},
|
|
|
|
|
{"enter", 13},
|
|
|
|
|
{"esc", 27},
|
|
|
|
|
{"escape", 27},
|
|
|
|
|
{"space", ' '},
|
|
|
|
|
{"&", '&'},
|
|
|
|
|
{"and", '&'},
|
|
|
|
|
{"<", '<'},
|
|
|
|
|
{">", '>'},
|
|
|
|
|
{"f1", PU_KEY_F1},
|
|
|
|
|
{"f2", PU_KEY_F2},
|
|
|
|
|
{"f3", PU_KEY_F3},
|
|
|
|
|
{"f4", PU_KEY_F4},
|
|
|
|
|
{"f5", PU_KEY_F5},
|
|
|
|
|
{"f6", PU_KEY_F6},
|
|
|
|
|
{"f7", PU_KEY_F7},
|
|
|
|
|
{"f8", PU_KEY_F8},
|
|
|
|
|
{"f9", PU_KEY_F9},
|
|
|
|
|
{"f10", PU_KEY_F10},
|
|
|
|
|
{"f11", PU_KEY_F11},
|
|
|
|
|
{"f12", PU_KEY_F12},
|
|
|
|
|
{"left", PU_KEY_LEFT},
|
|
|
|
|
{"up", PU_KEY_UP},
|
|
|
|
|
{"right", PU_KEY_RIGHT},
|
|
|
|
|
{"down", PU_KEY_DOWN},
|
|
|
|
|
{"pageup", PU_KEY_PAGE_UP},
|
|
|
|
|
{"pagedn", PU_KEY_PAGE_DOWN},
|
|
|
|
|
{"home", PU_KEY_HOME},
|
|
|
|
|
{"end", PU_KEY_END},
|
|
|
|
|
{"insert", PU_KEY_INSERT},
|
|
|
|
|
{0, -1},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
FGDialog::getKeyCode(const char *str)
|
|
|
|
|
{
|
|
|
|
|
enum {
|
|
|
|
|
CTRL = 0x1,
|
|
|
|
|
SHIFT = 0x2,
|
|
|
|
|
ALT = 0x4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
while (*str == ' ')
|
|
|
|
|
str++;
|
|
|
|
|
|
|
|
|
|
char *buf = new char[strlen(str) + 1];
|
|
|
|
|
strcpy(buf, str);
|
|
|
|
|
char *s = buf + strlen(buf);
|
|
|
|
|
while (s > str && s[-1] == ' ')
|
|
|
|
|
s--;
|
|
|
|
|
*s = 0;
|
|
|
|
|
s = buf;
|
|
|
|
|
|
|
|
|
|
int mod = 0;
|
|
|
|
|
while (1) {
|
|
|
|
|
if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
|
|
|
|
|
s += 5, mod |= CTRL;
|
|
|
|
|
else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
|
|
|
|
|
s += 6, mod |= SHIFT;
|
|
|
|
|
else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
|
|
|
|
|
s += 4, mod |= ALT;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int key = -1;
|
|
|
|
|
if (strlen(s) == 1 && isascii(*s)) {
|
|
|
|
|
key = *s;
|
|
|
|
|
if (mod & SHIFT)
|
|
|
|
|
key = toupper(key);
|
|
|
|
|
if (mod & CTRL)
|
|
|
|
|
key = toupper(key) - 64;
|
|
|
|
|
if (mod & ALT)
|
|
|
|
|
; // Alt not propagated to the gui
|
|
|
|
|
} else {
|
|
|
|
|
for (char *t = s; *t; t++)
|
|
|
|
|
*t = tolower(*t);
|
|
|
|
|
for (int i = 0; keymap[i].name; i++) {
|
|
|
|
|
if (!strcmp(s, keymap[i].name)) {
|
|
|
|
|
key = keymap[i].key;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete[] buf;
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGDialog::PropertyObject.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FGDialog::PropertyObject::PropertyObject (const char * n,
|
|
|
|
|
puObject * o,
|
|
|
|
|
SGPropertyNode_ptr p)
|
|
|
|
|
: name(n),
|
|
|
|
|
object(o),
|
|
|
|
|
node(p)
|
2006-04-28 11:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2006-05-20 11:35:28 +00:00
|
|
|
|
// Implementation of fgValueList and derived pui widgets
|
2006-05-16 12:45:38 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fgValueList::fgValueList(SGPropertyNode *p) :
|
|
|
|
|
_props(p)
|
2003-01-20 16:01:16 +00:00
|
|
|
|
{
|
2006-05-16 12:45:38 +00:00
|
|
|
|
make_list();
|
2003-01-20 16:01:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-28 11:49:11 +00:00
|
|
|
|
void
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgValueList::update()
|
2006-04-28 11:49:11 +00:00
|
|
|
|
{
|
2006-05-16 12:45:38 +00:00
|
|
|
|
destroy_list();
|
|
|
|
|
make_list();
|
2006-04-28 11:49:11 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgValueList::~fgValueList()
|
|
|
|
|
{
|
|
|
|
|
destroy_list();
|
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
void
|
|
|
|
|
fgValueList::make_list()
|
|
|
|
|
{
|
|
|
|
|
vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
|
|
|
|
|
_list = new char *[value_nodes.size() + 1];
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < value_nodes.size(); i++)
|
|
|
|
|
_list[i] = strdup((char *)value_nodes[i]->getStringValue());
|
|
|
|
|
_list[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fgValueList::destroy_list()
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-05-16 12:45:38 +00:00
|
|
|
|
for (int i = 0; _list[i] != 0; i++)
|
|
|
|
|
if (_list[i])
|
|
|
|
|
free(_list[i]);
|
|
|
|
|
delete[] _list;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fgList::update()
|
|
|
|
|
{
|
|
|
|
|
fgValueList::update();
|
|
|
|
|
newList(_list);
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
// end of dialog.cxx
|