Restructured classes to better fit with style of the rest of the OSG.

This commit is contained in:
Robert Osfield 2008-07-25 19:57:17 +00:00
parent 727925a1c2
commit ff5da51dcb
18 changed files with 2230 additions and 2193 deletions

View File

@ -8,30 +8,33 @@
namespace osgWidget { namespace osgWidget {
class OSGWIDGET_EXPORT Box: public Window { class OSGWIDGET_EXPORT Box: public Window
{
public: public:
enum BOX_TYPE { enum BOX_TYPE {
VERTICAL, VERTICAL,
HORIZONTAL HORIZONTAL
}; };
private:
BOX_TYPE _boxType;
bool _uniform;
unsigned int _lastAdd;
protected:
virtual void _resizeImplementation(point_type, point_type);
virtual Sizes _getWidthImplementation () const;
virtual Sizes _getHeightImplementation () const;
public:
META_Object (osgWidget, Box); META_Object (osgWidget, Box);
META_UIObject (Box); META_UIObject (Box);
Box (const std::string& = "", BOX_TYPE = HORIZONTAL, bool = false); Box (const std::string& = "", BOX_TYPE = HORIZONTAL, bool = false);
Box (const Box&, const osg::CopyOp&); Box (const Box&, const osg::CopyOp&);
protected:
virtual void _resizeImplementation(point_type, point_type);
virtual Sizes _getWidthImplementation () const;
virtual Sizes _getHeightImplementation () const;
private:
BOX_TYPE _boxType;
bool _uniform;
unsigned int _lastAdd;
}; };
} }

View File

@ -8,10 +8,8 @@
namespace osgWidget { namespace osgWidget {
class OSGWIDGET_EXPORT Canvas: public Window { class OSGWIDGET_EXPORT Canvas: public Window
protected: {
virtual void _resizeImplementation(point_type, point_type);
public: public:
META_Object (osgWidget, Canvas); META_Object (osgWidget, Canvas);
META_UIObject (Canvas); META_UIObject (Canvas);
@ -21,6 +19,10 @@ public:
// This would conflict with the normal addWidget if there were default values. :( // This would conflict with the normal addWidget if there were default values. :(
virtual bool addWidget(Widget*, point_type, point_type); virtual bool addWidget(Widget*, point_type, point_type);
protected:
virtual void _resizeImplementation(point_type, point_type);
}; };
} }

View File

