Files
OpenSceneGraph/include/osgViewer/GraphicsWindow
Robert Osfield 822868ca31 From Mathias Froelich, "have done an interface to change the mouse cursor in the X11 graphics
window.
The win32 implementation is still in its original shape since I have no win32
implementation available.

I have chosen the enum approach for the first cut. That is benefitial since
the user does not need to track creation of mouse cursors for different
windows and displays in presence of multiple viewer windows.

The default set of available mouse shapes is the same set that was available
with glut. That set served many OpenGL applications well, so the hope is that
this is enough.

Even though, that implementation is still extensible:
I have digged out the way SDL defines new mouse cursors and added a still
documented out function prototype in the GraphicsWindow that can be used to
extend the current implemtation for arbitrary mouse shapes. That is not
implemented yet.

I hope that somebody with a win32 test system can catch up that implementation
on win32."
2007-06-01 19:43:28 +00:00

156 lines
7.7 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_GRAPHICWINDOW
#define OSGVIEWER_GRAPHICWINDOW 1
#include <osg/GraphicsContext>
#include <osg/Notify>
#include <osgGA/EventQueue>
#include <osgGA/GUIActionAdapter>
#include <osgViewer/Export>
namespace osgViewer {
/** Base class for providing Windowing API agnostic access to creating and managing graphisc window and events.
* Note, the GraphicsWindow is subclassed from osg::GraphicsContext, and to provide an implemention you'll need to implement its
* range of pure virtual functions, you'll find these all have naming convention methodNameImplemention(..).
* GraphicsWindow adds the event queue ontop of the GraphicsContext, thereby adding a mechnism for adapting Windowing events
* as well as basics graphics context work, you should wire up custom GraphicsWindowImplementation to push their events through
* into the EventQueue. */
class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgGA::GUIActionAdapter
{
public:
GraphicsWindow() { _eventQueue = new osgGA::EventQueue; }
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
virtual void checkEvents() {}
/** Set the window's position and size.*/
virtual void setWindowRectangle(int /*x*/, int /*y*/, int /*width*/, int /*height*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowRectangle(..) not implemented."<<std::endl; }
/** Get the window's position and size.*/
virtual void getWindowRectangle(int& x, int& y, int& width, int& height) { if (_traits.valid()) { x = _traits->x; y = _traits->y; width = _traits->width; height = _traits->height; } }
/** Set Window decoration.*/
virtual void setWindowDecoration(bool /*flag*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowDecoration(..) not implemented."<<std::endl; }
/** Set Window decoration.*/
virtual bool getWindowDecoration() const { return _traits.valid() ? _traits->windowDecoration : false; }
/** Get focus.*/
virtual void grabFocus() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocus(..) not implemented."<<std::endl; }
/** Get focus on if the pointer is in this window.*/
virtual void grabFocusIfPointerInWindow() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocusIfPointerInWindow(..) not implemented."<<std::endl; }
/** Mouse cursor types, the same ones already present with ancient glut ... */
enum MouseCursor {
InheritCursor,
NoCursor,
RightArrowCursor,
LeftArrowCursor,
InfoCursor,
DestroyCursor,
HelpCursor,
CycleCursor,
SprayCursor,
WaitCursor,
TextCursor,
CrosshairCursor,
UpDownCursor,
LeftRightCursor,
TopSideCursor,
BottomSideCursor,
LeftSideCursor,
RightSideCursor,
TopLeftCorner,
TopRightCorner,
BottomRightCorner,
BottomLeftCorner
};
/** Switch on/off the cursor.*/
virtual void useCursor(bool cursorOn) { setCursor(cursorOn ? InheritCursor : NoCursor); }
/** Set mouse cursor to a specific shape.*/
virtual void setCursor(MouseCursor /*mouseCursor*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setCursor(..) not implemented."<<std::endl; }
/** Create a new mouse cursor from the usual bitmap data.*/
//virtual MouseCursor createCursor(const char *data, const char *mask, unsigned w, unsigned h, unsigned hotx, unsigned hoty) { osg::notify(osg::NOTICE)<<"GraphicsWindow::createCursor(..) not implemented."<<std::endl; }
public:
/** Return whether a valid and usable GraphicsContext has been created.*/
virtual bool valid() const { osg::notify(osg::NOTICE)<<"GraphicsWindow::realizeImplementation() not implemented."<<std::endl; return false; }
/** Realise the GraphicsContext implementation,
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual bool realizeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::realizeImplementation() not implemented."<<std::endl; return false; }
/** Return true if the graphics context has been realised, and is ready to use, implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual bool isRealizedImplementation() const { osg::notify(osg::NOTICE)<<"GraphicsWindow::isRealizedImplementation() not implemented."<<std::endl; return false; }
/** Close the graphics context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void closeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::closeImplementation() not implemented."<<std::endl; }
/** Make this graphics context current implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual bool makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; return false;}
/** Make this graphics context current with specified read context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false;}
/** Release the graphics context.*/
virtual bool releaseContextImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::releaseContextImplementation(..) not implemented."<<std::endl; return false; }
/** Pure virtual, Bind the graphics context to associated texture implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::bindPBufferToTextureImplementation(..) not implemented."<<std::endl; }
/** Swap the front and back buffers implementation.
* Pure virtual - must be implemented by Concrate implementations of GraphicsContext. */
virtual void swapBuffersImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow:: swapBuffersImplementation() not implemented."<<std::endl; }
public:
// Override from GUIActionAdapter
virtual void requestRedraw() {}
// Override from GUIActionAdapter
virtual void requestContinuousUpdate(bool /*needed*/=true) {}
// Override from GUIActionAdapter
virtual void requestWarpPointer(float /*x*/,float /*y*/) {}
protected:
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
};
}
#endif