1
0
Fork 0

Fix a segmentation fault when switching to a new style and selecting a new dialog. I still need to find out why getColor doesn't work properly.

This commit is contained in:
ehofman 2005-07-18 10:00:02 +00:00
parent 0ec8fa64a4
commit 0666590909
3 changed files with 29 additions and 27 deletions

View file

@ -670,11 +670,11 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
if (type == "") if (type == "")
type = "dialog"; type = "dialog";
FGColor c(_gui->getColor("background")); FGColor *c = new FGColor(_gui->getColor("background"));
c.merge(_gui->getColor(type)); c->merge(_gui->getColor(type));
c.merge(props->getNode("color")); c->merge(props->getNode("color"));
if (c.isValid()) if (c->isValid())
object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha()); object->setColourScheme(c->red(), c->green(), c->blue(), c->alpha());
const int numcol = 6; const int numcol = 6;
const struct { const struct {
@ -693,18 +693,18 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
for (int i = 0; i < numcol; i++) { for (int i = 0; i < numcol; i++) {
bool dirty = false; bool dirty = false;
c.clear(); c->clear();
c.setAlpha(1.0); c->setAlpha(1.0);
dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name)); dirty |= c->merge(_gui->getColor(type + '-' + pucol[i].name));
if (which & pucol[i].mask) if (which & pucol[i].mask)
dirty |= c.merge(props->getNode("color")); dirty |= c->merge(props->getNode("color"));
if ((pucol[i].mask == LABEL) && !c.isValid()) if ((pucol[i].mask == LABEL) && !c->isValid())
dirty |= c.merge(_gui->getColor("label")); dirty |= c->merge(_gui->getColor("label"));
if (c.isValid() && dirty) if (c->isValid() && dirty)
object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha()); object->setColor(pucol[i].id, c->red(), c->green(), c->blue(), c->alpha());
} }
} }

View file

@ -379,17 +379,17 @@ FGColor::merge(const SGPropertyNode *node)
} }
bool bool
FGColor::merge(const FGColor& color) FGColor::merge(const FGColor *color)
{ {
bool dirty = false; bool dirty = false;
if (color._red >= 0.0) if (color && color->_red >= 0.0)
_red = color._red, dirty = true; _red = color->_red, dirty = true;
if (color._green >= 0.0) if (color && color->_green >= 0.0)
_green = color._green, dirty = true; _green = color->_green, dirty = true;
if (color._blue >= 0.0) if (color && color->_blue >= 0.0)
_blue = color._blue, dirty = true; _blue = color->_blue, dirty = true;
if (color._alpha >= 0.0) if (color && color->_alpha >= 0.0)
_alpha = color._alpha, dirty = true; _alpha = color->_alpha, dirty = true;
return dirty; return dirty;
} }

View file

@ -156,11 +156,11 @@ public:
virtual FGColor *getColor (const char * name) const { virtual FGColor *getColor (const char * name) const {
_itt_t it = _colors.find(name); _itt_t it = _colors.find(name);
return it->second; return (it != _colors.end()) ? it->second : NULL;
} }
virtual FGColor *getColor (const string &name) const { virtual FGColor *getColor (const string &name) const {
_itt_t it = _colors.find(name.c_str()); _itt_t it = _colors.find(name.c_str());
return it->second; return (it != _colors.end()) ? it->second : NULL;
} }
virtual puFont *getDefaultFont() { return &_font; } virtual puFont *getDefaultFont() { return &_font; }
@ -217,15 +217,17 @@ public:
FGColor() { clear(); } FGColor() { clear(); }
FGColor(float r, float g, float b, float a = 1.0f) { set(r, g, b, a); } FGColor(float r, float g, float b, float a = 1.0f) { set(r, g, b, a); }
FGColor(const SGPropertyNode *prop) { set(prop); } FGColor(const SGPropertyNode *prop) { set(prop); }
FGColor(FGColor *c) { set(c->_red, c->_green, c->_blue, c->_alpha); } FGColor(FGColor *c) {
if (c) set(c->_red, c->_green, c->_blue, c->_alpha);
}
inline void clear() { _red = _green = _blue = _alpha = -1.0f; } inline void clear() { _red = _green = _blue = _alpha = -1.0f; }
// merges in non-negative components from property with children <red> etc. // merges in non-negative components from property with children <red> etc.
bool merge(const SGPropertyNode *prop); bool merge(const SGPropertyNode *prop);
bool merge(const FGColor& color); bool merge(const FGColor *color);
bool set(const SGPropertyNode *prop) { clear(); return merge(prop); }; bool set(const SGPropertyNode *prop) { clear(); return merge(prop); };
bool set(const FGColor& color) { clear(); return merge(color); } bool set(const FGColor *color) { clear(); return merge(color); }
bool set(float r, float g, float b, float a = 1.0f) { bool set(float r, float g, float b, float a = 1.0f) {
_red = r, _green = g, _blue = b, _alpha = a; _red = r, _green = g, _blue = b, _alpha = a;
return true; return true;