@ -16,7 +16,8 @@ class WindowManager;
class Window; class Window;
class Widget; class Widget;
enum EVENT_TYPE { enum EVENT_TYPE
{
EVENT_NONE = 0x0000, EVENT_NONE = 0x0000,
EVENT_FOCUS = 0x0001, EVENT_FOCUS = 0x0001,
EVENT_UNFOCUS = 0x0002, EVENT_UNFOCUS = 0x0002,
@ -34,7 +35,8 @@ enum EVENT_TYPE {
// Helpful wrapper around using the raw types, since it often doesn't make sense to // Helpful wrapper around using the raw types, since it often doesn't make sense to
// use some without the others. // use some without the others.
enum EVENT_MASK { enum EVENT_MASK
{
EVENT_MASK_FOCUS = EVENT_FOCUS | EVENT_UNFOCUS, EVENT_MASK_FOCUS = EVENT_FOCUS | EVENT_UNFOCUS,
EVENT_MASK_MOUSE_MOVE = EVENT_MOUSE_ENTER | EVENT_MOUSE_OVER | EVENT_MOUSE_LEAVE, EVENT_MASK_MOUSE_MOVE = EVENT_MOUSE_ENTER | EVENT_MOUSE_OVER | EVENT_MOUSE_LEAVE,
EVENT_MASK_MOUSE_CLICK = EVENT_MOUSE_PUSH | EVENT_MOUSE_RELEASE, EVENT_MASK_MOUSE_CLICK = EVENT_MOUSE_PUSH | EVENT_MOUSE_RELEASE,
@ -42,15 +44,8 @@ enum EVENT_MASK {
EVENT_MASK_KEY = EVENT_KEY_UP | EVENT_KEY_DOWN EVENT_MASK_KEY = EVENT_KEY_UP | EVENT_KEY_DOWN
}; };
class OSGWIDGET_EXPORT Event { class OSGWIDGET_EXPORT Event
friend class WindowManager; {
friend class Window;
WindowManager* _wm;
Window* _window;
Widget* _widget;
void* _data;
public: public:
EVENT_TYPE type; EVENT_TYPE type;
double x; double x;
@ -94,9 +89,7 @@ public:
return *this; return *this;
} }
WindowManager* getWindowManager() { WindowManager* getWindowManager() { return _wm; }
return _wm;
}
const WindowManager* getWindowManager() const { const WindowManager* getWindowManager() const {
return _wm; return _wm;
@ -129,6 +122,17 @@ public:
void setData(void* data) { void setData(void* data) {
_data = data; _data = data;
} }
protected:
friend class WindowManager;
friend class Window;
WindowManager* _wm;
Window* _window;
Widget* _widget;
void* _data;
}; };
// The Callback interface was inspired by the CEGUI project: // The Callback interface was inspired by the CEGUI project:
@ -140,24 +144,20 @@ public:
// to the CEGUI project! // to the CEGUI project!
// The CallbackInterface, which the highest-level functor keeps a pointer to. // The CallbackInterface, which the highest-level functor keeps a pointer to.
struct CallbackInterface: public osg::Referenced { struct CallbackInterface: public osg::Referenced
virtual ~CallbackInterface() { {
} virtual ~CallbackInterface() {}
virtual bool operator()(Event&) = 0; virtual bool operator()(Event&) = 0;
}; };
// The object that facilitates a class method as a callback. // The object that facilitates a class method as a callback.
template<typename T> template<typename T>
class ObjectCallback: public CallbackInterface { class ObjectCallback: public CallbackInterface
{
public: public:
typedef bool (T::*ObjectCallbackType)(Event&); typedef bool (T::*ObjectCallbackType)(Event&);
private:
ObjectCallbackType _callback;
T* _object;
public:
ObjectCallback(ObjectCallbackType callback, T* obj): ObjectCallback(ObjectCallbackType callback, T* obj):
_callback (callback), _callback (callback),
_object (obj) { _object (obj) {
@ -166,13 +166,17 @@ public:
virtual bool operator()(Event& ev) { virtual bool operator()(Event& ev) {
return (_object->*_callback)(ev); return (_object->*_callback)(ev);
} }
private:
ObjectCallbackType _callback;
T* _object;
}; };
// The object that facilitates general functions as callbacks. // The object that facilitates general functions as callbacks.
template<typename T> template<typename T>
class FunctionCallback: public CallbackInterface { class FunctionCallback: public CallbackInterface
T* _callback; {
public: public:
FunctionCallback(T* callback): FunctionCallback(T* callback):
_callback(callback) { _callback(callback) {
@ -181,16 +185,13 @@ public:
virtual bool operator()(Event& ev) { virtual bool operator()(Event& ev) {
return (*_callback)(ev); return (*_callback)(ev);
} }
protected:
T* _callback;
}; };
// The highlevel functor. // The highlevel functor.
class OSGWIDGET_EXPORT Callback { class OSGWIDGET_EXPORT Callback
EVENT_TYPE _type; {
void* _data;
// We use a ref_ptr here so that we don't have to worry about memory.
osg::ref_ptr<CallbackInterface> _callback;
public: public:
// Creates a Callback that is bound to a member function. // Creates a Callback that is bound to a member function.
template<typename T> template<typename T>
@ -223,28 +224,26 @@ public:
const void* getData() const { const void* getData() const {
return _data; return _data;
} }
protected:
EVENT_TYPE _type;
void* _data;
// We use a ref_ptr here so that we don't have to worry about memory.
osg::ref_ptr<CallbackInterface> _callback;
}; };
class OSGWIDGET_EXPORT EventInterface { class OSGWIDGET_EXPORT EventInterface
private: {
typedef std::list<Callback> CallbackList;
unsigned int _eventMask;
CallbackList _callbacks;
public: public:
EventInterface(): EventInterface(): _eventMask(EVENT_NONE) {}
_eventMask(EVENT_NONE) {
}
EventInterface(const EventInterface& ei): EventInterface(const EventInterface& ei):
_eventMask (ei._eventMask), _eventMask (ei._eventMask),
_callbacks (ei._callbacks) { _callbacks (ei._callbacks) {}
}
virtual ~EventInterface() { virtual ~EventInterface() {}
}
// These functions take as their final argument the WindowManager which issued the // These functions take as their final argument the WindowManager which issued the
// request. This is sometimes useful to get information about key state, etc. // request. This is sometimes useful to get information about key state, etc.
@ -369,6 +368,13 @@ public:
bool canKeyDown () const { return (_eventMask & EVENT_KEY_DOWN) != 0; } bool canKeyDown () const { return (_eventMask & EVENT_KEY_DOWN) != 0; }
bool canKeyUp () const { return (_eventMask & EVENT_KEY_UP) != 0; } bool canKeyUp () const { return (_eventMask & EVENT_KEY_UP) != 0; }
private:
typedef std::list<Callback> CallbackList;
unsigned int _eventMask;
CallbackList _callbacks;
}; };
} }

View File

@ -8,33 +8,31 @@
namespace osgWidget { namespace osgWidget {
class OSGWIDGET_EXPORT Frame: public Table { class OSGWIDGET_EXPORT Frame: public Table
{
public: public:
enum CORNER {
enum CORNER
{
CORNER_LOWER_LEFT, CORNER_LOWER_LEFT,
CORNER_LOWER_RIGHT, CORNER_LOWER_RIGHT,
CORNER_UPPER_LEFT, CORNER_UPPER_LEFT,
CORNER_UPPER_RIGHT CORNER_UPPER_RIGHT
}; };
enum BORDER { enum BORDER
{
BORDER_LEFT, BORDER_LEFT,
BORDER_RIGHT, BORDER_RIGHT,
BORDER_TOP, BORDER_TOP,
BORDER_BOTTOM BORDER_BOTTOM
}; };
protected:
Widget* _getCorner (CORNER) const;
Widget* _getBorder (BORDER) const;
public:
static std::string cornerToString (CORNER); static std::string cornerToString (CORNER);
static std::string borderToString (BORDER); static std::string borderToString (BORDER);
class OSGWIDGET_EXPORT Corner: public Widget { class OSGWIDGET_EXPORT Corner: public Widget
CORNER _corner; {
public: public:
META_Object (osgWidget, Corner); META_Object (osgWidget, Corner);
META_UIObject (Corner); META_UIObject (Corner);
@ -56,11 +54,13 @@ public:
_corner = corner; _corner = corner;
_name = cornerToString(corner); _name = cornerToString(corner);
} }
protected:
CORNER _corner;
}; };
class OSGWIDGET_EXPORT Border: public Widget { class OSGWIDGET_EXPORT Border: public Widget
BORDER _border; {
public: public:
META_Object (osgWidget, Border); META_Object (osgWidget, Border);
META_UIObject (Border); META_UIObject (Border);
@ -82,6 +82,11 @@ public:
_border = border; _border = border;
_name = borderToString(border); _name = borderToString(border);
} }
protected:
BORDER _border;
}; };
META_Object (osgWidget, Frame); META_Object (osgWidget, Frame);
@ -113,7 +118,8 @@ public:
Frame* = 0 Frame* = 0
); );
void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h) { void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h)
{
createSimpleFrame(_name, cw, ch, w, h, this); createSimpleFrame(_name, cw, ch, w, h, this);
} }
@ -125,35 +131,30 @@ public:
point_type ch, point_type ch,
point_type w, point_type w,
point_type h point_type h
) { )
{
createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this); createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this);
} }
bool setWindow(Window*); bool setWindow(Window*);
EmbeddedWindow* getEmbeddedWindow() { EmbeddedWindow* getEmbeddedWindow() { return dynamic_cast<EmbeddedWindow*>(getByRowCol(1, 1)); }
return dynamic_cast<EmbeddedWindow*>(getByRowCol(1, 1));
}
const EmbeddedWindow* getEmbeddedWindow() const { const EmbeddedWindow* getEmbeddedWindow() const { return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1)); }
return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1));
}
Corner* getCorner(CORNER c) { Corner* getCorner(CORNER c) { return dynamic_cast<Corner*>(_getCorner(c)); }
return dynamic_cast<Corner*>(_getCorner(c));
}
const Corner* getCorner(CORNER c) const { const Corner* getCorner(CORNER c) const { return dynamic_cast<const Corner*>(_getCorner(c)); }
return dynamic_cast<const Corner*>(_getCorner(c));
}
Border* getBorder(BORDER b) { Border* getBorder(BORDER b) { return dynamic_cast<Border*>(_getBorder(b)); }
return dynamic_cast<Border*>(_getBorder(b));
} const Border* getBorder(BORDER b) const { return dynamic_cast<const Border*>(_getBorder(b)); }
protected:
Widget* _getCorner (CORNER) const;
Widget* _getBorder (BORDER) const;
const Border* getBorder(BORDER b) const {
return dynamic_cast<const Border*>(_getBorder(b));
}
}; };
} }

