root/OpenSceneGraph/trunk/include/osgViewer/api/X11/GraphicsWindowX11 @ 13429

Revision 13429, 6.4 kB (checked in by robert, 4 hours ago)

From Mattias Helsing, "Seems I was only half right given what you asked for. CMP0017 only
says that modules that are found and ran from cmake modules dir should
prefer cmake-provided modules. find_package() and include() still look
in CMAKE_MODULE_PATH first.

After some investigating I've come up with a proposal examplified in
the attached FindGDAL.cmake script. It simply calls the cmake provided
FindGDAL.cmake if it exists and returns if it succeeds in finding GDAL
using that, otherwise continue with our local cmake code.
Pro: Wont clutter our root CMakeLists.txt
Con: If we begin to write more advanced Findxxx modules (using
COMPONENTS, REQUIRED etc.) we may have to revise this scheme.
"

  • 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_GRAPHICSWINDOWX11
20#define OSGVIEWER_GRAPHICSWINDOWX11 1
21
22#include <osgViewer/GraphicsWindow>
23#include <osgViewer/api/X11/GraphicsHandleX11>
24
25#include <string.h>
26
27namespace osgViewer
28{
29
30class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleX11
31{
32    public:
33
34        GraphicsWindowX11(osg::GraphicsContext::Traits* traits):
35            _valid(false),
36            _eventDisplay(0),
37            _parent(0),
38            _window(0),
39            _visualInfo(0),
40            #ifdef OSG_USE_EGL
41            _eglDisplay(0),
42            _eglSurface(0),
43            #endif
44            _currentCursor(0),
45            _initialized(false),
46            _realized(false),
47            _timeOfLastCheckEvents(-1.0),
48            _lastEventType(0),
49            _modifierState(0),
50            _numLockMask(0)
51        {
52            _traits = traits;
53            memset(_keyMap, 0, 32);
54
55            init();
56           
57            if (valid())
58            {
59                setState( new osg::State );
60                getState()->setGraphicsContext(this);
61
62                if (_traits.valid() && _traits->sharedContext.valid())
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   
75        virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowX11*>(object)!=0; }
76        virtual const char* libraryName() const { return "osgViewer"; }
77        virtual const char* className() const { return "GraphicsWindowX11"; }
78
79        virtual bool valid() const { return _valid; }
80
81        /** Realise the GraphicsContext.*/
82        virtual bool realizeImplementation();
83
84        /** Return true if the graphics context has been realised and is ready to use.*/
85        virtual bool isRealizedImplementation() const { return _realized; }
86
87        /** Close the graphics context.*/
88        virtual void closeImplementation();
89
90        /** Make this graphics context current.*/
91        virtual bool makeCurrentImplementation();
92
93        /** Release the graphics context.*/
94        virtual bool releaseContextImplementation();
95
96        /** Swap the front and back buffers.*/
97        virtual void swapBuffersImplementation();
98       
99        /** Check to see if any events have been generated.*/
100        virtual bool checkEvents();
101
102        /** Set Window decoration.*/
103        virtual bool setWindowDecorationImplementation(bool flag);
104
105        /** Get focus.*/
106        virtual void grabFocus();
107       
108        /** Get focus on if the pointer is in this window.*/
109        virtual void grabFocusIfPointerInWindow();
110
111        /** Raise specified window */
112        virtual void raiseWindow();
113
114        // Override from GUIActionAdapter
115        virtual void requestWarpPointer(float x,float y);
116
117        /** Set the window's position and size.*/
118        virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
119
120        /** Set the name of the window */
121        virtual void setWindowName(const std::string& name);
122
123        /** Set mouse cursor to a specific shape.*/
124        virtual void setCursor(MouseCursor cursor);
125
126        /** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */
127        struct WindowData : public osg::Referenced
128        {
129            WindowData(Window window):
130                _window(window) {}
131               
132            Window          _window;
133        };
134
135    public:
136   
137        // X11 specific access functions
138
139        Display* getEventDisplay() const { return _eventDisplay; }
140        Display* getDisplayToUse() const ;
141
142       
143        Window& getParent() { return _parent; }
144        Window& getWindow() { return _window; }
145
146        Cursor getCurrentCursor() { return _currentCursor; }
147
148    protected:
149   
150        ~GraphicsWindowX11();
151   
152        Cursor getOrCreateCursor(MouseCursor mouseShape);
153       
154        bool createVisualInfo();
155
156        bool createWindow();
157
158        bool setWindow(Window window);
159       
160        void init();
161
162        bool checkAndSendEventFullScreenIfNeeded(Display* display, int x, int y, int width, int height, bool windowDecoration);
163
164
165        void transformMouseXY(float& x, float& y);
166        void adaptKey(XKeyEvent& keyevent, int& keySymbol, int& unmodifiedKeySymbol);
167        void forceKey(int key, double time, bool state);
168        void rescanModifierMapping();
169        void getModifierMap(char* keymap) const;
170        int getModifierMask() const;
171        void syncLocks();
172        void flushKeyEvents();
173       
174        bool            _valid;
175        Display*        _eventDisplay;
176        Window          _parent;
177        Window          _window;
178        XVisualInfo*    _visualInfo;
179
180        #ifdef OSG_USE_EGL
181        EGLDisplay      _eglDisplay;
182        EGLSurface      _eglSurface;
183        #endif
184
185        Cursor          _currentCursor;
186
187        Atom            _deleteWindow;
188       
189        bool            _initialized;
190        bool            _realized;
191        bool            _ownsWindow;
192
193        double          _timeOfLastCheckEvents;
194        int             _lastEventType;
195        int             _modifierState;
196        int             _numLockMask;
197
198        char            _keyMap[32];
199        std::map<MouseCursor,Cursor> _mouseCursorMap;
200};
201
202}
203
204#endif
Note: See TracBrowser for help on using the browser.