0032137: Coding Rules - merge redundant .lxx files into header files within Package gp
[occt.git] / samples / glfw / GlfwOcctWindow.h
CommitLineData
9c0787df 1// Copyright (c) 2019 OPEN CASCADE SAS
2//
3// This file is part of the examples of the Open CASCADE Technology software library.
4//
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:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
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
21
22#ifndef _GlfwOcctWindow_Header
23#define _GlfwOcctWindow_Header
24
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>
30
31struct GLFWwindow;
32
33//! GLFWwindow wrapper implementing Aspect_Window interface.
34class GlfwOcctWindow : public Aspect_Window
35{
36 DEFINE_STANDARD_RTTI_INLINE(GlfwOcctWindow, Aspect_Window)
37public:
38 //! Main constructor.
39 GlfwOcctWindow (int theWidth, int theHeight, const TCollection_AsciiString& theTitle);
40
41 //! Close the window.
42 virtual ~GlfwOcctWindow() { Close(); }
43
44 //! Close the window.
45 void Close();
46
47 //! Return X Display connection.
48 const Handle(Aspect_DisplayConnection)& GetDisplay() const { return myDisplay; }
49
50 //! Return GLFW window.
51 GLFWwindow* getGlfwWindow() { return myGlfwWindow; }
52
53 //! Return native OpenGL context.
54 Aspect_RenderingContext NativeGlContext() const;
55
56 //! Return cursor position.
57 Graphic3d_Vec2i CursorPosition() const;
58
59public:
60
61 //! Returns native Window handle
62 virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE;
63
64 //! Returns parent of native Window handle.
65 virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return 0; }
66
67 //! Applies the resizing to the window <me>
1a5007a9 68 virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
9c0787df 69
70 //! Returns True if the window <me> is opened and False if the window is closed.
71 virtual Standard_Boolean IsMapped() const Standard_OVERRIDE;
72
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; }
75
76 //! Opens the window <me>.
77 virtual void Map() const Standard_OVERRIDE;
78
79 //! Closes the window <me>.
80 virtual void Unmap() const Standard_OVERRIDE;
81
82 virtual void Position (Standard_Integer& theX1, Standard_Integer& theY1,
83 Standard_Integer& theX2, Standard_Integer& theY2) const Standard_OVERRIDE
84 {
85 theX1 = myXLeft;
86 theX2 = myXRight;
87 theY1 = myYTop;
88 theY2 = myYBottom;
89 }
90
91 //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions.
92 virtual Standard_Real Ratio() const Standard_OVERRIDE
93 {
94 return Standard_Real (myXRight - myXLeft) / Standard_Real (myYBottom - myYTop);
95 }
96
97 //! Return window size.
98 virtual void Size (Standard_Integer& theWidth, Standard_Integer& theHeight) const Standard_OVERRIDE
99 {
100 theWidth = myXRight - myXLeft;
101 theHeight = myYBottom - myYTop;
102 }
103
104 virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
105
106protected:
107 Handle(Aspect_DisplayConnection) myDisplay;
108 GLFWwindow* myGlfwWindow;
109 Standard_Integer myXLeft;
110 Standard_Integer myYTop;
111 Standard_Integer myXRight;
112 Standard_Integer myYBottom;
113};
114
115#endif // _GlfwOcctWindow_Header