View File

@ -8,23 +8,8 @@
namespace osgWidget { namespace osgWidget {
class OSGWIDGET_EXPORT Input: public Label { class OSGWIDGET_EXPORT Input: public Label
point_type _xoff; {
point_type _yoff;
unsigned int _index;
unsigned int _size;
unsigned int _cursorIndex;
unsigned int _maxSize;
std::vector<point_type> _offsets;
osg::ref_ptr<Widget> _cursor;
protected:
virtual void _calculateSize(const XYCoord&);
void _calculateCursorOffsets();
public: public:
Input(const std::string& = "", const std::string& = "", unsigned int = 20); Input(const std::string& = "", const std::string& = "", unsigned int = 20);
@ -70,6 +55,22 @@ public:
XYCoord getXYOffset() const { XYCoord getXYOffset() const {
return XYCoord(_xoff, _yoff); return XYCoord(_xoff, _yoff);
} }
protected:
virtual void _calculateSize(const XYCoord&);
void _calculateCursorOffsets();
point_type _xoff;
point_type _yoff;
unsigned int _index;
unsigned int _size;
unsigned int _cursorIndex;
unsigned int _maxSize;
std::vector<point_type> _offsets;
osg::ref_ptr<Widget> _cursor;
}; };
} }

View File

@ -10,15 +10,10 @@
namespace osgWidget { namespace osgWidget {
class OSGWIDGET_EXPORT Label: public Widget { class OSGWIDGET_EXPORT Label: public Widget
unsigned int _textIndex; {
protected:
osg::ref_ptr<osgText::Text> _text;
virtual void _calculateSize(const XYCoord&);
public: public:
META_Object (osgWidget, Label); META_Object (osgWidget, Label);
META_UIObject (Label); META_UIObject (Label);
@ -39,19 +34,21 @@ public:
XYCoord getTextSize() const; XYCoord getTextSize() const;
std::string getLabel() const { std::string getLabel() const { return _text->getText().createUTF8EncodedString(); }
return _text->getText().createUTF8EncodedString();
}
void setFontColor(point_type r, point_type g, point_type b, point_type a) { void setFontColor(point_type r, point_type g, point_type b, point_type a) { setFontColor(Color(r, g, b, a)); }
setFontColor(Color(r, g, b, a));
}
// For now you only get a const pointer, because we have a highly specific // For now you only get a const pointer, because we have a highly specific
// interface with the osgText library. // interface with the osgText library.
const osgText::Text* getText() const { const osgText::Text* getText() const { return _text.get(); }
return _text.get();
} protected:
osg::ref_ptr<osgText::Text> _text;
unsigned int _textIndex;
virtual void _calculateSize(const XYCoord&);
}; };
} }

