GlfmWindow.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "WindowListener.hpp"
4 #include "Window.hpp"
5 #include "../OpenGL/RenderTarget.hpp"
7 #include <optional>
8 #include <unordered_map>
9 
10 class GLFMDisplay;
11 
12 #if IV_GLPLATFORM_GLFM
13 #include <glfm.h>
14 #endif
15 
16 namespace iv
17 {
18 
20 {
21 public:
25 };
26 
27 class GlfmWindow : public Window
28 {
29 public:
30  GlfmWindow( GLFMDisplay * display );
31  ~GlfmWindow();
32 
33  virtual void set_listener( WindowListener * listener ) override;
34  virtual RenderTarget::Geometry geometry() override;
35  virtual RenderTarget * render_target() override;
36  virtual bool gpu_enabled() override;
37 
38  // InputSource
39  virtual int2 input_position( Input::Key key, int device_id ) override;
40  virtual float input_value( Input::Key key, int device_id ) override;
41  virtual unsigned input_character() override;
42 
43 private:
44 #if IV_GLPLATFORM_GLFM
45  static void s_onSurfaceCreated( GLFMDisplay * display, int width, int height );
46  void onSurfaceCreated( int width, int height );
47 
48  static void s_onSurfaceDestroyed( GLFMDisplay * display );
49  void onSurfaceDestroyed();
50 
51  static void s_onSurfaceResized( GLFMDisplay * display, int width, int height );
52  void onSurfaceResized( int width, int height );
53 
54  static bool s_TouchFunc( GLFMDisplay * display, int touch, GLFMTouchPhase phase, double x, double y );
55  bool TouchFunc( int touch, GLFMTouchPhase phase, double x, double y );
56 
57  static void s_SurfaceErrorFunc( GLFMDisplay * display, const char * message );
58  void SurfaceErrorFunc( const char * message );
59 
60  static void s_MemoryWarningFunc( GLFMDisplay * display );
61  void MemoryWarningFunc();
62 
63  static void s_FocusFunc( GLFMDisplay * display, bool focused );
64  void FocusFunc( bool focused );
65 
66  static void s_onFrame( GLFMDisplay * display, double frameTime_s );
67  void onFrame( double frameTime_s );
68 
69  static bool s_KeyFunc( GLFMDisplay * display, GLFMKey keyCode, GLFMKeyAction action, int modifiers );
70  bool KeyFunc( GLFMKey keyCode, GLFMKeyAction action, int modifiers );
71 
72  static void s_CharFunc( GLFMDisplay * display, const char * utf8, int modifiers );
73  void CharFunc( const char * utf8, int modifiers );
74 
75  static bool s_EmscriptenKeyFunc( GLFMDisplay * display, const char * code, GLFMKeyAction action, int modifiers );
76  bool EmscriptenKeyFunc( const char * code, GLFMKeyAction action, int modifiers );
77 #endif
78 
79 private:
80  void render();
81  void PopulateEmscriptenKeyMap();
82 
83 private:
84  GLFMDisplay * display;
85 
86  //
87  WindowListener * listener;
88 
89  //
90  GlfmRenderTarget _render_target;
91 
92  //
93  double _lastFrameTime_s;
94 
95  // input
96  std::unordered_map< int, int2 > _touches;
97  std::unordered_map< std::string, Input::Key > emscriptenKeyMap;
98  unsigned _current_character;
99 
100  //
101  bool _gpu;
102 };
103 
104 }