19 #ifndef OSGVIEWER_GRAPHICSWINDOWCOCOA
20 #define OSGVIEWER_GRAPHICSWINDOWCOCOA 1
25 @class GraphicsWindowCocoaWindow;
26 @class GraphicsWindowCocoaGLView;
27 @class NSOpenGLContext;
28 @class NSOpenGLPixelFormat;
32 class GraphicsWindowCocoaGLView;
33 class GraphicsWindowCocoaWindow;
34 class NSOpenGLContext;
35 class NSOpenGLPixelFormat;
40 #include <osgViewer/GraphicsWindow>
41 #include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
59 _closeRequested(false),
60 _checkForEvents(true),
62 _currentCursor(RightArrowCursor),
67 _updateContext(false),
68 _multiTouchEnabled(false)
77 getState()->setGraphicsContext(
this);
79 if (_traits.valid() && _traits->sharedContext.valid())
81 getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
82 incrementContextIDUsageCount( getState()->getContextID() );
91 virtual bool isSameKindAs(
const Object*
object)
const {
return dynamic_cast<const GraphicsWindowCocoa*
>(object)!=0; }
92 virtual const char* libraryName()
const {
return "osgViewer"; }
93 virtual const char* className()
const {
return "GraphicsWindowCocoa"; }
95 virtual bool valid()
const {
return _valid; }
98 virtual bool realizeImplementation();
101 virtual bool isRealizedImplementation()
const {
return _realized; }
104 virtual void closeImplementation();
107 virtual bool makeCurrentImplementation();
110 virtual bool releaseContextImplementation();
113 virtual void swapBuffersImplementation();
116 virtual bool checkEvents();
119 virtual bool setWindowDecorationImplementation(
bool flag);
122 virtual void grabFocus();
125 virtual void grabFocusIfPointerInWindow();
127 bool requestClose() {
bool b = _closeRequested; _closeRequested =
true;
return b; }
129 virtual void resizedImplementation(
int x,
int y,
int width,
int height);
131 virtual bool setWindowRectangleImplementation(
int x,
int y,
int width,
int height);
133 virtual void setWindowName (
const std::string & name);
134 virtual void requestWarpPointer(
float x,
float y);
135 virtual void useCursor(
bool cursorOn);
136 virtual void setCursor(MouseCursor mouseCursor);
142 enum Options { CreateOnlyView = 1, CheckForEvents = 2, PoseAsStandaloneApp = 4, EnableMultiTouch = 8};
143 WindowData(
unsigned int options)
144 : _createOnlyView(options & CreateOnlyView),
145 _checkForEvents(options & CheckForEvents),
146 _poseAsStandaloneApp(options & PoseAsStandaloneApp),
147 _multiTouchEnabled(options & EnableMultiTouch),
152 inline NSView* getCreatedNSView() {
return _view; }
153 bool createOnlyView()
const {
return _createOnlyView; }
154 bool checkForEvents()
const {
return _checkForEvents; }
155 bool poseAsStandaloneApp()
const {
return _poseAsStandaloneApp; }
156 bool isMultiTouchEnabled()
const {
return _multiTouchEnabled; }
159 inline void setCreatedNSView(NSView* view) { _view = view; }
162 bool _createOnlyView, _checkForEvents, _poseAsStandaloneApp, _multiTouchEnabled;
165 friend class GraphicsWindowCocoa;
169 NSOpenGLContext* getContext() {
return _context; }
170 GraphicsWindowCocoaWindow* getWindow() {
return _window; }
171 NSOpenGLPixelFormat* getPixelFormat() {
return _pixelformat; }
173 virtual void setSyncToVBlank(
bool f);
176 void adaptResize(
int x,
int y,
int w,
int h);
178 bool isMultiTouchEnabled();
179 void setMultiTouchEnabled(
bool b);
185 void transformMouseXY(
float& x,
float& y);
186 void setupNSWindow(NSWindow* win);
189 virtual ~GraphicsWindowCocoa();
195 bool _useWindowDecoration;
202 bool _closeRequested, _checkForEvents,_ownsWindow;
203 MouseCursor _currentCursor;
204 GraphicsWindowCocoaWindow* _window;
205 GraphicsWindowCocoaGLView* _view;
206 NSOpenGLContext* _context;
207 NSOpenGLPixelFormat* _pixelformat;
208 bool _updateContext, _multiTouchEnabled;
GLint GLenum GLsizei width
static unsigned int createNewContextID()
GLint GLenum GLsizei GLsizei height