root/OpenSceneGraph/trunk/include/osgViewer/api/Carbon/GraphicsWindowCarbon @ 13429

Revision 13429, 6.4 kB (checked in by robert, 3 days ago)

Fixed comment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
27namespace osgViewer
28{
29
30class 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
69        /** Realise the GraphicsContext.*/
70        virtual bool realizeImplementation();
71
72        /** Return true if the graphics context has been realised and is ready to use.*/
73        virtual bool isRealizedImplementation() const { return _realized; }
74
75        /** Close the graphics context.*/
76        virtual void closeImplementation();
77
78        /** Make this graphics context current.*/
79        virtual bool makeCurrentImplementation();
80       
81        /** Release the graphics context.*/
82        virtual bool releaseContextImplementation();
83
84        /** Swap the front and back buffers.*/
85        virtual void swapBuffersImplementation();
86       
87        /** Check to see if any events have been generated.*/
88        virtual bool checkEvents();
89
90        /** Set the window's position and size.*/
91        virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
92
93        /** Set Window decoration.*/
94        virtual bool setWindowDecorationImplementation(bool flag);
95
96        // Override from GUIActionAdapter
97        virtual void requestWarpPointer( float x, float y);
98
99        /** Get focus.*/
100        virtual void grabFocus();
101       
102        /** Get focus on if the pointer is in this window.*/
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
113        /** Set sync-to-vblank. */
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
122        /** WindowData is used to pass in the Carbon window handle attached the GraphicsContext::Traits structure. */
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       
141        /// install the standard os-eventhandler
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:       
167        /// computes the window attributes
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
Note: See TracBrowser for help on using the browser.