View File

@ -13,10 +13,8 @@ struct LuaEngineData;
// The actual Engine itself. Every attempt is made to export the implemenation into the // The actual Engine itself. Every attempt is made to export the implemenation into the
// source file, rather than having it here. // source file, rather than having it here.
class OSGWIDGET_EXPORT LuaEngine: public ScriptEngine { class OSGWIDGET_EXPORT LuaEngine: public ScriptEngine
LuaEngineData* _data; {
WindowManager* _wm;
public: public:
LuaEngine(WindowManager* = 0); LuaEngine(WindowManager* = 0);
@ -24,6 +22,11 @@ public:
bool close (); bool close ();
bool eval (const std::string&); bool eval (const std::string&);
bool runFile (const std::string&); bool runFile (const std::string&);
protected:
LuaEngineData* _data;
WindowManager* _wm;
}; };
} }

View File

@ -11,9 +11,6 @@ namespace osgWidget {
struct PythonEngineData; struct PythonEngineData;
class OSGWIDGET_EXPORT PythonEngine: public ScriptEngine { class OSGWIDGET_EXPORT PythonEngine: public ScriptEngine {
PythonEngineData* _data;
WindowManager* _wm;
public: public:
PythonEngine(WindowManager* = 0); PythonEngine(WindowManager* = 0);
@ -21,6 +18,11 @@ public:
bool close (); bool close ();
bool eval (const std::string&); bool eval (const std::string&);
bool runFile (const std::string&); bool runFile (const std::string&);
protected:
PythonEngineData* _data;
WindowManager* _wm;
}; };
} }

