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 _GlfwOcctView_Header |
23 | #define _GlfwOcctView_Header |
24 | |
25 | #include "GlfwOcctWindow.h" |
26 | |
27 | #include <AIS_InteractiveContext.hxx> |
3818aaca |
28 | #include <AIS_ViewController.hxx> |
9c0787df |
29 | #include <V3d_View.hxx> |
30 | |
31 | //! Sample class creating 3D Viewer within GLFW window. |
3818aaca |
32 | class GlfwOcctView : protected AIS_ViewController |
9c0787df |
33 | { |
9c0787df |
34 | public: |
35 | //! Default constructor. |
36 | GlfwOcctView(); |
37 | |
38 | //! Destructor. |
39 | ~GlfwOcctView(); |
40 | |
41 | //! Main application entry point. |
42 | void run(); |
43 | |
44 | private: |
45 | |
46 | //! Create GLFW window. |
47 | void initWindow (int theWidth, int theHeight, const char* theTitle); |
48 | |
49 | //! Create 3D Viewer. |
50 | void initViewer(); |
51 | |
52 | //! Fill 3D Viewer with a DEMO items. |
53 | void initDemoScene(); |
54 | |
55 | //! Application event loop. |
56 | void mainloop(); |
57 | |
58 | //! Clean up before . |
59 | void cleanup(); |
60 | |
61 | //! @name GLWF callbacks |
62 | private: |
63 | //! Window resize event. |
64 | void onResize (int theWidth, int theHeight); |
65 | |
66 | //! Mouse scroll event. |
67 | void onMouseScroll (double theOffsetX, double theOffsetY); |
68 | |
69 | //! Mouse click event. |
70 | void onMouseButton (int theButton, int theAction, int theMods); |
71 | |
72 | //! Mouse move event. |
73 | void onMouseMove (int thePosX, int thePosY); |
74 | |
75 | //! @name GLWF callbacks (static functions) |
76 | private: |
77 | |
78 | //! GLFW callback redirecting messages into Message::DefaultMessenger(). |
79 | static void errorCallback (int theError, const char* theDescription); |
80 | |
81 | //! Wrapper for glfwGetWindowUserPointer() returning this class instance. |
82 | static GlfwOcctView* toView (GLFWwindow* theWin); |
83 | |
84 | //! Window resize callback. |
85 | static void onResizeCallback (GLFWwindow* theWin, int theWidth, int theHeight) |
86 | { toView(theWin)->onResize (theWidth, theHeight); } |
87 | |
88 | //! Frame-buffer resize callback. |
89 | static void onFBResizeCallback (GLFWwindow* theWin, int theWidth, int theHeight) |
90 | { toView(theWin)->onResize (theWidth, theHeight); } |
91 | |
92 | //! Mouse scroll callback. |
93 | static void onMouseScrollCallback (GLFWwindow* theWin, double theOffsetX, double theOffsetY) |
94 | { toView(theWin)->onMouseScroll (theOffsetX, theOffsetY); } |
95 | |
96 | //! Mouse click callback. |
97 | static void onMouseButtonCallback (GLFWwindow* theWin, int theButton, int theAction, int theMods) |
98 | { toView(theWin)->onMouseButton (theButton, theAction, theMods); } |
99 | |
100 | //! Mouse move callback. |
101 | static void onMouseMoveCallback (GLFWwindow* theWin, double thePosX, double thePosY) |
102 | { toView(theWin)->onMouseMove ((int )thePosX, (int )thePosY); } |
103 | |
104 | private: |
105 | |
106 | Handle(GlfwOcctWindow) myOcctWindow; |
107 | Handle(V3d_View) myView; |
108 | Handle(AIS_InteractiveContext) myContext; |
109 | |
9c0787df |
110 | }; |
111 | |
112 | #endif // _GlfwOcctView_Header |