// 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>
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" );
- }
-
display(props);
}
FGDialog::~FGDialog ()
{
+ int x, y;
+ _object->getAbsolutePosition(&x, &y);
+ _props->setIntValue("lastx", x);
+ _props->setIntValue("lasty", y);
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());
+
+ puList * obj = new puList(x, y, x + width, y + height, entries);
setupObject(obj, props);
setColor(obj, props);
return obj;
} 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);
+#ifdef PUCOL_EDITFIELD // plib > 0.8.4
+ setColor(obj, props, EDITFIELD);
+#else
setColor(obj, props, FOREGROUND|LABEL);
+#endif
return obj;
} else if (type == "slider") {
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);
+#ifdef PUCOL_EDITFIELD // plib > 0.8.4
+ setColor(obj, props, EDITFIELD);
+#else
setColor(obj, props, FOREGROUND|LABEL);
+#endif
return obj;
} else {
return 0;
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")) {
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));
{ HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
{ LABEL, PUCOL_LABEL, "label", "color-label" },
{ LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
- { MISC, PUCOL_MISC, "misc", "color-misc" }
+ { MISC, PUCOL_MISC, "misc", "color-misc" },
+#ifdef PUCOL_EDITFIELD // plib > 0.8.4
+ { EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
+#endif
};
const int numcol = sizeof(pucol) / sizeof(pucol[0]);