// dialog.cxx: implementation of an XML-configurable dialog box.
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdlib.h> // atof()
#include <Input/input.hxx>
+#include <Scripting/NasalSys.hxx>
#include "dialog.hxx"
#include "new_gui.hxx"
// Special case to handle lists, as getStringValue cannot be overridden
if(object->getType() & PUCLASS_LIST)
{
- node->setStringValue(((puList *) object)->getListStringValue());
+ const char *s = ((puList *) object)->getListStringValue();
+ if (s)
+ node->setStringValue(s);
}
else
{
FGDialog::FGDialog (SGPropertyNode * props)
: _object(0),
- _gui((NewGUI *)globals->get_subsystem("gui"))
+ _gui((NewGUI *)globals->get_subsystem("gui")),
+ _props(props)
{
- char* envp = ::getenv( "FG_FONTS" );
- if ( envp != NULL ) {
- _font_path.set( envp );
- } else {
- _font_path.set( globals->get_fg_root() );
- _font_path.append( "Fonts" );
+ _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");
+ nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+ }
}
-
display(props);
}
FGDialog::~FGDialog ()
{
+ int x, y;
+ _object->getAbsolutePosition(&x, &y);
+ _props->setIntValue("lastx", x);
+ _props->setIntValue("lasty", y);
+
+ FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
+ if (_nasal_close) {
+ const char *s = _nasal_close->getStringValue();
+ nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s));
+ }
+ nas->deleteModule(_module.c_str());
+
puDeleteObject(_object);
unsigned int i;
// Let the layout widget work in the same property subtree.
LayoutWidget wid(props);
- puFont *fnt = _gui->getDefaultFont();
- wid.setDefaultFont(fnt, int(fnt->getPointSize()));
+ SGPropertyNode *fontnode = props->getNode("font");
+ if (fontnode) {
+ FGFontCache *fc = _gui->get_fontcache();
+ _font = fc->get(fontnode);
+ } else {
+ _font = _gui->getDefaultFont();
+ }
+ wid.setDefaultFont(_font, int(_font->getPointSize()));
int pw=0, ph=0;
int px, py, savex, savey;
// Negative x/y coordinates are interpreted as distance from the top/right
// corner rather than bottom/left.
- if (px < 0)
+ if (userx && px < 0)
px = screenw - pw + px;
- if (py < 0)
+ if (usery && py < 0)
py = screenh - ph + py;
// Define "x", "y", "width" and/or "height" in the property tree if they
return obj;
} else if (type == "list") {
- puList * obj = new puList(x, y, x + width, y + height);
+ vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
+ char ** entries = make_char_array(value_nodes.size());
+ for (unsigned int i = 0; i < value_nodes.size(); i++)
+ entries[i] = strdup((char *)value_nodes[i]->getStringValue());
+
+ int slider_width = props->getIntValue("slider", 20);
+ puList * obj = new puList(x, y, x + width, y + height, entries, slider_width);
+ if (presetSize)
+ obj->setSize(width, height);
setupObject(obj, props);
setColor(obj, props);
return obj;
} else if (type == "airport-list") {
AirportList * obj = new AirportList(x, y, x + width, y + height);
+ if (presetSize)
+ obj->setSize(width, height);
setupObject(obj, props);
setColor(obj, props);
return obj;
}
// Layed-out objects need their size set, and non-layout ones
// get a different placement.
- if(presetSize) obj->setSize(width, height);
- else obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
+ if (presetSize)
+ obj->setSize(width, height);
+ else
+ obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
setColor(obj, props, LABEL);
return obj;
obj = new puOneShot(x, y, legend);
else
obj = new puButton(x, y, legend);
- if(presetSize)
+ if (presetSize)
obj->setSize(width, height);
setupObject(obj, props);
setColor(obj, props);
} else if (type == "combo") {
vector<SGPropertyNode_ptr> value_nodes = props->getChildren("value");
char ** entries = make_char_array(value_nodes.size());
- for (unsigned int i = 0, j = value_nodes.size() - 1;
- i < value_nodes.size();
- i++, j--)
+ for (unsigned int i = 0; i < value_nodes.size(); i++)
entries[i] = strdup((char *)value_nodes[i]->getStringValue());
+
puComboBox * obj = new puComboBox(x, y, x + width, y + height, entries,
props->getBoolValue("editable", false));
setupObject(obj, props);
obj->setMinValue(props->getFloatValue("min", 0.0));
obj->setMaxValue(props->getFloatValue("max", 1.0));
setupObject(obj, props);
- if(presetSize)
+ if (presetSize)
obj->setSize(width, height);
setColor(obj, props, FOREGROUND|LABEL);
return obj;
return obj;
} else if (type == "textbox") {
- int slider_width = props->getIntValue("slider", parentHeight);
+ int slider_width = props->getIntValue("slider", 20);
int wrap = props->getBoolValue("wrap", true);
- if (slider_width==0) slider_width=20;
puLargeInput * obj = new puLargeInput(x, y,
x+width, x+height, 2, slider_width, wrap);
else
obj->enableInput();
}
+ if (presetSize)
+ obj->setSize(width, height);
setupObject(obj, props);
setColor(obj, props, FOREGROUND|LABEL);
return obj;
value_nodes.push_back(selection_node->getChild(q));
char ** entries = make_char_array(value_nodes.size());
- for (unsigned int i = 0, j = value_nodes.size() - 1;
- i < value_nodes.size();
- i++, j--)
+ for (unsigned int i = 0; i < value_nodes.size(); i++)
entries[i] = strdup((char *)value_nodes[i]->getName());
+
puSelectBox * obj =
new puSelectBox(x, y, x + width, y + height, entries);
setupObject(obj, props);
void
FGDialog::setupObject (puObject * object, SGPropertyNode * props)
{
+ string type = props->getName();
object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
if (props->hasValue("legend"))
object->setBorderThickness( props->getIntValue("border", 2) );
if ( SGPropertyNode *nft = props->getNode("font", false) ) {
- SGPath path( _font_path );
- const char *name = nft->getStringValue("name", "default");
- float size = nft->getFloatValue("size", 13.0);
- float slant = nft->getFloatValue("slant", 0.0);
- path.append( name );
- path.concat( ".txf" );
-
- fntFont *font = new fntTexFont;
- font->load( (char *)path.c_str() );
-
- puFont lfnt(font, size, slant);
- object->setLabelFont( lfnt );
+ FGFontCache *fc = _gui->get_fontcache();
+ puFont *lfnt = fc->get(nft);
+ object->setLabelFont(*lfnt);
+ } else {
+ object->setLabelFont(*_font);
}
if (props->hasValue("property")) {
while (dest->getChild("binding", j))
j++;
+ const char *cmd = bindings[i]->getStringValue("command");
+ if (!strcmp(cmd, "nasal"))
+ bindings[i]->setStringValue("module", _module.c_str());
+
binding = dest->getChild("binding", j, true);
copyProperties(bindings[i], binding);
info->bindings.push_back(new FGBinding(binding));
}
object->setCallback(action_callback);
+
+ if (type == "input" && props->getBoolValue("live"))
+ object->setDownCallback(action_callback);
+
object->setUserData(info);
_info.push_back(info);
}
string type = props->getName();
if (type == "")
type = "dialog";
+ if (type == "textbox" && props->getBoolValue("editable"))
+ type += "-editable";
FGColor *c = new FGColor(_gui->getColor("background"));
c->merge(_gui->getColor(type));
if ((pucol[i].mask == LABEL) && !c->isValid())
dirty |= c->merge(_gui->getColor("label"));
+ dirty |= c->merge(props->getNode(pucol[i].cname));
+
if (c->isValid() && dirty)
object->setColor(pucol[i].id, c->red(), c->green(), c->blue(), c->alpha());
}
const char *name;
int key;
} keymap[] = {
+ {"backspace", 8},
{"tab", 9},
{"return", 13},
{"enter", 13},