UnitreeCameraSDK  1.0.1
unitree stereo camra apis
glwindow.hpp
1 // Copyright (c) Ethan Eade, https://bitbucket.org/ethaneade/glwindow
2 
3 #pragma once
4 
5 #include <vector>
6 
7 namespace glwindow {
8 
9  namespace ButtonEvent {
10  enum Buttons {
11  LEFT=1, MIDDLE=2, RIGHT=4, WHEEL=8,
12  MODKEY_CTRL=16, MODKEY_SHIFT=32,
13  };
14  };
15 
16  namespace KeyCode {
17  enum Codes {
18  BACKSPACE=0x8,
19  TAB=0x9,
20  ENTER=0xD,
21  ESCAPE=0x1B,
22  DEL=0x7F,
23 
24  SHIFT=0xFF00,
25  CTRL,
26  ALT,
27  SUPER,
28  CAPSLOCK,
29  LEFT,
30  UP,
31  RIGHT,
32  DOWN,
33  };
34  };
35 
36 
37  class GLWindow;
38 
39  struct EventHandler
40  {
41  public:
42  virtual ~EventHandler() {}
43  virtual bool on_key_down(GLWindow& win, int key) { return false; }
44  virtual bool on_key_up(GLWindow& win, int key) { return false; }
45  virtual bool on_text(GLWindow& win, const char *text, int len) { return false; }
46  virtual bool on_button_down(GLWindow& win, int btn, int state, int x, int y) { return false; }
47  virtual bool on_button_up(GLWindow& win, int btn, int state, int x, int y) { return false; }
48  virtual bool on_mouse_move(GLWindow& win, int state, int x, int y) { return false; }
49  virtual bool on_mouse_wheel(GLWindow& win, int state, int x, int y, int dx, int dy) { return false; }
50  virtual bool on_resize(GLWindow& win, int x, int y, int w, int h) { return false; }
51  virtual bool on_close(GLWindow& win) { return false; }
52  };
53 
54  // Dispatches to each handler in reverse order until one returns true
56  {
57  public:
58  const std::vector<EventHandler*> &handlers;
59  EventDispatcher(const std::vector<EventHandler*> &h) :
60  handlers(h) {}
61  bool on_key_down(GLWindow& win, int key);
62  bool on_key_up(GLWindow& win, int key);
63  bool on_text(GLWindow& win, const char *text, int len);
64  bool on_button_down(GLWindow& win, int btn, int state, int x, int y);
65  bool on_button_up(GLWindow& win, int btn, int state, int x, int y);
66  bool on_mouse_move(GLWindow& win, int state, int x, int y);
67  bool on_mouse_wheel(GLWindow& win, int state, int x, int y, int dx, int dy);
68  bool on_resize(GLWindow& win, int x, int y, int w, int h);
69  bool on_close(GLWindow& win);
70  };
71 
72  class GLWindow
73  {
74  public:
75  GLWindow(int w=-1, int h=-1, const char *title=0);
76  virtual ~GLWindow();
77 
78  int width() const;
79  int height() const;
80  bool visible() const;
81  bool alive() const;
82 
83  bool make_current();
84  bool push_context();
85  void pop_context();
86 
87  struct ScopedContext {
88  GLWindow &win;
89  ScopedContext(GLWindow &w) : win(w) {
90  win.push_context();
91  }
92  ~ScopedContext() {
93  win.pop_context();
94  }
95  };
96 
97  void swap_buffers();
98 
99  void set_size(int w, int h);
100  void set_position(int x, int y);
101 
102  void set_title(const char* title);
103 
104  void add_handler(EventHandler* handler);
105  bool remove_handler(EventHandler *handler);
106  void handle_events();
107  static void handle_all_events();
108 
109  void destroy();
110 
111  void draw_text(double x, double y, const char *text, int xywh[4]=0);
112  protected:
113  struct SystemState;
114  SystemState *sys_state;
115 
116  std::vector<EventHandler*> handlers;
117  GLWindow *prev_active;
118 
119  static GLWindow *active_context;
120  static std::vector<GLWindow*> all_windows;
121  static void add_window(GLWindow *win);
122  static bool remove_window(GLWindow *win);
123  };
124 }
Definition: glwindow.hpp:7
Definition: glwindow.hpp:39
Definition: glwindow.hpp:55
Definition: glwindow.hpp:72
Definition: glwindow_x11.cpp:176
Definition: glwindow.hpp:87