View File

@ -11,10 +11,8 @@ namespace osgWidget {
// An interface for our scripting API so that we can have a unified way to talk to both // An interface for our scripting API so that we can have a unified way to talk to both
// Lua and Python; perhaps even more! Furthermore, this will allow us to put the // Lua and Python; perhaps even more! Furthermore, this will allow us to put the
// entire implementation into a source file... // entire implementation into a source file...
class ScriptEngine: public osg::Referenced { class ScriptEngine: public osg::Referenced
protected: {
std::string _err;
public: public:
virtual bool initialize () { return false; } virtual bool initialize () { return false; }
virtual bool close () { return false; } virtual bool close () { return false; }
@ -22,6 +20,9 @@ public:
virtual bool runFile (const std::string&) { return false; } virtual bool runFile (const std::string&) { return false; }
virtual const std::string& getLastErrorText() const { return _err; } virtual const std::string& getLastErrorText() const { return _err; }
protected:
std::string _err;
}; };
} }

View File

@ -8,30 +8,21 @@ namespace osgWidget {
#include <osgWidget/Export> #include <osgWidget/Export>
class OSGWIDGET_EXPORT StyleInterface { class OSGWIDGET_EXPORT StyleInterface
{
public:
StyleInterface(): _style("") {}
StyleInterface(const StyleInterface& si): _style(si._style) {}
void setStyle(const std::string& style) { _style = style; }
std::string& getStyle() { return _style; }
const std::string& getStyle() const { return _style; }
private: private:
std::string _style; std::string _style;
public:
StyleInterface():
_style("") {
}
StyleInterface(const StyleInterface& si):
_style(si._style) {
}
void setStyle(const std::string& style) {
_style = style;
}
std::string& getStyle() {
return _style;
}
const std::string& getStyle() const {
return _style;
}
}; };
} }

View File

