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

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

View File

@ -8,30 +8,33 @@
namespace osgWidget {
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&);
};
}

View File

@ -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);
};
}

View File

@ -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<typename T>
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<typename T>
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<typename T>
Callback(bool (T::*function)(Event&), T* obj, EVENT_TYPE type, void* data=0):
_type (type),
_data (data),
_callback (new ObjectCallback<T>(function, obj)) {
}
// We use a ref_ptr here so that we don't have to worry about memory.
osg::ref_ptr<CallbackInterface> _callback;
// Creates a Callback that is bound to a functor pointer.
template<typename T>
Callback(T* functor, EVENT_TYPE type, void* data=0):
_type (type),
_data (data),
_callback (new FunctionCallback<T>(functor)) {
}
public:
// Creates a Callback that is bound to a member function.
template<typename T>
Callback(bool (T::*function)(Event&), T* obj, EVENT_TYPE type, void* data=0):
_type (type),
_data (data),
_callback (new ObjectCallback<T>(function, obj)) {
}
bool operator()(Event& ev) {
return (*_callback)(ev);
}
// Creates a Callback that is bound to a functor pointer.
template<typename T>
Callback(T* functor, EVENT_TYPE type, void* data=0):
_type (type),
_data (data),
_callback (new FunctionCallback<T>(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<CallbackInterface> _callback;
const void* getData() const {
return _data;
}
};
class OSGWIDGET_EXPORT EventInterface {
private:
typedef std::list<Callback> 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<Callback> CallbackList;
unsigned int _eventMask;
CallbackList _callbacks;
bool canKeyDown () const { return (_eventMask & EVENT_KEY_DOWN) != 0; }
bool canKeyUp () const { return (_eventMask & EVENT_KEY_UP) != 0; }
};
}

View File

@ -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<EmbeddedWindow*>(getByRowCol(1, 1)); }
EmbeddedWindow* getEmbeddedWindow() {
return dynamic_cast<EmbeddedWindow*>(getByRowCol(1, 1));
}
const EmbeddedWindow* getEmbeddedWindow() const { return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1)); }
const EmbeddedWindow* getEmbeddedWindow() const {
return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1));
}
Corner* getCorner(CORNER c) { return dynamic_cast<Corner*>(_getCorner(c)); }
Corner* getCorner(CORNER c) {
return dynamic_cast<Corner*>(_getCorner(c));
}
const Corner* getCorner(CORNER c) const { return dynamic_cast<const Corner*>(_getCorner(c)); }
const Corner* getCorner(CORNER c) const {
return dynamic_cast<const Corner*>(_getCorner(c));
}
Border* getBorder(BORDER b) { return dynamic_cast<Border*>(_getBorder(b)); }
Border* getBorder(BORDER b) {
return dynamic_cast<Border*>(_getBorder(b));
}
const Border* getBorder(BORDER b) const { return dynamic_cast<const Border*>(_getBorder(b)); }
protected:
Widget* _getCorner (CORNER) const;
Widget* _getBorder (BORDER) const;
const Border* getBorder(BORDER b) const {
return dynamic_cast<const Border*>(_getBorder(b));
}
};
}

View File

@ -8,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<point_type> _offsets;
osg::ref_ptr<Widget> _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<point_type> _offsets;
osg::ref_ptr<Widget> _cursor;
};
}

View File

@ -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<osgText::Text> _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<osgText::Text> _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();
}
};
}

View File

@ -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;
};
}

View File

@ -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;
};
}

View File

@ -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; }
};
}

View File

@ -8,30 +8,21 @@ namespace osgWidget {
#include <osgWidget/Export>
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;
}
};
}

View File

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

View File

@ -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<point_type> CellSizes;
typedef std::vector<point_type> 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;
};
}

View File

@ -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<name *>(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<name *>(this->clone(co)); \
obj->setName(newName); \
return obj; \
}
template <typename T>
class UIObjectParent {
public:
typedef T object_type;
typedef osg::observer_ptr<object_type> ptr_type;
typedef std::vector<ptr_type> Vector;
typedef typename Vector::iterator Iterator;
typedef typename Vector::const_iterator ConstIterator;
class UIObjectParent
{
public:
typedef T object_type;
typedef osg::observer_ptr<object_type> ptr_type;
typedef std::vector<ptr_type> 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;
}
};
}

View File

@ -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 <typename T>
inline bool hasDecimal(T v) {
return (v - static_cast<T>(static_cast<long>(v))) > 0.0f;
inline bool hasDecimal(T v)
{
return (v - static_cast<T>(static_cast<long>(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*);

View File

@ -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<WindowManager> _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<WindowManager> _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<WindowManager> _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<WindowManager> _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<WindowManager> _wm;
osg::ref_ptr<osg::Camera> _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<WindowManager> _wm;
osg::ref_ptr<osg::Camera> _camera;
virtual bool handle(
const osgGA::GUIEventAdapter&,
osgGA::GUIActionAdapter&,
osg::Object*,
osg::NodeVisitor*
);
};
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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<Window> {
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<ptr_type, ptr_type, bool> {
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<ScriptEngine> _lua;
osg::ref_ptr<ScriptEngine> _python;
osg::ref_ptr<StyleManager> _styleManager;
virtual ~WindowManager();
osg::observer_ptr<Widget> _widget;
osg::observer_ptr<Window> _focused;
osg::observer_ptr<Window> _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<typename T>
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<typename T>
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<ptr_type, ptr_type, bool> {
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<ScriptEngine> _lua;
osg::ref_ptr<ScriptEngine> _python;
osg::ref_ptr<StyleManager> _styleManager;
osg::observer_ptr<Widget> _widget;
osg::observer_ptr<Window> _focused;
osg::observer_ptr<Window> _pickWindow;
void childInserted (unsigned int);
void childRemoved (unsigned int, unsigned int);
bool _handleMousePushed (float, float, bool&);
bool _handleMouseReleased (float, float, bool&);
bool _haneldMouseScrolled (float, float, bool = false);
void _getPointerXYDiff (float&, float&);
void _updatePickWindow (const WidgetList*, point_type, point_type);
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<typename T>
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;
}
}