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

Revision 9120, 6.3 kB (checked in by robert, 5 years ago)

From Martins Innus, "Here is a fix to add requestWarpPointer for OS X. It seems to work for me, I just took what osgProducer had. These are updated files to 2.7.3"

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[5948]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#ifdef __APPLE__
23
24#include <osgViewer/GraphicsWindow>
25#include <Carbon/Carbon.h>
26#include <AGL/agl.h>
27namespace osgViewer
28{
29
30class GraphicsWindowCarbon : public osgViewer::GraphicsWindow
31{
32    public:
33
34        GraphicsWindowCarbon(osg::GraphicsContext::Traits* traits):
35            _valid(false),
36            _initialized(false),
[6420]37            _realized(false),
[8017]38            _ownsWindow(true),
39            _currentCursor(RightArrowCursor)
[5948]40        {
41            _traits = traits;
42
[6404]43            init();
[5948]44           
45            if (valid())
46            {
47                setState( new osg::State );
[6192]48                getState()->setGraphicsContext(this);
[6204]49
50                if (_traits.valid() && _traits->sharedContext)
51                {
52                    getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
53                    incrementContextIDUsageCount( getState()->getContextID() );   
54                }
55                else
56                {
57                    getState()->setContextID( osg::GraphicsContext::createNewContextID() );
58                }
[5948]59            }
60        }
61   
[6943]62        virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowCarbon*>(object)!=0; }
63        virtual const char* libraryName() const { return "osgViewer"; }
64        virtual const char* className() const { return "GraphicsWindowCarbon"; }
65
[5948]66        virtual bool valid() const { return _valid; }
67
68        /** Realise the GraphicsContext.*/
69        virtual bool realizeImplementation();
70
71        /** Return true if the graphics context has been realised and is ready to use.*/
72        virtual bool isRealizedImplementation() const { return _realized; }
73
74        /** Close the graphics context.*/
75        virtual void closeImplementation();
76
77        /** Make this graphics context current.*/
78        virtual bool makeCurrentImplementation();
79       
80        /** Release the graphics context.*/
81        virtual bool releaseContextImplementation();
82
83        /** Swap the front and back buffers.*/
84        virtual void swapBuffersImplementation();
85       
86        /** Check to see if any events have been generated.*/
87        virtual void checkEvents();
88
[6495]89        /** Set the window's position and size.*/
[6931]90        virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
[6495]91
[5948]92        /** Set Window decoration.*/
[6931]93        virtual bool setWindowDecorationImplementation(bool flag);
[5948]94
[9120]95        // Override from GUIActionAdapter
96        virtual void requestWarpPointer( float x, float y);
97
[5948]98        /** Get focus.*/
99        virtual void grabFocus();
100       
101        /** Get focus on if the pointer is in this window.*/
102        virtual void grabFocusIfPointerInWindow();
103       
104        void requestClose() { _closeRequested = true; }
105       
106        virtual void resizedImplementation(int x, int y, int width, int height);
[5978]107       
[7709]108        virtual void setWindowName (const std::string & name);
109        virtual void useCursor(bool cursorOn);
[8017]110        virtual void setCursor(MouseCursor mouseCursor);
[7709]111       
[5978]112        WindowRef getNativeWindowRef() { return _window; }
113       
114        bool handleMouseEvent(EventRef theEvent);
115        bool handleKeyboardEvent(EventRef theEvent);
[7884]116        bool handleModifierKeys(EventRef theEvent);
[5948]117
[6420]118        /** WindowData is used to pass in the Carbon window handle attached the GraphicsContext::Traits structure. */
[6706]119        class WindowData : public osg::Referenced
[6366]120        {
[6706]121            public:
[7866]122                WindowData(WindowRef window, AGLDrawable* drawable=NULL ): //ADEGLI
123                    _window(window), _AGLDrawable(drawable) ,_installEventHandler(false) {} //ADEGLI
[6366]124               
[6706]125                WindowRef getNativeWindowRef() { return _window; }
126                void setInstallEventHandler(bool flag) { _installEventHandler = flag; }
127                bool installEventHandler() { return _installEventHandler; }
[7866]128                AGLDrawable* getAGLDrawable() { return _AGLDrawable; } //ADEGLI
129               
[6706]130            private:
[7866]131                WindowRef    _window;
132                AGLDrawable* _AGLDrawable; //ADEGLI
133                bool         _installEventHandler;
[6706]134           
[6366]135        };
[6706]136       
137        /// install the standard os-eventhandler
138        void installEventHandler();
[6907]139       
140        /// get the AGL context
141        AGLContext getAGLContext() { return _context; }
142       
143        // get the pixelformat
144        AGLPixelFormat getAGLPixelFormat() { return _pixelFormat; }
[6366]145
[5948]146    protected:
147   
[6404]148        void init();
[5948]149       
150        void transformMouseXY(float& x, float& y);
151       
[6706]152       
[6907]153       
[5948]154
[6706]155
[5948]156        bool            _valid;
157        bool            _initialized;
158        bool            _realized;
159        bool            _useWindowDecoration;
160
[6366]161        bool            _ownsWindow;
[5948]162        WindowRef       _window;
163        AGLContext      _context;
164        AGLPixelFormat  _pixelFormat;
[6678]165       
[6706]166        int             _windowTitleHeight;   
167    private:       
168        /// computes the window attributes
169        WindowAttributes computeWindowAttributes(bool useWindowDecoration, bool supportsResize);
[7884]170        void handleModifierKey(UInt32 modifierKey, UInt32 modifierMask, osgGA::GUIEventAdapter::KeySymbol keySymbol);
171
[6706]172       
[7884]173        bool            _closeRequested;
[8017]174        UInt32          _lastModifierKeys;
175        MouseCursor     _currentCursor;
[5948]176};
177
178}
179
180#endif
181#endif
Note: See TracBrowser for help on using the browser.