@ -14,19 +14,8 @@ namespace osgWidget {
typedef osgDB::FieldReaderIterator& Reader; typedef osgDB::FieldReaderIterator& Reader;
class OSGWIDGET_EXPORT Style: public osg::Object { class OSGWIDGET_EXPORT Style: public osg::Object
std::string _style; {
bool _match(const char* seq, Reader r) {
if(r.matchSequence(seq)) {
++r;
return true;
}
return false;
}
public: public:
META_Object(osgWidget, Style); META_Object(osgWidget, Style);
@ -60,14 +49,44 @@ public:
static Widget::HORIZONTAL_ALIGNMENT strToHAlign (const std::string&); static Widget::HORIZONTAL_ALIGNMENT strToHAlign (const std::string&);
static Widget::COORDINATE_MODE strToCoordMode (const std::string&); static Widget::COORDINATE_MODE strToCoordMode (const std::string&);
static bool strToFill (const std::string&); static bool strToFill (const std::string&);
protected:
std::string _style;
bool _match(const char* seq, Reader r) {
if(r.matchSequence(seq)) {
++r;
return true;
}
return false;
}
}; };
class OSGWIDGET_EXPORT StyleManager: public osg::Object { class OSGWIDGET_EXPORT StyleManager: public osg::Object
{
public: public:
typedef std::map<std::string, osg::ref_ptr<Style> > Styles; typedef std::map<std::string, osg::ref_ptr<Style> > Styles;
typedef Styles::iterator Iterator; typedef Styles::iterator Iterator;
typedef Styles::const_iterator ConstIterator; typedef Styles::const_iterator ConstIterator;
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);
}
private: private:
Styles _styles; Styles _styles;
@ -113,8 +132,10 @@ private:
// 2. Check and see if each component working backward--minus the last--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. // 3. Check to see if just the className() is available.
template<typename T> template<typename T>
bool _applyStyles(T* t) { bool _applyStyles(T* t)
if(!t) { {
if(!t)
{
warn() warn()
<< "Cannot call StyleManager::applyStyle with a NULL object." << "Cannot call StyleManager::applyStyle with a NULL object."
<< std::endl << std::endl
@ -125,7 +146,8 @@ private:
osg::Object* obj = dynamic_cast<osg::Object*>(t); osg::Object* obj = dynamic_cast<osg::Object*>(t);
if(!obj) { if(!obj)
{
warn() warn()
<< "Cannot coerce object into osg::Object in StyleManager:::applyStyle" << "Cannot coerce object into osg::Object in StyleManager:::applyStyle"
<< std::endl << std::endl
@ -137,7 +159,8 @@ private:
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. // Case 3; there's no explicit Style set, so see if there's one for the class.
if(t->getStyle().empty()) { if(t->getStyle().empty())
{
// Couldn't find the className, so we exit. // Couldn't find the className, so we exit.
if(_styles.find(c) == _styles.end()) return false; if(_styles.find(c) == _styles.end()) return false;
@ -153,21 +176,6 @@ private:
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);
}
}; };
} }

View File

@ -8,27 +8,12 @@
namespace osgWidget { namespace osgWidget {
class OSGWIDGET_EXPORT Table: public Window { class OSGWIDGET_EXPORT Table: public Window
unsigned int _rows; {
unsigned int _cols;
unsigned int _lastRowAdd;
unsigned int _lastColAdd;
public: public:
typedef std::vector<point_type> CellSizes; typedef std::vector<point_type> CellSizes;
protected:
unsigned int _calculateIndex(unsigned int, unsigned int) const;
void _getRows (CellSizes&, Getter) const;
void _getColumns (CellSizes&, Getter) const;
virtual void _resizeImplementation(point_type, point_type);
virtual Sizes _getWidthImplementation () const;
virtual Sizes _getHeightImplementation () const;
public:
META_Object (osgWidget, Table); META_Object (osgWidget, Table);
META_UIObject (Table); META_UIObject (Table);
@ -49,13 +34,32 @@ public:
bool isRowVerticallyFillable (unsigned int) const; bool isRowVerticallyFillable (unsigned int) const;
bool isColumnHorizontallyFillable (unsigned int) const; bool isColumnHorizontallyFillable (unsigned int) const;
Widget* getByRowCol(unsigned int row, unsigned int col) { Widget* getByRowCol(unsigned int row, unsigned int col)
{
return getObjects()[_calculateIndex(row, col)].get(); return getObjects()[_calculateIndex(row, col)].get();
} }
const Widget* getByRowCol(unsigned int row, unsigned int col) const { const Widget* getByRowCol(unsigned int row, unsigned int col) const
{
return getObjects()[_calculateIndex(row, col)].get(); return getObjects()[_calculateIndex(row, col)].get();
} }
protected:
unsigned int _rows;
unsigned int _cols;
unsigned int _lastRowAdd;
unsigned int _lastColAdd;
unsigned int _calculateIndex(unsigned int, unsigned int) const;
void _getRows (CellSizes&, Getter) const;
void _getColumns (CellSizes&, Getter) const;
virtual void _resizeImplementation(point_type, point_type);
virtual Sizes _getWidthImplementation () const;
virtual Sizes _getHeightImplementation () const;
}; };
} }

View File

@ -17,7 +17,8 @@ namespace osgWidget {
} }
template <typename T> template <typename T>
class UIObjectParent { class UIObjectParent
{
public: public:
typedef T object_type; typedef T object_type;
typedef osg::observer_ptr<object_type> ptr_type; typedef osg::observer_ptr<object_type> ptr_type;
@ -25,10 +26,6 @@ public:
typedef typename Vector::iterator Iterator; typedef typename Vector::iterator Iterator;
typedef typename Vector::const_iterator ConstIterator; typedef typename Vector::const_iterator ConstIterator;
protected:
Vector _objects;
public:
Iterator begin() { Iterator begin() {
return _objects.begin(); return _objects.begin();
} }
@ -49,25 +46,6 @@ public:
return _objects.size(); return _objects.size();
} }
private:
// I had to add this to avoid ambiguity errors with MSVC. Garbage.
object_type* _getByName(const std::string& name) const {
for(ConstIterator i = begin(); i != end(); i++) {
if(i->valid() && i->get()->getName() == name) return i->get();
}
return 0;
}
object_type* _getByIndex(unsigned int index) const {
for(ConstIterator i = begin(); i != end(); i++) {
if(i->valid() && i->get()->getIndex() == index) return i->get();
}
return 0;
}
public:
object_type* getByName(const std::string& name) { object_type* getByName(const std::string& name) {
return _getByName(name); return _getByName(name);
} }
@ -97,6 +75,7 @@ public:
} }
protected: protected:
bool _remove(object_type* obj) { bool _remove(object_type* obj) {
Iterator i = std::find(begin(), end(), obj); Iterator i = std::find(begin(), end(), obj);
@ -116,6 +95,28 @@ protected:
return false; return false;
} }
Vector _objects;
private:
// I had to add this to avoid ambiguity errors with MSVC. Garbage.
object_type* _getByName(const std::string& name) const {
for(ConstIterator i = begin(); i != end(); i++) {
if(i->valid() && i->get()->getName() == name) return i->get();
}
return 0;
}
object_type* _getByIndex(unsigned int index) const {
for(ConstIterator i = begin(); i != end(); i++) {
if(i->valid() && i->get()->getIndex() == index) return i->get();
}
return 0;
}
}; };
} }

