Added new osgGA - GUI Adapter library submitted by Neil Salter. This will
replace the current GUI adapter code inside osgUtil.
This commit is contained in:
70
include/osgGA/CameraManipulator
Normal file
70
include/osgGA/CameraManipulator
Normal file
@@ -0,0 +1,70 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_CAMERAMANIPULATOR
|
||||
#define OSGGA_CAMERAMANIPULATOR 1
|
||||
|
||||
#include <osg/Camera>
|
||||
#include <osg/Node>
|
||||
|
||||
#include <osgGA/Export>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
CameraManipulator();
|
||||
virtual ~CameraManipulator();
|
||||
|
||||
/** attach a camera to the manipulator to be used for specifying view.*/
|
||||
virtual void setCamera(osg::Camera*);
|
||||
|
||||
/** get the attached camera.*/
|
||||
virtual const osg::Camera * getCamera() const;
|
||||
|
||||
/** get the attached camera.*/
|
||||
virtual osg::Camera * getCamera();
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*) {}
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const { return NULL; }
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual osg::Node* getNode() { return NULL; }
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
||||
|
||||
/** Handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Handle visitations */
|
||||
virtual void accept(GUIEventHandlerVisitor& v) { v.visit(*this); }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Reference pointer to a camera
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
75
include/osgGA/DriveManipulator
Normal file
75
include/osgGA/DriveManipulator
Normal file
@@ -0,0 +1,75 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_DRIVEMANIPULATOR
|
||||
#define OSGGA_DRIVEMANIPULATOR 1
|
||||
|
||||
#include <osgGA/CameraManipulator>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT DriveManipulator : public CameraManipulator
|
||||
{
|
||||
public:
|
||||
|
||||
DriveManipulator();
|
||||
virtual ~DriveManipulator();
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*);
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const;
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual osg::Node* getNode();
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
private:
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const GUIEventAdapter& ea);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
// Internal event stack comprising last three mouse events.
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
float _modelScale;
|
||||
float _velocity;
|
||||
float _height;
|
||||
float _buffer;
|
||||
|
||||
enum SpeedControlMode {
|
||||
USE_MOUSE_Y_FOR_SPEED,
|
||||
USE_MOUSE_BUTTONS_FOR_SPEED
|
||||
};
|
||||
|
||||
SpeedControlMode _speedMode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
53
include/osgGA/Export
Normal file
53
include/osgGA/Export
Normal file
@@ -0,0 +1,53 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
// The following symbol has a underscore suffix for compatibility.
|
||||
#ifndef OSGGA_EXPORT_
|
||||
#define OSGGA_EXPORT_ 1
|
||||
|
||||
#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
|
||||
#pragma warning( disable : 4244 )
|
||||
#pragma warning( disable : 4251 )
|
||||
#pragma warning( disable : 4275 )
|
||||
#pragma warning( disable : 4786 )
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
|
||||
# ifdef OSGGA_LIBRARY
|
||||
# define OSGGA_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define OSGGA_EXPORT __declspec(dllimport)
|
||||
#endif /* OSGUTIL_LIBRARY */
|
||||
#else
|
||||
#define OSGGA_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
|
||||
\namespace osgGA
|
||||
|
||||
The 'GA' in osgGA stands for 'GUI Abstraction'.
|
||||
|
||||
As the OpenSceneGraph is a cross-platform, window system-agnostic class library,
|
||||
it has no direct ties to any given windowing environment. Viewers, however, must at
|
||||
some level interact with a window system - where Window system may refer to a windowing
|
||||
API, e.g. GLUT, Qt, FLTK, MFC, ...
|
||||
|
||||
There is much commonality in the implementation of Viewers for varying windowing
|
||||
environments. E.g. most Viewers will update a Camera position in response to a mouse
|
||||
event, and may request that a timer be started as a result of a model being 'spun'.
|
||||
|
||||
The purpose of the osgGA namespace is to centralise the common areas of this
|
||||
functionality. With this centralised, the viewer writer needs only write a
|
||||
GUIEventAdapter, a GUIActionAdapter, and assemble a collection of GUIEventHandlers
|
||||
as appropriate for the viewer.
|
||||
|
||||
Events from the windowing environment are adpated, and then fed into the GUIEventHandlers.
|
||||
The GUIEventHandlers analyse and take action, and make requests of the windowing
|
||||
environemnt via the GUIActionAdapter. The viewer writer should honour these requests.
|
||||
|
||||
*/
|
||||
76
include/osgGA/FlightManipulator
Normal file
76
include/osgGA/FlightManipulator
Normal file
@@ -0,0 +1,76 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_FLIGHTMANIPULATOR
|
||||
#define OSGGA_FLIGHTMANIPULATOR 1
|
||||
|
||||
#include <osgGA/CameraManipulator>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT FlightManipulator : public CameraManipulator
|
||||
{
|
||||
public:
|
||||
|
||||
FlightManipulator();
|
||||
virtual ~FlightManipulator();
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*);
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const;
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual osg::Node* getNode();
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
enum YawControlMode {
|
||||
YAW_AUTOMATICALLY_WHEN_BANKED,
|
||||
NO_AUTOMATIC_YAW
|
||||
};
|
||||
|
||||
/** Set the yaw control between no yaw and yawing when banked.*/
|
||||
void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; }
|
||||
|
||||
private:
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const GUIEventAdapter& ea);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
// Internal event stack comprising last three mouse events.
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
float _modelScale;
|
||||
float _velocity;
|
||||
|
||||
YawControlMode _yawMode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
55
include/osgGA/GUIActionAdapter
Normal file
55
include/osgGA/GUIActionAdapter
Normal file
@@ -0,0 +1,55 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_GUIACTIONADAPTER
|
||||
#define OSGGA_GUIACTIONADAPTER 1
|
||||
|
||||
#include <osgGA/Export>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
|
||||
/** Pure virtual base class for adapting the GUI actions requested by CameraManipulators
|
||||
* into actions which are handled by the GUI toolkit of the users application.
|
||||
*
|
||||
* There are several was of using the ActionAdapter either inheriting it as
|
||||
* done with osgGLUT::Viewer class or passing a simple struct to the camera
|
||||
* manipulator then unpacking the results and working out what to do to respond
|
||||
* to the requests.
|
||||
*
|
||||
* Also there are several ways to run your app and handle the updating of
|
||||
* the window. osgGLUT::Viewer always has a idle callback registered which does a
|
||||
* redraw all the time. osgGLUT::Viewer can safely ignore both requestRedraw() and
|
||||
* requestContinousUpdate() as these are happening all the time anyway.
|
||||
*
|
||||
* Other apps will probably want to respond to the requestRedraw() and
|
||||
* requestContinousUpdate(bool) and again there is more than one way to handle it.
|
||||
* You can override requestRedraw() and implement to call your own window
|
||||
* redraw straight away. Or you can implement so that a flag is set and
|
||||
* then you then respond the flag being set in your own leisure.
|
||||
*
|
||||
* requestContinousUpdate(bool) is for enabling a throw or idle
|
||||
* callback to be requested by the camera manipulator. Again you can respond
|
||||
* to this immediately by registering a idle callback or a timed callback, or
|
||||
* you can delay setting the callback and do at you own leisure.
|
||||
*
|
||||
* requestWarpPointer(int,int) is requesting a respositioning of a mouse pointer
|
||||
* to a specified x,y location on the window. Used by some camera manipulators
|
||||
* to initialize the mouse pointer when mouse position relative to a controls
|
||||
* neutral mouse position is required, i.e when mimicking a aircrafts joystick.
|
||||
*/
|
||||
class GUIActionAdapter
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void requestRedraw() = 0;
|
||||
virtual void requestContinuousUpdate(bool needed=true) = 0;
|
||||
virtual void requestWarpPointer(int x,int y) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
89
include/osgGA/GUIEventAdapter
Normal file
89
include/osgGA/GUIEventAdapter
Normal file
@@ -0,0 +1,89 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_GUIEVENTADAPTER
|
||||
#define OSGGA_GUIEVENTADAPTER 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osgGA/Export>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
|
||||
/** Pure virtual base class for adapting platform specific events into
|
||||
* generic keyboard and mouse events.
|
||||
*
|
||||
* Used as GUI toolkit independent input into the osgUtil::CameraManipualor's.
|
||||
* For an example of how GUIEventAdapter is specialised for a particular GUI
|
||||
* Toolkit see osgGLUT::GLUTEventAdapter.
|
||||
*/
|
||||
class GUIEventAdapter : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
GUIEventAdapter() {}
|
||||
|
||||
|
||||
enum MouseButtonMask {
|
||||
LEFT_MOUSE_BUTTON=1,
|
||||
MIDDLE_MOUSE_BUTTON=2,
|
||||
RIGHT_MOUSE_BUTTON=4
|
||||
};
|
||||
|
||||
enum EventType {
|
||||
PUSH,
|
||||
RELEASE,
|
||||
DRAG,
|
||||
MOVE,
|
||||
KEYBOARD,
|
||||
FRAME,
|
||||
RESIZE,
|
||||
NONE
|
||||
};
|
||||
|
||||
/** Get the EventType of the GUI event.*/
|
||||
virtual EventType getEventType() const = 0;
|
||||
|
||||
/** key pressed, return -1 if inappropriate for this event. */
|
||||
virtual int getKey() const = 0;
|
||||
|
||||
/** button pressed/released, return -1 if inappropriate for this event.*/
|
||||
virtual int getButton() const = 0;
|
||||
|
||||
/** window minimum x. */
|
||||
virtual int getXmin() const = 0;
|
||||
|
||||
/** window maximum x. */
|
||||
virtual int getXmax() const = 0;
|
||||
|
||||
/** window minimum y. */
|
||||
virtual int getYmin() const = 0;
|
||||
|
||||
/** window maximum y. */
|
||||
virtual int getYmax() const = 0;
|
||||
|
||||
/** current mouse x position.*/
|
||||
virtual int getX() const = 0;
|
||||
|
||||
/** current mouse y position.*/
|
||||
virtual int getY() const = 0;
|
||||
|
||||
/** current mouse button state */
|
||||
virtual unsigned int getButtonMask() const = 0;
|
||||
|
||||
/** time in seconds of event. */
|
||||
virtual float time() const = 0;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Force users to create on heap, so that multiple referencing is safe.*/
|
||||
virtual ~GUIEventAdapter() {}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
123
include/osgGA/GUIEventHandler
Normal file
123
include/osgGA/GUIEventHandler
Normal file
@@ -0,0 +1,123 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_GUIEVENTHANDLER
|
||||
#define OSGGA_GUIEVENTHANDLER 1
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <osg/Referenced>
|
||||
|
||||
#include <osgGA/Export>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
#include <osgGA/GUIEventHandlerVisitor>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class CompositeGUIEventHandler;
|
||||
|
||||
/**
|
||||
|
||||
GUIEventHandler provides a basic interface for any class which wants to handle
|
||||
a GUI Events.
|
||||
|
||||
The GUIEvent is supplied by a GUIEventAdapter. Feedback resulting from the
|
||||
handle method is supplied by a GUIActionAdapter, which allows the GUIEventHandler
|
||||
to ask the GUI to take some action in response to an incoming event.
|
||||
|
||||
For example, consider a Trackball Viewer class which takes mouse events and
|
||||
manipulates a scene camera in response. The Trackball Viewer is a GUIEventHandler,
|
||||
and receives the events via the handle method. If the user 'throws' the model,
|
||||
the Trackball Viewer class can detect this via the incoming events, and
|
||||
request that the GUI set up a timer callback to continually redraw the view.
|
||||
This request is made via the GUIActionAdapter class.
|
||||
|
||||
*/
|
||||
|
||||
class OSGGA_EXPORT GUIEventHandler : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
/** Handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us)=0;
|
||||
|
||||
/** Is this const GUIEventHandler a composite? */
|
||||
virtual const CompositeGUIEventHandler* getComposite() const { return 0; }
|
||||
|
||||
/** Is this non-const GUIEventHandler a composite? */
|
||||
virtual CompositeGUIEventHandler* getComposite() { return 0; }
|
||||
|
||||
/** Accept visits from GUIEventHandler visitors */
|
||||
virtual void accept(GUIEventHandlerVisitor&) = 0;
|
||||
//virtual void accept(GUIEventHandlerVisitor&) { }
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
CompositeGUIEventHandler allows GUIEventHandlers to be composed into hierarchies.
|
||||
*/
|
||||
|
||||
class OSGGA_EXPORT CompositeGUIEventHandler : public GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::vector< osg::ref_ptr<GUIEventHandler> > ChildList;
|
||||
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& aa);
|
||||
|
||||
virtual const CompositeGUIEventHandler* getComposite() const { return this; }
|
||||
|
||||
virtual CompositeGUIEventHandler* getComposite() { return this; }
|
||||
|
||||
virtual void accept(GUIEventHandlerVisitor& v) { v.visit(*this); }
|
||||
|
||||
|
||||
|
||||
/* Composite-specific methods below */
|
||||
|
||||
virtual bool addChild(GUIEventHandler *geh);
|
||||
|
||||
virtual bool removeChild(GUIEventHandler *geh);
|
||||
|
||||
const int getNumChildren() const { return _children.size(); }
|
||||
|
||||
GUIEventHandler *getChild( int i) { return _children[i].get(); }
|
||||
|
||||
const GUIEventHandler *getChild( int i ) const { return _children[i].get(); }
|
||||
|
||||
bool containsNode( const GUIEventHandler* node ) const
|
||||
{
|
||||
|
||||
for (ChildList::const_iterator itr=_children.begin();
|
||||
itr!=_children.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->get()==node) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ChildList::iterator findChild( const GUIEventHandler* node )
|
||||
{
|
||||
for (ChildList::iterator itr=_children.begin();
|
||||
itr!=_children.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->get()==node) return itr;
|
||||
}
|
||||
return _children.end();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
ChildList _children;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
55
include/osgGA/GUIEventHandlerVisitor
Normal file
55
include/osgGA/GUIEventHandlerVisitor
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef OSGGA_GUIEVENTHANDLERVISITOR
|
||||
#define OSGGA_GUIEVENTHANDLERVISITOR 1
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osgGA/Export>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
// Some forward declarations
|
||||
class GUIActionAdapter;
|
||||
class CompositeGUIEventHandler;
|
||||
class CameraManipulator;
|
||||
class StateSetManipulator;
|
||||
|
||||
/** Base class primarily for visiting GUIEventHandlers.
|
||||
|
||||
A Default Visitor, (Might want to make it an Extrinsic Visitor at some point).
|
||||
By default, it does nothing to the things it visits. Sub classes of this Visitor
|
||||
need only override visit operations for the types of object they're interested in.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class OSGGA_EXPORT GUIEventHandlerVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void visit(CompositeGUIEventHandler&);
|
||||
virtual void visit(CameraManipulator&) {};
|
||||
virtual void visit(StateSetManipulator&) {};
|
||||
|
||||
// Accessors
|
||||
|
||||
/** Get the GUI EventAdapter associated with this GUIEventHandlerVisitor */
|
||||
const GUIEventAdapter *getGUIEventAdapter() { return _gea.get(); }
|
||||
|
||||
/** Get the GUI Action Adapter associated with this GEH Visitor */
|
||||
GUIActionAdapter *getGUIActionAdapter() { return _gaa; }
|
||||
|
||||
protected:
|
||||
|
||||
GUIEventHandlerVisitor(GUIEventAdapter* in, GUIActionAdapter* out):_gea(in),_gaa(out) {}
|
||||
virtual ~GUIEventHandlerVisitor() {}
|
||||
|
||||
private:
|
||||
|
||||
osg::ref_ptr<GUIEventAdapter> _gea;
|
||||
GUIActionAdapter* _gaa; // Just a pointer. NOT owned by this object.
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
70
include/osgGA/KeySwitchCameraManipulator
Normal file
70
include/osgGA/KeySwitchCameraManipulator
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef OSGUTIL_KEYSWITCCAMERAMANIPULATORHER
|
||||
#define OSGUTIL_KEYSWITCHCAMERAMANIPULATORER 1
|
||||
|
||||
#include <osgGA/Export>
|
||||
#include <osgGA/CameraManipulator>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgGA/GUIEventHandlerVisitor>
|
||||
//#include <osgUtil/CallbackList>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class GUIEventAdapter;
|
||||
class GUIActionAdapter;
|
||||
|
||||
class OSGGA_EXPORT KeySwitchCameraManipulator : public CameraManipulator
|
||||
{
|
||||
public:
|
||||
|
||||
// Local methods
|
||||
|
||||
void addCameraManipulator(int key, std::string name, CameraManipulator *cm);
|
||||
|
||||
//typedef void (* Callback)(KeySwitchCameraManipulator *);
|
||||
|
||||
// class Callback: public osgUtil::CallbackList<KeySwitchCameraManipulator>::Callback {
|
||||
// public:
|
||||
// virtual ~Callback() {};
|
||||
// virtual void operator()(KeySwitchCameraManipulator *) = 0;
|
||||
// };
|
||||
//
|
||||
// void addCallback(Callback*);
|
||||
//
|
||||
// void removeCallback(Callback*);
|
||||
|
||||
// Overrides from CameraManipulator...
|
||||
|
||||
virtual void setCamera(osg::Camera* c) { _current->setCamera(c); }
|
||||
|
||||
virtual const osg::Camera * getCamera() const { return _current->getCamera(); }
|
||||
|
||||
virtual osg::Camera * getCamera() { return _current->getCamera(); }
|
||||
|
||||
virtual void setNode(osg::Node* n) { _current->setNode(n); }
|
||||
|
||||
virtual const osg::Node* getNode() const { return _current->getNode(); }
|
||||
|
||||
virtual osg::Node* getNode() { return _current->getNode(); }
|
||||
|
||||
virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa) { _current->home(ee,aa); }
|
||||
|
||||
virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { _current->init(ee,aa); }
|
||||
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
private:
|
||||
|
||||
typedef std::pair<std::string, osg::ref_ptr<CameraManipulator> > NamedManipulator;
|
||||
typedef std::map<int, NamedManipulator> KeyManipMap;
|
||||
KeyManipMap _manips;
|
||||
|
||||
osg::ref_ptr<CameraManipulator> _current;
|
||||
|
||||
// Callbacks
|
||||
//CallbackList<KeySwitchCameraManipulator> _cameraManipChangeCallbacks;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
40
include/osgGA/SetSceneViewVisitor
Normal file
40
include/osgGA/SetSceneViewVisitor
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef OSGGA_SETSCENEVIEWGEHVISITOR
|
||||
#define OSGGA_SETSCENEVIEWGEHVISITOR 1
|
||||
|
||||
#include <osgGA/GUIEventHandlerVisitor>
|
||||
#include <osgUtil/SceneView>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
// Some forward declarations
|
||||
class GUIEventHandler;
|
||||
class CameraManipulator;
|
||||
|
||||
/** SetSceneViewGUIEventHandlerVisitor which visits various types of GUIEventHandler and
|
||||
sets them up appropriately, given a new scene view.
|
||||
. */
|
||||
|
||||
class OSGGA_EXPORT SetSceneViewVisitor: public GUIEventHandlerVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
SetSceneViewVisitor(GUIEventAdapter* in,
|
||||
GUIActionAdapter* out,
|
||||
osgUtil::SceneView* sv):
|
||||
GUIEventHandlerVisitor(in,out),
|
||||
_sceneView(sv) {}
|
||||
|
||||
virtual ~SetSceneViewVisitor() {}
|
||||
|
||||
virtual void visit(CameraManipulator& cm);
|
||||
virtual void visit(StateSetManipulator& cm);
|
||||
|
||||
private:
|
||||
|
||||
osg::ref_ptr<osgUtil::SceneView> _sceneView;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
51
include/osgGA/StateSetManipulator
Normal file
51
include/osgGA/StateSetManipulator
Normal file
@@ -0,0 +1,51 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_GEOSTATE_MANIPULATOR
|
||||
#define OSGGA_GEOSTATE_MANIPULATOR 1
|
||||
|
||||
#include <osg/StateSet>
|
||||
|
||||
#include <osgGA/Export>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT StateSetManipulator : public GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
StateSetManipulator();
|
||||
virtual ~StateSetManipulator();
|
||||
|
||||
/** attach a geostate to the manipulator to be used for specifying view.*/
|
||||
virtual void setStateSet(osg::StateSet*);
|
||||
|
||||
/** get the attached a geostate.*/
|
||||
virtual osg::StateSet * getStateSet();
|
||||
|
||||
/** get the attached a geostate.*/
|
||||
virtual const osg::StateSet * getStateSet() const;
|
||||
|
||||
/** Handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Handle visitations */
|
||||
virtual void accept(GUIEventHandlerVisitor&);
|
||||
|
||||
protected:
|
||||
|
||||
// Reference pointer to a geostate
|
||||
osg::ref_ptr<osg::StateSet> _drawState;
|
||||
|
||||
bool _backface;
|
||||
bool _lighting;
|
||||
bool _texture;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
77
include/osgGA/TrackballManipulator
Normal file
77
include/osgGA/TrackballManipulator
Normal file
@@ -0,0 +1,77 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_TRACKBALLMANIPULATOR
|
||||
#define OSGGA_TRACKBALLMANIPULATOR 1
|
||||
|
||||
#include <osgGA/CameraManipulator>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT TrackballManipulator : public CameraManipulator
|
||||
{
|
||||
public:
|
||||
|
||||
TrackballManipulator();
|
||||
virtual ~TrackballManipulator();
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*);
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const;
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual osg::Node* getNode();
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
|
||||
/** handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
private:
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const GUIEventAdapter& ea);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
|
||||
float tb_project_to_sphere(float r, float x, float y);
|
||||
|
||||
|
||||
/** Check the speed at which the mouse is moving.
|
||||
If speed is below a threshold then return false, otherwise return true.*/
|
||||
bool isMouseMoving();
|
||||
|
||||
// Internal event stack comprising last three mouse events.
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
float _modelScale;
|
||||
float _minimumZoomScale;
|
||||
|
||||
bool _thrown;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
39
include/osgGA/Version
Normal file
39
include/osgGA/Version
Normal file
@@ -0,0 +1,39 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGA_VERSION
|
||||
#define OSGGA_VERSION 1
|
||||
|
||||
#include <osgGA/Export>
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
/**
|
||||
* getVersion_osgGA() returns the library version number.
|
||||
* Numbering convention : osg_src-0.8-31 will return 0.8.31 from getVersion_osgGA.
|
||||
*
|
||||
* This C function can be also used to check for the existence of the OpenSceneGraph
|
||||
* library using autoconf and its m4 macro AC_CHECK_LIB.
|
||||
*
|
||||
* Here is the code to add to your configure.in:
|
||||
\verbatim
|
||||
#
|
||||
# Check for the OpenSceneGraph (OSG) utility library
|
||||
#
|
||||
AC_CHECK_LIB(osg, osgGAGetVersion, ,
|
||||
[AC_MSG_ERROR(OpenSceneGraph utility library not found. See http://www.openscenegraph.org)],)
|
||||
\endverbatim
|
||||
*/
|
||||
extern OSGGA_EXPORT const char* osgGAGetVersion();
|
||||
|
||||
/**
|
||||
* getLibraryName_osgGA() returns the library name in human friendly form.
|
||||
*/
|
||||
extern OSGGA_EXPORT const char* osgGAGetLibraryName();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user