Shiokaze Framework
A research-oriented fluid solver for computer graphics
UI_interface.h
Go to the documentation of this file.
1 /*
2 ** UI_interface.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on July 16, 2019.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_UI_INTERFACE_H
26 #define SHKZ_UI_INTERFACE_H
27 //
29 #include <dlfcn.h>
30 //
32 //
33 static bool *g_shkz_has_graphical_interface {nullptr};
34 //
36 class UI_interface {
39 public:
40  //
43  enum ACTION {
46  RELEASE = 0,
49  PRESS = 1,
52  REPEAT = 2,
53  };
54  //
57  enum MODIFIER {
60  MOD_SHIFT = 0x0001,
63  MOD_CONTROL = 0x0002,
66  MOD_ALT = 0x0004,
69  MOD_SUPER = 0x0008,
72  MOD_CAPS_LOCK = 0x0010,
75  MOD_NUM_LOCK = 0x0020,
76  };
77  //
80  enum MOUSE_BUTTON {
83  LEFT = 1,
86  RIGHT = 2,
89  MIDDLE = 3,
90  };
91  //
92  #include "keymap.h"
93  //
96  struct event_structure {
97  //
100  enum EVENT_TYPE {
122  };
128  int button {0};
131  int key {0};
134  int action {0};
137  int mods {0};
140  int width {0};
143  int height {0};
146  double x {0.0};
149  double y {0.0};
152  double z {0.0};
155  double u {0.0};
158  double v {0.0};
161  double w {0.0};
164  graphics_engine *g {nullptr};
165  };
172  virtual bool handle_event( const event_structure &event ) {
173  switch( event.type ) {
175  return keyboard(event.key,event.action,event.mods);
176  break;
178  cursor(event.x,event.y,event.z);
179  break;
181  mouse(event.x,event.y,event.z,event.button,event.action,event.mods);
182  break;
184  scroll(event.x,event.y);
185  break;
187  drag(event.x,event.y,event.z,event.u,event.v,event.w);
188  break;
190  resize(event.width,event.height);
191  break;
193  assert(event.g);
194  draw(*event.g);
195  break;
196  }
197  return false;
198  }
207  virtual bool relay_event( const event_structure &event ) const { return true; }
208  //
211  enum CURSOR_TYPE {
230  };
237  virtual CURSOR_TYPE get_current_cursor() const {
238  return ARROW_CURSOR;
239  }
246  static bool has_graphical_interface() {
247  if( ! g_shkz_has_graphical_interface ) {
248  g_shkz_has_graphical_interface = static_cast<bool *>(::dlsym(RTLD_DEFAULT,"g_shkz_has_graphical_interface"));
249  assert(g_shkz_has_graphical_interface);
250  }
251  return *g_shkz_has_graphical_interface;
252  }
253  //
254 protected:
255  //
264  virtual void resize( int width, int height ) {}
271  virtual void draw( graphics_engine &g ) const {}
282  virtual bool keyboard( int key, int action, int mods ) { return false; }
293  virtual void cursor( double x, double y, double z ) {};
304  virtual void mouse( double x, double y, double z, int button, int action, int mods ) {};
313  virtual void scroll( double xoffset, double yoffset ) {};
328  virtual void drag( double x, double y, double z, double u, double v, double w ) {};
329 };
330 //
332 //
333 #endif
334 //
UI_interface::MOD_SHIFT
@ MOD_SHIFT
Shift modifier bit.
Definition: UI_interface.h:60
UI_interface::event_structure::RESIZE
@ RESIZE
Resize event.
Definition: UI_interface.h:118
UI_interface::event_structure::EVENT_TYPE
EVENT_TYPE
Event type.
Definition: UI_interface.h:100
UI_interface::relay_event
virtual bool relay_event(const event_structure &event) const
Get if the event shoule be relayed to other instances after handle_event of this instance is called.
Definition: UI_interface.h:207
UI_interface::REPEAT
@ REPEAT
Repeat event.
Definition: UI_interface.h:52
UI_interface::resize
virtual void resize(int width, int height)
Function that catches window resizing events.
Definition: UI_interface.h:264
UI_interface::MODIFIER
MODIFIER
Modifier bits.
Definition: UI_interface.h:57
UI_interface::MOD_ALT
@ MOD_ALT
ALT modifier bit.
Definition: UI_interface.h:66
UI_interface::ACTION
ACTION
Key and mose action type.
Definition: UI_interface.h:43
UI_interface::event_structure::x
double x
X coordinate value.
Definition: UI_interface.h:146
UI_interface::MOD_CAPS_LOCK
@ MOD_CAPS_LOCK
Capslock modifier bit.
Definition: UI_interface.h:72
UI_interface::event_structure::KEYBOARD
@ KEYBOARD
Keyboard event.
Definition: UI_interface.h:103
UI_interface::event_structure::width
int width
Width.
Definition: UI_interface.h:140
UI_interface::event_structure::DRAG
@ DRAG
Drag event.
Definition: UI_interface.h:115
UI_interface::has_graphical_interface
static bool has_graphical_interface()
Get if a graphical interface is available.
Definition: UI_interface.h:246
UI_interface::MIDDLE
@ MIDDLE
Middle button.
Definition: UI_interface.h:89
UI_interface::event_structure::y
double y
Y coordinate value.
Definition: UI_interface.h:149
UI_interface::event_structure::z
double z
Z coordinate value.
Definition: UI_interface.h:152
UI_interface::handle_event
virtual bool handle_event(const event_structure &event)
Definition: UI_interface.h:172
UI_interface::event_structure::w
double w
Z coordinate displacement value.
Definition: UI_interface.h:161
UI_interface::event_structure::mods
int mods
Modifier information.
Definition: UI_interface.h:137
UI_interface::event_structure::height
int height
Height.
Definition: UI_interface.h:143
UI_interface::IBEAM_CURSOR
@ IBEAM_CURSOR
Text input I beam cursor.
Definition: UI_interface.h:220
UI_interface::RELEASE
@ RELEASE
Release event.
Definition: UI_interface.h:46
UI_interface::event_structure::key
int key
Key type.
Definition: UI_interface.h:131
keymap.h
UI_interface::CURSOR_TYPE
CURSOR_TYPE
Cursor icon type.
Definition: UI_interface.h:211
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
UI_interface::keyboard
virtual bool keyboard(int key, int action, int mods)
Function that catches key down event.
Definition: UI_interface.h:282
UI_interface::event_structure::DRAW
@ DRAW
Draw event.
Definition: UI_interface.h:121
UI_interface::VRESIZE_CURSOR
@ VRESIZE_CURSOR
Vertical resizing cursor.
Definition: UI_interface.h:229
UI_interface::event_structure::SCROLL
@ SCROLL
Scroll event.
Definition: UI_interface.h:112
UI_interface::event_structure::button
int button
Button type.
Definition: UI_interface.h:128
UI_interface::MOD_SUPER
@ MOD_SUPER
SUPER modifier bit.
Definition: UI_interface.h:69
UI_interface::MOD_CONTROL
@ MOD_CONTROL
Control modifier bit.
Definition: UI_interface.h:63
UI_interface::mouse
virtual void mouse(double x, double y, double z, int button, int action, int mods)
Function that catches mouse event.
Definition: UI_interface.h:304
UI_interface::HAND_CURSOR
@ HAND_CURSOR
Hand cursor.
Definition: UI_interface.h:217
UI_interface::event_structure
Event information structure.
Definition: UI_interface.h:96
UI_interface::event_structure::MOUSE
@ MOUSE
Mouse event.
Definition: UI_interface.h:109
UI_interface::event_structure::action
int action
Action type.
Definition: UI_interface.h:134
UI_interface::MOD_NUM_LOCK
@ MOD_NUM_LOCK
NUM lock modifier bit.
Definition: UI_interface.h:75
UI_interface::event_structure::type
EVENT_TYPE type
Event type.
Definition: UI_interface.h:125
UI_interface
Interface for input APIs.
Definition: UI_interface.h:38
UI_interface::drag
virtual void drag(double x, double y, double z, double u, double v, double w)
Function that catches drag event.
Definition: UI_interface.h:328
UI_interface::event_structure::v
double v
Y coordinate displacement value.
Definition: UI_interface.h:158
UI_interface::PRESS
@ PRESS
Press event.
Definition: UI_interface.h:49
UI_interface::RIGHT
@ RIGHT
Right button.
Definition: UI_interface.h:86
UI_interface::CROSSHAIR_CURSOR
@ CROSSHAIR_CURSOR
Cross hair cursor.
Definition: UI_interface.h:223
UI_interface::event_structure::u
double u
X coordinate displacement value.
Definition: UI_interface.h:155
UI_interface::event_structure::CURSOR
@ CURSOR
Cursor event.
Definition: UI_interface.h:106
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
UI_interface::LEFT
@ LEFT
Left button.
Definition: UI_interface.h:83
UI_interface::cursor
virtual void cursor(double x, double y, double z)
Function that catches passive cursor event.
Definition: UI_interface.h:293
UI_interface::HRESIZE_CURSOR
@ HRESIZE_CURSOR
Horizontal resizing cursor.
Definition: UI_interface.h:226
UI_interface::scroll
virtual void scroll(double xoffset, double yoffset)
Function that catches scroll event.
Definition: UI_interface.h:313
UI_interface::ARROW_CURSOR
@ ARROW_CURSOR
Regular arrow cursor.
Definition: UI_interface.h:214
graphics_engine
Interface for handling drawing operations.
Definition: graphics_engine.h:38
UI_interface::event_structure::g
graphics_engine * g
Pointer to the graphics engine.
Definition: UI_interface.h:164
UI_interface::draw
virtual void draw(graphics_engine &g) const
Function that catches draw event.
Definition: UI_interface.h:271
UI_interface::MOUSE_BUTTON
MOUSE_BUTTON
Mouse button type.
Definition: UI_interface.h:80
UI_interface::get_current_cursor
virtual CURSOR_TYPE get_current_cursor() const
Get current cursor icon.
Definition: UI_interface.h:237
graphics_engine.h