View File

@ -18,21 +18,25 @@ namespace osgWidget {
// These are NOT OSGWIDGET_EXPORT'd; these are internal only! // These are NOT OSGWIDGET_EXPORT'd; these are internal only!
inline std::ostream& _notify(osg::NotifySeverity ns = osg::INFO) { inline std::ostream& _notify(osg::NotifySeverity ns = osg::INFO)
{
std::ostream& n = osg::notify(ns); std::ostream& n = osg::notify(ns);
return n << "osgWidget: "; return n << "osgWidget: ";
} }
inline std::ostream& warn() { inline std::ostream& warn()
{
return _notify(osg::WARN); return _notify(osg::WARN);
} }
inline std::ostream& info() { inline std::ostream& info()
{
return _notify(); return _notify();
} }
inline std::string lowerCase(const std::string& str) { inline std::string lowerCase(const std::string& str)
{
std::string s = str; std::string s = str;
// TODO: Why can't I specify std::tolower? // TODO: Why can't I specify std::tolower?
@ -43,7 +47,8 @@ inline std::string lowerCase(const std::string& str) {
// TODO: Is this totally ghetto or what? // TODO: Is this totally ghetto or what?
template <typename T> template <typename T>
inline bool hasDecimal(T v) { inline bool hasDecimal(T v)
{
return (v - static_cast<T>(static_cast<long>(v))) > 0.0f; return (v - static_cast<T>(static_cast<long>(v))) > 0.0f;
} }

View File

@ -15,7 +15,20 @@
namespace osgWidget { namespace osgWidget {
// This handles the pressing/moving of mouse buttons, etc. // This handles the pressing/moving of mouse buttons, etc.
class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler { class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler
{
public:
MouseHandler(WindowManager*);
virtual bool handle(
const osgGA::GUIEventAdapter&,
osgGA::GUIActionAdapter&,
osg::Object*,
osg::NodeVisitor*
);
protected:
osg::ref_ptr<WindowManager> _wm; osg::ref_ptr<WindowManager> _wm;
bool _handleMousePush (float, float, int); bool _handleMousePush (float, float, int);
@ -31,21 +44,11 @@ class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler {
MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const; MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const;
bool _doMouseEvent (float, float, MouseEvent); bool _doMouseEvent (float, float, MouseEvent);
public:
MouseHandler(WindowManager*);
virtual bool handle(
const osgGA::GUIEventAdapter&,
osgGA::GUIActionAdapter&,
osg::Object*,
osg::NodeVisitor*
);
}; };
// This handles the forwarding of keypress events. // This handles the forwarding of keypress events.
class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler { class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler
osg::ref_ptr<WindowManager> _wm; {
public: public:
KeyboardHandler(WindowManager*); KeyboardHandler(WindowManager*);
@ -55,13 +58,15 @@ public:
osg::Object*, osg::Object*,
osg::NodeVisitor* osg::NodeVisitor*
); );
protected:
osg::ref_ptr<WindowManager> _wm;
}; };
// This class offers a default kind of handling for resizing. // This class offers a default kind of handling for resizing.
class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler { class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler
osg::ref_ptr<WindowManager> _wm; {
osg::ref_ptr<osg::Camera> _camera;
public: public:
ResizeHandler(WindowManager*, osg::Camera*); ResizeHandler(WindowManager*, osg::Camera*);
@ -71,6 +76,12 @@ public:
osg::Object*, osg::Object*,
osg::NodeVisitor* osg::NodeVisitor*
); );
protected:
osg::ref_ptr<WindowManager> _wm;
osg::ref_ptr<osg::Camera> _camera;
}; };
} }

View File

@ -48,53 +48,6 @@ public:
PFM_SLOPPY = 0x00000002 PFM_SLOPPY = 0x00000002
}; };
private:
// A functor used to sort the Windows by their Z component in descending order.
struct WindowZCompare: public std::binary_function<ptr_type, ptr_type, bool> {
bool operator()(const ptr_type& x, const ptr_type& y) {
return x.get()->getZ() > y.get()->getZ();
}
};
point_type _width;
point_type _height;
point_type _zNear;
point_type _zFar;
matrix_type _numForeground;
matrix_type _numBackground;
unsigned int _flags;
unsigned int _nodeMask;
osgViewer::View* _view;
float _lastX;
float _lastY;
EventInterface* _lastEvent;
EventInterface* _lastPush;
POINTER_DIRECTION _lastVertical;
POINTER_DIRECTION _lastHorizontal;
POINTER_FOCUS_MODE _focusMode;
bool _leftDown;
bool _middleDown;
bool _rightDown;
osgGA::GUIEventAdapter::ScrollingMotion _scrolling;
osg::ref_ptr<ScriptEngine> _lua;
osg::ref_ptr<ScriptEngine> _python;
osg::ref_ptr<StyleManager> _styleManager;
osg::observer_ptr<Widget> _widget;
osg::observer_ptr<Window> _focused;
osg::observer_ptr<Window> _pickWindow;
void childInserted (unsigned int);
void childRemoved (unsigned int, unsigned int);
bool _handleMousePushed (float, float, bool&);
bool _handleMouseReleased (float, float, bool&);
bool _haneldMouseScrolled (float, float, bool = false);
void _getPointerXYDiff (float&, float&);
void _updatePickWindow (const WidgetList*, point_type, point_type);
public: public:
META_Object(osgWidget, WindowManager); META_Object(osgWidget, WindowManager);
@ -307,6 +260,54 @@ public:
// can be compared to osgGA::GUIEventAdapter::{KeySymbol,KeyModMask}. // can be compared to osgGA::GUIEventAdapter::{KeySymbol,KeyModMask}.
bool keyDown (int, int); bool keyDown (int, int);
bool keyUp (int, int); bool keyUp (int, int);
private:
// A functor used to sort the Windows by their Z component in descending order.
struct WindowZCompare: public std::binary_function<ptr_type, ptr_type, bool> {
bool operator()(const ptr_type& x, const ptr_type& y) {
return x.get()->getZ() > y.get()->getZ();
}
};
point_type _width;
point_type _height;
point_type _zNear;
point_type _zFar;
matrix_type _numForeground;
matrix_type _numBackground;
unsigned int _flags;
unsigned int _nodeMask;
osgViewer::View* _view;
float _lastX;
float _lastY;
EventInterface* _lastEvent;
EventInterface* _lastPush;
POINTER_DIRECTION _lastVertical;
POINTER_DIRECTION _lastHorizontal;
POINTER_FOCUS_MODE _focusMode;
bool _leftDown;
bool _middleDown;
bool _rightDown;
osgGA::GUIEventAdapter::ScrollingMotion _scrolling;
osg::ref_ptr<ScriptEngine> _lua;
osg::ref_ptr<ScriptEngine> _python;
osg::ref_ptr<StyleManager> _styleManager;
osg::observer_ptr<Widget> _widget;
osg::observer_ptr<Window> _focused;
osg::observer_ptr<Window> _pickWindow;
void childInserted (unsigned int);
void childRemoved (unsigned int, unsigned int);
bool _handleMousePushed (float, float, bool&);
bool _handleMouseReleased (float, float, bool&);
bool _haneldMouseScrolled (float, float, bool = false);
void _getPointerXYDiff (float&, float&);
void _updatePickWindow (const WidgetList*, point_type, point_type);
}; };
// We use a template here because the container could be a list or a vector; or something // We use a template here because the container could be a list or a vector; or something