Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
GLFWWindow.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef GLFW_Window_INCLUDE_ONCE
33 #define GLFW_Window_INCLUDE_ONCE
34 
35 #include <vlGLFW/link_config.hpp>
36 #include <vlCore/Vector4.hpp>
38 #include <GLFW/glfw3.h>
39 #include <map>
40 
41 namespace vlGLFW
42 {
43  //-----------------------------------------------------------------------------
44  // GLFWWindow
45  //-----------------------------------------------------------------------------
46 
51  {
52  public:
53  typedef std::map< ::GLFWwindow*, vlGLFW::GLFWWindow* > WinMapType;
54 
55  public:
56  GLFWWindow();
57 
64  GLFWWindow(const vl::String& title, const vl::OpenGLContextFormat& info, int width, int height, GLFWwindow* share = NULL);
65 
72  bool initGLFWWindow(const vl::String& title, const vl::OpenGLContextFormat& info, int width, int height, GLFWwindow* share = NULL);
73 
74  ~GLFWWindow();
75 
77  void quitApplication() {
78  WinMapType windows = mWinMap;
79  for( WinMapType::iterator it = windows.begin(); it != windows.end(); ++it ) {
80  it->second->destroyWindow();
81  }
82  }
83 
84  void makeCurrent();
85 
86  void update();
87 
88  void swapBuffers();
89 
90  bool setFullscreen(bool fs);
91 
92  void setWindowTitle(const vl::String& title);
93 
94  void setPosition(int x, int y) ;
95 
96  void setSize(int w, int h) ;
97 
98  vl::ivec2 position() const;
99 
100  vl::ivec2 size() const;
101 
102  void show();
103 
104  void hide();
105 
106  void getFocus();
107 
108  void setMouseVisible(bool visible);
109 
110  void setMousePosition(int x, int y);
111 
112  // ---
113 
114  const GLFWwindow* handle() const { return mHandle; }
115 
116  GLFWwindow* handle() { return mHandle; }
117 
118  void destroyWindow();
119 
120  static const WinMapType& windows() { return mWinMap; }
121 
122  protected:
123  static void glfw_size_callback(GLFWwindow* window, int w, int h);
124 
125  static void glfw_pos_callback(GLFWwindow* window, int x, int y);
126 
127  static void glfw_refresh_callback(GLFWwindow* window);
128 
129  static void glfw_close_callback(GLFWwindow* window);
130 
131  static void glfw_focus_callback(GLFWwindow* window, int);
132 
133  static void glfw_iconify_callback(GLFWwindow* window, int);
134 
135  // ---
136 
137  static vl::EKey translateKey(int key, int scancode, int mods);
138 
139  static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
140 
141  static void glfw_unicode_callback(GLFWwindow *, unsigned int);
142 
143  static void glfw_cursor_enter_callback(GLFWwindow *, int);
144 
145  static void glfw_cursor_pos_callback(GLFWwindow *, double, double);
146 
147  static void glfw_mouse_button_callback(GLFWwindow *, int, int, int);
148 
149  static void glfw_scroll_callback(GLFWwindow *, double, double);
150 
151  static void glfw_drop_callback(GLFWwindow *, int, const char**);
152 
153  protected:
154  static WinMapType mWinMap;
155  unsigned short mUnicodeChar;
156  GLFWwindow* mHandle;
157  };
158 }
159 
160 #endif
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
unsigned short mUnicodeChar
Definition: GLFWWindow.hpp:155
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
The GLFW bindings namespace.
The GLFWWindow class implements an OpenGLContext using the GLFW API.
Definition: GLFWWindow.hpp:50
GLFWwindow * mHandle
Definition: GLFWWindow.hpp:156
void quitApplication()
Attempts to quits the program by destroying all windows.
Definition: GLFWWindow.hpp:77
void translateKey(int &unicode, EKey &key, const wxKeyEvent &ev)
Definition: WXGLCanvas.cpp:172
std::map< ::GLFWwindow *, vlGLFW::GLFWWindow *> WinMapType
Definition: GLFWWindow.hpp:53
The OpenGLContextFormat class encapsulates the settings of an OpenGL rendering context.
static WinMapType mWinMap
Definition: GLFWWindow.hpp:154
GLFWwindow * handle()
Definition: GLFWWindow.hpp:116
static const WinMapType & windows()
Definition: GLFWWindow.hpp:120
const GLFWwindow * handle() const
Definition: GLFWWindow.hpp:114
#define NULL
Definition: OpenGLDefs.hpp:81