| 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 | |
|---|
| 25 | namespace osgViewer |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | class 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 | /** Handle a native (Win32) windowing event as received from the system */ |
|---|
| 94 | virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); |
|---|
| 95 | |
|---|
| 96 | /** WindowData is used to pass in the Win32 window handle attached the GraphicsContext::Traits structure.*/ |
|---|
| 97 | struct WindowData : public osg::Referenced |
|---|
| 98 | { |
|---|
| 99 | WindowData(HWND window, bool installEventHandler = true): |
|---|
| 100 | _hwnd(window), _installEventHandler(installEventHandler) {} |
|---|
| 101 | |
|---|
| 102 | HWND _hwnd; |
|---|
| 103 | bool _installEventHandler; |
|---|
| 104 | }; |
|---|
| 105 | |
|---|
| 106 | protected: |
|---|
| 107 | |
|---|
| 108 | void init(); |
|---|
| 109 | |
|---|
| 110 | void registerWindow(); |
|---|
| 111 | void unregisterWindow(); |
|---|
| 112 | |
|---|
| 113 | bool registerWindowProcedure(); |
|---|
| 114 | bool unregisterWindowProcedure(); |
|---|
| 115 | |
|---|
| 116 | HGLRC createContextImplementation(); |
|---|
| 117 | bool createWindow(); |
|---|
| 118 | bool setWindow( HWND handle ); |
|---|
| 119 | |
|---|
| 120 | void destroyWindow( bool deleteNativeWindow = true ); |
|---|
| 121 | void recreateWindow(); |
|---|
| 122 | |
|---|
| 123 | bool determineWindowPositionAndStyle( unsigned int screenNum, |
|---|
| 124 | int clientAreaX, |
|---|
| 125 | int clientAreaY, |
|---|
| 126 | unsigned int clientAreaWidth, |
|---|
| 127 | unsigned int clientAreaHeight, |
|---|
| 128 | bool decorated, |
|---|
| 129 | int& x, |
|---|
| 130 | int& y, |
|---|
| 131 | unsigned int& w, |
|---|
| 132 | unsigned int& h, |
|---|
| 133 | unsigned int& style, |
|---|
| 134 | unsigned int& extendedStyle ); |
|---|
| 135 | |
|---|
| 136 | bool setPixelFormat(); |
|---|
| 137 | |
|---|
| 138 | void adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask ); |
|---|
| 139 | |
|---|
| 140 | void transformMouseXY(float& x, float& y); |
|---|
| 141 | |
|---|
| 142 | void setCursorImpl(MouseCursor cursor); |
|---|
| 143 | |
|---|
| 144 | HCURSOR getOrCreateCursor(MouseCursor mouseShape); |
|---|
| 145 | |
|---|
| 146 | HCURSOR _currentCursor; |
|---|
| 147 | |
|---|
| 148 | WNDPROC _windowProcedure; |
|---|
| 149 | |
|---|
| 150 | double _timeOfLastCheckEvents; |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | int _screenOriginX; |
|---|
| 156 | int _screenOriginY; |
|---|
| 157 | unsigned int _screenWidth; |
|---|
| 158 | unsigned int _screenHeight; |
|---|
| 159 | |
|---|
| 160 | int _windowOriginXToRealize; |
|---|
| 161 | int _windowOriginYToRealize; |
|---|
| 162 | unsigned int _windowWidthToRealize; |
|---|
| 163 | unsigned int _windowHeightToRealize; |
|---|
| 164 | |
|---|
| 165 | bool _initialized; |
|---|
| 166 | bool _valid; |
|---|
| 167 | bool _realized; |
|---|
| 168 | |
|---|
| 169 | bool _ownsWindow; |
|---|
| 170 | bool _closeWindow; |
|---|
| 171 | bool _destroyWindow; |
|---|
| 172 | bool _destroying; |
|---|
| 173 | |
|---|
| 174 | MouseCursor _mouseCursor; |
|---|
| 175 | |
|---|
| 176 | /// Persist which mouse cursor was used before switching to the resize cursors. |
|---|
| 177 | MouseCursor _appMouseCursor; |
|---|
| 178 | |
|---|
| 179 | std::map<MouseCursor,HCURSOR> _mouseCursorMap; |
|---|
| 180 | |
|---|
| 181 | std::map<int, bool> _keyMap; |
|---|
| 182 | |
|---|
| 183 | bool _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues; |
|---|
| 184 | }; |
|---|
| 185 | |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | #endif |
|---|