Restructured classes to better fit with style of the rest of the OSG.
This commit is contained in:
parent
727925a1c2
commit
ff5da51dcb
@ -8,30 +8,33 @@
|
||||
|
||||
namespace osgWidget {
|
||||
|
||||
class OSGWIDGET_EXPORT Box: public Window {
|
||||
class OSGWIDGET_EXPORT Box: public Window
|
||||
{
|
||||
public:
|
||||
enum BOX_TYPE {
|
||||
VERTICAL,
|
||||
HORIZONTAL
|
||||
};
|
||||
|
||||
private:
|
||||
BOX_TYPE _boxType;
|
||||
bool _uniform;
|
||||
unsigned int _lastAdd;
|
||||
|
||||
protected:
|
||||
virtual void _resizeImplementation(point_type, point_type);
|
||||
|
||||
virtual Sizes _getWidthImplementation () const;
|
||||
virtual Sizes _getHeightImplementation () const;
|
||||
|
||||
public:
|
||||
META_Object (osgWidget, Box);
|
||||
META_UIObject (Box);
|
||||
|
||||
Box (const std::string& = "", BOX_TYPE = HORIZONTAL, bool = false);
|
||||
Box (const Box&, const osg::CopyOp&);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void _resizeImplementation(point_type, point_type);
|
||||
|
||||
virtual Sizes _getWidthImplementation () const;
|
||||
virtual Sizes _getHeightImplementation () const;
|
||||
|
||||
private:
|
||||
|
||||
BOX_TYPE _boxType;
|
||||
bool _uniform;
|
||||
unsigned int _lastAdd;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,10 +8,8 @@
|
||||
|
||||
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);
|
||||
@ -21,6 +19,10 @@ public:
|
||||
|
||||
// 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);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ class WindowManager;
|
||||
class Window;
|
||||
class Widget;
|
||||
|
||||
enum EVENT_TYPE {
|
||||
enum EVENT_TYPE
|
||||
{
|
||||
EVENT_NONE = 0x0000,
|
||||
EVENT_FOCUS = 0x0001,
|
||||
EVENT_UNFOCUS = 0x0002,
|
||||
@ -34,7 +35,8 @@ enum EVENT_TYPE {
|
||||
|
||||
// Helpful wrapper around using the raw types, since it often doesn't make sense to
|
||||
// use some without the others.
|
||||
enum EVENT_MASK {
|
||||
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,
|
||||
@ -42,15 +44,8 @@ enum EVENT_MASK {
|
||||
EVENT_MASK_KEY = EVENT_KEY_UP | EVENT_KEY_DOWN
|
||||
};
|
||||
|
||||
class OSGWIDGET_EXPORT Event {
|
||||
friend class WindowManager;
|
||||
friend class Window;
|
||||
|
||||
WindowManager* _wm;
|
||||
Window* _window;
|
||||
Widget* _widget;
|
||||
void* _data;
|
||||
|
||||
class OSGWIDGET_EXPORT Event
|
||||
{
|
||||
public:
|
||||
EVENT_TYPE type;
|
||||
double x;
|
||||
@ -94,9 +89,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowManager* getWindowManager() {
|
||||
return _wm;
|
||||
}
|
||||
WindowManager* getWindowManager() { return _wm; }
|
||||
|
||||
const WindowManager* getWindowManager() const {
|
||||
return _wm;
|
||||
@ -129,6 +122,17 @@ public:
|
||||
void setData(void* data) {
|
||||
_data = data;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
friend class WindowManager;
|
||||
friend class Window;
|
||||
|
||||
WindowManager* _wm;
|
||||
Window* _window;
|
||||
Widget* _widget;
|
||||
void* _data;
|
||||
|
||||
};
|
||||
|
||||
// The Callback interface was inspired by the CEGUI project:
|
||||
@ -140,24 +144,20 @@ public:
|
||||
// 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;
|
||||
};
|
||||
|
||||
// The object that facilitates a class method as a callback.
|
||||
template<typename T>
|
||||
class ObjectCallback: public CallbackInterface {
|
||||
class ObjectCallback: public CallbackInterface
|
||||
{
|
||||
public:
|
||||
typedef bool (T::*ObjectCallbackType)(Event&);
|
||||
|
||||
private:
|
||||
ObjectCallbackType _callback;
|
||||
T* _object;
|
||||
|
||||
public:
|
||||
ObjectCallback(ObjectCallbackType callback, T* obj):
|
||||
_callback (callback),
|
||||
_object (obj) {
|
||||
@ -166,13 +166,17 @@ public:
|
||||
virtual bool operator()(Event& ev) {
|
||||
return (_object->*_callback)(ev);
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectCallbackType _callback;
|
||||
T* _object;
|
||||
|
||||
};
|
||||
|
||||
// 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) {
|
||||
@ -181,16 +185,13 @@ public:
|
||||
virtual bool operator()(Event& ev) {
|
||||
return (*_callback)(ev);
|
||||
}
|
||||
protected:
|
||||
T* _callback;
|
||||
};
|
||||
|
||||
// The highlevel functor.
|
||||
class OSGWIDGET_EXPORT Callback {
|
||||
EVENT_TYPE _type;
|
||||
void* _data;
|
||||
|
||||
// We use a ref_ptr here so that we don't have to worry about memory.
|
||||
osg::ref_ptr<CallbackInterface> _callback;
|
||||
|
||||
class OSGWIDGET_EXPORT Callback
|
||||
{
|
||||
public:
|
||||
// Creates a Callback that is bound to a member function.
|
||||
template<typename T>
|
||||
@ -223,28 +224,26 @@ public:
|
||||
const void* getData() const {
|
||||
return _data;
|
||||
}
|
||||
protected:
|
||||
EVENT_TYPE _type;
|
||||
void* _data;
|
||||
|
||||
// We use a ref_ptr here so that we don't have to worry about memory.
|
||||
osg::ref_ptr<CallbackInterface> _callback;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class OSGWIDGET_EXPORT EventInterface {
|
||||
private:
|
||||
typedef std::list<Callback> CallbackList;
|
||||
|
||||
unsigned int _eventMask;
|
||||
CallbackList _callbacks;
|
||||
|
||||
class OSGWIDGET_EXPORT EventInterface
|
||||
{
|
||||
public:
|
||||
EventInterface():
|
||||
_eventMask(EVENT_NONE) {
|
||||
}
|
||||
EventInterface(): _eventMask(EVENT_NONE) {}
|
||||
|
||||
EventInterface(const EventInterface& ei):
|
||||
_eventMask (ei._eventMask),
|
||||
_callbacks (ei._callbacks) {
|
||||
}
|
||||
_callbacks (ei._callbacks) {}
|
||||
|
||||
virtual ~EventInterface() {
|
||||
}
|
||||
virtual ~EventInterface() {}
|
||||
|
||||
// These functions take as their final argument the WindowManager which issued the
|
||||
// request. This is sometimes useful to get information about key state, etc.
|
||||
@ -369,6 +368,13 @@ public:
|
||||
|
||||
bool canKeyDown () const { return (_eventMask & EVENT_KEY_DOWN) != 0; }
|
||||
bool canKeyUp () const { return (_eventMask & EVENT_KEY_UP) != 0; }
|
||||
|
||||
private:
|
||||
typedef std::list<Callback> CallbackList;
|
||||
|
||||
unsigned int _eventMask;
|
||||
CallbackList _callbacks;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,33 +8,31 @@
|
||||
|
||||
namespace osgWidget {
|
||||
|
||||
class OSGWIDGET_EXPORT Frame: public Table {
|
||||
class OSGWIDGET_EXPORT Frame: public Table
|
||||
{
|
||||
public:
|
||||
enum CORNER {
|
||||
|
||||
enum CORNER
|
||||
{
|
||||
CORNER_LOWER_LEFT,
|
||||
CORNER_LOWER_RIGHT,
|
||||
CORNER_UPPER_LEFT,
|
||||
CORNER_UPPER_RIGHT
|
||||
};
|
||||
|
||||
enum BORDER {
|
||||
enum BORDER
|
||||
{
|
||||
BORDER_LEFT,
|
||||
BORDER_RIGHT,
|
||||
BORDER_TOP,
|
||||
BORDER_BOTTOM
|
||||
};
|
||||
|
||||
protected:
|
||||
Widget* _getCorner (CORNER) const;
|
||||
Widget* _getBorder (BORDER) const;
|
||||
|
||||
public:
|
||||
static std::string cornerToString (CORNER);
|
||||
static std::string borderToString (BORDER);
|
||||
|
||||
class OSGWIDGET_EXPORT Corner: public Widget {
|
||||
CORNER _corner;
|
||||
|
||||
class OSGWIDGET_EXPORT Corner: public Widget
|
||||
{
|
||||
public:
|
||||
META_Object (osgWidget, Corner);
|
||||
META_UIObject (Corner);
|
||||
@ -56,11 +54,13 @@ public:
|
||||
_corner = corner;
|
||||
_name = cornerToString(corner);
|
||||
}
|
||||
|
||||
protected:
|
||||
CORNER _corner;
|
||||
};
|
||||
|
||||
class OSGWIDGET_EXPORT Border: public Widget {
|
||||
BORDER _border;
|
||||
|
||||
class OSGWIDGET_EXPORT Border: public Widget
|
||||
{
|
||||
public:
|
||||
META_Object (osgWidget, Border);
|
||||
META_UIObject (Border);
|
||||
@ -82,6 +82,11 @@ public:
|
||||
_border = border;
|
||||
_name = borderToString(border);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
BORDER _border;
|
||||
|
||||
};
|
||||
|
||||
META_Object (osgWidget, Frame);
|
||||
@ -113,7 +118,8 @@ public:
|
||||
Frame* = 0
|
||||
);
|
||||
|
||||
void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h) {
|
||||
void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h)
|
||||
{
|
||||
createSimpleFrame(_name, cw, ch, w, h, this);
|
||||
}
|
||||
|
||||
@ -125,35 +131,30 @@ public:
|
||||
point_type ch,
|
||||
point_type w,
|
||||
point_type h
|
||||
) {
|
||||
)
|
||||
{
|
||||
createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,23 +8,8 @@
|
||||
|
||||
namespace osgWidget {
|
||||
|
||||
class OSGWIDGET_EXPORT Input: public Label {
|
||||
point_type _xoff;
|
||||
point_type _yoff;
|
||||
|
||||
unsigned int _index;
|
||||
unsigned int _size;
|
||||
unsigned int _cursorIndex;
|
||||
unsigned int _maxSize;
|
||||
|
||||
std::vector<point_type> _offsets;
|
||||
osg::ref_ptr<Widget> _cursor;
|
||||
|
||||
protected:
|
||||
virtual void _calculateSize(const XYCoord&);
|
||||
|
||||
void _calculateCursorOffsets();
|
||||
|
||||
class OSGWIDGET_EXPORT Input: public Label
|
||||
{
|
||||
public:
|
||||
Input(const std::string& = "", const std::string& = "", unsigned int = 20);
|
||||
|
||||
@ -70,6 +55,22 @@ public:
|
||||
XYCoord getXYOffset() const {
|
||||
return XYCoord(_xoff, _yoff);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _calculateSize(const XYCoord&);
|
||||
|
||||
void _calculateCursorOffsets();
|
||||
|
||||
point_type _xoff;
|
||||
point_type _yoff;
|
||||
|
||||
unsigned int _index;
|
||||
unsigned int _size;
|
||||
unsigned int _cursorIndex;
|
||||
unsigned int _maxSize;
|
||||
|
||||
std::vector<point_type> _offsets;
|
||||
osg::ref_ptr<Widget> _cursor;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -10,15 +10,10 @@
|
||||
|
||||
namespace osgWidget {
|
||||
|
||||
class OSGWIDGET_EXPORT Label: public Widget {
|
||||
unsigned int _textIndex;
|
||||
|
||||
protected:
|
||||
osg::ref_ptr<osgText::Text> _text;
|
||||
|
||||
virtual void _calculateSize(const XYCoord&);
|
||||
|
||||
class OSGWIDGET_EXPORT Label: public Widget
|
||||
{
|
||||
public:
|
||||
|
||||
META_Object (osgWidget, Label);
|
||||
META_UIObject (Label);
|
||||
|
||||
@ -39,19 +34,21 @@ public:
|
||||
|
||||
XYCoord getTextSize() const;
|
||||
|
||||
std::string getLabel() const {
|
||||
return _text->getText().createUTF8EncodedString();
|
||||
}
|
||||
std::string getLabel() const { return _text->getText().createUTF8EncodedString(); }
|
||||
|
||||
void setFontColor(point_type r, point_type g, point_type b, point_type a) {
|
||||
setFontColor(Color(r, g, b, a));
|
||||
}
|
||||
void setFontColor(point_type r, point_type g, point_type b, point_type a) { setFontColor(Color(r, g, b, a)); }
|
||||
|
||||
// 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();
|
||||
}
|
||||
const osgText::Text* getText() const { return _text.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<osgText::Text> _text;
|
||||
unsigned int _textIndex;
|
||||
|
||||
virtual void _calculateSize(const XYCoord&);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -13,10 +13,8 @@ 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);
|
||||
|
||||
@ -24,6 +22,11 @@ public:
|
||||
bool close ();
|
||||
bool eval (const std::string&);
|
||||
bool runFile (const std::string&);
|
||||
|
||||
protected:
|
||||
|
||||
LuaEngineData* _data;
|
||||
WindowManager* _wm;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -11,9 +11,6 @@ namespace osgWidget {
|
||||
struct PythonEngineData;
|
||||
|
||||
class OSGWIDGET_EXPORT PythonEngine: public ScriptEngine {
|
||||
PythonEngineData* _data;
|
||||
WindowManager* _wm;
|
||||
|
||||
public:
|
||||
PythonEngine(WindowManager* = 0);
|
||||
|
||||
@ -21,6 +18,11 @@ public:
|
||||
bool close ();
|
||||
bool eval (const std::string&);
|
||||
bool runFile (const std::string&);
|
||||
|
||||
protected:
|
||||
|
||||
PythonEngineData* _data;
|
||||
WindowManager* _wm;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,8 @@ 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; }
|
||||
@ -22,6 +20,9 @@ public:
|
||||
virtual bool runFile (const std::string&) { return false; }
|
||||
|
||||
virtual const std::string& getLastErrorText() const { return _err; }
|
||||
protected:
|
||||
std::string _err;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,30 +8,21 @@ namespace osgWidget {
|
||||
|
||||
#include <osgWidget/Export>
|
||||
|
||||
class OSGWIDGET_EXPORT StyleInterface {
|
||||
class OSGWIDGET_EXPORT StyleInterface
|
||||
{
|
||||
public:
|
||||
StyleInterface(): _style("") {}
|
||||
|
||||
StyleInterface(const StyleInterface& si): _style(si._style) {}
|
||||
|
||||
void setStyle(const std::string& style) { _style = style; }
|
||||
|
||||
std::string& getStyle() { return _style; }
|
||||
|
||||
const std::string& getStyle() const { return _style; }
|
||||
private:
|
||||
std::string _style;
|
||||
|
||||
public:
|
||||
StyleInterface():
|
||||
_style("") {
|
||||
}
|
||||
|
||||
StyleInterface(const StyleInterface& si):
|
||||
_style(si._style) {
|
||||
}
|
||||
|
||||
void setStyle(const std::string& style) {
|
||||
_style = style;
|
||||
}
|
||||
|
||||
std::string& getStyle() {
|
||||
return _style;
|
||||
}
|
||||
|
||||
const std::string& getStyle() const {
|
||||
return _style;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -14,19 +14,8 @@ namespace osgWidget {
|
||||
|
||||
typedef osgDB::FieldReaderIterator& Reader;
|
||||
|
||||
class OSGWIDGET_EXPORT Style: public osg::Object {
|
||||
std::string _style;
|
||||
|
||||
bool _match(const char* seq, Reader r) {
|
||||
if(r.matchSequence(seq)) {
|
||||
++r;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
class OSGWIDGET_EXPORT Style: public osg::Object
|
||||
{
|
||||
public:
|
||||
META_Object(osgWidget, Style);
|
||||
|
||||
@ -60,14 +49,44 @@ public:
|
||||
static Widget::HORIZONTAL_ALIGNMENT strToHAlign (const std::string&);
|
||||
static Widget::COORDINATE_MODE strToCoordMode (const std::string&);
|
||||
static bool strToFill (const std::string&);
|
||||
|
||||
protected:
|
||||
|
||||
std::string _style;
|
||||
|
||||
bool _match(const char* seq, Reader r) {
|
||||
if(r.matchSequence(seq)) {
|
||||
++r;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class OSGWIDGET_EXPORT StyleManager: public osg::Object {
|
||||
class OSGWIDGET_EXPORT StyleManager: public osg::Object
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, osg::ref_ptr<Style> > Styles;
|
||||
typedef Styles::iterator Iterator;
|
||||
typedef Styles::const_iterator ConstIterator;
|
||||
|
||||
META_Object(osgWidget, StyleManager);
|
||||
|
||||
StyleManager ();
|
||||
StyleManager (const StyleManager&, const osg::CopyOp&);
|
||||
|
||||
bool addStyle(Style*);
|
||||
|
||||
bool applyStyles(Widget* widget) {
|
||||
return _applyStyles(widget);
|
||||
}
|
||||
|
||||
bool applyStyles(Window* window) {
|
||||
return _applyStyles(window);
|
||||
}
|
||||
|
||||
private:
|
||||
Styles _styles;
|
||||
|
||||
@ -113,8 +132,10 @@ private:
|
||||
// 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) {
|
||||
bool _applyStyles(T* t)
|
||||
{
|
||||
if(!t)
|
||||
{
|
||||
warn()
|
||||
<< "Cannot call StyleManager::applyStyle with a NULL object."
|
||||
<< std::endl
|
||||
@ -125,7 +146,8 @@ private:
|
||||
|
||||
osg::Object* obj = dynamic_cast<osg::Object*>(t);
|
||||
|
||||
if(!obj) {
|
||||
if(!obj)
|
||||
{
|
||||
warn()
|
||||
<< "Cannot coerce object into osg::Object in StyleManager:::applyStyle"
|
||||
<< std::endl
|
||||
@ -137,7 +159,8 @@ private:
|
||||
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()) {
|
||||
if(t->getStyle().empty())
|
||||
{
|
||||
// Couldn't find the className, so we exit.
|
||||
if(_styles.find(c) == _styles.end()) return false;
|
||||
|
||||
@ -153,21 +176,6 @@ private:
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,27 +8,12 @@
|
||||
|
||||
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:
|
||||
|
||||
typedef std::vector<point_type> CellSizes;
|
||||
|
||||
protected:
|
||||
unsigned int _calculateIndex(unsigned int, unsigned int) const;
|
||||
|
||||
void _getRows (CellSizes&, Getter) const;
|
||||
void _getColumns (CellSizes&, Getter) const;
|
||||
|
||||
virtual void _resizeImplementation(point_type, point_type);
|
||||
|
||||
virtual Sizes _getWidthImplementation () const;
|
||||
virtual Sizes _getHeightImplementation () const;
|
||||
|
||||
public:
|
||||
META_Object (osgWidget, Table);
|
||||
META_UIObject (Table);
|
||||
|
||||
@ -49,13 +34,32 @@ public:
|
||||
bool isRowVerticallyFillable (unsigned int) const;
|
||||
bool isColumnHorizontallyFillable (unsigned int) const;
|
||||
|
||||
Widget* getByRowCol(unsigned int row, unsigned int col) {
|
||||
Widget* getByRowCol(unsigned int row, unsigned int col)
|
||||
{
|
||||
return getObjects()[_calculateIndex(row, col)].get();
|
||||
}
|
||||
|
||||
const Widget* getByRowCol(unsigned int row, unsigned int col) const {
|
||||
const Widget* getByRowCol(unsigned int row, unsigned int col) const
|
||||
{
|
||||
return getObjects()[_calculateIndex(row, col)].get();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int _rows;
|
||||
unsigned int _cols;
|
||||
unsigned int _lastRowAdd;
|
||||
unsigned int _lastColAdd;
|
||||
|
||||
unsigned int _calculateIndex(unsigned int, unsigned int) const;
|
||||
|
||||
void _getRows (CellSizes&, Getter) const;
|
||||
void _getColumns (CellSizes&, Getter) const;
|
||||
|
||||
virtual void _resizeImplementation(point_type, point_type);
|
||||
|
||||
virtual Sizes _getWidthImplementation () const;
|
||||
virtual Sizes _getHeightImplementation () const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ namespace osgWidget {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class UIObjectParent {
|
||||
class UIObjectParent
|
||||
{
|
||||
public:
|
||||
typedef T object_type;
|
||||
typedef osg::observer_ptr<object_type> ptr_type;
|
||||
@ -25,10 +26,6 @@ public:
|
||||
typedef typename Vector::iterator Iterator;
|
||||
typedef typename Vector::const_iterator ConstIterator;
|
||||
|
||||
protected:
|
||||
Vector _objects;
|
||||
|
||||
public:
|
||||
Iterator begin() {
|
||||
return _objects.begin();
|
||||
}
|
||||
@ -49,25 +46,6 @@ public:
|
||||
return _objects.size();
|
||||
}
|
||||
|
||||
private:
|
||||
// I had to add this to avoid ambiguity errors with MSVC. Garbage.
|
||||
object_type* _getByName(const std::string& name) const {
|
||||
for(ConstIterator i = begin(); i != end(); i++) {
|
||||
if(i->valid() && i->get()->getName() == name) return i->get();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
object_type* _getByIndex(unsigned int index) const {
|
||||
for(ConstIterator i = begin(); i != end(); i++) {
|
||||
if(i->valid() && i->get()->getIndex() == index) return i->get();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
object_type* getByName(const std::string& name) {
|
||||
return _getByName(name);
|
||||
}
|
||||
@ -97,6 +75,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
bool _remove(object_type* obj) {
|
||||
Iterator i = std::find(begin(), end(), obj);
|
||||
|
||||
@ -116,6 +95,28 @@ protected:
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector _objects;
|
||||
|
||||
private:
|
||||
|
||||
// I had to add this to avoid ambiguity errors with MSVC. Garbage.
|
||||
object_type* _getByName(const std::string& name) const {
|
||||
for(ConstIterator i = begin(); i != end(); i++) {
|
||||
if(i->valid() && i->get()->getName() == name) return i->get();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
object_type* _getByIndex(unsigned int index) const {
|
||||
for(ConstIterator i = begin(); i != end(); i++) {
|
||||
if(i->valid() && i->get()->getIndex() == index) return i->get();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -18,21 +18,25 @@ namespace osgWidget {
|
||||
|
||||
// These are NOT OSGWIDGET_EXPORT'd; these are internal only!
|
||||
|
||||
inline std::ostream& _notify(osg::NotifySeverity ns = osg::INFO) {
|
||||
inline std::ostream& _notify(osg::NotifySeverity ns = osg::INFO)
|
||||
{
|
||||
std::ostream& n = osg::notify(ns);
|
||||
|
||||
return n << "osgWidget: ";
|
||||
}
|
||||
|
||||
inline std::ostream& warn() {
|
||||
inline std::ostream& warn()
|
||||
{
|
||||
return _notify(osg::WARN);
|
||||
}
|
||||
|
||||
inline std::ostream& info() {
|
||||
inline std::ostream& info()
|
||||
{
|
||||
return _notify();
|
||||
}
|
||||
|
||||
inline std::string lowerCase(const std::string& str) {
|
||||
inline std::string lowerCase(const std::string& str)
|
||||
{
|
||||
std::string s = str;
|
||||
|
||||
// TODO: Why can't I specify std::tolower?
|
||||
@ -43,7 +47,8 @@ inline std::string lowerCase(const std::string& str) {
|
||||
|
||||
// TODO: Is this totally ghetto or what?
|
||||
template <typename T>
|
||||
inline bool hasDecimal(T v) {
|
||||
inline bool hasDecimal(T v)
|
||||
{
|
||||
return (v - static_cast<T>(static_cast<long>(v))) > 0.0f;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,20 @@
|
||||
namespace osgWidget {
|
||||
|
||||
// This handles the pressing/moving of mouse buttons, etc.
|
||||
class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler {
|
||||
class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
MouseHandler(WindowManager*);
|
||||
|
||||
virtual bool handle(
|
||||
const osgGA::GUIEventAdapter&,
|
||||
osgGA::GUIActionAdapter&,
|
||||
osg::Object*,
|
||||
osg::NodeVisitor*
|
||||
);
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<WindowManager> _wm;
|
||||
|
||||
bool _handleMousePush (float, float, int);
|
||||
@ -31,21 +44,11 @@ class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler {
|
||||
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*);
|
||||
|
||||
@ -55,13 +58,15 @@ public:
|
||||
osg::Object*,
|
||||
osg::NodeVisitor*
|
||||
);
|
||||
|
||||
protected:
|
||||
osg::ref_ptr<WindowManager> _wm;
|
||||
|
||||
};
|
||||
|
||||
// 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*);
|
||||
|
||||
@ -71,6 +76,12 @@ public:
|
||||
osg::Object*,
|
||||
osg::NodeVisitor*
|
||||
);
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<WindowManager> _wm;
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -48,53 +48,6 @@ public:
|
||||
PFM_SLOPPY = 0x00000002
|
||||
};
|
||||
|
||||
private:
|
||||
// A functor used to sort the Windows by their Z component in descending order.
|
||||
struct WindowZCompare: public std::binary_function<ptr_type, ptr_type, bool> {
|
||||
bool operator()(const ptr_type& x, const ptr_type& y) {
|
||||
return x.get()->getZ() > y.get()->getZ();
|
||||
}
|
||||
};
|
||||
|
||||
point_type _width;
|
||||
point_type _height;
|
||||
point_type _zNear;
|
||||
point_type _zFar;
|
||||
matrix_type _numForeground;
|
||||
matrix_type _numBackground;
|
||||
unsigned int _flags;
|
||||
unsigned int _nodeMask;
|
||||
osgViewer::View* _view;
|
||||
float _lastX;
|
||||
float _lastY;
|
||||
EventInterface* _lastEvent;
|
||||
EventInterface* _lastPush;
|
||||
POINTER_DIRECTION _lastVertical;
|
||||
POINTER_DIRECTION _lastHorizontal;
|
||||
POINTER_FOCUS_MODE _focusMode;
|
||||
bool _leftDown;
|
||||
bool _middleDown;
|
||||
bool _rightDown;
|
||||
|
||||
osgGA::GUIEventAdapter::ScrollingMotion _scrolling;
|
||||
|
||||
osg::ref_ptr<ScriptEngine> _lua;
|
||||
osg::ref_ptr<ScriptEngine> _python;
|
||||
osg::ref_ptr<StyleManager> _styleManager;
|
||||
|
||||
osg::observer_ptr<Widget> _widget;
|
||||
osg::observer_ptr<Window> _focused;
|
||||
osg::observer_ptr<Window> _pickWindow;
|
||||
|
||||
void childInserted (unsigned int);
|
||||
void childRemoved (unsigned int, unsigned int);
|
||||
|
||||
bool _handleMousePushed (float, float, bool&);
|
||||
bool _handleMouseReleased (float, float, bool&);
|
||||
bool _haneldMouseScrolled (float, float, bool = false);
|
||||
void _getPointerXYDiff (float&, float&);
|
||||
void _updatePickWindow (const WidgetList*, point_type, point_type);
|
||||
|
||||
public:
|
||||
META_Object(osgWidget, WindowManager);
|
||||
|
||||
@ -307,6 +260,54 @@ public:
|
||||
// can be compared to osgGA::GUIEventAdapter::{KeySymbol,KeyModMask}.
|
||||
bool keyDown (int, int);
|
||||
bool keyUp (int, int);
|
||||
|
||||
private:
|
||||
// A functor used to sort the Windows by their Z component in descending order.
|
||||
struct WindowZCompare: public std::binary_function<ptr_type, ptr_type, bool> {
|
||||
bool operator()(const ptr_type& x, const ptr_type& y) {
|
||||
return x.get()->getZ() > y.get()->getZ();
|
||||
}
|
||||
};
|
||||
|
||||
point_type _width;
|
||||
point_type _height;
|
||||
point_type _zNear;
|
||||
point_type _zFar;
|
||||
matrix_type _numForeground;
|
||||
matrix_type _numBackground;
|
||||
unsigned int _flags;
|
||||
unsigned int _nodeMask;
|
||||
osgViewer::View* _view;
|
||||
float _lastX;
|
||||
float _lastY;
|
||||
EventInterface* _lastEvent;
|
||||
EventInterface* _lastPush;
|
||||
POINTER_DIRECTION _lastVertical;
|
||||
POINTER_DIRECTION _lastHorizontal;
|
||||
POINTER_FOCUS_MODE _focusMode;
|
||||
bool _leftDown;
|
||||
bool _middleDown;
|
||||
bool _rightDown;
|
||||
|
||||
osgGA::GUIEventAdapter::ScrollingMotion _scrolling;
|
||||
|
||||
osg::ref_ptr<ScriptEngine> _lua;
|
||||
osg::ref_ptr<ScriptEngine> _python;
|
||||
osg::ref_ptr<StyleManager> _styleManager;
|
||||
|
||||
osg::observer_ptr<Widget> _widget;
|
||||
osg::observer_ptr<Window> _focused;
|
||||
osg::observer_ptr<Window> _pickWindow;
|
||||
|
||||
void childInserted (unsigned int);
|
||||
void childRemoved (unsigned int, unsigned int);
|
||||
|
||||
bool _handleMousePushed (float, float, bool&);
|
||||
bool _handleMouseReleased (float, float, bool&);
|
||||
bool _haneldMouseScrolled (float, float, bool = false);
|
||||
void _getPointerXYDiff (float&, float&);
|
||||
void _updatePickWindow (const WidgetList*, point_type, point_type);
|
||||
|
||||
};
|
||||
|
||||
// We use a template here because the container could be a list or a vector; or something
|
||||
|
Loading…
Reference in New Issue
Block a user