From Jeremy Moles, updates to osgWidget

Merged my Robert Osfield from OpenSceneGraph-osgWidget-dev.
This commit is contained in:
Robert Osfield
2008-11-28 14:35:33 +00:00
parent d3b2d9b074
commit 9748fdd605
35 changed files with 1234 additions and 639 deletions

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Box 46 2008-04-30 16:11:51Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_BOX
#define OSGWIDGET_BOX
@@ -21,17 +20,26 @@
namespace osgWidget {
//! The Box object is a Window subclass that can be configured to uniformly (or
//! non-uniformly) position it's children either vertically or horizontally. It
//! is the most basic Window implementation, though there is some difficulty when
//! positioning children such that each child object ends up pixel-aligned.
class OSGWIDGET_EXPORT Box: public Window
{
public:
enum BOX_TYPE {
//! An enum corresponding to the type of Box alignment.
enum BoxType {
VERTICAL,
HORIZONTAL
};
META_Object (osgWidget, Box);
Box (const std::string& = "", BOX_TYPE = HORIZONTAL, bool = false);
META_Object(osgWidget, Box);
//! The main constructor; takes the string name, the BoxType orientation, and a
//! boolean indicating whether or not all of the Box regions should be uniformly
//! sized.
Box (const std::string& = "", BoxType = HORIZONTAL, bool = false);
Box (const Box&, const osg::CopyOp&);
protected:
@@ -43,10 +51,9 @@ class OSGWIDGET_EXPORT Box: public Window
private:
BOX_TYPE _boxType;
BoxType _boxType;
bool _uniform;
unsigned int _lastAdd;
};
}

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Canvas 66 2008-07-14 21:54:09Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_CANVAS
#define OSGWIDGET_CANVAS
@@ -24,12 +23,13 @@ namespace osgWidget {
class OSGWIDGET_EXPORT Canvas: public Window
{
public:
META_Object (osgWidget, Canvas);
META_Object(osgWidget, Canvas);
Canvas (const std::string& = "");
Canvas (const Canvas&, const osg::CopyOp&);
// This would conflict with the normal addWidget if there were default values. :(
//! Adds a Widget at the given XY coordinate.
virtual bool addWidget(Widget*, point_type, point_type);
protected:

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: EventInterface 64 2008-06-30 21:32:00Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_EVENT_INTERFACE
#define OSGWIDGET_EVENT_INTERFACE
@@ -67,15 +66,15 @@ class OSGWIDGET_EXPORT Event
int keyMask;
Event(WindowManager* wm, EventType _type = EVENT_NONE):
_wm (wm),
_window (0),
_widget (0),
_data (0),
type (_type),
x (0.0f),
y (0.0f),
key (-1),
keyMask (-1) {
keyMask (-1),
_wm (wm),
_window (0),
_widget (0),
_data (0) {
}
Event& makeType(EventType _type) {
@@ -203,13 +202,19 @@ class FunctionCallback: public CallbackInterface
};
// The highlevel functor.
class OSGWIDGET_EXPORT Callback
class OSGWIDGET_EXPORT Callback: public osg::Referenced
{
public:
Callback():_type(EVENT_NONE),_data(0) {}
Callback(const Callback& rhs):_type(rhs._type),_data(rhs._data),_callback(rhs._callback) {}
Callback(): _type(EVENT_NONE), _data(0), _callback(0) {}
Callback(const Callback& rhs): osg::Referenced(rhs), _type(rhs._type), _data(rhs._data), _callback(rhs._callback) {}
// The more traditional style of OSG Callbacks.
Callback(EventType type, void* data=0):
_type (type),
_data (data),
_callback (0) {
}
// Creates a Callback that is bound to a member function.
template<typename T>
Callback(bool (T::*function)(Event&), T* obj, EventType type, void* data=0):
@@ -226,7 +231,11 @@ class OSGWIDGET_EXPORT Callback
_callback (new FunctionCallback<T>(functor)) {
}
bool operator()(Event& ev) {
virtual ~Callback() {}
virtual bool operator()(Event& ev) {
if(!_callback) return false;
return (*_callback)(ev);
}
@@ -241,9 +250,10 @@ class OSGWIDGET_EXPORT Callback
const void* getData() const {
return _data;
}
protected:
EventType _type;
void* _data;
void* _data;
// We use a ref_ptr here so that we don't have to worry about memory.
osg::ref_ptr<CallbackInterface> _callback;
@@ -301,7 +311,7 @@ class OSGWIDGET_EXPORT EventInterface
return _eventMask;
}
void addCallback(const Callback& cb) {
void addCallback(Callback* cb) {
_callbacks.push_back(cb);
}
@@ -312,10 +322,10 @@ class OSGWIDGET_EXPORT EventInterface
// 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->get()->getType() & ev.type) {
ev.setData(i->get()->getData());
if((*i)(ev)) return true;
if((*i->get())(ev)) return true;
}
}
@@ -387,7 +397,7 @@ class OSGWIDGET_EXPORT EventInterface
bool canKeyUp () const { return (_eventMask & EVENT_KEY_UP) != 0; }
private:
typedef std::list<Callback> CallbackList;
typedef std::list<osg::ref_ptr<Callback> > CallbackList;
unsigned int _eventMask;
CallbackList _callbacks;

View File

@@ -11,6 +11,8 @@
* OpenSceneGraph Public License for more details.
*/
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_EXPORT_
#define OSGWIDGET_EXPORT_ 1
@@ -41,7 +43,7 @@
\namespace osgWidget
The osgWidget library is a NodeKit that extends the core scene graph to support 3D GUI widget set.
The osgWidget library is a NodeKit that extends the core scene graph to support a 2D (and eventually 3D) GUI widget set.
*/
#endif

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Frame 59 2008-05-15 20:55:31Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_FRAME
#define OSGWIDGET_FRAME
@@ -21,11 +20,46 @@
namespace osgWidget {
/*
Lets take a moment and explain how Frame texturing works. When you create a Frame, you use
a specially designed texture that is "chopped" up horizontally by the Frame code into 8 equal
regions. Each region is then textured to a corresponding portion of the Frame, in the
following order:
+---+---+---+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
+---+---+---+---+---+---+---+---+
1. Upper-Left corner.
2. Top border (rotated 90 degrees CCW).
3. Upper-Right corner.
4. Left border.
5. Right border.
6. Bottom-Left corner.
7. Bottom border (rotated 90 degrees CCW).
8. Bottom-Right corner.
Now, these should be pretty self-explanatory if you visualize a frame as a 3x3 "table"
(which is exactly what it is), but note how regions 2 and 7 are rotated counter-clockwise.
We do this for a VERY important reason: we want to enable texture repeat on the border
regions, so that when the frame is resized the borders cleanly paint the texture over
the entire are (and don't stretch it). However, it is impossible in OpenGL to repeat a
sub-region of a texture without including either the vertical or horizontal bounds, so the
artist is required to rotate the region during their rendering so that our code can properly
rotate it back internally and have it repeat in the desired way.
This method of texturing a Frame object is inspired by World of Warcraft "edge files", and it
is both efficient and easy-to-use--once you understand the basics. If you're still confused,
take a look at this URL, or any of the example themes:
http://www.wowwiki.com/EdgeFiles
*/
class OSGWIDGET_EXPORT Frame: public Table
{
public:
enum CORNER
enum CornerType
{
CORNER_LOWER_LEFT,
CORNER_LOWER_RIGHT,
@@ -33,7 +67,7 @@ class OSGWIDGET_EXPORT Frame: public Table
CORNER_UPPER_RIGHT
};
enum BORDER
enum BorderType
{
BORDER_LEFT,
BORDER_RIGHT,
@@ -41,109 +75,127 @@ class OSGWIDGET_EXPORT Frame: public Table
BORDER_BOTTOM
};
static std::string cornerToString (CORNER);
static std::string borderToString (BORDER);
enum FrameOptions
{
FRAME_RESIZE = 1,
FRAME_MOVE = 2,
FRAME_TEXTURE = 4,
FRAME_ALL = FRAME_RESIZE | FRAME_MOVE | FRAME_TEXTURE
};
static std::string cornerTypeToString (CornerType);
static std::string borderTypeToString (BorderType);
class OSGWIDGET_EXPORT Corner: public Widget
{
public:
META_Object (osgWidget, Corner);
META_Object(osgWidget, Corner);
Corner (CORNER = CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f);
Corner (CornerType = CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f);
Corner (const Corner&, const osg::CopyOp&);
bool mouseDrag(double, double, WindowManager*);
virtual void parented (Window*);
virtual bool mouseDrag (double, double, WindowManager*);
CORNER getCorner() const {
CornerType getCornerType() const
{
return _corner;
}
void setCorner(CORNER corner) {
void setCornerType(CornerType corner)
{
_corner = corner;
}
void setCornerAndName(CORNER corner) {
void setCornerTypeAndName(CornerType corner)
{
_corner = corner;
_name = cornerToString(corner);
_name = cornerTypeToString(corner);
}
protected:
CORNER _corner;
CornerType _corner;
};
class OSGWIDGET_EXPORT Border: public Widget
{
public:
META_Object (osgWidget, Border);
META_Object(osgWidget, Border);
Border (BORDER = BORDER_LEFT, point_type = 0.0f, point_type = 0.0f);
Border (BorderType = BORDER_LEFT, point_type = 0.0f, point_type = 0.0f);
Border (const Border&, const osg::CopyOp&);
bool mouseDrag(double, double, WindowManager*);
virtual void parented (Window*);
virtual void positioned ();
virtual bool mouseDrag (double, double, WindowManager*);
BORDER getBorder() const {
BorderType getBorderType() const
{
return _border;
}
void setBorder(BORDER border) {
void setBorderType(BorderType border)
{
_border = border;
}
void setBorderAndName(BORDER border) {
void setBorderTypeAndName(BorderType border)
{
_border = border;
_name = borderToString(border);
_name = borderTypeToString(border);
}
protected:
BORDER _border;
BorderType _border;
};
META_Object (osgWidget, Frame);
META_Object(osgWidget, Frame);
Frame (const std::string& = "");
Frame (const std::string& = "", unsigned int = 0);
Frame (const Frame&, const osg::CopyOp&);
virtual void managed(WindowManager*);
static Frame* createSimpleFrame(
const std::string&,
point_type,
point_type,
point_type,
point_type,
Frame* = 0
unsigned int = 0,
Frame* = 0
);
static Frame* createSimpleFrameWithSingleTexture(
const std::string&,
osg::Image*,
point_type,
point_type,
unsigned int = 0,
Frame* = 0
);
static Frame* createSimpleFrameFromTheme(
const std::string&,
osg::Image*,
point_type,
point_type,
point_type,
point_type,
point_type,
point_type,
Frame* = 0
unsigned int = 0,
Frame* = 0
);
void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h)
{
createSimpleFrame(_name, cw, ch, w, h, this);
createSimpleFrame(_name, cw, ch, w, h, 0, 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
osg::Image* image,
point_type w,
point_type h
)
{
createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this);
createSimpleFrameWithSingleTexture(_name, image, w, h, 0, this);
}
bool setWindow(Window*);
@@ -152,19 +204,49 @@ class OSGWIDGET_EXPORT Frame: public Table
const EmbeddedWindow* getEmbeddedWindow() const { return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1)); }
Corner* getCorner(CORNER c) { return dynamic_cast<Corner*>(_getCorner(c)); }
Corner* getCorner(CornerType c) { return dynamic_cast<Corner*>(_getCorner(c)); }
const Corner* getCorner(CORNER c) const { return dynamic_cast<const Corner*>(_getCorner(c)); }
const Corner* getCorner(CornerType c) const { return dynamic_cast<const Corner*>(_getCorner(c)); }
Border* getBorder(BORDER b) { return dynamic_cast<Border*>(_getBorder(b)); }
Border* getBorder(BorderType b) { return dynamic_cast<Border*>(_getBorder(b)); }
const Border* getBorder(BORDER b) const { return dynamic_cast<const Border*>(_getBorder(b)); }
const Border* getBorder(BorderType b) const { return dynamic_cast<const Border*>(_getBorder(b)); }
// This method resizes the internal EmbeddedWindow object and then properly resizes
// the reset of the Frame based on the sizes of the Corners, Borders, etc.
bool resizeFrame(point_type, point_type);
unsigned int getFlags() const
{
return _flags;
}
void setFlags(unsigned int flags)
{
_flags = flags;
}
bool canResize() const
{
return (_flags & FRAME_RESIZE) != 0;
}
bool canMove() const
{
return (_flags & FRAME_MOVE) != 0;
}
bool canTexture() const
{
return (_flags & FRAME_TEXTURE) != 0;
}
protected:
Widget* _getCorner (CORNER) const;
Widget* _getBorder (BORDER) const;
Widget* _getCorner (CornerType) const;
Widget* _getBorder (BorderType) const;
unsigned int _flags;
};
}

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Input 45 2008-04-23 16:46:11Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_INPUT
#define OSGWIDGET_INPUT
@@ -21,9 +20,15 @@
namespace osgWidget {
// This is a string of values we use to try and determine the best Y
// descent value (yoffset); you're welcome to use what works best for
// your font.
const std::string DESCENT_STRING("qpl");
class OSGWIDGET_EXPORT Input: public Label
{
public:
Input(const std::string& = "", const std::string& = "", unsigned int = 20);
virtual void parented (Window*);
@@ -34,7 +39,8 @@ class OSGWIDGET_EXPORT Input: public Label
virtual bool keyUp (int, int, WindowManager*);
virtual bool keyDown (int, int, WindowManager*);
void setCursor(Widget*);
void setCursor (Widget*);
unsigned int calculateBestYOffset (const std::string& = "qgl");
void setXOffset(point_type xo) {
_xoff = xo;

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Label 59 2008-05-15 20:55:31Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_LABEL
#define OSGWIDGET_LABEL
@@ -34,10 +33,8 @@ class OSGWIDGET_EXPORT Label: public Widget
virtual void parented (Window*);
virtual void unparented (Window*);
virtual void managed (WindowManager*);
virtual void positioned ();
void update ();
void setLabel (const std::string&);
void setFont (const std::string&);
void setFontSize (unsigned int);

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Lua 2 2008-01-24 16:11:26Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_LUA
#define OSGWIDGET_LUA

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Python 2 2008-01-24 16:11:26Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_PYTHON
#define OSGWIDGET_PYTHON

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: ScriptEngine 2 2008-01-24 16:11:26Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_SCRIPT_ENGINE
#define OSGWIDGET_SCRIPT_ENGINE

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: StyleInterface 63 2008-06-30 19:18:37Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_STYLE_INTERFACE
#define OSGWIDGET_STYLE_INTERFACE

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: StyleManager 61 2008-06-24 20:24:26Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_STYLE_MANAGER
#define OSGWIDGET_STYLE_MANAGER

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Table 48 2008-05-05 14:13:20Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_TABLE
#define OSGWIDGET_TABLE

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Types 33 2008-04-04 19:03:12Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_TYPES
#define OSGWIDGET_TYPES
@@ -39,6 +38,11 @@ typedef osg::Vec4 Quad;
typedef osg::Matrix::value_type matrix_type;
// This is multiplied by a normalized Z value [0.0f, -1.0f] to create a RenderBin number
// to set the state of the Window/Widget with. Perhaps at some later time this should
// be configurable.
const int OSGWIDGET_RENDERBIN_MOD = 5000;
}
#endif

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: UIObjectParent 55 2008-05-12 19:14:42Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_UI_OBJECT_PARENT
#define OSGWIDGET_UI_OBJECT_PARENT
@@ -26,6 +25,7 @@ template <typename T>
class UIObjectParent
{
public:
typedef T object_type;
typedef osg::observer_ptr<object_type> ptr_type;
typedef std::vector<ptr_type> Vector;

View File

@@ -11,13 +11,12 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Util 59 2008-05-15 20:55:31Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_UTIL
#define OSGWIDGET_UTIL
#include <ctype.h>
#include <cctype>
#include <algorithm>
#include <sstream>
#include <osg/Camera>
@@ -71,26 +70,12 @@ class WindowManager;
OSGWIDGET_EXPORT std::string getFilePath (const std::string&);
OSGWIDGET_EXPORT std::string generateRandomName (const std::string&);
OSGWIDGET_EXPORT osg::Matrix createInvertedYOrthoProjectionMatrix (matrix_type, matrix_type);
OSGWIDGET_EXPORT osg::Camera* createOrthoCamera (matrix_type, matrix_type);
OSGWIDGET_EXPORT osg::Camera* createInvertedYOrthoCamera (matrix_type, matrix_type);
OSGWIDGET_EXPORT osg::Camera* createOrthoCamera (matrix_type, matrix_type);
// This function sets up our basic example framework, and optionally sets some root
// scene data.
OSGWIDGET_EXPORT int createExample(osgViewer::Viewer&, WindowManager*, osg::Node* = 0);
// This function works like the above routine, except creates an additional "outside"
// view for looking at your 2D scene.
// TODO: Fix this!
OSGWIDGET_EXPORT int createCompositeExample(
osgViewer::CompositeViewer&,
osgViewer::View*,
WindowManager*,
osg::Node* = 0
);
OSGWIDGET_EXPORT bool writeWindowManagerNode(WindowManager*);
OSGWIDGET_EXPORT int createExample (osgViewer::Viewer&, WindowManager*, osg::Node* = 0);
OSGWIDGET_EXPORT bool writeWindowManagerNode (WindowManager*);
}

View File

@@ -1,5 +1,4 @@
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Version 64 2008-06-30 21:32:00Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_VERSION
#define OSGWIDGET_VERSION

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: ViewerEventHandlers 31 2008-04-01 19:36:41Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_VIEWER_EVENT_HANDLERS
#define OSGWIDGET_VIEWER_EVENT_HANDLERS
@@ -31,6 +30,7 @@ namespace osgWidget {
class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler
{
public:
MouseHandler(WindowManager*);
virtual bool handle(
@@ -46,7 +46,7 @@ class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler
protected:
osg::ref_ptr<WindowManager> _wm;
osg::observer_ptr<WindowManager> _wm;
bool _handleMousePush (float, float, int);
bool _handleMouseRelease (float, float, int);
@@ -57,13 +57,13 @@ class OSGWIDGET_EXPORT MouseHandler: public osgGA::GUIEventHandler
MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const;
bool _doMouseEvent (float, float, MouseEvent);
};
// This handles the forwarding of keypress events.
class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler
{
public:
KeyboardHandler(WindowManager*);
virtual bool handle(
@@ -74,7 +74,7 @@ class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler
);
protected:
osg::ref_ptr<WindowManager> _wm;
osg::observer_ptr<WindowManager> _wm;
};
@@ -82,7 +82,8 @@ class OSGWIDGET_EXPORT KeyboardHandler: public osgGA::GUIEventHandler
class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler
{
public:
ResizeHandler(WindowManager*, osg::Camera*);
ResizeHandler(WindowManager*, osg::Camera* = 0);
virtual bool handle(
const osgGA::GUIEventAdapter&,
@@ -93,9 +94,30 @@ class OSGWIDGET_EXPORT ResizeHandler: public osgGA::GUIEventHandler
protected:
osg::ref_ptr<WindowManager> _wm;
osg::ref_ptr<osg::Camera> _camera;
osg::observer_ptr<WindowManager> _wm;
osg::observer_ptr<osg::Camera> _camera;
};
// This class provides a hotkey that lets you toggle back and forth between
// a camera and setting the CameraManipulator's home point.
class OSGWIDGET_EXPORT CameraSwitchHandler: public osgGA::GUIEventHandler
{
public:
CameraSwitchHandler(WindowManager*, osg::Camera*);
virtual bool handle(
const osgGA::GUIEventAdapter&,
osgGA::GUIActionAdapter&,
osg::Object*,
osg::NodeVisitor*
);
protected:
osg::observer_ptr<WindowManager> _wm;
osg::observer_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::Node> _oldNode;
};
}

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Widget 64 2008-06-30 21:32:00Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_WIDGET
#define OSGWIDGET_WIDGET
@@ -44,14 +43,14 @@ public:
LR = LOWER_RIGHT,
UR = UPPER_RIGHT,
UL = UPPER_LEFT,
ALL_CORNERS = 4
ALL_CORNERS = 4
};
enum Layer {
LAYER_TOP = 20,
LAYER_HIGH = 15,
LAYER_MIDDLE = 10,
LAYER_LOW = 5,
LAYER_TOP = 100,
LAYER_HIGH = 75,
LAYER_MIDDLE = 50,
LAYER_LOW = 25,
LAYER_BG = 0
};
@@ -94,7 +93,8 @@ public:
// WindowManager object. The base managed method (WHICH YOU MUST REMEMBER
// TO CALL IN YOUR DERIVED METHODS!) sets the TexMat properly depending
// on what coordinate system you're using.
virtual void managed(WindowManager*);
virtual void managed(WindowManager*) {
}
virtual void unmanaged(WindowManager*) {
}
@@ -117,6 +117,7 @@ public:
void setColor (color_type, color_type, color_type, color_type, Corner = ALL_CORNERS);
void addColor (color_type, color_type, color_type, color_type, Corner = ALL_CORNERS);
void setTexCoord (texcoord_type, texcoord_type, Corner = ALL_CORNERS);
void setLayer (Layer l, unsigned int offset = 0);
// These are additional texture coordinate setting methods.
// This method will use a given origin as the LOWER_LEFT point and texture the
@@ -127,8 +128,9 @@ public:
void setTexCoordWrapHorizontal ();
void setTexCoordWrapVertical ();
bool setImage (osg::Image*, bool=false);
bool setImage (const std::string&, bool=false);
bool setImage (osg::Image*, bool = false, bool = false);
bool setImage (const std::string&, bool = false, bool = false);
bool setTexture (osg::Texture*, bool = false, bool = false);
void addX (point_type);
void addY (point_type);
@@ -149,7 +151,6 @@ public:
const Color& getColor (Corner = ALL_CORNERS) const;
const TexCoord& getTexCoord (Corner = ALL_CORNERS) const;
Corner convertCorner (Corner) const;
Color getImageColorAtXY (point_type x, point_type y) const;
XYCoord localXY (double, double) const;
@@ -216,6 +217,14 @@ public:
setTexCoordRegion(xy.x(), xy.y(), w, h);
}
void setTexCoordRegion(point_type x, point_type y, const XYCoord& wh) {
setTexCoordRegion(x, y, wh.x(), wh.y());
}
void setTexCoordRegion(const XYCoord& xy, const XYCoord& wh) {
setTexCoordRegion(xy.x(), xy.y(), wh.x(), wh.y());
}
void addColor(const Color& col, Corner p = ALL_CORNERS) {
addColor(col.r(), col.g(), col.b(), col.a(), p);
}
@@ -237,11 +246,6 @@ public:
setMinimumSize(xy.x(), xy.y());
}
// TODO: Refine this...
void setLayer(Layer l, unsigned int offset = 0) {
_layer = l + offset;
}
void setPadLeft(point_type p) {
_padLeft = p;
}
@@ -394,8 +398,6 @@ public:
protected:
point_type _calculateZ(unsigned int) const;
PointArray* _verts() {
@@ -422,15 +424,23 @@ public:
return dynamic_cast<const TexCoordArray*>(getTexCoordArray(0));
}
osg::Texture2D* _texture() {
osg::Texture* _texture() {
osg::StateSet* ss = getStateSet();
if(!ss) return 0;
return dynamic_cast<osg::Texture2D*>(
getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE)
ss->getTextureAttribute(0, osg::StateAttribute::TEXTURE)
);
}
const osg::Texture2D* _texture() const {
const osg::Texture* _texture() const {
const osg::StateSet* ss = getStateSet();
if(!ss) return 0;
return dynamic_cast<const osg::Texture2D*>(
getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE)
ss->getTextureAttribute(0, osg::StateAttribute::TEXTURE)
);
}

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Window 66 2008-07-14 21:54:09Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_WINDOW
#define OSGWIDGET_WINDOW
@@ -73,7 +72,8 @@ class OSGWIDGET_EXPORT Window:
virtual void unmanaged (WindowManager*);
virtual void positioned ();
bool setWindow(Window*);
bool setWindow (Window*);
void updateSizeFromWindow ();
Window* getWindow() {
return _window.get();
@@ -139,7 +139,8 @@ class OSGWIDGET_EXPORT Window:
// This method wraps our Geode's addDrawable() method and returns the index of
// the newly-added Drawable.
unsigned int addDrawableAndGetIndex(osg::Drawable*);
unsigned int addDrawableAndGetIndex (osg::Drawable*);
unsigned int addChildAndGetIndex (osg::Node*);
bool isVisible () const;
bool isXYWithinVisible (float, float) const;
@@ -147,6 +148,7 @@ class OSGWIDGET_EXPORT Window:
void addVisibleArea (int = 0, int = 0, int = 0, int = 0);
bool setFocused (const Widget*);
bool setFocused (const std::string&);
bool grabFocus ();
bool setFirstFocusable ();
bool setNextFocusable ();
bool getFocusList (WidgetList&) const;
@@ -157,7 +159,11 @@ class OSGWIDGET_EXPORT Window:
XYCoord getAbsoluteOrigin () const;
// This method wraps the current Window in a EmbeddedWindow object and returns it.
EmbeddedWindow* embed();
EmbeddedWindow* embed(
const std::string& = "",
Widget::Layer = Widget::LAYER_MIDDLE,
unsigned int = 0
);
Widget* getFocused() {
return _focused.get();
@@ -313,6 +319,14 @@ class OSGWIDGET_EXPORT Window:
_y = y;
}
void setZ(matrix_type z) {
_z = z;
}
void setZRange(matrix_type zRange) {
_zRange = zRange;
}
void setPosition(matrix_type x, matrix_type y, matrix_type z) {
_x = x;
_y = y;
@@ -328,6 +342,10 @@ class OSGWIDGET_EXPORT Window:
_y = y;
}
void setOrigin(const XYCoord& xy) {
setOrigin(xy.x(), xy.y());
}
void setRotate(matrix_type r) {
_r = r;
}
@@ -382,19 +400,19 @@ class OSGWIDGET_EXPORT Window:
}
void attachMoveCallback() {
addCallback(Callback(&callbackWindowMove, EVENT_MOUSE_DRAG));
addCallback(new Callback(&callbackWindowMove, EVENT_MOUSE_DRAG));
}
void attachRotateCallback() {
addCallback(Callback(&callbackWindowRotate, EVENT_MOUSE_DRAG));
addCallback(new Callback(&callbackWindowRotate, EVENT_MOUSE_DRAG));
}
void attachScaleCallback() {
addCallback(Callback(&callbackWindowScale, EVENT_MOUSE_DRAG));
addCallback(new Callback(&callbackWindowScale, EVENT_MOUSE_DRAG));
}
void attachTabFocusCallback() {
addCallback(Callback(&callbackWindowTabFocus, EVENT_KEY_DOWN));
addCallback(new Callback(&callbackWindowTabFocus, EVENT_KEY_DOWN));
}
typedef point_type (Widget::*Getter)() const;

View File

@@ -11,8 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: WindowManager 66 2008-07-14 21:54:09Z cubicool $
// Code by: Jeremy Moles (cubicool) 2007-2008
#ifndef OSGWIDGET_WINDOW_MANAGER
#define OSGWIDGET_WINDOW_MANAGER
@@ -40,11 +39,10 @@ typedef osgUtil::LineSegmentIntersector::Intersections Intersections;
class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<Window> {
public:
enum WmFlags {
WM_USE_LUA = 0x00000001,
WM_USE_PYTHON = 0x00000002,
WM_PICK_DEBUG = 0x00000004,
WM_NO_INVERT_Y = 0x00000008,
WM_NO_BETA_WARN = 0x00000010
WM_USE_LUA = 0x00000001,
WM_USE_PYTHON = 0x00000002,
WM_USE_RENDERBINS = 0x00000004,
WM_PICK_DEBUG = 0x00000008
};
enum PointerDirection {
@@ -91,6 +89,9 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
void setStyleManager (StyleManager*);
void resizeAllWindows (bool = true);
XYCoord windowXY (double, double) const;
XYCoord localXY (double, double) const;
// 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);
@@ -119,8 +120,8 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
return (_flags & WM_USE_PYTHON) != 0;
}
bool isInvertedY() const {
return (_flags & WM_NO_INVERT_Y) == 0;
bool isUsingRenderBins() const {
return (_flags & WM_USE_RENDERBINS) != 0;
}
int getMouseKeysDown() const {
@@ -242,6 +243,11 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
_height = h;
}
void setWindowSize(point_type w, point_type h) {
_windowWidth = w;
_windowHeight = h;
}
// Wrappers around the real calls. These only pertains to mouse buttons,
// particularly 3-button mice, although there are other more generic
// "pointer" API methods.
@@ -282,10 +288,20 @@ class OSGWIDGET_EXPORT WindowManager: public osg::Switch, public UIObjectParent<
}
};
// A functor used to sort the Windows by their BinNum component in descending order.
struct WindowBinNumberCompare: public std::binary_function<ptr_type, ptr_type, bool> {
bool operator()(const ptr_type& x, const ptr_type& y) {
return
x.get()->getOrCreateStateSet()->getBinNumber() >
y.get()->getOrCreateStateSet()->getBinNumber()
;
}
};
point_type _width;
point_type _height;
point_type _zNear;
point_type _zFar;
point_type _windowWidth;
point_type _windowHeight;
matrix_type _numForeground;
matrix_type _numBackground;
unsigned int _flags;