2003-01-18 15:16:34 +00:00
|
|
|
|
// dialog.cxx: implementation of an XML-configurable dialog box.
|
|
|
|
|
|
2005-03-26 10:09:34 +00:00
|
|
|
|
#include <stdlib.h> // atof()
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
#include <Input/input.hxx>
|
|
|
|
|
|
|
|
|
|
#include "dialog.hxx"
|
|
|
|
|
#include "new_gui.hxx"
|
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
|
#include "puList.hxx"
|
|
|
|
|
#include "AirportList.hxx"
|
2004-05-12 15:36:07 +00:00
|
|
|
|
#include "layout.hxx"
|
2003-11-27 23:41:00 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
node->setStringValue(((puList *) object)->getListStringValue());
|
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
|
_gui((NewGUI *)globals->get_subsystem("gui"))
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2005-05-03 12:20:17 +00:00
|
|
|
|
char* envp = ::getenv( "FG_FONTS" );
|
|
|
|
|
if ( envp != NULL ) {
|
|
|
|
|
_font_path.set( envp );
|
|
|
|
|
} else {
|
|
|
|
|
_font_path.set( globals->get_fg_root() );
|
|
|
|
|
_font_path.append( "Fonts" );
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
display(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGDialog::~FGDialog ()
|
|
|
|
|
{
|
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 arrays we made
|
|
|
|
|
// and were forced to keep around
|
|
|
|
|
// because PUI won't do its own
|
|
|
|
|
// memory management.
|
|
|
|
|
for (i = 0; i < _char_arrays.size(); i++) {
|
|
|
|
|
for (int j = 0; _char_arrays[i][j] != 0; j++)
|
|
|
|
|
free(_char_arrays[i][j]); // added with strdup
|
2003-05-22 08:42:38 +00:00
|
|
|
|
delete[] _char_arrays[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
|
|
|
|
|
FGDialog::updateValue (const char * objectName)
|
|
|
|
|
{
|
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;
|
|
|
|
|
if (name == objectName)
|
|
|
|
|
copy_to_pui(_propertyObjects[i]->node,
|
|
|
|
|
_propertyObjects[i]->object);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGDialog::applyValue (const char * objectName)
|
|
|
|
|
{
|
2003-03-21 20:39:27 +00:00
|
|
|
|
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (_propertyObjects[i]->name == objectName)
|
2003-01-19 17:21:38 +00:00
|
|
|
|
copy_from_pui(_propertyObjects[i]->object,
|
|
|
|
|
_propertyObjects[i]->node);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGDialog::updateValues ()
|
|
|
|
|
{
|
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
|
|
|
|
copy_to_pui(_propertyObjects[i]->node, _propertyObjects[i]->object);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGDialog::applyValues ()
|
|
|
|
|
{
|
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
|
|
|
|
copy_from_pui(_propertyObjects[i]->object,
|
|
|
|
|
_propertyObjects[i]->node);
|
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
|
|
|
|
|
2005-07-08 20:12:06 +00:00
|
|
|
|
puFont *fnt = _gui->getDefaultFont();
|
2005-07-09 14:01:52 +00:00
|
|
|
|
wid.setDefaultFont(fnt, int(fnt->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.
|
|
|
|
|
if (px < 0)
|
|
|
|
|
px = screenw - pw + px;
|
|
|
|
|
if (py < 0)
|
|
|
|
|
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") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
puList * obj = new puList(x, y, x + width, y + 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-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);
|
|
|
|
|
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.
|
2005-07-07 21:30:34 +00:00
|
|
|
|
if(presetSize) obj->setSize(width, height);
|
|
|
|
|
else obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
|
|
|
|
|
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);
|
2004-05-12 15:36:07 +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") {
|
|
|
|
|
vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
|
2003-01-20 16:01:16 +00:00
|
|
|
|
char ** entries = make_char_array(value_nodes.size());
|
2003-03-21 20:39:27 +00:00
|
|
|
|
for (unsigned int i = 0, j = value_nodes.size() - 1;
|
2003-01-19 23:04:03 +00:00
|
|
|
|
i < value_nodes.size();
|
|
|
|
|
i++, j--)
|
2003-01-20 16:01:16 +00:00
|
|
|
|
entries[i] = strdup((char *)value_nodes[i]->getStringValue());
|
2005-11-06 14:27:17 +00:00
|
|
|
|
puComboBox * obj = new puComboBox(x, y, x + width, y + height, entries,
|
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);
|
2004-05-14 17:16:35 +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") {
|
2005-07-07 21:30:34 +00:00
|
|
|
|
int slider_width = props->getIntValue("slider", parentHeight);
|
|
|
|
|
int wrap = props->getBoolValue("wrap", true);
|
|
|
|
|
if (slider_width==0) slider_width=20;
|
2005-11-06 14:27:17 +00:00
|
|
|
|
puLargeInput * obj = new puLargeInput(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();
|
|
|
|
|
}
|
|
|
|
|
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") {
|
|
|
|
|
vector<SGPropertyNode_ptr> value_nodes;
|
|
|
|
|
SGPropertyNode * selection_node =
|
|
|
|
|
fgGetNode(props->getChild("selection")->getStringValue(), true);
|
|
|
|
|
|
|
|
|
|
for (int q = 0; q < selection_node->nChildren(); q++)
|
|
|
|
|
value_nodes.push_back(selection_node->getChild(q));
|
|
|
|
|
|
|
|
|
|
char ** entries = make_char_array(value_nodes.size());
|
2003-05-09 20:40:59 +00:00
|
|
|
|
for (unsigned int i = 0, j = value_nodes.size() - 1;
|
2003-03-29 15:04:52 +00:00
|
|
|
|
i < value_nodes.size();
|
|
|
|
|
i++, j--)
|
|
|
|
|
entries[i] = strdup((char *)value_nodes[i]->getName());
|
2005-11-06 14:27:17 +00:00
|
|
|
|
puSelectBox * obj =
|
|
|
|
|
new puSelectBox(x, y, x + width, y + height, entries);
|
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)
|
|
|
|
|
{
|
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) ) {
|
|
|
|
|
SGPath path( _font_path );
|
2005-05-03 12:48:31 +00:00
|
|
|
|
const char *name = nft->getStringValue("name", "default");
|
|
|
|
|
float size = nft->getFloatValue("size", 13.0);
|
|
|
|
|
float slant = nft->getFloatValue("slant", 0.0);
|
2005-05-03 11:58:33 +00:00
|
|
|
|
path.append( name );
|
|
|
|
|
path.concat( ".txf" );
|
|
|
|
|
|
|
|
|
|
fntFont *font = new fntTexFont;
|
|
|
|
|
font->load( (char *)path.c_str() );
|
|
|
|
|
|
|
|
|
|
puFont lfnt(font, size, slant);
|
|
|
|
|
object->setLabelFont( lfnt );
|
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);
|
2004-05-14 17:16:35 +00:00
|
|
|
|
PropertyObject* po = new PropertyObject(name, object, node);
|
|
|
|
|
_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++;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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-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
|
|
|
|
|
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[] = {
|
|
|
|
|
{"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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 16:01:16 +00:00
|
|
|
|
char **
|
|
|
|
|
FGDialog::make_char_array (int size)
|
|
|
|
|
{
|
|
|
|
|
char ** list = new char*[size+1];
|
|
|
|
|
for (int i = 0; i <= size; i++)
|
|
|
|
|
list[i] = 0;
|
|
|
|
|
_char_arrays.push_back(list);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGDialog::PropertyObject.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FGDialog::PropertyObject::PropertyObject (const char * n,
|
|
|
|
|
puObject * o,
|
|
|
|
|
SGPropertyNode_ptr p)
|
|
|
|
|
: name(n),
|
|
|
|
|
object(o),
|
|
|
|
|
node(p)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// end of dialog.cxx
|