From 8ecf508fda3294f950451b9ad15c79e263964733 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Aug 2008 11:21:41 +0000 Subject: [PATCH] From Sergey Leontyev, "1. In StyleManager when applying styles to a Label element the code below runs in a infinite loop. The reason for this is that nothing increments the Reader "r" in the case when applying a style to label, so I advance the reader when no match was found. ( To replicate the error apply style to any label) replaced this: while(!r.eof()) if(_styles[style]->applyStyle(t, r)) inc = true; with this: while(!r.eof()) { if(_styles[style]->applyStyle(t, r)) inc = true; else r.advanceOverCurrentFieldOrBlock(); } I tested it and it works well for me, I did not find any problems with it. 2. Added style support for Canvas element, event though there is no styles to apply yet. It is usefull for someone who inherits from Canvas class to develop another element. If applyStyle(Canvas) does not exist there is no way to apply style to the element that inherited from Canvas element. Added virtual bool applyStyle(Canvas). and in added call to apply style if the Object is of type Canvas: StyleManager::_applyStyleToObject(osg::Object* obj, const std::string& style) { ... else if(!std::string("Canvas").compare(c)) return _coerceAndApply(obj,style,c); " --- include/osgWidget/StyleManager | 17 +++++++++++++++-- src/osgWidget/StyleManager.cpp | 11 +++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/osgWidget/StyleManager b/include/osgWidget/StyleManager index 19c5f7ce6..edea6a0a4 100644 --- a/include/osgWidget/StyleManager +++ b/include/osgWidget/StyleManager @@ -22,6 +22,7 @@ #include #include #include +#include namespace osgWidget { @@ -44,6 +45,9 @@ class OSGWIDGET_EXPORT Style: public osg::Object virtual bool applyStyle (Box*, Reader); virtual bool applyStyle (Frame::Corner*, Reader); virtual bool applyStyle (Frame::Border*, Reader); + virtual bool applyStyle (Canvas*, Reader); + + void setStyle(const std::string& style) { _style = style; @@ -104,7 +108,8 @@ class OSGWIDGET_EXPORT StyleManager: public osg::Object Styles _styles; template - bool _applySpecificStyle(T* t, const std::string& style) { + bool _applySpecificStyle(T* t, const std::string& style) + { osgDB::FieldReaderIterator r; std::istringstream input(_styles[style]->getStyle()); @@ -113,7 +118,15 @@ class OSGWIDGET_EXPORT StyleManager: public osg::Object bool inc = false; - while(!r.eof()) if(_styles[style]->applyStyle(t, r)) inc = true; + while(!r.eof()) + { + if(_styles[style]->applyStyle(t, r)) + inc = true; + else + r.advanceOverCurrentFieldOrBlock(); + } + + return inc; } diff --git a/src/osgWidget/StyleManager.cpp b/src/osgWidget/StyleManager.cpp index 48e129a2e..e9f3b39c2 100644 --- a/src/osgWidget/StyleManager.cpp +++ b/src/osgWidget/StyleManager.cpp @@ -218,6 +218,11 @@ bool Style::applyStyle(Window* window, Reader r) { return true; } +bool Style::applyStyle(Canvas* label, Reader r) { + return false; +} + + bool Style::applyStyle(Window::EmbeddedWindow*, Reader r) { return false; } @@ -353,6 +358,12 @@ bool StyleManager::_applyStyleToObject(osg::Object* obj, const std::string& styl style, c ); + else if(!std::string("Canvas").compare(c)) return _coerceAndApply( + obj, + style, + c + ); + else warn() << "StyleManager does not support coercion of objects of type "