OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GraphicsWindowCarbon.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 /* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
15  * a guide to use of X11/GLX and copiying directly in the case of setBorder().
16  * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
17  */
18 
19 #ifndef OSGVIEWER_GRAPHICSWINDOWCARBON
20 #define OSGVIEWER_GRAPHICSWINDOWCARBON 1
21 
22 #if defined (__APPLE__) && (!__LP64__)
23 
24 #include <osgViewer/GraphicsWindow>
25 #include <osgViewer/api/Carbon/GraphicsHandleCarbon>
26 
27 namespace osgViewer
28 {
29 
30 class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleCarbon
31 {
32  public:
33 
34  GraphicsWindowCarbon(osg::GraphicsContext::Traits* traits):
35  _valid(false),
36  _initialized(false),
37  _realized(false),
38  _ownsWindow(true),
39  _currentCursor(RightArrowCursor),
40  _currentVSync(true)
41  {
42  _traits = traits;
43 
44  init();
45 
46  if (valid())
47  {
48  setState( new osg::State );
49  getState()->setGraphicsContext(this);
50 
51  if (_traits.valid() && _traits->sharedContext.valid())
52  {
53  getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
54  incrementContextIDUsageCount( getState()->getContextID() );
55  }
56  else
57  {
58  getState()->setContextID( osg::GraphicsContext::createNewContextID() );
59  }
60  }
61  }
62 
63  virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowCarbon*>(object)!=0; }
64  virtual const char* libraryName() const { return "osgViewer"; }
65  virtual const char* className() const { return "GraphicsWindowCarbon"; }
66 
67  virtual bool valid() const { return _valid; }
68 
70  virtual bool realizeImplementation();
71 
73  virtual bool isRealizedImplementation() const { return _realized; }
74 
76  virtual void closeImplementation();
77 
79  virtual bool makeCurrentImplementation();
80 
82  virtual bool releaseContextImplementation();
83 
85  virtual void swapBuffersImplementation();
86 
88  virtual bool checkEvents();
89 
91  virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
92 
94  virtual bool setWindowDecorationImplementation(bool flag);
95 
96  // Override from GUIActionAdapter
97  virtual void requestWarpPointer( float x, float y);
98 
100  virtual void grabFocus();
101 
103  virtual void grabFocusIfPointerInWindow();
104 
105  void requestClose() { _closeRequested = true; }
106 
107  virtual void resizedImplementation(int x, int y, int width, int height);
108 
109  virtual void setWindowName (const std::string & name);
110  virtual void useCursor(bool cursorOn);
111  virtual void setCursor(MouseCursor mouseCursor);
112 
114  virtual void setSyncToVBlank(bool on);
115 
116  WindowRef getNativeWindowRef() { return _window; }
117 
118  bool handleMouseEvent(EventRef theEvent);
119  bool handleKeyboardEvent(EventRef theEvent);
120  bool handleModifierKeys(EventRef theEvent);
121 
123  class WindowData : public osg::Referenced
124  {
125  public:
126  WindowData(WindowRef window, AGLDrawable* drawable=NULL ): //ADEGLI
127  _window(window), _AGLDrawable(drawable) ,_installEventHandler(false) {} //ADEGLI
128 
129  WindowRef getNativeWindowRef() { return _window; }
130  void setInstallEventHandler(bool flag) { _installEventHandler = flag; }
131  bool installEventHandler() { return _installEventHandler; }
132  AGLDrawable* getAGLDrawable() { return _AGLDrawable; } //ADEGLI
133 
134  private:
135  WindowRef _window;
136  AGLDrawable* _AGLDrawable; //ADEGLI
137  bool _installEventHandler;
138 
139  };
140 
142  void installEventHandler();
143 
144  // get the pixelformat
145  AGLPixelFormat getAGLPixelFormat() { return _pixelFormat; }
146 
147  void adaptResize(int x, int y, int w, int h);
148 
149  protected:
150 
151  void init();
152 
153  void transformMouseXY(float& x, float& y);
154 
155 
156  bool _valid;
157  bool _initialized;
158  bool _realized;
159  bool _useWindowDecoration;
160 
161  bool _ownsWindow;
162  WindowRef _window;
163  AGLPixelFormat _pixelFormat;
164 
165  int _windowTitleHeight;
166  private:
168  WindowAttributes computeWindowAttributes(bool useWindowDecoration, bool supportsResize);
169  void handleModifierKey(UInt32 modifierKey, UInt32 modifierMask, osgGA::GUIEventAdapter::KeySymbol keySymbol);
170 
171 
172  bool _closeRequested;
173  UInt32 _lastModifierKeys;
174  MouseCursor _currentCursor;
175  bool _currentVSync;
176 };
177 
178 }
179 
180 #endif
181 #endif
#define NULL
Definition: Export.h:59
GLint GLenum GLsizei width
Definition: GLU.h:71
static unsigned int createNewContextID()
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71