GraphicsWindowWin32 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
  14. * a guide to use of X11/GLX and copiying directly in the case of setBorder().
  15. * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
  16. */
  17. #ifndef OSGVIEWER_GRAPHICSWINDOWWIN32
  18. #define OSGVIEWER_GRAPHICSWINDOWWIN32 1
  19. #include <osgViewer/GraphicsWindow>
  20. #include <osgViewer/api/Win32/GraphicsHandleWin32>
  21. namespace osgViewer
  22. {
  23. class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleWin32
  24. {
  25. public:
  26. GraphicsWindowWin32(osg::GraphicsContext::Traits* traits);
  27. ~GraphicsWindowWin32();
  28. virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowWin32*>(object)!=0; }
  29. virtual const char* libraryName() const { return "osgViewer"; }
  30. virtual const char* className() const { return "GraphicsWindowWin32"; }
  31. virtual bool valid() const { return _valid; }
  32. /** Realize the GraphicsContext.*/
  33. virtual bool realizeImplementation();
  34. /** Return true if the graphics context has been realized and is ready to use.*/
  35. virtual bool isRealizedImplementation() const { return _realized; }
  36. /** Close the graphics context.*/
  37. virtual void closeImplementation();
  38. /** Make this graphics context current.*/
  39. virtual bool makeCurrentImplementation();
  40. /** Release the graphics context.*/
  41. virtual bool releaseContextImplementation();
  42. /** Swap the front and back buffers.*/
  43. virtual void swapBuffersImplementation();
  44. /** Check to see if any events have been generated.*/
  45. virtual bool checkEvents();
  46. /** Set the window's position and size.*/
  47. virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
  48. /** Set Window decoration.*/
  49. virtual bool setWindowDecorationImplementation(bool flag);
  50. /** Get focus.*/
  51. virtual void grabFocus();
  52. /** Get focus on if the pointer is in this window.*/
  53. virtual void grabFocusIfPointerInWindow();
  54. /** Override from GUIActionAdapter.*/
  55. virtual void requestWarpPointer(float x,float y);
  56. /** Raise specified window */
  57. virtual void raiseWindow();
  58. /** Set the name of the window */
  59. virtual void setWindowName(const std::string& /*name*/);
  60. /** Switch on/off the cursor.*/
  61. virtual void useCursor(bool /*cursorOn*/);
  62. /** Set mouse cursor to a specific shape.*/
  63. virtual void setCursor(MouseCursor cursor);
  64. /** Set sync-to-vblank. */
  65. virtual void setSyncToVBlank(bool on);
  66. /** Set swap group. */
  67. virtual void setSwapGroup(bool on, GLuint group, GLuint barrier);
  68. /** Handle a native (Win32) windowing event as received from the system */
  69. virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  70. /** WindowData is used to pass in the Win32 window handle attached the GraphicsContext::Traits structure.*/
  71. struct WindowData : public osg::Referenced
  72. {
  73. WindowData(HWND window, bool installEventHandler = true):
  74. _hwnd(window), _installEventHandler(installEventHandler) {}
  75. HWND _hwnd;
  76. bool _installEventHandler;
  77. };
  78. protected:
  79. virtual void init();
  80. virtual void registerWindow();
  81. virtual void unregisterWindow();
  82. virtual bool registerWindowProcedure();
  83. virtual bool unregisterWindowProcedure();
  84. virtual HGLRC createContextImplementation();
  85. virtual bool createWindow();
  86. virtual bool setWindow( HWND handle );
  87. virtual void destroyWindow( bool deleteNativeWindow = true );
  88. virtual bool determineWindowPositionAndStyle( unsigned int screenNum,
  89. int clientAreaX,
  90. int clientAreaY,
  91. unsigned int clientAreaWidth,
  92. unsigned int clientAreaHeight,
  93. bool decorated,
  94. int& x,
  95. int& y,
  96. unsigned int& w,
  97. unsigned int& h,
  98. unsigned int& style,
  99. unsigned int& extendedStyle );
  100. virtual bool setPixelFormat();
  101. virtual void adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask, int& unmodifiedKeySymbol );
  102. virtual void transformMouseXY(float& x, float& y);
  103. virtual void setCursorImpl(MouseCursor cursor);
  104. virtual HCURSOR getOrCreateCursor(MouseCursor mouseShape);
  105. HCURSOR _currentCursor;
  106. WNDPROC _windowProcedure;
  107. double _timeOfLastCheckEvents;
  108. int _screenOriginX;
  109. int _screenOriginY;
  110. unsigned int _screenWidth;
  111. unsigned int _screenHeight;
  112. int _windowOriginXToRealize;
  113. int _windowOriginYToRealize;
  114. unsigned int _windowWidthToRealize;
  115. unsigned int _windowHeightToRealize;
  116. bool _initialized;
  117. bool _valid;
  118. bool _realized;
  119. bool _ownsWindow;
  120. bool _closeWindow;
  121. bool _destroyWindow;
  122. bool _destroying;
  123. MouseCursor _mouseCursor;
  124. /// Persist which mouse cursor was used before switching to the resize cursors.
  125. MouseCursor _appMouseCursor;
  126. std::map<MouseCursor,HCURSOR> _mouseCursorMap;
  127. std::map<std::pair<int, int>, bool> _keyMap;
  128. std::set<int> _capturedMouseButtons;
  129. bool _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues;
  130. };
  131. }
  132. #endif