From ff5da51dcb3a7c474cb6813a47ec90ba2b6a88ae Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 25 Jul 2008 19:57:17 +0000 Subject: [PATCH] Restructured classes to better fit with style of the rest of the OSG. --- include/osgWidget/Box | 41 +- include/osgWidget/Canvas | 22 +- include/osgWidget/EventInterface | 540 ++++++------ include/osgWidget/Frame | 233 ++--- include/osgWidget/Input | 93 +- include/osgWidget/Label | 61 +- include/osgWidget/Lua | 21 +- include/osgWidget/Python | 18 +- include/osgWidget/ScriptEngine | 19 +- include/osgWidget/StyleInterface | 29 +- include/osgWidget/StyleManager | 244 +++--- include/osgWidget/Table | 74 +- include/osgWidget/UIObjectParent | 167 ++-- include/osgWidget/Util | 43 +- include/osgWidget/ViewerEventHandlers | 95 +- include/osgWidget/Widget | 1050 +++++++++++----------- include/osgWidget/Window | 1170 ++++++++++++------------- include/osgWidget/WindowManager | 503 +++++------ 18 files changed, 2230 insertions(+), 2193 deletions(-) diff --git a/include/osgWidget/Box b/include/osgWidget/Box index 96838cfb9..a69393568 100644 --- a/include/osgWidget/Box +++ b/include/osgWidget/Box @@ -8,30 +8,33 @@ namespace osgWidget { -class OSGWIDGET_EXPORT Box: public Window { -public: - enum BOX_TYPE { - VERTICAL, - HORIZONTAL - }; +class OSGWIDGET_EXPORT Box: public Window +{ + public: + enum BOX_TYPE { + VERTICAL, + HORIZONTAL + }; -private: - BOX_TYPE _boxType; - bool _uniform; - unsigned int _lastAdd; + META_Object (osgWidget, Box); + META_UIObject (Box); -protected: - virtual void _resizeImplementation(point_type, point_type); + Box (const std::string& = "", BOX_TYPE = HORIZONTAL, bool = false); + Box (const Box&, const osg::CopyOp&); - virtual Sizes _getWidthImplementation () const; - virtual Sizes _getHeightImplementation () const; + protected: -public: - META_Object (osgWidget, Box); - META_UIObject (Box); + virtual void _resizeImplementation(point_type, point_type); + + virtual Sizes _getWidthImplementation () const; + virtual Sizes _getHeightImplementation () const; + + private: + + BOX_TYPE _boxType; + bool _uniform; + unsigned int _lastAdd; - Box (const std::string& = "", BOX_TYPE = HORIZONTAL, bool = false); - Box (const Box&, const osg::CopyOp&); }; } diff --git a/include/osgWidget/Canvas b/include/osgWidget/Canvas index 4216aa97c..511ca7fb2 100644 --- a/include/osgWidget/Canvas +++ b/include/osgWidget/Canvas @@ -8,19 +8,21 @@ namespace osgWidget { -class OSGWIDGET_EXPORT Canvas: public Window { -protected: - virtual void _resizeImplementation(point_type, point_type); +class OSGWIDGET_EXPORT Canvas: public Window +{ + public: + META_Object (osgWidget, Canvas); + META_UIObject (Canvas); -public: - META_Object (osgWidget, Canvas); - META_UIObject (Canvas); + Canvas (const std::string& = ""); + Canvas (const Canvas&, const osg::CopyOp&); - Canvas (const std::string& = ""); - Canvas (const Canvas&, const osg::CopyOp&); + // This would conflict with the normal addWidget if there were default values. :( + virtual bool addWidget(Widget*, point_type, point_type); + + protected: + virtual void _resizeImplementation(point_type, point_type); - // This would conflict with the normal addWidget if there were default values. :( - virtual bool addWidget(Widget*, point_type, point_type); }; } diff --git a/include/osgWidget/EventInterface b/include/osgWidget/EventInterface index b4f891a0d..96afa7aa1 100644 --- a/include/osgWidget/EventInterface +++ b/include/osgWidget/EventInterface @@ -16,359 +16,365 @@ class WindowManager; class Window; class Widget; -enum EVENT_TYPE { - EVENT_NONE = 0x0000, - EVENT_FOCUS = 0x0001, - EVENT_UNFOCUS = 0x0002, - EVENT_MOUSE_ENTER = 0x0004, - EVENT_MOUSE_OVER = 0x0008, - EVENT_MOUSE_LEAVE = 0x0010, - EVENT_MOUSE_DRAG = 0x0020, - EVENT_MOUSE_PUSH = 0x0040, - EVENT_MOUSE_RELEASE = 0x0080, - EVENT_MOUSE_SCROLL = 0x0100, - EVENT_KEY_DOWN = 0x0200, - EVENT_KEY_UP = 0x0400, - EVENT_ALL = 0xFFFF +enum EVENT_TYPE +{ + EVENT_NONE = 0x0000, + EVENT_FOCUS = 0x0001, + EVENT_UNFOCUS = 0x0002, + EVENT_MOUSE_ENTER = 0x0004, + EVENT_MOUSE_OVER = 0x0008, + EVENT_MOUSE_LEAVE = 0x0010, + EVENT_MOUSE_DRAG = 0x0020, + EVENT_MOUSE_PUSH = 0x0040, + EVENT_MOUSE_RELEASE = 0x0080, + EVENT_MOUSE_SCROLL = 0x0100, + EVENT_KEY_DOWN = 0x0200, + EVENT_KEY_UP = 0x0400, + EVENT_ALL = 0xFFFF }; // Helpful wrapper around using the raw types, since it often doesn't make sense to // use some without the others. -enum EVENT_MASK { - EVENT_MASK_FOCUS = EVENT_FOCUS | EVENT_UNFOCUS, - 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_DRAG = EVENT_MASK_MOUSE_MOVE | EVENT_MASK_MOUSE_CLICK | EVENT_MOUSE_DRAG, - EVENT_MASK_KEY = EVENT_KEY_UP | EVENT_KEY_DOWN +enum EVENT_MASK +{ + EVENT_MASK_FOCUS = EVENT_FOCUS | EVENT_UNFOCUS, + 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_DRAG = EVENT_MASK_MOUSE_MOVE | EVENT_MASK_MOUSE_CLICK | EVENT_MOUSE_DRAG, + EVENT_MASK_KEY = EVENT_KEY_UP | EVENT_KEY_DOWN }; -class OSGWIDGET_EXPORT Event { - friend class WindowManager; - friend class Window; +class OSGWIDGET_EXPORT Event +{ + public: + EVENT_TYPE type; + double x; + double y; + int key; + int keyMask; - WindowManager* _wm; - Window* _window; - Widget* _widget; - void* _data; + Event(WindowManager* wm, EVENT_TYPE _type = EVENT_NONE): + _wm (wm), + _window (0), + _widget (0), + _data (0), + type (_type), + x (0.0f), + y (0.0f), + key (-1), + keyMask (-1) { + } -public: - EVENT_TYPE type; - double x; - double y; - int key; - int keyMask; + Event& makeType(EVENT_TYPE _type) { + if(_type != EVENT_NONE) type = _type; - Event(WindowManager* wm, EVENT_TYPE _type = EVENT_NONE): - _wm (wm), - _window (0), - _widget (0), - _data (0), - type (_type), - x (0.0f), - y (0.0f), - key (-1), - keyMask (-1) { - } + return *this; + } - Event& makeType(EVENT_TYPE _type) { - if(_type != EVENT_NONE) type = _type; + Event& makeMouse(double _x, double _y, EVENT_TYPE _type = EVENT_NONE) { + x = _x; + y = _y; - return *this; - } + if(_type != EVENT_NONE) type = _type; - Event& makeMouse(double _x, double _y, EVENT_TYPE _type = EVENT_NONE) { - x = _x; - y = _y; + return *this; + } - if(_type != EVENT_NONE) type = _type; + Event& makeKey(int _key, int _keyMask, EVENT_TYPE _type = EVENT_NONE) { + key = _key; + keyMask = _keyMask; - return *this; - } + if(_type != EVENT_NONE) type = _type; - Event& makeKey(int _key, int _keyMask, EVENT_TYPE _type = EVENT_NONE) { - key = _key; - keyMask = _keyMask; + return *this; + } - if(_type != EVENT_NONE) type = _type; + WindowManager* getWindowManager() { return _wm; } - return *this; - } + const WindowManager* getWindowManager() const { + return _wm; + } - WindowManager* getWindowManager() { - return _wm; - } + Window* getWindow() { + return _window; + } - const WindowManager* getWindowManager() const { - return _wm; - } + const Window* getWindow() const { + return _window; + } - Window* getWindow() { - return _window; - } + Widget* getWidget() { + return _widget; + } - const Window* getWindow() const { - return _window; - } + const Widget* getWidget() const { + return _widget; + } - Widget* getWidget() { - return _widget; - } + void* getData() { + return _data; + } - const Widget* getWidget() const { - return _widget; - } + const void* getData() const { + return _data; + } - void* getData() { - return _data; - } + void setData(void* data) { + _data = data; + } - const void* getData() const { - return _data; - } + protected: + + friend class WindowManager; + friend class Window; + + WindowManager* _wm; + Window* _window; + Widget* _widget; + void* _data; - void setData(void* data) { - _data = data; - } }; // The Callback interface was inspired by the CEGUI project: // -// http://www.cegui.org.uk/wiki/index.php/Main_Page +// http://www.cegui.org.uk/wiki/index.php/Main_Page // // It's a great little way to cleanly implement callbacks for events, although // I did change the names a bit to make them more appropriate for OSG. MANY THANKS // to the CEGUI project! // The CallbackInterface, which the highest-level functor keeps a pointer to. -struct CallbackInterface: public osg::Referenced { - virtual ~CallbackInterface() { - } +struct CallbackInterface: public osg::Referenced +{ + virtual ~CallbackInterface() {} - virtual bool operator()(Event&) = 0; + virtual bool operator()(Event&) = 0; }; // The object that facilitates a class method as a callback. template -class ObjectCallback: public CallbackInterface { -public: - typedef bool (T::*ObjectCallbackType)(Event&); +class ObjectCallback: public CallbackInterface +{ + public: + typedef bool (T::*ObjectCallbackType)(Event&); -private: - ObjectCallbackType _callback; - T* _object; + ObjectCallback(ObjectCallbackType callback, T* obj): + _callback (callback), + _object (obj) { + } -public: - ObjectCallback(ObjectCallbackType callback, T* obj): - _callback (callback), - _object (obj) { - } + virtual bool operator()(Event& ev) { + return (_object->*_callback)(ev); + } + + private: + ObjectCallbackType _callback; + T* _object; - virtual bool operator()(Event& ev) { - return (_object->*_callback)(ev); - } }; // The object that facilitates general functions as callbacks. template -class FunctionCallback: public CallbackInterface { - T* _callback; +class FunctionCallback: public CallbackInterface +{ + public: + FunctionCallback(T* callback): + _callback(callback) { + } -public: - FunctionCallback(T* callback): - _callback(callback) { - } - - virtual bool operator()(Event& ev) { - return (*_callback)(ev); - } + virtual bool operator()(Event& ev) { + return (*_callback)(ev); + } + protected: + T* _callback; }; // The highlevel functor. -class OSGWIDGET_EXPORT Callback { - EVENT_TYPE _type; - void* _data; +class OSGWIDGET_EXPORT Callback +{ + public: + // Creates a Callback that is bound to a member function. + template + Callback(bool (T::*function)(Event&), T* obj, EVENT_TYPE type, void* data=0): + _type (type), + _data (data), + _callback (new ObjectCallback(function, obj)) { + } - // We use a ref_ptr here so that we don't have to worry about memory. - osg::ref_ptr _callback; + // Creates a Callback that is bound to a functor pointer. + template + Callback(T* functor, EVENT_TYPE type, void* data=0): + _type (type), + _data (data), + _callback (new FunctionCallback(functor)) { + } -public: - // Creates a Callback that is bound to a member function. - template - Callback(bool (T::*function)(Event&), T* obj, EVENT_TYPE type, void* data=0): - _type (type), - _data (data), - _callback (new ObjectCallback(function, obj)) { - } + bool operator()(Event& ev) { + return (*_callback)(ev); + } - // Creates a Callback that is bound to a functor pointer. - template - Callback(T* functor, EVENT_TYPE type, void* data=0): - _type (type), - _data (data), - _callback (new FunctionCallback(functor)) { - } + EVENT_TYPE getType() const { + return _type; + } - bool operator()(Event& ev) { - return (*_callback)(ev); - } + void* getData() { + return _data; + } - EVENT_TYPE getType() const { - return _type; - } + const void* getData() const { + return _data; + } + protected: + EVENT_TYPE _type; + void* _data; - void* getData() { - return _data; - } + // We use a ref_ptr here so that we don't have to worry about memory. + osg::ref_ptr _callback; - const void* getData() const { - return _data; - } }; -class OSGWIDGET_EXPORT EventInterface { -private: - typedef std::list CallbackList; +class OSGWIDGET_EXPORT EventInterface +{ + public: + EventInterface(): _eventMask(EVENT_NONE) {} - unsigned int _eventMask; - CallbackList _callbacks; + EventInterface(const EventInterface& ei): + _eventMask (ei._eventMask), + _callbacks (ei._callbacks) {} -public: - EventInterface(): - _eventMask(EVENT_NONE) { - } + virtual ~EventInterface() {} - EventInterface(const EventInterface& ei): - _eventMask (ei._eventMask), - _callbacks (ei._callbacks) { - } + // These functions take as their final argument the WindowManager which issued the + // request. This is sometimes useful to get information about key state, etc. - virtual ~EventInterface() { - } + // Notify the EventInterface object that is has been focused or unfocused; since + // this isn't always bound to a mouse event (i.e., if you want to be able to use + // the TAB key to focus), we need seperate events here. + virtual bool focus (WindowManager*) { return false; } + virtual bool unfocus (WindowManager*) { return false; } - // These functions take as their final argument the WindowManager which issued the - // request. This is sometimes useful to get information about key state, etc. - - // Notify the EventInterface object that is has been focused or unfocused; since - // this isn't always bound to a mouse event (i.e., if you want to be able to use - // the TAB key to focus), we need seperate events here. - virtual bool focus (WindowManager*) { return false; } - virtual bool unfocus (WindowManager*) { return false; } - - // Mouse events, pretty self-explanatory. - virtual bool mouseEnter (double, double, WindowManager*) { return false; } - virtual bool mouseOver (double, double, WindowManager*) { return false; } - virtual bool mouseLeave (double, double, WindowManager*) { return false; } - virtual bool mouseDrag (double, double, WindowManager*) { return false; } - virtual bool mousePush (double, double, WindowManager*) { return false; } - virtual bool mouseRelease (double, double, WindowManager*) { return false; } - virtual bool mouseScroll (double, double, WindowManager*) { return false; } + // Mouse events, pretty self-explanatory. + virtual bool mouseEnter (double, double, WindowManager*) { return false; } + virtual bool mouseOver (double, double, WindowManager*) { return false; } + virtual bool mouseLeave (double, double, WindowManager*) { return false; } + virtual bool mouseDrag (double, double, WindowManager*) { return false; } + virtual bool mousePush (double, double, WindowManager*) { return false; } + virtual bool mouseRelease (double, double, WindowManager*) { return false; } + virtual bool mouseScroll (double, double, WindowManager*) { return false; } - // These functions pass the osgGA::GUIEventAdapter::KeySymbol and KeyModMask and, - // as above, the WindowManager. - virtual bool keyDown (int, int, WindowManager*) { return false; } - virtual bool keyUp (int, int, WindowManager*) { return false; } + // These functions pass the osgGA::GUIEventAdapter::KeySymbol and KeyModMask and, + // as above, the WindowManager. + virtual bool keyDown (int, int, WindowManager*) { return false; } + virtual bool keyUp (int, int, WindowManager*) { return false; } - void setEventMask(unsigned int mask) { - _eventMask = mask; - } + void setEventMask(unsigned int mask) { + _eventMask = mask; + } - void addEventMask(unsigned int mask) { - _eventMask |= mask; - } + void addEventMask(unsigned int mask) { + _eventMask |= mask; + } - void removeEventMask(unsigned int mask) { - _eventMask ^= mask; - } + void removeEventMask(unsigned int mask) { + _eventMask ^= mask; + } - unsigned int getEventMask() const { - return _eventMask; - } + unsigned int getEventMask() const { + return _eventMask; + } - void addCallback(const Callback& cb) { - _callbacks.push_back(cb); - } + void addCallback(const Callback& cb) { + _callbacks.push_back(cb); + } - bool callCallbacks(Event& ev) { - if(ev.type == EVENT_NONE || !(_eventMask & ev.type)) return false; + bool callCallbacks(Event& ev) { + if(ev.type == EVENT_NONE || !(_eventMask & ev.type)) return false; - for(CallbackList::iterator i = _callbacks.begin(); i != _callbacks.end(); i++) { - // This is the OLD method; testing a new method below. - // if(i->getType() == ev.type && (*i)(ev)) return true; + for(CallbackList::iterator i = _callbacks.begin(); i != _callbacks.end(); i++) { + // This is the OLD method; testing a new method below. + // if(i->getType() == ev.type && (*i)(ev)) return true; - if(i->getType() == ev.type) { - ev.setData(i->getData()); + if(i->getType() == ev.type) { + ev.setData(i->getData()); - if((*i)(ev)) return true; - } - } + if((*i)(ev)) return true; + } + } - return false; - } + return false; + } - bool callMethodAndCallbacks(Event& ev) { - if(ev.type == EVENT_NONE || !(_eventMask & ev.type)) return false; - - bool handled = false; + bool callMethodAndCallbacks(Event& ev) { + if(ev.type == EVENT_NONE || !(_eventMask & ev.type)) return false; - if(ev.type == EVENT_FOCUS) handled = focus(ev.getWindowManager()); + bool handled = false; - else if(ev.type == EVENT_UNFOCUS) handled = unfocus(ev.getWindowManager()); - - else if(ev.type == EVENT_MOUSE_ENTER) - handled = mouseEnter(ev.x, ev.y, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_MOUSE_OVER) - handled = mouseOver(ev.x, ev.y, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_MOUSE_LEAVE) - handled = mouseLeave(ev.x, ev.y, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_MOUSE_DRAG) - handled = mouseDrag(ev.x, ev.y, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_MOUSE_PUSH) - handled = mousePush(ev.x, ev.y, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_MOUSE_RELEASE) - handled = mouseRelease(ev.x, ev.y, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_MOUSE_SCROLL) - handled = mouseScroll(ev.x, ev.y, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_KEY_DOWN) - handled = keyDown(ev.key, ev.keyMask, ev.getWindowManager()) - ; - - else if(ev.type == EVENT_KEY_UP) - handled = keyUp(ev.key, ev.keyMask, ev.getWindowManager()) - ; + if(ev.type == EVENT_FOCUS) handled = focus(ev.getWindowManager()); - else return false; + else if(ev.type == EVENT_UNFOCUS) handled = unfocus(ev.getWindowManager()); - return callCallbacks(ev) || handled; - } + else if(ev.type == EVENT_MOUSE_ENTER) + handled = mouseEnter(ev.x, ev.y, ev.getWindowManager()) + ; - bool canFocus () const { return (_eventMask & EVENT_FOCUS) != 0; } - bool canUnfocus () const { return (_eventMask & EVENT_UNFOCUS) != 0; } + else if(ev.type == EVENT_MOUSE_OVER) + handled = mouseOver(ev.x, ev.y, ev.getWindowManager()) + ; - bool canMouseEnter () const { return (_eventMask & EVENT_MOUSE_ENTER) != 0; } - bool canMouseOver () const { return (_eventMask & EVENT_MOUSE_OVER) != 0; } - bool canMouseLeave () const { return (_eventMask & EVENT_MOUSE_LEAVE) != 0; } - bool canMouseDrag () const { return (_eventMask & EVENT_MOUSE_DRAG) != 0; } - bool canMousePush () const { return (_eventMask & EVENT_MOUSE_PUSH) != 0; } - bool canMouseRelease () const { return (_eventMask & EVENT_MOUSE_RELEASE) != 0; } - bool canMouseScroll () const { return (_eventMask & EVENT_MOUSE_SCROLL) != 0; } + else if(ev.type == EVENT_MOUSE_LEAVE) + handled = mouseLeave(ev.x, ev.y, ev.getWindowManager()) + ; + + else if(ev.type == EVENT_MOUSE_DRAG) + handled = mouseDrag(ev.x, ev.y, ev.getWindowManager()) + ; + + else if(ev.type == EVENT_MOUSE_PUSH) + handled = mousePush(ev.x, ev.y, ev.getWindowManager()) + ; + + else if(ev.type == EVENT_MOUSE_RELEASE) + handled = mouseRelease(ev.x, ev.y, ev.getWindowManager()) + ; + + else if(ev.type == EVENT_MOUSE_SCROLL) + handled = mouseScroll(ev.x, ev.y, ev.getWindowManager()) + ; + + else if(ev.type == EVENT_KEY_DOWN) + handled = keyDown(ev.key, ev.keyMask, ev.getWindowManager()) + ; + + else if(ev.type == EVENT_KEY_UP) + handled = keyUp(ev.key, ev.keyMask, ev.getWindowManager()) + ; + + else return false; + + return callCallbacks(ev) || handled; + } + + bool canFocus () const { return (_eventMask & EVENT_FOCUS) != 0; } + bool canUnfocus () const { return (_eventMask & EVENT_UNFOCUS) != 0; } + + bool canMouseEnter () const { return (_eventMask & EVENT_MOUSE_ENTER) != 0; } + bool canMouseOver () const { return (_eventMask & EVENT_MOUSE_OVER) != 0; } + bool canMouseLeave () const { return (_eventMask & EVENT_MOUSE_LEAVE) != 0; } + bool canMouseDrag () const { return (_eventMask & EVENT_MOUSE_DRAG) != 0; } + bool canMousePush () const { return (_eventMask & EVENT_MOUSE_PUSH) != 0; } + bool canMouseRelease () const { return (_eventMask & EVENT_MOUSE_RELEASE) != 0; } + bool canMouseScroll () const { return (_eventMask & EVENT_MOUSE_SCROLL) != 0; } + + bool canKeyDown () const { return (_eventMask & EVENT_KEY_DOWN) != 0; } + bool canKeyUp () const { return (_eventMask & EVENT_KEY_UP) != 0; } + + private: + typedef std::list CallbackList; + + unsigned int _eventMask; + CallbackList _callbacks; - bool canKeyDown () const { return (_eventMask & EVENT_KEY_DOWN) != 0; } - bool canKeyUp () const { return (_eventMask & EVENT_KEY_UP) != 0; } }; } diff --git a/include/osgWidget/Frame b/include/osgWidget/Frame index 001f94431..0947bf1a9 100644 --- a/include/osgWidget/Frame +++ b/include/osgWidget/Frame @@ -8,152 +8,153 @@ namespace osgWidget { -class OSGWIDGET_EXPORT Frame: public Table { -public: - enum CORNER { - CORNER_LOWER_LEFT, - CORNER_LOWER_RIGHT, - CORNER_UPPER_LEFT, - CORNER_UPPER_RIGHT - }; +class OSGWIDGET_EXPORT Frame: public Table +{ + public: + + enum CORNER + { + CORNER_LOWER_LEFT, + CORNER_LOWER_RIGHT, + CORNER_UPPER_LEFT, + CORNER_UPPER_RIGHT + }; - enum BORDER { - BORDER_LEFT, - BORDER_RIGHT, - BORDER_TOP, - BORDER_BOTTOM - }; + enum BORDER + { + BORDER_LEFT, + BORDER_RIGHT, + BORDER_TOP, + BORDER_BOTTOM + }; -protected: - Widget* _getCorner (CORNER) const; - Widget* _getBorder (BORDER) const; + static std::string cornerToString (CORNER); + static std::string borderToString (BORDER); -public: - static std::string cornerToString (CORNER); - static std::string borderToString (BORDER); + class OSGWIDGET_EXPORT Corner: public Widget + { + public: + META_Object (osgWidget, Corner); + META_UIObject (Corner); - class OSGWIDGET_EXPORT Corner: public Widget { - CORNER _corner; + Corner (CORNER = CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f); + Corner (const Corner&, const osg::CopyOp&); - public: - META_Object (osgWidget, Corner); - META_UIObject (Corner); + bool mouseDrag(double, double, WindowManager*); - Corner (CORNER = CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f); - Corner (const Corner&, const osg::CopyOp&); + CORNER getCorner() const { + return _corner; + } - bool mouseDrag(double, double, WindowManager*); + void setCorner(CORNER corner) { + _corner = corner; + } - CORNER getCorner() const { - return _corner; - } + void setCornerAndName(CORNER corner) { + _corner = corner; + _name = cornerToString(corner); + } + + protected: + CORNER _corner; + }; - void setCorner(CORNER corner) { - _corner = corner; - } + class OSGWIDGET_EXPORT Border: public Widget + { + public: + META_Object (osgWidget, Border); + META_UIObject (Border); - void setCornerAndName(CORNER corner) { - _corner = corner; - _name = cornerToString(corner); - } - }; - - class OSGWIDGET_EXPORT Border: public Widget { - BORDER _border; + Border (BORDER = BORDER_LEFT, point_type = 0.0f, point_type = 0.0f); + Border (const Border&, const osg::CopyOp&); - public: - META_Object (osgWidget, Border); - META_UIObject (Border); + bool mouseDrag(double, double, WindowManager*); - Border (BORDER = BORDER_LEFT, point_type = 0.0f, point_type = 0.0f); - Border (const Border&, const osg::CopyOp&); + BORDER getBorder() const { + return _border; + } - bool mouseDrag(double, double, WindowManager*); + void setBorder(BORDER border) { + _border = border; + } - BORDER getBorder() const { - return _border; - } + void setBorderAndName(BORDER border) { + _border = border; + _name = borderToString(border); + } + + protected: + + BORDER _border; - void setBorder(BORDER border) { - _border = border; - } + }; - void setBorderAndName(BORDER border) { - _border = border; - _name = borderToString(border); - } - }; + META_Object (osgWidget, Frame); + META_UIObject (Frame); - META_Object (osgWidget, Frame); - META_UIObject (Frame); + Frame (const std::string& = ""); + Frame (const Frame&, const osg::CopyOp&); - Frame (const std::string& = ""); - Frame (const Frame&, const osg::CopyOp&); + virtual void managed(WindowManager*); - virtual void managed(WindowManager*); + static Frame* createSimpleFrame( + const std::string&, + point_type, + point_type, + point_type, + point_type, + Frame* = 0 + ); - static Frame* createSimpleFrame( - const std::string&, - point_type, - point_type, - point_type, - point_type, - Frame* = 0 - ); + static Frame* createSimpleFrameWithSingleTexture( + const std::string&, + const std::string&, + point_type, + point_type, + point_type, + point_type, + point_type, + point_type, + Frame* = 0 + ); - static Frame* createSimpleFrameWithSingleTexture( - const std::string&, - const std::string&, - point_type, - point_type, - point_type, - point_type, - point_type, - point_type, - Frame* = 0 - ); + void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h) + { + createSimpleFrame(_name, cw, ch, w, h, this); + } - void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h) { - createSimpleFrame(_name, cw, ch, w, h, this); - } + void createSimpleFrameWithSingleTexture( + const std::string& tex, + point_type tw, + point_type th, + point_type cw, + point_type ch, + point_type w, + point_type h + ) + { + createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this); + } - void createSimpleFrameWithSingleTexture( - const std::string& tex, - point_type tw, - point_type th, - point_type cw, - point_type ch, - point_type w, - point_type h - ) { - createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this); - } + bool setWindow(Window*); - bool setWindow(Window*); + EmbeddedWindow* getEmbeddedWindow() { return dynamic_cast(getByRowCol(1, 1)); } - EmbeddedWindow* getEmbeddedWindow() { - return dynamic_cast(getByRowCol(1, 1)); - } + const EmbeddedWindow* getEmbeddedWindow() const { return dynamic_cast(getByRowCol(1, 1)); } - const EmbeddedWindow* getEmbeddedWindow() const { - return dynamic_cast(getByRowCol(1, 1)); - } + Corner* getCorner(CORNER c) { return dynamic_cast(_getCorner(c)); } - Corner* getCorner(CORNER c) { - return dynamic_cast(_getCorner(c)); - } + const Corner* getCorner(CORNER c) const { return dynamic_cast(_getCorner(c)); } - const Corner* getCorner(CORNER c) const { - return dynamic_cast(_getCorner(c)); - } + Border* getBorder(BORDER b) { return dynamic_cast(_getBorder(b)); } - Border* getBorder(BORDER b) { - return dynamic_cast(_getBorder(b)); - } + const Border* getBorder(BORDER b) const { return dynamic_cast(_getBorder(b)); } + + protected: + + Widget* _getCorner (CORNER) const; + Widget* _getBorder (BORDER) const; - const Border* getBorder(BORDER b) const { - return dynamic_cast(_getBorder(b)); - } }; } diff --git a/include/osgWidget/Input b/include/osgWidget/Input index 260ec7da0..889144959 100644 --- a/include/osgWidget/Input +++ b/include/osgWidget/Input @@ -8,68 +8,69 @@ namespace osgWidget { -class OSGWIDGET_EXPORT Input: public Label { - point_type _xoff; - point_type _yoff; +class OSGWIDGET_EXPORT Input: public Label +{ + public: + Input(const std::string& = "", const std::string& = "", unsigned int = 20); - unsigned int _index; - unsigned int _size; - unsigned int _cursorIndex; - unsigned int _maxSize; + virtual void parented (Window*); + virtual void positioned (); - std::vector _offsets; - osg::ref_ptr _cursor; + virtual bool focus (WindowManager*); + virtual bool unfocus (WindowManager*); + virtual bool keyUp (int, int, WindowManager*); + virtual bool keyDown (int, int, WindowManager*); -protected: - virtual void _calculateSize(const XYCoord&); + void setCursor(Widget*); - void _calculateCursorOffsets(); + void setXOffset(point_type xo) { + _xoff = xo; + } -public: - Input(const std::string& = "", const std::string& = "", unsigned int = 20); + void setYOffset(point_type yo) { + _yoff = yo; + } - virtual void parented (Window*); - virtual void positioned (); + void setXYOffset(point_type xo, point_type yo) { + _xoff = xo; + _yoff = yo; + } - virtual bool focus (WindowManager*); - virtual bool unfocus (WindowManager*); - virtual bool keyUp (int, int, WindowManager*); - virtual bool keyDown (int, int, WindowManager*); + osg::Drawable* getCursor() { + return _cursor.get(); + } - void setCursor(Widget*); + const osg::Drawable* getCursor() const { + return _cursor.get(); + } - void setXOffset(point_type xo) { - _xoff = xo; - } + point_type getXOffset() const { + return _xoff; + } - void setYOffset(point_type yo) { - _yoff = yo; - } + point_type getYOffset() const { + return _yoff; + } - void setXYOffset(point_type xo, point_type yo) { - _xoff = xo; - _yoff = yo; - } + XYCoord getXYOffset() const { + return XYCoord(_xoff, _yoff); + } - osg::Drawable* getCursor() { - return _cursor.get(); - } + protected: + virtual void _calculateSize(const XYCoord&); - const osg::Drawable* getCursor() const { - return _cursor.get(); - } + void _calculateCursorOffsets(); - point_type getXOffset() const { - return _xoff; - } + point_type _xoff; + point_type _yoff; - point_type getYOffset() const { - return _yoff; - } + unsigned int _index; + unsigned int _size; + unsigned int _cursorIndex; + unsigned int _maxSize; - XYCoord getXYOffset() const { - return XYCoord(_xoff, _yoff); - } + std::vector _offsets; + osg::ref_ptr _cursor; }; } diff --git a/include/osgWidget/Label b/include/osgWidget/Label index be59e1df8..f095a39d8 100644 --- a/include/osgWidget/Label +++ b/include/osgWidget/Label @@ -10,48 +10,45 @@ namespace osgWidget { -class OSGWIDGET_EXPORT Label: public Widget { - unsigned int _textIndex; +class OSGWIDGET_EXPORT Label: public Widget +{ + public: -protected: - osg::ref_ptr _text; + META_Object (osgWidget, Label); + META_UIObject (Label); - virtual void _calculateSize(const XYCoord&); + Label (const std::string& = "", const std::string& = ""); + Label (const Label&, const osg::CopyOp&); -public: - META_Object (osgWidget, Label); - META_UIObject (Label); + virtual void parented (Window*); + virtual void unparented (Window*); + virtual void managed (WindowManager*); + virtual void positioned (); - Label (const std::string& = "", const std::string& = ""); - Label (const Label&, const osg::CopyOp&); + void update (); + void setLabel (const std::string&); + void setFont (const std::string&); + void setFontSize (unsigned int); + void setFontColor (const Color&); + void setShadow (point_type); - virtual void parented (Window*); - virtual void unparented (Window*); - virtual void managed (WindowManager*); - virtual void positioned (); + XYCoord getTextSize() const; - void update (); - void setLabel (const std::string&); - void setFont (const std::string&); - void setFontSize (unsigned int); - void setFontColor (const Color&); - void setShadow (point_type); + std::string getLabel() const { return _text->getText().createUTF8EncodedString(); } - XYCoord getTextSize() const; + void setFontColor(point_type r, point_type g, point_type b, point_type a) { setFontColor(Color(r, g, b, a)); } - std::string getLabel() const { - return _text->getText().createUTF8EncodedString(); - } + // For now you only get a const pointer, because we have a highly specific + // interface with the osgText library. + const osgText::Text* getText() const { return _text.get(); } - void setFontColor(point_type r, point_type g, point_type b, point_type a) { - setFontColor(Color(r, g, b, a)); - } + protected: + + osg::ref_ptr _text; + unsigned int _textIndex; + + virtual void _calculateSize(const XYCoord&); - // For now you only get a const pointer, because we have a highly specific - // interface with the osgText library. - const osgText::Text* getText() const { - return _text.get(); - } }; } diff --git a/include/osgWidget/Lua b/include/osgWidget/Lua index 81b612364..109acfc99 100644 --- a/include/osgWidget/Lua +++ b/include/osgWidget/Lua @@ -13,17 +13,20 @@ struct LuaEngineData; // The actual Engine itself. Every attempt is made to export the implemenation into the // source file, rather than having it here. -class OSGWIDGET_EXPORT LuaEngine: public ScriptEngine { - LuaEngineData* _data; - WindowManager* _wm; +class OSGWIDGET_EXPORT LuaEngine: public ScriptEngine +{ + public: + LuaEngine(WindowManager* = 0); -public: - LuaEngine(WindowManager* = 0); + bool initialize (); + bool close (); + bool eval (const std::string&); + bool runFile (const std::string&); - bool initialize (); - bool close (); - bool eval (const std::string&); - bool runFile (const std::string&); + protected: + + LuaEngineData* _data; + WindowManager* _wm; }; } diff --git a/include/osgWidget/Python b/include/osgWidget/Python index 9cb0d6928..87375e50b 100644 --- a/include/osgWidget/Python +++ b/include/osgWidget/Python @@ -11,16 +11,18 @@ namespace osgWidget { struct PythonEngineData; class OSGWIDGET_EXPORT PythonEngine: public ScriptEngine { - PythonEngineData* _data; - WindowManager* _wm; + public: + PythonEngine(WindowManager* = 0); -public: - PythonEngine(WindowManager* = 0); + bool initialize (); + bool close (); + bool eval (const std::string&); + bool runFile (const std::string&); - bool initialize (); - bool close (); - bool eval (const std::string&); - bool runFile (const std::string&); + protected: + + PythonEngineData* _data; + WindowManager* _wm; }; } diff --git a/include/osgWidget/ScriptEngine b/include/osgWidget/ScriptEngine index 7f2550e9f..e16f2147b 100644 --- a/include/osgWidget/ScriptEngine +++ b/include/osgWidget/ScriptEngine @@ -11,17 +11,18 @@ namespace osgWidget { // 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 // entire implementation into a source file... -class ScriptEngine: public osg::Referenced { -protected: - std::string _err; +class ScriptEngine: public osg::Referenced +{ + public: + virtual bool initialize () { return false; } + virtual bool close () { return false; } + virtual bool eval (const std::string&) { return false; } + virtual bool runFile (const std::string&) { return false; } -public: - virtual bool initialize () { return false; } - virtual bool close () { return false; } - virtual bool eval (const std::string&) { return false; } - virtual bool runFile (const std::string&) { return false; } + virtual const std::string& getLastErrorText() const { return _err; } + protected: + std::string _err; - virtual const std::string& getLastErrorText() const { return _err; } }; } diff --git a/include/osgWidget/StyleInterface b/include/osgWidget/StyleInterface index f3acf9856..8a0b9da16 100644 --- a/include/osgWidget/StyleInterface +++ b/include/osgWidget/StyleInterface @@ -8,30 +8,21 @@ namespace osgWidget { #include -class OSGWIDGET_EXPORT StyleInterface { -private: - std::string _style; +class OSGWIDGET_EXPORT StyleInterface +{ + public: + StyleInterface(): _style("") {} -public: - StyleInterface(): - _style("") { - } + StyleInterface(const StyleInterface& si): _style(si._style) {} - StyleInterface(const StyleInterface& si): - _style(si._style) { - } + void setStyle(const std::string& style) { _style = style; } - void setStyle(const std::string& style) { - _style = style; - } + std::string& getStyle() { return _style; } - std::string& getStyle() { - return _style; - } + const std::string& getStyle() const { return _style; } + private: + std::string _style; - const std::string& getStyle() const { - return _style; - } }; } diff --git a/include/osgWidget/StyleManager b/include/osgWidget/StyleManager index b1ffbceec..0798d0afc 100644 --- a/include/osgWidget/StyleManager +++ b/include/osgWidget/StyleManager @@ -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 > Styles; - typedef Styles::iterator Iterator; - typedef Styles::const_iterator ConstIterator; +class OSGWIDGET_EXPORT StyleManager: public osg::Object +{ + public: + typedef std::map > Styles; + typedef Styles::iterator Iterator; + typedef Styles::const_iterator ConstIterator; -private: - Styles _styles; + META_Object(osgWidget, StyleManager); - template - 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 + bool _applySpecificStyle(T* t, const std::string& style) { + osgDB::FieldReaderIterator r; - template - bool _coerceAndApply( - osg::Object* obj, - const std::string& style, - const std::string& className - ) { - T* t = dynamic_cast(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 + bool _coerceAndApply( + osg::Object* obj, + const std::string& style, + const std::string& className + ) { + T* t = dynamic_cast(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 - 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 + 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(t); + osg::Object* obj = dynamic_cast(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); - } }; } diff --git a/include/osgWidget/Table b/include/osgWidget/Table index 12db854cd..8eaba1a89 100644 --- a/include/osgWidget/Table +++ b/include/osgWidget/Table @@ -8,54 +8,58 @@ namespace osgWidget { -class OSGWIDGET_EXPORT Table: public Window { - unsigned int _rows; - unsigned int _cols; - unsigned int _lastRowAdd; - unsigned int _lastColAdd; +class OSGWIDGET_EXPORT Table: public Window +{ + public: -public: - typedef std::vector CellSizes; + typedef std::vector CellSizes; -protected: - unsigned int _calculateIndex(unsigned int, unsigned int) const; + META_Object (osgWidget, Table); + META_UIObject (Table); - void _getRows (CellSizes&, Getter) const; - void _getColumns (CellSizes&, Getter) const; + Table (const std::string& = "", unsigned int = 0, unsigned int = 0); + Table (const Table&, const osg::CopyOp&); - virtual void _resizeImplementation(point_type, point_type); + virtual bool addWidget (Widget*); + virtual bool addWidget (Widget*, unsigned int, unsigned int); - virtual Sizes _getWidthImplementation () const; - virtual Sizes _getHeightImplementation () const; + void getRowHeights (CellSizes&) const; + void getRowMinHeights (CellSizes&) const; + void getColumnWidths (CellSizes&) const; + void getColumnMinWidths (CellSizes&) const; -public: - META_Object (osgWidget, Table); - META_UIObject (Table); + void addHeightToRow (unsigned int, point_type); + void addWidthToColumn (unsigned int, point_type); - Table (const std::string& = "", unsigned int = 0, unsigned int = 0); - Table (const Table&, const osg::CopyOp&); + bool isRowVerticallyFillable (unsigned int) const; + bool isColumnHorizontallyFillable (unsigned int) const; - virtual bool addWidget (Widget*); - virtual bool addWidget (Widget*, unsigned int, unsigned int); + Widget* getByRowCol(unsigned int row, unsigned int col) + { + return getObjects()[_calculateIndex(row, col)].get(); + } - void getRowHeights (CellSizes&) const; - void getRowMinHeights (CellSizes&) const; - void getColumnWidths (CellSizes&) const; - void getColumnMinWidths (CellSizes&) const; + const Widget* getByRowCol(unsigned int row, unsigned int col) const + { + return getObjects()[_calculateIndex(row, col)].get(); + } - void addHeightToRow (unsigned int, point_type); - void addWidthToColumn (unsigned int, point_type); + protected: + + unsigned int _rows; + unsigned int _cols; + unsigned int _lastRowAdd; + unsigned int _lastColAdd; - bool isRowVerticallyFillable (unsigned int) const; - bool isColumnHorizontallyFillable (unsigned int) const; + unsigned int _calculateIndex(unsigned int, unsigned int) const; - Widget* getByRowCol(unsigned int row, unsigned int col) { - return getObjects()[_calculateIndex(row, col)].get(); - } + void _getRows (CellSizes&, Getter) const; + void _getColumns (CellSizes&, Getter) const; - const Widget* getByRowCol(unsigned int row, unsigned int col) const { - return getObjects()[_calculateIndex(row, col)].get(); - } + virtual void _resizeImplementation(point_type, point_type); + + virtual Sizes _getWidthImplementation () const; + virtual Sizes _getHeightImplementation () const; }; } diff --git a/include/osgWidget/UIObjectParent b/include/osgWidget/UIObjectParent index 5aaf5e1da..3cc21c0a5 100644 --- a/include/osgWidget/UIObjectParent +++ b/include/osgWidget/UIObjectParent @@ -7,115 +7,116 @@ namespace osgWidget { #define META_UIObject(name) \ - name * cloneAs(\ - const std::string& newName, \ - const osg::CopyOp& co = osg::CopyOp::DEEP_COPY_ALL \ - ) const { \ - name * obj = dynamic_cast(this->clone(co)); \ - obj->setName(newName); \ - return obj; \ - } + name * cloneAs(\ + const std::string& newName, \ + const osg::CopyOp& co = osg::CopyOp::DEEP_COPY_ALL \ + ) const { \ + name * obj = dynamic_cast(this->clone(co)); \ + obj->setName(newName); \ + return obj; \ + } template -class UIObjectParent { -public: - typedef T object_type; - typedef osg::observer_ptr ptr_type; - typedef std::vector Vector; - typedef typename Vector::iterator Iterator; - typedef typename Vector::const_iterator ConstIterator; +class UIObjectParent +{ + public: + typedef T object_type; + typedef osg::observer_ptr ptr_type; + typedef std::vector Vector; + typedef typename Vector::iterator Iterator; + typedef typename Vector::const_iterator ConstIterator; -protected: - Vector _objects; + Iterator begin() { + return _objects.begin(); + } -public: - Iterator begin() { - return _objects.begin(); - } + ConstIterator begin() const { + return _objects.begin(); + } - ConstIterator begin() const { - return _objects.begin(); - } + Iterator end() { + return _objects.end(); + } - Iterator end() { - return _objects.end(); - } + ConstIterator end() const { + return _objects.end(); + } - ConstIterator end() const { - return _objects.end(); - } + typename Vector::size_type size() const { + return _objects.size(); + } - typename Vector::size_type size() const { - return _objects.size(); - } + object_type* getByName(const std::string& name) { + return _getByName(name); + } -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(); - } + const object_type* getByName(const std::string& name) const { + return _getByName(name); + } - return 0; - } + object_type* getByIndex(unsigned int index) { + return _getByIndex(index); + } - object_type* _getByIndex(unsigned int index) const { - for(ConstIterator i = begin(); i != end(); i++) { - if(i->valid() && i->get()->getIndex() == index) return i->get(); - } + const object_type* getByIndex(unsigned int index) const { + return _getByIndex(index); + } - return 0; - } + unsigned int getNumObjects() const { + return _objects.size(); + } -public: - object_type* getByName(const std::string& name) { - return _getByName(name); - } + Vector& getObjects() { + return _objects; + } - const object_type* getByName(const std::string& name) const { - return _getByName(name); - } + const Vector& getObjects() const { + return _objects; + } - object_type* getByIndex(unsigned int index) { - return _getByIndex(index); - } + protected: - const object_type* getByIndex(unsigned int index) const { - return _getByIndex(index); - } + bool _remove(object_type* obj) { + Iterator i = std::find(begin(), end(), obj); - unsigned int getNumObjects() const { - return _objects.size(); - } + if(i == end()) return false; - Vector& getObjects() { - return _objects; - } + _objects.erase(i); - const Vector& getObjects() const { - return _objects; - } + return true; + } -protected: - bool _remove(object_type* obj) { - Iterator i = std::find(begin(), end(), obj); + bool _removeByName(const std::string& name) { + for(Iterator i = begin(); i != end(); i++) if(i->get()->getName() == name) { + _objects.erase(i); - if(i == end()) return false; + return true; + } - _objects.erase(i); + return false; + } - return true; - } + Vector _objects; - bool _removeByName(const std::string& name) { - for(Iterator i = begin(); i != end(); i++) if(i->get()->getName() == name) { - _objects.erase(i); + private: - return true; - } + // 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; + } - return false; - } }; } diff --git a/include/osgWidget/Util b/include/osgWidget/Util index b8cee8a82..4a34837ca 100644 --- a/include/osgWidget/Util +++ b/include/osgWidget/Util @@ -18,33 +18,38 @@ namespace osgWidget { // These are NOT OSGWIDGET_EXPORT'd; these are internal only! -inline std::ostream& _notify(osg::NotifySeverity ns = osg::INFO) { - std::ostream& n = osg::notify(ns); - - return n << "osgWidget: "; +inline std::ostream& _notify(osg::NotifySeverity ns = osg::INFO) +{ + std::ostream& n = osg::notify(ns); + + return n << "osgWidget: "; } -inline std::ostream& warn() { - return _notify(osg::WARN); +inline std::ostream& warn() +{ + return _notify(osg::WARN); } -inline std::ostream& info() { - return _notify(); +inline std::ostream& info() +{ + return _notify(); } -inline std::string lowerCase(const std::string& str) { - std::string s = str; +inline std::string lowerCase(const std::string& str) +{ + std::string s = str; - // TODO: Why can't I specify std::tolower? - std::transform(s.begin(), s.end(), s.begin(), ::tolower); + // TODO: Why can't I specify std::tolower? + std::transform(s.begin(), s.end(), s.begin(), ::tolower); - return s; + return s; } // TODO: Is this totally ghetto or what? template -inline bool hasDecimal(T v) { - return (v - static_cast(static_cast(v))) > 0.0f; +inline bool hasDecimal(T v) +{ + return (v - static_cast(static_cast(v))) > 0.0f; } class WindowManager; @@ -66,10 +71,10 @@ OSGWIDGET_EXPORT int createExample(osgViewer::Viewer&, WindowManager*, osg::Node // view for looking at your 2D scene. // TODO: Fix this! OSGWIDGET_EXPORT int createCompositeExample( - osgViewer::CompositeViewer&, - osgViewer::View*, - WindowManager*, - osg::Node* = 0 + osgViewer::CompositeViewer&, + osgViewer::View*, + WindowManager*, + osg::Node* = 0 ); OSGWIDGET_EXPORT bool writeWindowManagerNode(WindowManager*); diff --git a/include/osgWidget/ViewerEventHandlers b/include/osgWidget/ViewerEventHandlers index b78e8cb65..1d83a3579 100644 --- a/include/osgWidget/ViewerEventHandlers +++ b/include/osgWidget/ViewerEventHandlers @@ -15,62 +15,73 @@ namespace osgWidget { // This handles the pressing/moving of mouse buttons, etc. -class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler { - osg::ref_ptr _wm; +class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler +{ + public: + MouseHandler(WindowManager*); - bool _handleMousePush (float, float, int); - bool _handleMouseRelease (float, float, int); - bool _handleMouseDoubleClick (float, float, int); - bool _handleMouseDrag (float, float, int); - bool _handleMouseMove (float, float, int); - bool _handleMouseScroll (float, float, int); + virtual bool handle( + const osgGA::GUIEventAdapter&, + osgGA::GUIActionAdapter&, + osg::Object*, + osg::NodeVisitor* + ); - typedef bool (MouseHandler::*MouseAction)(float, float, int); - typedef bool (WindowManager::*MouseEvent)(float, float); + protected: - MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const; - bool _doMouseEvent (float, float, MouseEvent); + osg::ref_ptr _wm; + + bool _handleMousePush (float, float, int); + bool _handleMouseRelease (float, float, int); + bool _handleMouseDoubleClick (float, float, int); + bool _handleMouseDrag (float, float, int); + bool _handleMouseMove (float, float, int); + bool _handleMouseScroll (float, float, int); + + typedef bool (MouseHandler::*MouseAction)(float, float, int); + typedef bool (WindowManager::*MouseEvent)(float, float); + + MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const; + 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. -class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler { - osg::ref_ptr _wm; +class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler +{ + public: + KeyboardHandler(WindowManager*); -public: - KeyboardHandler(WindowManager*); + virtual bool handle( + const osgGA::GUIEventAdapter&, + osgGA::GUIActionAdapter&, + osg::Object*, + osg::NodeVisitor* + ); + + protected: + osg::ref_ptr _wm; - virtual bool handle( - const osgGA::GUIEventAdapter&, - osgGA::GUIActionAdapter&, - osg::Object*, - osg::NodeVisitor* - ); }; // This class offers a default kind of handling for resizing. -class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler { - osg::ref_ptr _wm; - osg::ref_ptr _camera; +class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler +{ + public: + ResizeHandler(WindowManager*, osg::Camera*); -public: - ResizeHandler(WindowManager*, osg::Camera*); + virtual bool handle( + const osgGA::GUIEventAdapter&, + osgGA::GUIActionAdapter&, + osg::Object*, + osg::NodeVisitor* + ); + + protected: + + osg::ref_ptr _wm; + osg::ref_ptr _camera; - virtual bool handle( - const osgGA::GUIEventAdapter&, - osgGA::GUIActionAdapter&, - osg::Object*, - osg::NodeVisitor* - ); }; } diff --git a/include/osgWidget/Widget b/include/osgWidget/Widget index bf5c23388..cedf43306 100644 --- a/include/osgWidget/Widget +++ b/include/osgWidget/Widget @@ -22,466 +22,466 @@ class WindowManager; // or relative). class OSGWIDGET_EXPORT Widget: public osg::Geometry, public EventInterface, public StyleInterface { public: - enum POINT { - LOWER_LEFT = 0, - LOWER_RIGHT = 1, - UPPER_RIGHT = 2, - UPPER_LEFT = 3, - LL = LOWER_LEFT, - LR = LOWER_RIGHT, - UR = UPPER_RIGHT, - UL = UPPER_LEFT, - ALL_POINTS = 4 - }; - - enum LAYER { - LAYER_TOP = 20, - LAYER_HIGH = 15, - LAYER_MIDDLE = 10, - LAYER_LOW = 5, - LAYER_BG = 0 - }; - - enum VERTICAL_ALIGNMENT { - VA_CENTER, - VA_TOP, - VA_BOTTOM - }; - - enum HORIZONTAL_ALIGNMENT { - HA_CENTER, - HA_LEFT, - HA_RIGHT - }; - - enum COORDINATE_MODE { - CM_ABSOLUTE, - CM_RELATIVE - }; - - - Widget (const std::string& = "", point_type = 0.0f, point_type = 0.0f); - Widget (const Widget&, const osg::CopyOp&); - - META_Object (osgWidget, Widget); - META_UIObject (Widget); - - - virtual ~Widget() { - } - - // This method is called when the widget is added to a Window; this is useful - // when the widget needs to do something advanced (like a Label). The parent - // is passed as the first argument, although _parent should already be set. - virtual void parented(Window*) { - } - - virtual void unparented(Window*) { - } - - // This method is called when the widget's parent Window is added to a - // WindowManager object. The base managed method (WHICH YOU MUST REMEMBER - // TO CALL IN YOUR DERIVED METHODS!) sets the TexMat properly depending - // on what coordinate system you're using. - virtual void managed(WindowManager*); - - virtual void unmanaged(WindowManager*) { - } - - // This method is called when the widget is resized or reallocated in any - // way. This is useful when the widget manages some internal Drawables that need - // to be modified in some way. - virtual void positioned() { - } - - void setDimensions( - point_type = -1.0f, - point_type = -1.0f, - point_type = -1.0f, - point_type = -1.0f, - point_type = -1.0f - ); - - void setPadding (point_type); - void setColor (color_type, color_type, color_type, color_type, POINT = ALL_POINTS); - void addColor (color_type, color_type, color_type, color_type, POINT = ALL_POINTS); - void setTexCoord (texcoord_type, texcoord_type, POINT = ALL_POINTS); - - // These are additional texture coordinate setting methods. - // This method will use a given origin as the LOWER_LEFT point and texture the - // remaining area based on some width and height values. - void setTexCoordRegion(point_type, point_type, point_type, point_type); - - // These are convenience methods for setting up wrapping modes. - void setTexCoordWrapHorizontal (); - void setTexCoordWrapVertical (); - - bool setImage (osg::Image*, bool=false); - bool setImage (const std::string&, bool=false); - - void addX (point_type); - void addY (point_type); - void addWidth (point_type); - void addHeight (point_type); - void addOrigin (point_type, point_type); - void addSize (point_type, point_type); - - point_type getWidth () const; - point_type getHeight () const; - point_type getX () const; - point_type getY () const; - point_type getZ () const; - point_type getPadHorizontal () const; - point_type getPadVertical () const; - - const Point& getPoint (POINT = ALL_POINTS) const; - const Color& getColor (POINT = ALL_POINTS) const; - const TexCoord& getTexCoord (POINT = ALL_POINTS) const; - - POINT convertPoint (POINT) const; - Color getImageColorAtXY (point_type x, point_type y) const; - XYCoord localXY (double, double) const; - - bool isPaddingUniform() const; - - bool isManaged() const { - return _isManaged; - } - - bool isStyled() const { - return _isStyled; - } - - void setDimensions(const Quad& q, point_type z = -1.0f) { - setDimensions(q[0], q[1], q[2], q[4], z); - } - - void setX(point_type x) { - setDimensions(x); - } - - void setY(point_type y) { - setDimensions(-1.0f, y); - } - - // This method should be use with extreme caution. - void setZ(point_type z) { - setDimensions(-1.0f, -1.0f, -1.0f, -1.0f, z); - } - - void setWidth(point_type w) { - setDimensions(-1.0f, -1.0f, w); - } - - void setHeight(point_type h) { - setDimensions(-1.0f, -1.0f, -1.0f, h); - } - - void setOrigin(point_type x, point_type y) { - setDimensions(x, y); - } - - void setOrigin(const XYCoord& xy) { - setOrigin(xy.x(), xy.y()); - } - - void setSize(point_type w, point_type h) { - setDimensions(-1.0f, -1.0f, w, h); - } - - void setSize(const XYCoord& xy) { - setSize(xy.x(), xy.y()); - } - - void setColor(const Color& col, POINT p = ALL_POINTS) { - setColor(col.r(), col.g(), col.b(), col.a(), p); - } - - void setTexCoord(const XYCoord& xy, POINT p = ALL_POINTS) { - setTexCoord(xy.x(), xy.y(), p); - } - - void setTexCoordRegion(const XYCoord& xy, point_type w, point_type h) { - setTexCoordRegion(xy.x(), xy.y(), w, h); - } - - void addColor(const Color& col, POINT p = ALL_POINTS) { - addColor(col.r(), col.g(), col.b(), col.a(), p); - } - - void addOrigin(const XYCoord& xy) { - addOrigin(xy.x(), xy.y()); - } - - void addSize(const XYCoord& xy) { - addSize(xy.x(), xy.y()); - } - - void setMinimumSize(point_type width, point_type height) { - _minWidth = width; - _minHeight = height; - } - - void setMinimumSize(const XYCoord& xy) { - setMinimumSize(xy.x(), xy.y()); - } - - // TODO: Refine this... - void setLayer(LAYER l, unsigned int offset = 0) { - _layer = l + offset; - } - - void setPadLeft(point_type p) { - _padLeft = p; - } - - void setPadRight(point_type p) { - _padRight = p; - } - - void setPadTop(point_type p) { - _padTop = p; - } - - void setPadBottom(point_type p) { - _padBottom = p; - } - - void setAlignHorizontal(HORIZONTAL_ALIGNMENT h) { - _halign = h; - } - - void setAlignVertical(VERTICAL_ALIGNMENT v) { - _valign = v; - } - - void setCoordinateMode(COORDINATE_MODE cm) { - _coordMode = cm; - } - - void setCanFill(bool f) { - _canFill = f; - } - - void setCanClone(bool c) { - _canClone = c; - } - - WindowManager* getWindowManager() { - return _getWindowManager(); - } - - const WindowManager* getWindowManager() const { - return _getWindowManager(); - } - - Window* getParent() { - return _parent; - } - - const Window* getParent() const { - return _parent; - } - - unsigned int getIndex() const { - return _index; - } + enum POINT { + LOWER_LEFT = 0, + LOWER_RIGHT = 1, + UPPER_RIGHT = 2, + UPPER_LEFT = 3, + LL = LOWER_LEFT, + LR = LOWER_RIGHT, + UR = UPPER_RIGHT, + UL = UPPER_LEFT, + ALL_POINTS = 4 + }; + + enum LAYER { + LAYER_TOP = 20, + LAYER_HIGH = 15, + LAYER_MIDDLE = 10, + LAYER_LOW = 5, + LAYER_BG = 0 + }; + + enum VERTICAL_ALIGNMENT { + VA_CENTER, + VA_TOP, + VA_BOTTOM + }; + + enum HORIZONTAL_ALIGNMENT { + HA_CENTER, + HA_LEFT, + HA_RIGHT + }; + + enum COORDINATE_MODE { + CM_ABSOLUTE, + CM_RELATIVE + }; + + + Widget (const std::string& = "", point_type = 0.0f, point_type = 0.0f); + Widget (const Widget&, const osg::CopyOp&); + + META_Object (osgWidget, Widget); + META_UIObject (Widget); + + + virtual ~Widget() { + } + + // This method is called when the widget is added to a Window; this is useful + // when the widget needs to do something advanced (like a Label). The parent + // is passed as the first argument, although _parent should already be set. + virtual void parented(Window*) { + } + + virtual void unparented(Window*) { + } + + // This method is called when the widget's parent Window is added to a + // WindowManager object. The base managed method (WHICH YOU MUST REMEMBER + // TO CALL IN YOUR DERIVED METHODS!) sets the TexMat properly depending + // on what coordinate system you're using. + virtual void managed(WindowManager*); + + virtual void unmanaged(WindowManager*) { + } + + // This method is called when the widget is resized or reallocated in any + // way. This is useful when the widget manages some internal Drawables that need + // to be modified in some way. + virtual void positioned() { + } + + void setDimensions( + point_type = -1.0f, + point_type = -1.0f, + point_type = -1.0f, + point_type = -1.0f, + point_type = -1.0f + ); + + void setPadding (point_type); + void setColor (color_type, color_type, color_type, color_type, POINT = ALL_POINTS); + void addColor (color_type, color_type, color_type, color_type, POINT = ALL_POINTS); + void setTexCoord (texcoord_type, texcoord_type, POINT = ALL_POINTS); + + // These are additional texture coordinate setting methods. + // This method will use a given origin as the LOWER_LEFT point and texture the + // remaining area based on some width and height values. + void setTexCoordRegion(point_type, point_type, point_type, point_type); + + // These are convenience methods for setting up wrapping modes. + void setTexCoordWrapHorizontal (); + void setTexCoordWrapVertical (); + + bool setImage (osg::Image*, bool=false); + bool setImage (const std::string&, bool=false); + + void addX (point_type); + void addY (point_type); + void addWidth (point_type); + void addHeight (point_type); + void addOrigin (point_type, point_type); + void addSize (point_type, point_type); + + point_type getWidth () const; + point_type getHeight () const; + point_type getX () const; + point_type getY () const; + point_type getZ () const; + point_type getPadHorizontal () const; + point_type getPadVertical () const; + + const Point& getPoint (POINT = ALL_POINTS) const; + const Color& getColor (POINT = ALL_POINTS) const; + const TexCoord& getTexCoord (POINT = ALL_POINTS) const; + + POINT convertPoint (POINT) const; + Color getImageColorAtXY (point_type x, point_type y) const; + XYCoord localXY (double, double) const; + + bool isPaddingUniform() const; + + bool isManaged() const { + return _isManaged; + } + + bool isStyled() const { + return _isStyled; + } + + void setDimensions(const Quad& q, point_type z = -1.0f) { + setDimensions(q[0], q[1], q[2], q[4], z); + } + + void setX(point_type x) { + setDimensions(x); + } + + void setY(point_type y) { + setDimensions(-1.0f, y); + } + + // This method should be use with extreme caution. + void setZ(point_type z) { + setDimensions(-1.0f, -1.0f, -1.0f, -1.0f, z); + } + + void setWidth(point_type w) { + setDimensions(-1.0f, -1.0f, w); + } + + void setHeight(point_type h) { + setDimensions(-1.0f, -1.0f, -1.0f, h); + } + + void setOrigin(point_type x, point_type y) { + setDimensions(x, y); + } + + void setOrigin(const XYCoord& xy) { + setOrigin(xy.x(), xy.y()); + } + + void setSize(point_type w, point_type h) { + setDimensions(-1.0f, -1.0f, w, h); + } + + void setSize(const XYCoord& xy) { + setSize(xy.x(), xy.y()); + } + + void setColor(const Color& col, POINT p = ALL_POINTS) { + setColor(col.r(), col.g(), col.b(), col.a(), p); + } + + void setTexCoord(const XYCoord& xy, POINT p = ALL_POINTS) { + setTexCoord(xy.x(), xy.y(), p); + } + + void setTexCoordRegion(const XYCoord& xy, point_type w, point_type h) { + setTexCoordRegion(xy.x(), xy.y(), w, h); + } + + void addColor(const Color& col, POINT p = ALL_POINTS) { + addColor(col.r(), col.g(), col.b(), col.a(), p); + } + + void addOrigin(const XYCoord& xy) { + addOrigin(xy.x(), xy.y()); + } + + void addSize(const XYCoord& xy) { + addSize(xy.x(), xy.y()); + } + + void setMinimumSize(point_type width, point_type height) { + _minWidth = width; + _minHeight = height; + } + + void setMinimumSize(const XYCoord& xy) { + setMinimumSize(xy.x(), xy.y()); + } + + // TODO: Refine this... + void setLayer(LAYER l, unsigned int offset = 0) { + _layer = l + offset; + } - XYCoord getOrigin() const { - return XYCoord(getX(), getY()); - } + void setPadLeft(point_type p) { + _padLeft = p; + } - Color getImageColorAtXY(const XYCoord& xy) const { - return getImageColorAtXY(xy.x(), xy.y()); - } + void setPadRight(point_type p) { + _padRight = p; + } - Color getImageColorAtPointerXY(double x, double y) const { - return getImageColorAtXY(localXY(x, y)); - } + void setPadTop(point_type p) { + _padTop = p; + } - Point getPosition() const { - return Point(getX(), getY(), getZ()); - } - - XYCoord getSize() const { - return XYCoord(getWidth(), getHeight()); - } - - Quad getDimensions() const { - return Quad(getX(), getY(), getWidth(), getHeight()); - } - - point_type getPadLeft() const { - return _padLeft; - } - - point_type getPadRight() const { - return _padRight; - } - - point_type getPadTop() const { - return _padTop; - } - - point_type getPadBottom() const { - return _padBottom; - } - - HORIZONTAL_ALIGNMENT getAlignHorizontal() const { - return _halign; - } - - VERTICAL_ALIGNMENT getAlignVertical() const { - return _valign; - } - - COORDINATE_MODE getCoordinateMode() const { - return _coordMode; - } - - bool canFill() const { - return _canFill; - } - - bool canClone() const { - return _canClone; - } - - // This casts the bool _fill variable to be used in iteratively in functions such - // as Window::_accumulate and whatnot. - point_type getFillAsNumeric() const { - return static_cast(_canFill); - } - - point_type getWidthTotal() const { - return getWidth() + getPadHorizontal(); - } - - point_type getHeightTotal() const { - return getHeight() + getPadVertical(); - } - - point_type getMinWidth() const { - return _minWidth; - } - - point_type getMinHeight() const { - return _minHeight; - } - - point_type getMinWidthTotal() const { - return _minWidth + getPadHorizontal(); - } + void setPadBottom(point_type p) { + _padBottom = p; + } - point_type getMinHeightTotal() const { - return _minHeight + getPadVertical(); - } - - unsigned int getLayer() const { - return _layer; - } + void setAlignHorizontal(HORIZONTAL_ALIGNMENT h) { + _halign = h; + } + + void setAlignVertical(VERTICAL_ALIGNMENT v) { + _valign = v; + } + + void setCoordinateMode(COORDINATE_MODE cm) { + _coordMode = cm; + } + + void setCanFill(bool f) { + _canFill = f; + } + + void setCanClone(bool c) { + _canClone = c; + } + + WindowManager* getWindowManager() { + return _getWindowManager(); + } + + const WindowManager* getWindowManager() const { + return _getWindowManager(); + } + + Window* getParent() { + return _parent; + } + + const Window* getParent() const { + return _parent; + } -protected: + unsigned int getIndex() const { + return _index; + } + XYCoord getOrigin() const { + return XYCoord(getX(), getY()); + } + Color getImageColorAtXY(const XYCoord& xy) const { + return getImageColorAtXY(xy.x(), xy.y()); + } - point_type _calculateZ(unsigned int) const; + Color getImageColorAtPointerXY(double x, double y) const { + return getImageColorAtXY(localXY(x, y)); + } - PointArray* _verts() { - return dynamic_cast(getVertexArray()); - } + Point getPosition() const { + return Point(getX(), getY(), getZ()); + } - const PointArray* _verts() const { - return dynamic_cast(getVertexArray()); - } + XYCoord getSize() const { + return XYCoord(getWidth(), getHeight()); + } - ColorArray* _cols() { - return dynamic_cast(getColorArray()); - } + Quad getDimensions() const { + return Quad(getX(), getY(), getWidth(), getHeight()); + } - const ColorArray* _cols() const { - return dynamic_cast(getColorArray()); - } - - TexCoordArray* _texs() { - return dynamic_cast(getTexCoordArray(0)); - } - - const TexCoordArray* _texs() const { - return dynamic_cast(getTexCoordArray(0)); - } + point_type getPadLeft() const { + return _padLeft; + } - osg::Texture2D* _texture() { - return dynamic_cast( - getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE) - ); - } + point_type getPadRight() const { + return _padRight; + } - const osg::Texture2D* _texture() const { - return dynamic_cast( - getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE) - ); - } + point_type getPadTop() const { + return _padTop; + } - osg::Image* _image() { - return _getImage(); - } + point_type getPadBottom() const { + return _padBottom; + } - const osg::Image* _image() const { - return _getImage(); - } + HORIZONTAL_ALIGNMENT getAlignHorizontal() const { + return _halign; + } - friend class Window; + VERTICAL_ALIGNMENT getAlignVertical() const { + return _valign; + } - // TODO: Because of the current class design, I don't think it's possible to - // have a ref_ptr here. :( - Window* _parent; + COORDINATE_MODE getCoordinateMode() const { + return _coordMode; + } - unsigned int _index; - unsigned int _layer; + bool canFill() const { + return _canFill; + } - // Padding is the value of pixels of space between whatever the widget is "contianed" - // in and the point at which it starts getting placed. - point_type _padLeft; - point_type _padRight; - point_type _padTop; - point_type _padBottom; + bool canClone() const { + return _canClone; + } - // The alignments are used in conjuction when the widget is NOT set to fill. - VERTICAL_ALIGNMENT _valign; - HORIZONTAL_ALIGNMENT _halign; + // This casts the bool _fill variable to be used in iteratively in functions such + // as Window::_accumulate and whatnot. + point_type getFillAsNumeric() const { + return static_cast(_canFill); + } - // This flag determines how sizing values are interpretted by setDimensions(). - COORDINATE_MODE _coordMode; + point_type getWidthTotal() const { + return getWidth() + getPadHorizontal(); + } - // These are the relative values, which are not stored directly in our verts - // array but kept around for calculation later. - Quad _relCoords; + point_type getHeightTotal() const { + return getHeight() + getPadVertical(); + } - // This fill flag determines whether or not the widget will resize itself to fill - // all available space. - bool _canFill; + point_type getMinWidth() const { + return _minWidth; + } - // Set this to false in an implementation to prevent copying. - bool _canClone; + point_type getMinHeight() const { + return _minHeight; + } - // This variable is only used by the Window object to determine if it's necessary - // to call managed(). - bool _isManaged; + point_type getMinWidthTotal() const { + return _minWidth + getPadHorizontal(); + } - // This variable is like _isManaged; it is used to store whether the Widget has - // been styled yet. - bool _isStyled; + point_type getMinHeightTotal() const { + return _minHeight + getPadVertical(); + } - // Set these variables to be the minimum size of a Widget so that it cannot be - // resized any smaller than this. - point_type _minWidth; - point_type _minHeight; + unsigned int getLayer() const { + return _layer; + } - static osg::ref_ptr _norms; + protected: - WindowManager* _getWindowManager () const; - osg::Image* _getImage () const; + + + point_type _calculateZ(unsigned int) const; + + PointArray* _verts() { + return dynamic_cast(getVertexArray()); + } + + const PointArray* _verts() const { + return dynamic_cast(getVertexArray()); + } + + ColorArray* _cols() { + return dynamic_cast(getColorArray()); + } + + const ColorArray* _cols() const { + return dynamic_cast(getColorArray()); + } + + TexCoordArray* _texs() { + return dynamic_cast(getTexCoordArray(0)); + } + + const TexCoordArray* _texs() const { + return dynamic_cast(getTexCoordArray(0)); + } + + osg::Texture2D* _texture() { + return dynamic_cast( + getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE) + ); + } + + const osg::Texture2D* _texture() const { + return dynamic_cast( + getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE) + ); + } + + osg::Image* _image() { + return _getImage(); + } + + const osg::Image* _image() const { + return _getImage(); + } + + friend class Window; + + // TODO: Because of the current class design, I don't think it's possible to + // have a ref_ptr here. :( + Window* _parent; + + unsigned int _index; + unsigned int _layer; + + // Padding is the value of pixels of space between whatever the widget is "contianed" + // in and the point at which it starts getting placed. + point_type _padLeft; + point_type _padRight; + point_type _padTop; + point_type _padBottom; + + // The alignments are used in conjuction when the widget is NOT set to fill. + VERTICAL_ALIGNMENT _valign; + HORIZONTAL_ALIGNMENT _halign; + + // This flag determines how sizing values are interpretted by setDimensions(). + COORDINATE_MODE _coordMode; + + // These are the relative values, which are not stored directly in our verts + // array but kept around for calculation later. + Quad _relCoords; + + // This fill flag determines whether or not the widget will resize itself to fill + // all available space. + bool _canFill; + + // Set this to false in an implementation to prevent copying. + bool _canClone; + + // This variable is only used by the Window object to determine if it's necessary + // to call managed(). + bool _isManaged; + + // This variable is like _isManaged; it is used to store whether the Widget has + // been styled yet. + bool _isStyled; + + // Set these variables to be the minimum size of a Widget so that it cannot be + // resized any smaller than this. + point_type _minWidth; + point_type _minHeight; + + static osg::ref_ptr _norms; + + WindowManager* _getWindowManager () const; + osg::Image* _getImage () const; }; @@ -489,140 +489,140 @@ typedef std::list > WidgetList; // A Widget subclass that prints stuff using osg::notify(). :) struct NotifyWidget: public Widget { - META_Object(osgWidget, NotifyWidget); + META_Object(osgWidget, NotifyWidget); - NotifyWidget(const std::string& n = "", point_type w = 0.0f, point_type h = 0.0f): - Widget(n, w, h) { - setEventMask(EVENT_ALL); - } + NotifyWidget(const std::string& n = "", point_type w = 0.0f, point_type h = 0.0f): + Widget(n, w, h) { + setEventMask(EVENT_ALL); + } - NotifyWidget(const NotifyWidget& widget, const osg::CopyOp& co): - Widget(widget, co) { - } + NotifyWidget(const NotifyWidget& widget, const osg::CopyOp& co): + Widget(widget, co) { + } - bool focus(const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > focus called" << std::endl; + bool focus(const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > focus called" << std::endl; - return false; - } + return false; + } - bool unfocus(const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > unfocus called" << std::endl; + bool unfocus(const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > unfocus called" << std::endl; - return false; - } + return false; + } - bool mouseEnter(double, double, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > mouseEnter called" << std::endl; + bool mouseEnter(double, double, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > mouseEnter called" << std::endl; - return false; - } + return false; + } - bool mouseOver(double, double, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > mouseOver called" << std::endl; + bool mouseOver(double, double, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > mouseOver called" << std::endl; - return false; - } - - bool mouseLeave(double, double, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > mouseLeave called" << std::endl; + return false; + } - return false; - } + bool mouseLeave(double, double, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > mouseLeave called" << std::endl; - bool mouseDrag(double, double, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > mouseDrag called" << std::endl; + return false; + } - return false; - } + bool mouseDrag(double, double, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > mouseDrag called" << std::endl; - bool mousePush(double, double, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > mousePush called" << std::endl; + return false; + } - return false; - } + bool mousePush(double, double, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > mousePush called" << std::endl; - bool mouseRelease(double, double, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > mouseRelease called" << std::endl; + return false; + } - return false; - } + bool mouseRelease(double, double, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > mouseRelease called" << std::endl; - bool mouseScroll(double, double, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > mouseScroll called" << std::endl; + return false; + } - return false; - } + bool mouseScroll(double, double, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > mouseScroll called" << std::endl; - bool keyPress(int, int, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > keyPress called" << std::endl; + return false; + } - return false; - } + bool keyPress(int, int, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > keyPress called" << std::endl; - bool keyRelease(int, int, const WindowManager*) { - osg::notify(osg::NOTICE) << _name << " > keyRelease called" << std::endl; + return false; + } - return false; - } + bool keyRelease(int, int, const WindowManager*) { + osg::notify(osg::NOTICE) << _name << " > keyRelease called" << std::endl; + + return false; + } }; // A Widget that eats all events and returns true. struct NullWidget: public Widget { - META_Object(osgWidget, NullWidget); + META_Object(osgWidget, NullWidget); - NullWidget(const std::string& n = "", point_type w = 0.0f, point_type h = 0.0f): - Widget(n, w, h) { - setEventMask(EVENT_ALL); - } + NullWidget(const std::string& n = "", point_type w = 0.0f, point_type h = 0.0f): + Widget(n, w, h) { + setEventMask(EVENT_ALL); + } - NullWidget(const NullWidget& widget, const osg::CopyOp& co): - Widget(widget, co) { - } + NullWidget(const NullWidget& widget, const osg::CopyOp& co): + Widget(widget, co) { + } - bool focus(const WindowManager*) { - return true; - } + bool focus(const WindowManager*) { + return true; + } - bool unfocus(const WindowManager*) { - return true; - } + bool unfocus(const WindowManager*) { + return true; + } - bool mouseEnter(double, double, const WindowManager*) { - return true; - } + bool mouseEnter(double, double, const WindowManager*) { + return true; + } - bool mouseOver(double, double, const WindowManager*) { - return true; - } - - bool mouseLeave(double, double, const WindowManager*) { - return true; - } + bool mouseOver(double, double, const WindowManager*) { + return true; + } - bool mouseDrag(double, double, const WindowManager*) { - return true; - } + bool mouseLeave(double, double, const WindowManager*) { + return true; + } - bool mousePush(double, double, const WindowManager*) { - return true; - } + bool mouseDrag(double, double, const WindowManager*) { + return true; + } - bool mouseRelease(double, double, const WindowManager*) { - return true; - } + bool mousePush(double, double, const WindowManager*) { + return true; + } - bool mouseScroll(double, double, const WindowManager*) { - return true; - } - - bool keyPress(int, int, const WindowManager*) { - return true; - } + bool mouseRelease(double, double, const WindowManager*) { + return true; + } - bool keyRelease(int, int, const WindowManager*) { - return true; - } + bool mouseScroll(double, double, const WindowManager*) { + return true; + } + + bool keyPress(int, int, const WindowManager*) { + return true; + } + + bool keyRelease(int, int, const WindowManager*) { + return true; + } }; } diff --git a/include/osgWidget/Window b/include/osgWidget/Window index 0fe0a50a4..fca1f7bab 100644 --- a/include/osgWidget/Window +++ b/include/osgWidget/Window @@ -25,604 +25,604 @@ bool callbackWindowScale (Event&); bool callbackWindowTabFocus(Event&); class OSGWIDGET_EXPORT Window: - public osg::MatrixTransform, - public UIObjectParent, - public EventInterface, - public StyleInterface + public osg::MatrixTransform, + public UIObjectParent, + public EventInterface, + public StyleInterface { -public: - typedef std::list > WindowList; - - struct Sizes { - point_type cur; - point_type min; - - Sizes(point_type c = -1.0f, point_type m = -1.0f): - cur(c), - min(m) { - } - }; - - // TODO: This is a class that puts (embeds) the Window inside of a Widget - // interface, to help assemble Windows with Windows, and what have you. - class OSGWIDGET_EXPORT EmbeddedWindow: public Widget { - osg::ref_ptr _window; - - public: - META_Object (osgWidget::Window, EmbeddedWindow); - META_UIObject (EmbeddedWindow); - - EmbeddedWindow (const std::string& = "", point_type = 0.0f, point_type = 0.0f); - EmbeddedWindow (const EmbeddedWindow&, const osg::CopyOp&); - - virtual void parented (Window*); - virtual void unparented (Window*); - virtual void managed (WindowManager*); - virtual void unmanaged (WindowManager*); - virtual void positioned (); - - bool setWindow(Window*); - - Window* getWindow() { - return _window.get(); - } - - const Window* getWindow() const { - return _window.get(); - } - }; - - // These correspond to special regions honored by the WindowManager. Most Windows - // will want to be NONE, unless they need to exist in the foreground or background - // for some reason. - enum STRATA { - STRATA_NONE, - STRATA_BACKGROUND, - STRATA_FOREGROUND - }; - - // If you only want to display a portion of a Window (such as when it is embedded), - // you will need to set the VISIBILITY_MODE to WM_PARTIAL. Otherwise, the entire - // Window is visible by default. The final enum, VM_ENTIRE, says that no Scissoring - // should take place at all, and is useful in cases where you want to properly - // scale or rotate Windows. - enum VISIBILITY_MODE { - VM_FULL, - VM_PARTIAL, - VM_ENTIRE - }; - - // Anchors are very similar in that they allow us to pre-apply transformations in the - // call to Window::update() that allow us to position a Window somewhere relative - // to the WindowManger's viewable area. However, unlike the ALIGNMENT enums, these - // are totally optional (whereas a Widget must always have some ALIGNMENT value set. - enum VERTICAL_ANCHOR { - VA_NONE, - VA_CENTER, - VA_TOP, - VA_BOTTOM - }; - - enum HORIZONTAL_ANCHOR { - HA_NONE, - HA_CENTER, - HA_LEFT, - HA_RIGHT - }; - - META_UIObject(Window); - - Window (const std::string& = ""); - Window (const Window&, const osg::CopyOp&); - - bool resize (point_type = 0.0f, point_type = 0.0f); - bool resizeAdd (point_type = 0.0f, point_type = 0.0f); - bool resizePercent (point_type = 0.0f, point_type = 0.0f); - - virtual void update (); - virtual void managed (WindowManager*); - virtual void unmanaged (WindowManager*); - virtual bool addWidget (Widget*); - virtual bool insertWidget (Widget*, unsigned int); - virtual bool removeWidget (Widget*); - virtual bool replaceWidget (Widget*, Widget*); - - // This method wraps our Geode's addDrawable() method and returns the index of - // the newly-added Drawable. - unsigned int addDrawableAndGetIndex(osg::Drawable*); - - bool isVisible () const; - bool isXYWithinVisible (float, float) const; - void setVisibleArea (int = 0, int = 0, int = 0, int = 0); - void addVisibleArea (int = 0, int = 0, int = 0, int = 0); - bool setFocused (const Widget*); - bool setFocused (const std::string&); - bool setFirstFocusable (); - bool setNextFocusable (); - bool getFocusList (WidgetList&) const; - bool getEmbeddedList (WindowList&) const; - void getParentList (WindowList&) const; - - XYCoord localXY (double, double) const; - XYCoord getAbsoluteOrigin () const; - - // This method wraps the current Window in a EmbeddedWindow object and returns it. - EmbeddedWindow* embed(); - - Widget* getFocused() { - return _focused.get(); - } - - const Widget* getFocused() const { - return _focused.get(); - } - - bool show() { - return _setVisible(true); - } - - bool hide() { - return _setVisible(false); - } - - bool isPointerXYWithinVisible(float x, float y) const { - XYCoord xy = localXY(x, y); - - return isXYWithinVisible(xy.x(), xy.y()); - } - - osg::Geode* getGeode() { - return _geode(); - } - - const osg::Geode* getGeode() const { - return _geode(); - } - - Widget* getBackground() { - return _bg(); - } - - const Widget* getBackground() const { - return _bg(); - } - - WindowManager* getWindowManager() { - return _wm; - } - - const WindowManager* getWindowManager() const { - return _wm; - } - - Window* getParent() { - return _parent; - } - - const Window* getParent() const { - return _parent; - } - - Window* getTopmostParent() { - return _getTopmostParent(); - } - - const Window* getTopmostParent() const { - return _getTopmostParent(); - } - - unsigned int getIndex() const { - return _index; - } - - matrix_type getX() const { - return _x; - } - - matrix_type getY() const { - return _y; - } - - matrix_type getZ() const { - return _z; - } - - point_type getWidth() const { - return _width.cur; - } - - point_type getHeight() const { - return _height.cur; - } - - point_type getMinWidth() const { - return _width.min; - } - - point_type getMinHeight() const { - return _height.min; - } - - VERTICAL_ANCHOR getAnchorVertical() const { - return _vAnchor; - } - - HORIZONTAL_ANCHOR getAnchorHorizontal() const { - return _hAnchor; - } - - XYCoord getOrigin() const { - return XYCoord(_x, _y); - } - - XYCoord getSize() const { - return XYCoord(_width.cur, _height.cur); - } - - XYCoord getMinSize() const { - return XYCoord(_width.min, _height.min); - } - - matrix_type getZRange() const { - return _zRange; - } - - STRATA getStrata() const { - return _strata; - } - - const Quad& getVisibleArea() const { - return _visibleArea; - } - - VISIBILITY_MODE getVisibilityMode() const { - return _vis; - } - - Point getPosition() const { - return Point(_x, _y, _z); - } - - matrix_type getRotate() const { - return _r; - } - - matrix_type getScale() const { - return _s; - } - - matrix_type getScaleDenominator() const { - return _scaleDenom; - } - - void setX(matrix_type x) { - _x = x; - } + public: + typedef std::list > WindowList; + + struct Sizes { + point_type cur; + point_type min; + + Sizes(point_type c = -1.0f, point_type m = -1.0f): + cur(c), + min(m) { + } + }; + + // TODO: This is a class that puts (embeds) the Window inside of a Widget + // interface, to help assemble Windows with Windows, and what have you. + class OSGWIDGET_EXPORT EmbeddedWindow: public Widget { + osg::ref_ptr _window; + + public: + META_Object (osgWidget::Window, EmbeddedWindow); + META_UIObject (EmbeddedWindow); + + EmbeddedWindow (const std::string& = "", point_type = 0.0f, point_type = 0.0f); + EmbeddedWindow (const EmbeddedWindow&, const osg::CopyOp&); + + virtual void parented (Window*); + virtual void unparented (Window*); + virtual void managed (WindowManager*); + virtual void unmanaged (WindowManager*); + virtual void positioned (); + + bool setWindow(Window*); + + Window* getWindow() { + return _window.get(); + } + + const Window* getWindow() const { + return _window.get(); + } + }; + + // These correspond to special regions honored by the WindowManager. Most Windows + // will want to be NONE, unless they need to exist in the foreground or background + // for some reason. + enum STRATA { + STRATA_NONE, + STRATA_BACKGROUND, + STRATA_FOREGROUND + }; + + // If you only want to display a portion of a Window (such as when it is embedded), + // you will need to set the VISIBILITY_MODE to WM_PARTIAL. Otherwise, the entire + // Window is visible by default. The final enum, VM_ENTIRE, says that no Scissoring + // should take place at all, and is useful in cases where you want to properly + // scale or rotate Windows. + enum VISIBILITY_MODE { + VM_FULL, + VM_PARTIAL, + VM_ENTIRE + }; + + // Anchors are very similar in that they allow us to pre-apply transformations in the + // call to Window::update() that allow us to position a Window somewhere relative + // to the WindowManger's viewable area. However, unlike the ALIGNMENT enums, these + // are totally optional (whereas a Widget must always have some ALIGNMENT value set. + enum VERTICAL_ANCHOR { + VA_NONE, + VA_CENTER, + VA_TOP, + VA_BOTTOM + }; + + enum HORIZONTAL_ANCHOR { + HA_NONE, + HA_CENTER, + HA_LEFT, + HA_RIGHT + }; + + META_UIObject(Window); + + Window (const std::string& = ""); + Window (const Window&, const osg::CopyOp&); + + bool resize (point_type = 0.0f, point_type = 0.0f); + bool resizeAdd (point_type = 0.0f, point_type = 0.0f); + bool resizePercent (point_type = 0.0f, point_type = 0.0f); + + virtual void update (); + virtual void managed (WindowManager*); + virtual void unmanaged (WindowManager*); + virtual bool addWidget (Widget*); + virtual bool insertWidget (Widget*, unsigned int); + virtual bool removeWidget (Widget*); + virtual bool replaceWidget (Widget*, Widget*); + + // This method wraps our Geode's addDrawable() method and returns the index of + // the newly-added Drawable. + unsigned int addDrawableAndGetIndex(osg::Drawable*); + + bool isVisible () const; + bool isXYWithinVisible (float, float) const; + void setVisibleArea (int = 0, int = 0, int = 0, int = 0); + void addVisibleArea (int = 0, int = 0, int = 0, int = 0); + bool setFocused (const Widget*); + bool setFocused (const std::string&); + bool setFirstFocusable (); + bool setNextFocusable (); + bool getFocusList (WidgetList&) const; + bool getEmbeddedList (WindowList&) const; + void getParentList (WindowList&) const; + + XYCoord localXY (double, double) const; + XYCoord getAbsoluteOrigin () const; + + // This method wraps the current Window in a EmbeddedWindow object and returns it. + EmbeddedWindow* embed(); + + Widget* getFocused() { + return _focused.get(); + } + + const Widget* getFocused() const { + return _focused.get(); + } + + bool show() { + return _setVisible(true); + } + + bool hide() { + return _setVisible(false); + } + + bool isPointerXYWithinVisible(float x, float y) const { + XYCoord xy = localXY(x, y); + + return isXYWithinVisible(xy.x(), xy.y()); + } + + osg::Geode* getGeode() { + return _geode(); + } + + const osg::Geode* getGeode() const { + return _geode(); + } + + Widget* getBackground() { + return _bg(); + } + + const Widget* getBackground() const { + return _bg(); + } + + WindowManager* getWindowManager() { + return _wm; + } + + const WindowManager* getWindowManager() const { + return _wm; + } + + Window* getParent() { + return _parent; + } + + const Window* getParent() const { + return _parent; + } + + Window* getTopmostParent() { + return _getTopmostParent(); + } + + const Window* getTopmostParent() const { + return _getTopmostParent(); + } + + unsigned int getIndex() const { + return _index; + } + + matrix_type getX() const { + return _x; + } + + matrix_type getY() const { + return _y; + } + + matrix_type getZ() const { + return _z; + } + + point_type getWidth() const { + return _width.cur; + } + + point_type getHeight() const { + return _height.cur; + } + + point_type getMinWidth() const { + return _width.min; + } - void setY(matrix_type y) { - _y = y; - } + point_type getMinHeight() const { + return _height.min; + } - void setPosition(matrix_type x, matrix_type y, matrix_type z) { - _x = x; - _y = y; - _z = z; - } + VERTICAL_ANCHOR getAnchorVertical() const { + return _vAnchor; + } - void setPosition(const Point& p) { - setPosition(p.x(), p.y(), p.z()); - } - - void setOrigin(matrix_type x, matrix_type y) { - _x = x; - _y = y; - } + HORIZONTAL_ANCHOR getAnchorHorizontal() const { + return _hAnchor; + } - void setRotate(matrix_type r) { - _r = r; - } + XYCoord getOrigin() const { + return XYCoord(_x, _y); + } - void setScale(matrix_type s) { - _s = s; - } + XYCoord getSize() const { + return XYCoord(_width.cur, _height.cur); + } - void setScaleDenominator(matrix_type sd) { - _scaleDenom = sd; - } + XYCoord getMinSize() const { + return XYCoord(_width.min, _height.min); + } - void setAnchorVertical(VERTICAL_ANCHOR va) { - _vAnchor = va; - } + matrix_type getZRange() const { + return _zRange; + } - void setAnchorHorizontal(HORIZONTAL_ANCHOR ha) { - _hAnchor = ha; - } + STRATA getStrata() const { + return _strata; + } - void setStrata(STRATA s) { - _strata = s; - } + const Quad& getVisibleArea() const { + return _visibleArea; + } - void setVisibilityMode(VISIBILITY_MODE v) { - _vis = v; - } + VISIBILITY_MODE getVisibilityMode() const { + return _vis; + } - void addX(matrix_type x) { - _x += x; - } + Point getPosition() const { + return Point(_x, _y, _z); + } - void addY(matrix_type y) { - _y += y; - } - - void addZ(matrix_type z) { - _z += z; - } - - void addRotate(matrix_type r) { - _r += r; - } - - void addScale(matrix_type s) { - _s += s / (_scaleDenom != 0.0f ? _scaleDenom : 1.0f); - } - - void addOrigin(matrix_type x, matrix_type y) { - _x += x; - _y += y; - } - - void attachMoveCallback() { - addCallback(Callback(&callbackWindowMove, EVENT_MOUSE_DRAG)); - } - - void attachRotateCallback() { - addCallback(Callback(&callbackWindowRotate, EVENT_MOUSE_DRAG)); - } - - void attachScaleCallback() { - addCallback(Callback(&callbackWindowScale, EVENT_MOUSE_DRAG)); - } - - void attachTabFocusCallback() { - addCallback(Callback(&callbackWindowTabFocus, EVENT_KEY_DOWN)); - } - -protected: - typedef point_type (Widget::*Getter)() const; - - typedef std::less Less; - typedef std::greater Greater; - typedef std::plus Plus; - - friend class WindowManager; - - // The (optional) Window that this Window is parented inside. - Window* _parent; - - // The WindowManger to which this window is attached. - WindowManager* _wm; - - // The positional index this Node holds within it's parent WindowManager. - unsigned int _index; - - // The X and Y values of the Window (origin). - matrix_type _x; - matrix_type _y; - - // A pair of values representing the currently calculated Z value and the - // depth range for all children to be used during the call to update(). - matrix_type _z; - matrix_type _zRange; - - // This is a special value that can be used to "force" a Window not to be - // focusable and instead always exist in the foreground or background. - STRATA _strata; - - // A flag determining whether our visible area is the full Window or rather - // a portion of the Window. - VISIBILITY_MODE _vis; - - // A rotation value in degrees. - matrix_type _r; - - // This will also need to adjust geom internally so that picking is correct. - matrix_type _s; - - matrix_type _scaleDenom; - - Sizes _width; - Sizes _height; - - VERTICAL_ANCHOR _vAnchor; - HORIZONTAL_ANCHOR _hAnchor; - - // Not all windows have widgets that can focus, but if they do this should - // be a pointer to it. - osg::observer_ptr _focused; - - // The "visible" area that will define both the glScissor bounds AND will - // be used to make sure our pick is valid. The values herein correspond to - // X, Y, W, and H--in that order. - Quad _visibleArea; - - // This helper method is used by _compare<>() and _accumulate<>(), so ignore this - // function and go see the docs for those instead. This thing is huge and unwieldy - // and not to be triffled with! :) - template - point_type _forEachAssignOrApply( - Getter get, - int begin, - int end, - int add, - bool assign - ) const { - point_type val = 0.0f; - unsigned int c = begin; - - ConstIterator e = end > 0 ? _objects.begin() + end : _objects.end() + end; - - // I WARNED YOU! If you try and understand what this does your head will - // explode! But let me say a few things: in MSVC you can't add to an iterator - // such that the add will cause it to increment past the end of the container. - // This appears to be safe in GCC, where it will just return the last - // item therein, but causes an assertion error in other compilers. I'm not - // sure if there is a cleaner remedy for this, so what we do for now is keep a - // count variable called "c" that makes sure our iterator's opterator+() - // method is safe to call. - for( - ConstIterator i = _objects.begin() + begin; - i < e; - c += add - ) { - point_type v = 0.0f; - - if(i->valid()) v = (i->get()->*get)(); - - // If you want to assign to val, and NOT add a sequence of them... - if(assign) { - if(T()(v, val)) val = v; - } - - // If you want to accumulate a value INTO val... - else val = T()(v, val); - - // Make sure our iterator is safe to increment. Otherwise, set it to - // whatever end is. - // TODO: This isn't 100% accurate, as it does not YET take into account - // our requested end in any way other than implicitly. It should, however, - // work okay for now. - if((c + add) < _objects.size()) i += add; - - else i = e; - } - - return val; - } - - void _setWidthAndHeightUnknownSizeError (const std::string&, point_type); - void _setWidthAndHeightNotPAError (const std::string&, point_type); - void _setWidthAndHeight (); - void _removeFromGeode (Widget*); - - Widget* _getBackground() const; - Window* _getTopmostParent() const; - - // This method will return the T'th value returned by applying the Getter member function - // pointer to each iterator in the range of iterators defined by offset and add. In - // plain language, this helper method will apply some standard Widget::get* function - // to a range of objects in the _objects Vector, and will return the T'th of that. - // The template T can be any functor accepting two point_type values that return - // a bool. For example, this is commonly used with std::less to find the smallest - // width in a range of Widgets. - template - point_type _compare( - Getter get, - int begin = 0, - int end = 0, - int add = 1 - ) const { - return _forEachAssignOrApply(get, begin, end, add, true); - } - - // This method will return the T'th value accumulated by applying the Getter member - // function to each iterator in the range of iterators defined by offset and add (similar - // to above). For example, this method can be used to apply std::plus to every - // width in a range of Widgets, and return the total. - template - point_type _accumulate( - Getter get, - int begin = 0, - int end = 0, - int add = 1 - ) const { - return _forEachAssignOrApply(get, begin, end, add, false); - } - - osg::Geode* _geode() { - return dynamic_cast(getChild(0)); - } - - const osg::Geode* _geode() const { - return dynamic_cast(getChild(0)); - } - - Widget* _bg() { - return _getBackground(); - } - - const Widget* _bg() const { - return _getBackground(); - } - - osg::Scissor* _scissor() { - return dynamic_cast( - getStateSet()->getAttribute(osg::StateAttribute::SCISSOR) - ); - } - - bool _setWidget (Widget*, int = -1); - bool _setVisible (bool); - void _setFocused (Widget*); - void _setStyled (Widget*); - void _setParented (Widget*, bool=false); - void _setManaged (Widget*, bool=false); - - void _positionWidget(Widget*, point_type, point_type); - - // These return the smallest and largest width and height values for the given - // range of Widgets. - point_type _getMinWidgetWidth (int = 0, int = 0, int = 1) const; - point_type _getMinWidgetHeight (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetWidth (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetHeight (int = 0, int = 0, int = 1) const; - - // These return the smallest and largest minWidth and minHeight values for - // the given range of Widgets. - point_type _getMinWidgetMinWidth (int = 0, int = 0, int = 1) const; - point_type _getMinWidgetMinHeight (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetMinWidth (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetMinHeight (int = 0, int = 0, int = 1) const; - - // These return the smallest and largest width and height total (width + pad) - // values for the given range of Widgets. - point_type _getMinWidgetWidthTotal (int = 0, int = 0, int = 1) const; - point_type _getMinWidgetHeightTotal (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetWidthTotal (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetHeightTotal (int = 0, int = 0, int = 1) const; - - // These return the smallest and largest minWidth and minHeight total - // (width + pad) values for the given range of Widgets. - point_type _getMinWidgetMinWidthTotal (int = 0, int = 0, int = 1) const; - point_type _getMinWidgetMinHeightTotal (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetMinWidthTotal (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetMinHeightTotal (int = 0, int = 0, int = 1) const; - - // These return the smallest and largest horizontal and vertical padding - // values for the given range of Widgets. - point_type _getMinWidgetPadHorizontal (int = 0, int = 0, int = 1) const; - point_type _getMinWidgetPadVertical (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetPadHorizontal (int = 0, int = 0, int = 1) const; - point_type _getMaxWidgetPadVertical (int = 0, int = 0, int = 1) const; - - point_type _getNumFill(int = 0, int = 0, int = 1) const; - - // This method is passed the additional values by which width and height should be - // modified as calculed by the parent method, Window::resize. Keep in mind that these - // values can be negative (indicating a potential "shrink" request) or positive (which - // would indicate a "grow" reqeust). - virtual void _resizeImplementation(point_type, point_type) = 0; - - // These are made into implementation functions since getting the width or height - // of a window can potentially be an expensive operation, and we'll want to cache - // results if possible (which is handled transparently by the actualy Window::resize - // method). They return a Sizes struct which contains two members: cur (for current) - // and min (minimum). It's important that the Window know it's minimum possible - // size so that it can ignore invaled requests to resize. - // - // Default versions using BoundingBox calculations are provided, but some Windows - // override this (Table, Box). - virtual Sizes _getWidthImplementation () const; - virtual Sizes _getHeightImplementation () const; + matrix_type getRotate() const { + return _r; + } + + matrix_type getScale() const { + return _s; + } + + matrix_type getScaleDenominator() const { + return _scaleDenom; + } + + void setX(matrix_type x) { + _x = x; + } + + void setY(matrix_type y) { + _y = y; + } + + void setPosition(matrix_type x, matrix_type y, matrix_type z) { + _x = x; + _y = y; + _z = z; + } + + void setPosition(const Point& p) { + setPosition(p.x(), p.y(), p.z()); + } + + void setOrigin(matrix_type x, matrix_type y) { + _x = x; + _y = y; + } + + void setRotate(matrix_type r) { + _r = r; + } + + void setScale(matrix_type s) { + _s = s; + } + + void setScaleDenominator(matrix_type sd) { + _scaleDenom = sd; + } + + void setAnchorVertical(VERTICAL_ANCHOR va) { + _vAnchor = va; + } + + void setAnchorHorizontal(HORIZONTAL_ANCHOR ha) { + _hAnchor = ha; + } + + void setStrata(STRATA s) { + _strata = s; + } + + void setVisibilityMode(VISIBILITY_MODE v) { + _vis = v; + } + + void addX(matrix_type x) { + _x += x; + } + + void addY(matrix_type y) { + _y += y; + } + + void addZ(matrix_type z) { + _z += z; + } + + void addRotate(matrix_type r) { + _r += r; + } + + void addScale(matrix_type s) { + _s += s / (_scaleDenom != 0.0f ? _scaleDenom : 1.0f); + } + + void addOrigin(matrix_type x, matrix_type y) { + _x += x; + _y += y; + } + + void attachMoveCallback() { + addCallback(Callback(&callbackWindowMove, EVENT_MOUSE_DRAG)); + } + + void attachRotateCallback() { + addCallback(Callback(&callbackWindowRotate, EVENT_MOUSE_DRAG)); + } + + void attachScaleCallback() { + addCallback(Callback(&callbackWindowScale, EVENT_MOUSE_DRAG)); + } + + void attachTabFocusCallback() { + addCallback(Callback(&callbackWindowTabFocus, EVENT_KEY_DOWN)); + } + + protected: + typedef point_type (Widget::*Getter)() const; + + typedef std::less Less; + typedef std::greater Greater; + typedef std::plus Plus; + + friend class WindowManager; + + // The (optional) Window that this Window is parented inside. + Window* _parent; + + // The WindowManger to which this window is attached. + WindowManager* _wm; + + // The positional index this Node holds within it's parent WindowManager. + unsigned int _index; + + // The X and Y values of the Window (origin). + matrix_type _x; + matrix_type _y; + + // A pair of values representing the currently calculated Z value and the + // depth range for all children to be used during the call to update(). + matrix_type _z; + matrix_type _zRange; + + // This is a special value that can be used to "force" a Window not to be + // focusable and instead always exist in the foreground or background. + STRATA _strata; + + // A flag determining whether our visible area is the full Window or rather + // a portion of the Window. + VISIBILITY_MODE _vis; + + // A rotation value in degrees. + matrix_type _r; + + // This will also need to adjust geom internally so that picking is correct. + matrix_type _s; + + matrix_type _scaleDenom; + + Sizes _width; + Sizes _height; + + VERTICAL_ANCHOR _vAnchor; + HORIZONTAL_ANCHOR _hAnchor; + + // Not all windows have widgets that can focus, but if they do this should + // be a pointer to it. + osg::observer_ptr _focused; + + // The "visible" area that will define both the glScissor bounds AND will + // be used to make sure our pick is valid. The values herein correspond to + // X, Y, W, and H--in that order. + Quad _visibleArea; + + // This helper method is used by _compare<>() and _accumulate<>(), so ignore this + // function and go see the docs for those instead. This thing is huge and unwieldy + // and not to be triffled with! :) + template + point_type _forEachAssignOrApply( + Getter get, + int begin, + int end, + int add, + bool assign + ) const { + point_type val = 0.0f; + unsigned int c = begin; + + ConstIterator e = end > 0 ? _objects.begin() + end : _objects.end() + end; + + // I WARNED YOU! If you try and understand what this does your head will + // explode! But let me say a few things: in MSVC you can't add to an iterator + // such that the add will cause it to increment past the end of the container. + // This appears to be safe in GCC, where it will just return the last + // item therein, but causes an assertion error in other compilers. I'm not + // sure if there is a cleaner remedy for this, so what we do for now is keep a + // count variable called "c" that makes sure our iterator's opterator+() + // method is safe to call. + for( + ConstIterator i = _objects.begin() + begin; + i < e; + c += add + ) { + point_type v = 0.0f; + + if(i->valid()) v = (i->get()->*get)(); + + // If you want to assign to val, and NOT add a sequence of them... + if(assign) { + if(T()(v, val)) val = v; + } + + // If you want to accumulate a value INTO val... + else val = T()(v, val); + + // Make sure our iterator is safe to increment. Otherwise, set it to + // whatever end is. + // TODO: This isn't 100% accurate, as it does not YET take into account + // our requested end in any way other than implicitly. It should, however, + // work okay for now. + if((c + add) < _objects.size()) i += add; + + else i = e; + } + + return val; + } + + void _setWidthAndHeightUnknownSizeError (const std::string&, point_type); + void _setWidthAndHeightNotPAError (const std::string&, point_type); + void _setWidthAndHeight (); + void _removeFromGeode (Widget*); + + Widget* _getBackground() const; + Window* _getTopmostParent() const; + + // This method will return the T'th value returned by applying the Getter member function + // pointer to each iterator in the range of iterators defined by offset and add. In + // plain language, this helper method will apply some standard Widget::get* function + // to a range of objects in the _objects Vector, and will return the T'th of that. + // The template T can be any functor accepting two point_type values that return + // a bool. For example, this is commonly used with std::less to find the smallest + // width in a range of Widgets. + template + point_type _compare( + Getter get, + int begin = 0, + int end = 0, + int add = 1 + ) const { + return _forEachAssignOrApply(get, begin, end, add, true); + } + + // This method will return the T'th value accumulated by applying the Getter member + // function to each iterator in the range of iterators defined by offset and add (similar + // to above). For example, this method can be used to apply std::plus to every + // width in a range of Widgets, and return the total. + template + point_type _accumulate( + Getter get, + int begin = 0, + int end = 0, + int add = 1 + ) const { + return _forEachAssignOrApply(get, begin, end, add, false); + } + + osg::Geode* _geode() { + return dynamic_cast(getChild(0)); + } + + const osg::Geode* _geode() const { + return dynamic_cast(getChild(0)); + } + + Widget* _bg() { + return _getBackground(); + } + + const Widget* _bg() const { + return _getBackground(); + } + + osg::Scissor* _scissor() { + return dynamic_cast( + getStateSet()->getAttribute(osg::StateAttribute::SCISSOR) + ); + } + + bool _setWidget (Widget*, int = -1); + bool _setVisible (bool); + void _setFocused (Widget*); + void _setStyled (Widget*); + void _setParented (Widget*, bool=false); + void _setManaged (Widget*, bool=false); + + void _positionWidget(Widget*, point_type, point_type); + + // These return the smallest and largest width and height values for the given + // range of Widgets. + point_type _getMinWidgetWidth (int = 0, int = 0, int = 1) const; + point_type _getMinWidgetHeight (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetWidth (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetHeight (int = 0, int = 0, int = 1) const; + + // These return the smallest and largest minWidth and minHeight values for + // the given range of Widgets. + point_type _getMinWidgetMinWidth (int = 0, int = 0, int = 1) const; + point_type _getMinWidgetMinHeight (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetMinWidth (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetMinHeight (int = 0, int = 0, int = 1) const; + + // These return the smallest and largest width and height total (width + pad) + // values for the given range of Widgets. + point_type _getMinWidgetWidthTotal (int = 0, int = 0, int = 1) const; + point_type _getMinWidgetHeightTotal (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetWidthTotal (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetHeightTotal (int = 0, int = 0, int = 1) const; + + // These return the smallest and largest minWidth and minHeight total + // (width + pad) values for the given range of Widgets. + point_type _getMinWidgetMinWidthTotal (int = 0, int = 0, int = 1) const; + point_type _getMinWidgetMinHeightTotal (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetMinWidthTotal (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetMinHeightTotal (int = 0, int = 0, int = 1) const; + + // These return the smallest and largest horizontal and vertical padding + // values for the given range of Widgets. + point_type _getMinWidgetPadHorizontal (int = 0, int = 0, int = 1) const; + point_type _getMinWidgetPadVertical (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetPadHorizontal (int = 0, int = 0, int = 1) const; + point_type _getMaxWidgetPadVertical (int = 0, int = 0, int = 1) const; + + point_type _getNumFill(int = 0, int = 0, int = 1) const; + + // This method is passed the additional values by which width and height should be + // modified as calculed by the parent method, Window::resize. Keep in mind that these + // values can be negative (indicating a potential "shrink" request) or positive (which + // would indicate a "grow" reqeust). + virtual void _resizeImplementation(point_type, point_type) = 0; + + // These are made into implementation functions since getting the width or height + // of a window can potentially be an expensive operation, and we'll want to cache + // results if possible (which is handled transparently by the actualy Window::resize + // method). They return a Sizes struct which contains two members: cur (for current) + // and min (minimum). It's important that the Window know it's minimum possible + // size so that it can ignore invaled requests to resize. + // + // Default versions using BoundingBox calculations are provided, but some Windows + // override this (Table, Box). + virtual Sizes _getWidthImplementation () const; + virtual Sizes _getHeightImplementation () const; }; diff --git a/include/osgWidget/WindowManager b/include/osgWidget/WindowManager index dbf059965..ec69ef70b 100644 --- a/include/osgWidget/WindowManager +++ b/include/osgWidget/WindowManager @@ -25,332 +25,333 @@ typedef osgUtil::LineSegmentIntersector::Intersections Intersections; // A WindowManager performs pointer interaction with the topmost (highest Z) Widget, // and performs keyboard input on the currently focused Window->Widget. class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent { -public: - enum WM_FLAGS { - WM_USE_LUA = 0x00000001, - WM_USE_PYTHON = 0x00000002, - WM_PICK_DEBUG = 0x00000004, - WM_NO_INVERT_Y = 0x00000008, - WM_NO_BETA_WARN = 0x00000010 - }; + public: + enum WM_FLAGS { + WM_USE_LUA = 0x00000001, + WM_USE_PYTHON = 0x00000002, + WM_PICK_DEBUG = 0x00000004, + WM_NO_INVERT_Y = 0x00000008, + WM_NO_BETA_WARN = 0x00000010 + }; - enum POINTER_DIRECTION { - PD_NONE = 0x00000000, - PD_LEFT = 0x00000001, - PD_RIGHT = 0x00000002, - PD_UP = 0x00000004, - PD_DOWN = 0x00000008 - }; + enum POINTER_DIRECTION { + PD_NONE = 0x00000000, + PD_LEFT = 0x00000001, + PD_RIGHT = 0x00000002, + PD_UP = 0x00000004, + PD_DOWN = 0x00000008 + }; - enum POINTER_FOCUS_MODE { - PFM_FOCUS = 0x00000000, - PFM_UNFOCUS = 0x00000001, - PFM_SLOPPY = 0x00000002 - }; + enum POINTER_FOCUS_MODE { + PFM_FOCUS = 0x00000000, + PFM_UNFOCUS = 0x00000001, + PFM_SLOPPY = 0x00000002 + }; -private: - // A functor used to sort the Windows by their Z component in descending order. - struct WindowZCompare: public std::binary_function { - bool operator()(const ptr_type& x, const ptr_type& y) { - return x.get()->getZ() > y.get()->getZ(); - } - }; + public: + META_Object(osgWidget, WindowManager); - 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; + WindowManager( + osgViewer::View* = 0, + point_type = 0.0f, + point_type = 0.0f, + unsigned int = 0, + unsigned int = 0 + ); - osgGA::GUIEventAdapter::ScrollingMotion _scrolling; + WindowManager(const WindowManager&, const osg::CopyOp&); - osg::ref_ptr _lua; - osg::ref_ptr _python; - osg::ref_ptr _styleManager; + virtual ~WindowManager(); - osg::observer_ptr _widget; - osg::observer_ptr _focused; - osg::observer_ptr _pickWindow; + // A static method that will set both the _widget and _window data of an Event + // reference from a passed-in Interface. + static void setEventFromInterface(Event&, EventInterface*); - void childInserted (unsigned int); - void childRemoved (unsigned int, unsigned int); + // A static template method that will iterate over a container and return a + // properly formed EventInterface*. + template + static EventInterface* getFirstEventInterface(T&, Event&); - 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); + bool pickAtXY (float, float, WidgetList&); + bool setFocused (Window*); + void setPointerXY (float, float); + void setStyleManager (StyleManager*); + void resizeAllWindows (bool = true); -public: - META_Object(osgWidget, WindowManager); + // Methods all called by the ViewerEventHandlers::MouseHandler object, or + // by some customer caller of your own. Examples of this to come... + bool pointerMove (float, float); + bool pointerDrag (float, float); + bool mouseScroll (float, float); - WindowManager( - osgViewer::View* = 0, - point_type = 0.0f, - point_type = 0.0f, - unsigned int = 0, - unsigned int = 0 - ); + osg::Camera* createParentOrthoCamera(); - WindowManager(const WindowManager&, const osg::CopyOp&); + unsigned int getNodeMask() const { + return _nodeMask; + } - virtual ~WindowManager(); + point_type getWidth() const { + return _width; + } - // A static method that will set both the _widget and _window data of an Event - // reference from a passed-in Interface. - static void setEventFromInterface(Event&, EventInterface*); + point_type getHeight() const { + return _height; + } - // A static template method that will iterate over a container and return a - // properly formed EventInterface*. - template - static EventInterface* getFirstEventInterface(T&, Event&); + bool isUsingLua() const { + return (_flags & WM_USE_LUA) != 0; + } - bool pickAtXY (float, float, WidgetList&); - bool setFocused (Window*); - void setPointerXY (float, float); - void setStyleManager (StyleManager*); - void resizeAllWindows (bool = true); + bool isUsingPython() const { + return (_flags & WM_USE_PYTHON) != 0; + } - // Methods all called by the ViewerEventHandlers::MouseHandler object, or - // by some customer caller of your own. Examples of this to come... - bool pointerMove (float, float); - bool pointerDrag (float, float); - bool mouseScroll (float, float); + bool isInvertedY() const { + return (_flags & WM_NO_INVERT_Y) == 0; + } - osg::Camera* createParentOrthoCamera(); + int getMouseKeysDown() const { + int flag = 0; - unsigned int getNodeMask() const { - return _nodeMask; - } + flag |= _leftDown ? osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON : 0; + flag |= _middleDown ? osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON: 0; + flag |= _rightDown ? osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON : 0; - point_type getWidth() const { - return _width; - } + return flag; + } - point_type getHeight() const { - return _height; - } + ScriptEngine* getLuaEngine() { + return _lua.get(); + } - bool isUsingLua() const { - return (_flags & WM_USE_LUA) != 0; - } + const ScriptEngine* getLuaEngine() const { + return _lua.get(); + } - bool isUsingPython() const { - return (_flags & WM_USE_PYTHON) != 0; - } + ScriptEngine* getPythonEngine() { + return _python.get(); + } - bool isInvertedY() const { - return (_flags & WM_NO_INVERT_Y) == 0; - } + const ScriptEngine* getPythonEngine() const { + return _python.get(); + } - int getMouseKeysDown() const { - int flag = 0; + StyleManager* getStyleManager() { + return _styleManager.get(); + } - flag |= _leftDown ? osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON : 0; - flag |= _middleDown ? osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON: 0; - flag |= _rightDown ? osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON : 0; + const StyleManager* getStyleManager() const { + return _styleManager.get(); + } - return flag; - } + POINTER_DIRECTION getPointerVerticalDirection() const { + return _lastVertical; + } - ScriptEngine* getLuaEngine() { - return _lua.get(); - } + POINTER_DIRECTION getPointerHorizontalDirection() const { + return _lastHorizontal; + } - const ScriptEngine* getLuaEngine() const { - return _lua.get(); - } + POINTER_FOCUS_MODE getPointerFocusMode() const { + return _focusMode; + } - ScriptEngine* getPythonEngine() { - return _python.get(); - } + int getPointerDirectionVector() const { + return _lastVertical | _lastHorizontal; + } - const ScriptEngine* getPythonEngine() const { - return _python.get(); - } + bool isPointerMovingUp() const { + return _lastVertical == PD_UP; + } - StyleManager* getStyleManager() { - return _styleManager.get(); - } + bool isPointerMovingDown() const { + return _lastVertical == PD_DOWN; + } - const StyleManager* getStyleManager() const { - return _styleManager.get(); - } + bool isPointerMovingLeft() const { + return _lastHorizontal == PD_LEFT; + } - POINTER_DIRECTION getPointerVerticalDirection() const { - return _lastVertical; - } + bool isPointerMovingRight() const { + return _lastHorizontal == PD_RIGHT; + } - POINTER_DIRECTION getPointerHorizontalDirection() const { - return _lastHorizontal; - } + bool isPointerMovingVertically() const { + return _lastVertical != PD_NONE; + } - POINTER_FOCUS_MODE getPointerFocusMode() const { - return _focusMode; - } + bool isPointerMovingHorizontally() const { + return _lastHorizontal != PD_NONE; + } - int getPointerDirectionVector() const { - return _lastVertical | _lastHorizontal; - } + bool isLeftMouseButtonDown() const { + return _leftDown; + } - bool isPointerMovingUp() const { - return _lastVertical == PD_UP; - } + bool isMiddleMouseButtonDown() const { + return _middleDown; + } - bool isPointerMovingDown() const { - return _lastVertical == PD_DOWN; - } + bool isRightMouseButtonDown() const { + return _rightDown; + } - bool isPointerMovingLeft() const { - return _lastHorizontal == PD_LEFT; - } + bool isMouseScrollingUp() const { + return _scrolling == osgGA::GUIEventAdapter::SCROLL_UP; + } - bool isPointerMovingRight() const { - return _lastHorizontal == PD_RIGHT; - } - - bool isPointerMovingVertically() const { - return _lastVertical != PD_NONE; - } + bool isMouseScrollingDown() const { + return _scrolling == osgGA::GUIEventAdapter::SCROLL_DOWN; + } - bool isPointerMovingHorizontally() const { - return _lastHorizontal != PD_NONE; - } + bool setFocusedByName(const std::string& name) { + return setFocused(getByName(name)); + } - bool isLeftMouseButtonDown() const { - return _leftDown; - } + void setScrollingMotion(osgGA::GUIEventAdapter::ScrollingMotion sm) { + _scrolling = sm; + } - bool isMiddleMouseButtonDown() const { - return _middleDown; - } + void setPointerFocusMode(POINTER_FOCUS_MODE pfm) { + _focusMode = pfm; + } - bool isRightMouseButtonDown() const { - return _rightDown; - } + void setWidth(point_type w) { + _width = w; + } - bool isMouseScrollingUp() const { - return _scrolling == osgGA::GUIEventAdapter::SCROLL_UP; - } + void setHeight(point_type h) { + _height = h; + } - bool isMouseScrollingDown() const { - return _scrolling == osgGA::GUIEventAdapter::SCROLL_DOWN; - } + void setSize(point_type w, point_type h) { + _width = w; + _height = h; + } - bool setFocusedByName(const std::string& name) { - return setFocused(getByName(name)); - } + // Wrappers around the real calls. These only pertains to mouse buttons, + // particularly 3-button mice, although there are other more generic + // "pointer" API methods. + bool mousePushedLeft(float x, float y) { + return _handleMousePushed(x, y, _leftDown); + } - void setScrollingMotion(osgGA::GUIEventAdapter::ScrollingMotion sm) { - _scrolling = sm; - } + bool mousePushedMiddle(float x, float y) { + return _handleMousePushed(x, y, _middleDown); + } - void setPointerFocusMode(POINTER_FOCUS_MODE pfm) { - _focusMode = pfm; - } + bool mousePushedRight(float x, float y) { + return _handleMousePushed(x, y, _rightDown); + } - void setWidth(point_type w) { - _width = w; - } + bool mouseReleasedLeft(float x, float y) { + return _handleMouseReleased(x, y, _leftDown); + } - void setHeight(point_type h) { - _height = h; - } + bool mouseReleasedMiddle(float x, float y) { + return _handleMouseReleased(x, y, _middleDown); + } - void setSize(point_type w, point_type h) { - _width = w; - _height = h; - } + bool mouseReleasedRight(float x, float y) { + return _handleMouseReleased(x, y, _rightDown); + } - // Wrappers around the real calls. These only pertains to mouse buttons, - // particularly 3-button mice, although there are other more generic - // "pointer" API methods. - bool mousePushedLeft(float x, float y) { - return _handleMousePushed(x, y, _leftDown); - } + // Keyboards wrappers, as above; takes the key and key's mask code, which + // can be compared to osgGA::GUIEventAdapter::{KeySymbol,KeyModMask}. + bool keyDown (int, int); + bool keyUp (int, int); - bool mousePushedMiddle(float x, float y) { - return _handleMousePushed(x, y, _middleDown); - } + private: + // A functor used to sort the Windows by their Z component in descending order. + struct WindowZCompare: public std::binary_function { + bool operator()(const ptr_type& x, const ptr_type& y) { + return x.get()->getZ() > y.get()->getZ(); + } + }; - bool mousePushedRight(float x, float y) { - return _handleMousePushed(x, y, _rightDown); - } + 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; - bool mouseReleasedLeft(float x, float y) { - return _handleMouseReleased(x, y, _leftDown); - } + osgGA::GUIEventAdapter::ScrollingMotion _scrolling; - bool mouseReleasedMiddle(float x, float y) { - return _handleMouseReleased(x, y, _middleDown); - } + osg::ref_ptr _lua; + osg::ref_ptr _python; + osg::ref_ptr _styleManager; + + osg::observer_ptr _widget; + osg::observer_ptr _focused; + osg::observer_ptr _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); - bool mouseReleasedRight(float x, float y) { - return _handleMouseReleased(x, y, _rightDown); - } - - // Keyboards wrappers, as above; takes the key and key's mask code, which - // can be compared to osgGA::GUIEventAdapter::{KeySymbol,KeyModMask}. - bool keyDown (int, int); - bool keyUp (int, int); }; // We use a template here because the container could be a list or a vector; or something // else that supports iteration! template EventInterface* WindowManager::getFirstEventInterface(T& container, Event& ev) { - if(!container.size()) return 0; + if(!container.size()) return 0; - // See if we can find a Widget that responds to this event... - for(typename T::iterator i = container.begin(); i != container.end(); i++) { - Widget* widget = i->get(); + // See if we can find a Widget that responds to this event... + for(typename T::iterator i = container.begin(); i != container.end(); i++) { + Widget* widget = i->get(); - // If so, set the _widget/_window members and return it. - if(widget->getEventMask() & ev.type) { - ev._window = widget->getParent(); - ev._widget = widget; + // If so, set the _widget/_window members and return it. + if(widget->getEventMask() & ev.type) { + ev._window = widget->getParent(); + ev._widget = widget; - return widget; - } - } + return widget; + } + } - // If we can't find a Widget that will accept this event, try and recurse all - // of the parent Windows and find one that can. - WindowList windowList; + // If we can't find a Widget that will accept this event, try and recurse all + // of the parent Windows and find one that can. + WindowList windowList; - Window* parent = container.back()->getParent(); + Window* parent = container.back()->getParent(); - if(parent) { - parent->getParentList(windowList); + if(parent) { + parent->getParentList(windowList); - // A WindowList from getParentList includes the Window the method was called - // on, and the entire tree of parentage. - for(WindowList::iterator i = windowList.begin(); i != windowList.end(); i++) { - Window* window = i->get(); + // A WindowList from getParentList includes the Window the method was called + // on, and the entire tree of parentage. + for(WindowList::iterator i = windowList.begin(); i != windowList.end(); i++) { + Window* window = i->get(); - if(window->getEventMask() & ev.type) { - ev._window = window; + if(window->getEventMask() & ev.type) { + ev._window = window; - return window; - } - } - } + return window; + } + } + } - return 0; + return 0; } }