root/OpenSceneGraph/trunk/include/osgViewer/api/Win32/GraphicsWindowWin32 @ 13195

Revision 13195, 6.9 kB (checked in by robert, 16 hours ago)

Implemented callbacks for validate(), textChanged() and returnPressed()

  • 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_GRAPHICSWINDOWWIN32
20#define OSGVIEWER_GRAPHICSWINDOWWIN32 1
21
22#include <osgViewer/GraphicsWindow>
23#include <osgViewer/api/Win32/GraphicsHandleWin32>
24
25namespace osgViewer
26{
27
28class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleWin32
29{
30    public:
31
32        GraphicsWindowWin32(osg::GraphicsContext::Traits* traits);
33       
34        ~GraphicsWindowWin32();
35   
36        virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowWin32*>(object)!=0; }
37        virtual const char* libraryName() const { return "osgViewer"; }
38        virtual const char* className() const { return "GraphicsWindowWin32"; }
39
40        virtual bool valid() const { return _valid; }
41       
42        /** Realize the GraphicsContext.*/
43        virtual bool realizeImplementation();
44
45        /** Return true if the graphics context has been realized and is ready to use.*/
46        virtual bool isRealizedImplementation() const { return _realized; }
47
48        /** Close the graphics context.*/
49        virtual void closeImplementation();
50
51        /** Make this graphics context current.*/
52        virtual bool makeCurrentImplementation();
53
54        /** Release the graphics context.*/
55        virtual bool releaseContextImplementation();
56
57        /** Swap the front and back buffers.*/
58        virtual void swapBuffersImplementation();
59       
60        /** Check to see if any events have been generated.*/
61        virtual void checkEvents();
62
63        /** Set the window's position and size.*/
64        virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
65
66        /** Set Window decoration.*/
67        virtual bool setWindowDecorationImplementation(bool flag);
68
69        /** Get focus.*/
70        virtual void grabFocus();
71       
72        /** Get focus on if the pointer is in this window.*/
73        virtual void grabFocusIfPointerInWindow();
74       
75        /** Override from GUIActionAdapter.*/
76        virtual void requestWarpPointer(float x,float y);
77
78        /** Raise specified window */
79        virtual void raiseWindow();
80
81        /** Set the name of the window */
82        virtual void setWindowName(const std::string& /*name*/);
83       
84        /** Switch on/off the cursor.*/
85        virtual void useCursor(bool /*cursorOn*/);
86       
87        /** Set mouse cursor to a specific shape.*/
88        virtual void setCursor(MouseCursor cursor);
89
90        /** Set sync-to-vblank. */
91        virtual void setSyncToVBlank(bool on);
92
93        /** Set swap group. */
94        virtual void setSwapGroup(bool on, GLuint group, GLuint barrier);
95
96        /** Handle a native (Win32) windowing event as received from the system */
97        virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
98       
99        /** WindowData is used to pass in the Win32 window handle attached the GraphicsContext::Traits structure.*/
100        struct WindowData : public osg::Referenced
101        {
102            WindowData(HWND window, bool installEventHandler = true):
103                _hwnd(window), _installEventHandler(installEventHandler) {}
104               
105            HWND    _hwnd;
106            bool   _installEventHandler;
107        };
108       
109    protected:
110   
111        void init();
112
113        void registerWindow();
114        void unregisterWindow();
115       
116        bool registerWindowProcedure();
117        bool unregisterWindowProcedure();
118       
119        HGLRC createContextImplementation();
120        bool createWindow();
121        bool setWindow( HWND handle );
122       
123        void destroyWindow( bool deleteNativeWindow = true );
124        void recreateWindow();
125       
126        bool determineWindowPositionAndStyle( unsigned int  screenNum,
127                                              int           clientAreaX,
128                                              int           clientAreaY,
129                                              unsigned int  clientAreaWidth,
130                                              unsigned int  clientAreaHeight,
131                                              bool          decorated,
132                                              int&          x,
133                                              int&          y,
134                                              unsigned int& w,
135                                              unsigned int& h,
136                                              unsigned int& style,
137                                              unsigned int& extendedStyle );
138       
139        bool setPixelFormat();
140       
141        void adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask, int& unmodifiedKeySymbol );
142               
143        void transformMouseXY(float& x, float& y);
144       
145        void setCursorImpl(MouseCursor cursor);
146
147        HCURSOR getOrCreateCursor(MouseCursor mouseShape);
148       
149        HCURSOR         _currentCursor;
150       
151        WNDPROC         _windowProcedure;
152       
153        double          _timeOfLastCheckEvents;
154       
155       
156       
157       
158        int             _screenOriginX;
159        int             _screenOriginY;
160        unsigned int    _screenWidth;
161        unsigned int    _screenHeight;
162       
163        int             _windowOriginXToRealize;
164        int             _windowOriginYToRealize;
165        unsigned int    _windowWidthToRealize;
166        unsigned int    _windowHeightToRealize;
167               
168        bool            _initialized;
169        bool            _valid;
170        bool            _realized;
171
172        bool            _ownsWindow;       
173        bool            _closeWindow;
174        bool            _destroyWindow;
175        bool            _destroying;
176
177        MouseCursor     _mouseCursor;
178
179        /// Persist which mouse cursor was used before switching to the resize cursors.
180        MouseCursor     _appMouseCursor;
181       
182        std::map<MouseCursor,HCURSOR> _mouseCursorMap;
183
184        std::map<std::pair<int, int>, bool> _keyMap;
185
186        std::set<int> _capturedMouseButtons;
187
188        bool   _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues;
189};
190
191}
192
193#endif
Note: See TracBrowser for help on using the browser.