1 // Copyright (c) 2019 OPEN CASCADE SAS
3 // This file is part of the examples of the Open CASCADE Technology software library.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
22 #ifndef _GlfwOcctWindow_Header
23 #define _GlfwOcctWindow_Header
25 #include <Aspect_DisplayConnection.hxx>
26 #include <Aspect_RenderingContext.hxx>
27 #include <Aspect_Window.hxx>
28 #include <Graphic3d_Vec.hxx>
29 #include <TCollection_AsciiString.hxx>
33 //! GLFWwindow wrapper implementing Aspect_Window interface.
34 class GlfwOcctWindow : public Aspect_Window
36 DEFINE_STANDARD_RTTI_INLINE(GlfwOcctWindow, Aspect_Window)
39 GlfwOcctWindow (int theWidth, int theHeight, const TCollection_AsciiString& theTitle);
42 virtual ~GlfwOcctWindow() { Close(); }
47 //! Return X Display connection.
48 const Handle(Aspect_DisplayConnection)& GetDisplay() const { return myDisplay; }
50 //! Return GLFW window.
51 GLFWwindow* getGlfwWindow() { return myGlfwWindow; }
53 //! Return native OpenGL context.
54 Aspect_RenderingContext NativeGlContext() const;
56 //! Return cursor position.
57 Graphic3d_Vec2i CursorPosition() const;
61 //! Returns native Window handle
62 virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE;
64 //! Returns parent of native Window handle.
65 virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return 0; }
67 //! Applies the resizing to the window <me>
68 virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE;
70 //! Returns True if the window <me> is opened and False if the window is closed.
71 virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
73 //! Apply the mapping change to the window <me> and returns TRUE if the window is mapped at screen.
74 virtual Standard_Boolean DoMapping() const Standard_OVERRIDE { return Standard_True; }
76 //! Opens the window <me>.
77 virtual void Map() const Standard_OVERRIDE;
79 //! Closes the window <me>.
80 virtual void Unmap() const Standard_OVERRIDE;
82 virtual void Position (Standard_Integer& theX1, Standard_Integer& theY1,
83 Standard_Integer& theX2, Standard_Integer& theY2) const Standard_OVERRIDE
91 //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions.
92 virtual Standard_Real Ratio() const Standard_OVERRIDE
94 return Standard_Real (myXRight - myXLeft) / Standard_Real (myYBottom - myYTop);
97 //! Return window size.
98 virtual void Size (Standard_Integer& theWidth, Standard_Integer& theHeight) const Standard_OVERRIDE
100 theWidth = myXRight - myXLeft;
101 theHeight = myYBottom - myYTop;
104 virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
107 Handle(Aspect_DisplayConnection) myDisplay;
108 GLFWwindow* myGlfwWindow;
109 Standard_Integer myXLeft;
110 Standard_Integer myYTop;
111 Standard_Integer myXRight;
112 Standard_Integer myYBottom;
115 #endif // _GlfwOcctWindow_Header