root/OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/GraphicsWindowCocoa @ 10887

Revision 10887, 6.8 kB (checked in by robert, 4 years ago)

From Stephan Huber, "attached you'll find the missing GraphicsHandleCocoa?-implementation."

  • Property svn:executable set to *
RevLine 
[9879]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_GRAPHICSWINDOWCOCOA
20#define OSGVIEWER_GRAPHICSWINDOWCOCOA 1
21
22#ifdef __APPLE__
23
24#ifdef __OBJC__
25@class GraphicsWindowCocoaWindow;
[10208]26@class GraphicsWindowCocoaGLView;
[9879]27@class NSOpenGLContext;
28@class NSWindow;
[10208]29@class NSView;
[9879]30#else
[10208]31class GraphicsWindowCocoaGLView;
[9879]32class GraphicsWindowCocoaWindow;
33class NSOpenGLContext;
34class NSWindow;
[10208]35class NSView;
[9879]36#endif
37
38#include <osgViewer/GraphicsWindow>
[10887]39#include <osgViewer/api/Cocoa/GraphicsHandleCocoa>
[9879]40
41// we may not include any cocoa-header here, because this will pollute the name-sapce and tend to compile-errors
42
43namespace osgViewer
44{
45
[10887]46class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleCocoa
[9879]47{
48    public:
[10208]49    class Implementation;
[9879]50
51        GraphicsWindowCocoa(osg::GraphicsContext::Traits* traits):
[10887]52            osgViewer::GraphicsWindow(),
53            osgViewer::GraphicsHandleCocoa(),
[9879]54            _valid(false),
55            _initialized(false),
56            _realized(false),
[10208]57            _closeRequested(false),
58            _checkForEvents(true),
[9879]59            _ownsWindow(true),
[10208]60            _currentCursor(RightArrowCursor),
[10887]61            _window(NULL)
[9879]62        {
63            _traits = traits;
64
65            init();
66           
67            if (valid())
68            {
69                setState( new osg::State );
70                getState()->setGraphicsContext(this);
71
72                if (_traits.valid() && _traits->sharedContext)
73                {
74                    getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
75                    incrementContextIDUsageCount( getState()->getContextID() );   
76                }
77                else
78                {
79                    getState()->setContextID( osg::GraphicsContext::createNewContextID() );
80                }
81            }
82        }
83   
84        virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowCocoa*>(object)!=0; }
85        virtual const char* libraryName() const { return "osgViewer"; }
86        virtual const char* className() const { return "GraphicsWindowCarbon"; }
87
88        virtual bool valid() const { return _valid; }
89
90        /** Realise the GraphicsContext.*/
91        virtual bool realizeImplementation();
92
93        /** Return true if the graphics context has been realised and is ready to use.*/
94        virtual bool isRealizedImplementation() const { return _realized; }
95
96        /** Close the graphics context.*/
97        virtual void closeImplementation();
98
99        /** Make this graphics context current.*/
100        virtual bool makeCurrentImplementation();
101       
102        /** Release the graphics context.*/
103        virtual bool releaseContextImplementation();
104
105        /** Swap the front and back buffers.*/
106        virtual void swapBuffersImplementation();
107       
108        /** Check to see if any events have been generated.*/
109        virtual void checkEvents();
110
111        /** Set Window decoration.*/
112        virtual bool setWindowDecorationImplementation(bool flag);
113
114        /** Get focus.*/
115        virtual void grabFocus();
116       
117        /** Get focus on if the pointer is in this window.*/
118        virtual void grabFocusIfPointerInWindow();
119       
120        bool requestClose() { bool b = _closeRequested; _closeRequested = true; return b; }
121       
122        virtual void resizedImplementation(int x, int y, int width, int height);
123       
124        virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
125       
126        virtual void setWindowName (const std::string & name);
127        virtual void useCursor(bool cursorOn);
128        virtual void setCursor(MouseCursor mouseCursor);
129               
130        /** WindowData is used to pass in the Cocoa window handle attached the GraphicsContext::Traits structure. */
131        class WindowData : public osg::Referenced
132        {
133            public:
[10208]134                enum Options { CreateOnlyView = 1, CheckForEvents = 2, PoseAsStandaloneApp = 4};
135                WindowData(unsigned int options)
136                :    _createOnlyView(options & CreateOnlyView),
137                    _checkForEvents(options & CheckForEvents),
138                    _poseAsStandaloneApp(options & PoseAsStandaloneApp),
139                    _view(NULL)
140                {
141                }
142                           
143                inline NSView* getCreatedNSView() { return _view; }
144                bool createOnlyView() const { return _createOnlyView; }
145                bool checkForEvents() const { return _checkForEvents; }
146                bool poseAsStandaloneApp() const { return _poseAsStandaloneApp; }
147           
148            protected:
149                inline void setCreatedNSView(NSView* view) { _view = view; }
150           
[9879]151            private:
[10208]152                bool         _createOnlyView, _checkForEvents, _poseAsStandaloneApp;
153                NSView*         _view;
[9879]154           
[10208]155            friend class GraphicsWindowCocoa;
156
[9879]157        };
158       
159        NSOpenGLContext* getContext() { return _context; }
160        GraphicsWindowCocoaWindow* getWindow() { return _window; }
161               
162        void setVSync(bool f);
163       
[10208]164        /** adapts a resize / move of the window, coords in global screen space */
165        void adaptResize(int x, int y, int w, int h);
166       
[9879]167    protected:
168   
169        void init();
170       
171        void transformMouseXY(float& x, float& y);
172        void setupNSWindow(NSWindow* win);
173       
174       
175        virtual ~GraphicsWindowCocoa();
176
177
178        bool            _valid;
179        bool            _initialized;
180        bool            _realized;
181        bool            _useWindowDecoration;
182
[10208]183   
[9879]184         
185    private:       
186       
187       
[10456]188        bool                            _closeRequested, _checkForEvents,_ownsWindow;
189        MouseCursor                     _currentCursor;
190        GraphicsWindowCocoaWindow*      _window;
191        GraphicsWindowCocoaGLView*      _view;
192        NSOpenGLContext*                _context;
193        bool                            _updateContext;
[9879]194};
195
196}
197
198#endif
199#endif
Note: See TracBrowser for help on using the browser.