openscenegraph
GraphicsWindowWin32
Go to the documentation of this file.
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 bool 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 virtual void init();
112
113 virtual void registerWindow();
114 virtual void unregisterWindow();
115
116 virtual bool registerWindowProcedure();
117 virtual bool unregisterWindowProcedure();
118
119 virtual HGLRC createContextImplementation();
120 virtual bool createWindow();
121 virtual bool setWindow( HWND handle );
122
123 virtual void destroyWindow( bool deleteNativeWindow = true );
124
125 virtual bool determineWindowPositionAndStyle( unsigned int screenNum,
126 int clientAreaX,
127 int clientAreaY,
128 unsigned int clientAreaWidth,
129 unsigned int clientAreaHeight,
130 bool decorated,
131 int& x,
132 int& y,
133 unsigned int& w,
134 unsigned int& h,
135 unsigned int& style,
136 unsigned int& extendedStyle );
137
138 virtual bool setPixelFormat();
139
140 virtual void adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask, int& unmodifiedKeySymbol );
141
142 virtual void transformMouseXY(float& x, float& y);
143
144 virtual void setCursorImpl(MouseCursor cursor);
145
146 virtual HCURSOR getOrCreateCursor(MouseCursor mouseShape);
147
148 HCURSOR _currentCursor;
149
150 WNDPROC _windowProcedure;
151
152 double _timeOfLastCheckEvents;
153
154
155
156
157 int _screenOriginX;
158 int _screenOriginY;
159 unsigned int _screenWidth;
160 unsigned int _screenHeight;
161
162 int _windowOriginXToRealize;
163 int _windowOriginYToRealize;
164 unsigned int _windowWidthToRealize;
165 unsigned int _windowHeightToRealize;
166
167 bool _initialized;
168 bool _valid;
169 bool _realized;
170
171 bool _ownsWindow;
172 bool _closeWindow;
173 bool _destroyWindow;
174 bool _destroying;
175
176 MouseCursor _mouseCursor;
177
178 /// Persist which mouse cursor was used before switching to the resize cursors.
179 MouseCursor _appMouseCursor;
180
181 std::map<MouseCursor,HCURSOR> _mouseCursorMap;
182
183 std::map<std::pair<int, int>, bool> _keyMap;
184
185 std::set<int> _capturedMouseButtons;
186
187 bool _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues;
188};
189
190}
191
192#endif