root/OpenSceneGraph/branches/osg-cocoa-dev/include/osgViewer/api/Cocoa/GraphicsWindowCocoa @ 9831

Revision 9831, 5.5 kB (checked in by shuber, 5 years ago)

* initial development of osgViewerCocoa
* initial import of imageio-plugin
* disabled quicktime-plugin for 64bit
* disabled GraphicsWindowCarbon? for 664bit

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