Restructured classes to better fit with style of the rest of the OSG.
This commit is contained in:
@@ -14,160 +14,168 @@ namespace osgWidget {
|
||||
|
||||
typedef osgDB::FieldReaderIterator& Reader;
|
||||
|
||||
class OSGWIDGET_EXPORT Style: public osg::Object {
|
||||
std::string _style;
|
||||
class OSGWIDGET_EXPORT Style: public osg::Object
|
||||
{
|
||||
public:
|
||||
META_Object(osgWidget, Style);
|
||||
|
||||
bool _match(const char* seq, Reader r) {
|
||||
if(r.matchSequence(seq)) {
|
||||
++r;
|
||||
// Class and contents...
|
||||
Style (const std::string& = "", const std::string& = "");
|
||||
Style (const Style&, const osg::CopyOp&);
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool applyStyle (Widget*, Reader);
|
||||
virtual bool applyStyle (Label*, Reader);
|
||||
virtual bool applyStyle (Input*, Reader);
|
||||
virtual bool applyStyle (Window*, Reader);
|
||||
virtual bool applyStyle (Window::EmbeddedWindow*, Reader);
|
||||
virtual bool applyStyle (Box*, Reader);
|
||||
virtual bool applyStyle (Frame::Corner*, Reader);
|
||||
virtual bool applyStyle (Frame::Border*, Reader);
|
||||
|
||||
return false;
|
||||
}
|
||||
void setStyle(const std::string& style) {
|
||||
_style = style;
|
||||
}
|
||||
|
||||
public:
|
||||
META_Object(osgWidget, Style);
|
||||
std::string& getStyle() {
|
||||
return _style;
|
||||
}
|
||||
|
||||
// Class and contents...
|
||||
Style (const std::string& = "", const std::string& = "");
|
||||
Style (const Style&, const osg::CopyOp&);
|
||||
const std::string& getStyle() const {
|
||||
return _style;
|
||||
}
|
||||
|
||||
virtual bool applyStyle (Widget*, Reader);
|
||||
virtual bool applyStyle (Label*, Reader);
|
||||
virtual bool applyStyle (Input*, Reader);
|
||||
virtual bool applyStyle (Window*, Reader);
|
||||
virtual bool applyStyle (Window::EmbeddedWindow*, Reader);
|
||||
virtual bool applyStyle (Box*, Reader);
|
||||
virtual bool applyStyle (Frame::Corner*, Reader);
|
||||
virtual bool applyStyle (Frame::Border*, Reader);
|
||||
static Widget::LAYER strToLayer (const std::string&);
|
||||
static Widget::VERTICAL_ALIGNMENT strToVAlign (const std::string&);
|
||||
static Widget::HORIZONTAL_ALIGNMENT strToHAlign (const std::string&);
|
||||
static Widget::COORDINATE_MODE strToCoordMode (const std::string&);
|
||||
static bool strToFill (const std::string&);
|
||||
|
||||
void setStyle(const std::string& style) {
|
||||
_style = style;
|
||||
}
|
||||
protected:
|
||||
|
||||
std::string& getStyle() {
|
||||
return _style;
|
||||
}
|
||||
std::string _style;
|
||||
|
||||
const std::string& getStyle() const {
|
||||
return _style;
|
||||
}
|
||||
bool _match(const char* seq, Reader r) {
|
||||
if(r.matchSequence(seq)) {
|
||||
++r;
|
||||
|
||||
static Widget::LAYER strToLayer (const std::string&);
|
||||
static Widget::VERTICAL_ALIGNMENT strToVAlign (const std::string&);
|
||||
static Widget::HORIZONTAL_ALIGNMENT strToHAlign (const std::string&);
|
||||
static Widget::COORDINATE_MODE strToCoordMode (const std::string&);
|
||||
static bool strToFill (const std::string&);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class OSGWIDGET_EXPORT StyleManager: public osg::Object {
|
||||
public:
|
||||
typedef std::map<std::string, osg::ref_ptr<Style> > Styles;
|
||||
typedef Styles::iterator Iterator;
|
||||
typedef Styles::const_iterator ConstIterator;
|
||||
class OSGWIDGET_EXPORT StyleManager: public osg::Object
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, osg::ref_ptr<Style> > Styles;
|
||||
typedef Styles::iterator Iterator;
|
||||
typedef Styles::const_iterator ConstIterator;
|
||||
|
||||
private:
|
||||
Styles _styles;
|
||||
META_Object(osgWidget, StyleManager);
|
||||
|
||||
template<typename T>
|
||||
bool _applySpecificStyle(T* t, const std::string& style) {
|
||||
osgDB::FieldReaderIterator r;
|
||||
StyleManager ();
|
||||
StyleManager (const StyleManager&, const osg::CopyOp&);
|
||||
|
||||
std::istringstream input(_styles[style]->getStyle());
|
||||
bool addStyle(Style*);
|
||||
|
||||
r.attach(&input);
|
||||
bool applyStyles(Widget* widget) {
|
||||
return _applyStyles(widget);
|
||||
}
|
||||
|
||||
bool inc = false;
|
||||
bool applyStyles(Window* window) {
|
||||
return _applyStyles(window);
|
||||
}
|
||||
|
||||
while(!r.eof()) if(_styles[style]->applyStyle(t, r)) inc = true;
|
||||
private:
|
||||
Styles _styles;
|
||||
|
||||
return inc;
|
||||
}
|
||||
template<typename T>
|
||||
bool _applySpecificStyle(T* t, const std::string& style) {
|
||||
osgDB::FieldReaderIterator r;
|
||||
|
||||
template<typename T>
|
||||
bool _coerceAndApply(
|
||||
osg::Object* obj,
|
||||
const std::string& style,
|
||||
const std::string& className
|
||||
) {
|
||||
T* t = dynamic_cast<T*>(obj);
|
||||
std::istringstream input(_styles[style]->getStyle());
|
||||
|
||||
if(!t) {
|
||||
warn()
|
||||
<< "An attempt was made to coerce Object [" << obj->getName()
|
||||
<< "] into a " << className << " but failed." << std::endl
|
||||
;
|
||||
r.attach(&input);
|
||||
|
||||
return 0;
|
||||
}
|
||||
bool inc = false;
|
||||
|
||||
return _applySpecificStyle(t, style);
|
||||
}
|
||||
while(!r.eof()) if(_styles[style]->applyStyle(t, r)) inc = true;
|
||||
|
||||
return inc;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool _coerceAndApply(
|
||||
osg::Object* obj,
|
||||
const std::string& style,
|
||||
const std::string& className
|
||||
) {
|
||||
T* t = dynamic_cast<T*>(obj);
|
||||
|
||||
if(!t) {
|
||||
warn()
|
||||
<< "An attempt was made to coerce Object [" << obj->getName()
|
||||
<< "] into a " << className << " but failed." << std::endl
|
||||
;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _applySpecificStyle(t, style);
|
||||
}
|
||||
|
||||
|
||||
bool _applyStyleToObject(osg::Object*, const std::string&);
|
||||
bool _applyStyleToObject(osg::Object*, const std::string&);
|
||||
|
||||
// 1. Check and see if the explicit FULL path is available.
|
||||
// 2. Check and see if each component working backward--minus the last--is available.
|
||||
// 3. Check to see if just the className() is available.
|
||||
template<typename T>
|
||||
bool _applyStyles(T* t) {
|
||||
if(!t) {
|
||||
warn()
|
||||
<< "Cannot call StyleManager::applyStyle with a NULL object."
|
||||
<< std::endl
|
||||
;
|
||||
// 1. Check and see if the explicit FULL path is available.
|
||||
// 2. Check and see if each component working backward--minus the last--is available.
|
||||
// 3. Check to see if just the className() is available.
|
||||
template<typename T>
|
||||
bool _applyStyles(T* t)
|
||||
{
|
||||
if(!t)
|
||||
{
|
||||
warn()
|
||||
<< "Cannot call StyleManager::applyStyle with a NULL object."
|
||||
<< std::endl
|
||||
;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
osg::Object* obj = dynamic_cast<osg::Object*>(t);
|
||||
osg::Object* obj = dynamic_cast<osg::Object*>(t);
|
||||
|
||||
if(!obj) {
|
||||
warn()
|
||||
<< "Cannot coerce object into osg::Object in StyleManager:::applyStyle"
|
||||
<< std::endl
|
||||
;
|
||||
if(!obj)
|
||||
{
|
||||
warn()
|
||||
<< "Cannot coerce object into osg::Object in StyleManager:::applyStyle"
|
||||
<< std::endl
|
||||
;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string c = obj->className();
|
||||
std::string c = obj->className();
|
||||
|
||||
// Case 3; there's no explicit Style set, so see if there's one for the class.
|
||||
if(t->getStyle().empty()) {
|
||||
// Couldn't find the className, so we exit.
|
||||
if(_styles.find(c) == _styles.end()) return false;
|
||||
// Case 3; there's no explicit Style set, so see if there's one for the class.
|
||||
if(t->getStyle().empty())
|
||||
{
|
||||
// Couldn't find the className, so we exit.
|
||||
if(_styles.find(c) == _styles.end()) return false;
|
||||
|
||||
return _applyStyleToObject(obj, c);
|
||||
}
|
||||
return _applyStyleToObject(obj, c);
|
||||
}
|
||||
|
||||
// Case 1...
|
||||
if(_styles.find(t->getStyle()) != _styles.end()) return _applyStyleToObject(
|
||||
obj,
|
||||
t->getStyle()
|
||||
);
|
||||
// Case 1...
|
||||
if(_styles.find(t->getStyle()) != _styles.end()) return _applyStyleToObject(
|
||||
obj,
|
||||
t->getStyle()
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
META_Object(osgWidget, StyleManager);
|
||||
|
||||
StyleManager ();
|
||||
StyleManager (const StyleManager&, const osg::CopyOp&);
|
||||
|
||||
bool addStyle(Style*);
|
||||
|
||||
bool applyStyles(Widget* widget) {
|
||||
return _applyStyles(widget);
|
||||
}
|
||||
|
||||
bool applyStyles(Window* window) {
|
||||
return _applyStyles(window);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user