Virtual Testbed
Ship dynamics simulator for extreme conditions
ImguiApplicationMonad.hh
1 #ifndef VTESTBED_GUI_IMGUIAPPLICATIONMONAD_HH
2 #define VTESTBED_GUI_IMGUIAPPLICATIONMONAD_HH
3 
4 #include <type_traits>
5 
6 #include <Magnum/GL/DefaultFramebuffer.h>
7 #include <vtestbed/gui/MagnumImgui/MagnumImGui.h>
8 #include <vtestbed/gui/imgui.hh>
9 #include <vtestbed/gui/types.hh>
10 
11 namespace vtb {
12 
13  namespace gui {
14 
15  template <class Base>
16  class ImguiApplicationMonad: public Base {
17 
18  static_assert(
20  "bad base class"
21  );
22 
23  private:
24  using typename Base::Arguments;
25  using typename Base::Configuration;
26 
27  private:
28  MagnumImGui _imgui;
29 
30  public:
31 
32  ImguiApplicationMonad(const Arguments& args, const Configuration& conf):
33  Base{args, conf} { this->initImGui(); }
34 
35  template <class ... Args>
36  inline explicit
37  ImguiApplicationMonad(Args&& ... args):
38  Base(std::forward<Args>(args)...) { this->initImGui(); }
39 
40  protected:
41 
42  inline void initImGui() { this->Base::initImGui(this->imgui()); }
43 
44  void
45  drawEvent() override {
46  using namespace Magnum;
47  GL::defaultFramebuffer.clear(
48  GL::FramebufferClear::Color|GL::FramebufferClear::Depth
49  );
50  this->imgui().newFrame(
51  this->windowSize(),
52  GL::defaultFramebuffer.viewport().size()
53  );
54  this->Base::drawEvent();
55  this->imgui().drawFrame();
56  this->swapBuffers();
57  this->redraw();
58  }
59 
60  void
61  keyPressEvent(KeyEvent& event) override {
62  if (this->imgui().keyPressEvent(event)) {
63  return;
64  }
65  this->Base::keyPressEvent(event);
66  }
67 
68  void
69  keyReleaseEvent(KeyEvent& event) override {
70  if (this->imgui().keyReleaseEvent(event)) {
71  return;
72  }
73  this->Base::keyReleaseEvent(event);
74  }
75 
76  void
77  mousePressEvent(MouseEvent& event) override {
78  if (this->imgui().mousePressEvent(event)) {
79  return;
80  }
81  this->Base::mousePressEvent(event);
82  }
83 
84  void
85  mouseReleaseEvent(MouseEvent& event) override {
86  if (this->imgui().mouseReleaseEvent(event)) {
87  return;
88  }
89  this->Base::mouseReleaseEvent(event);
90  }
91 
92  void
93  mouseMoveEvent(MouseMoveEvent& event) override {
94  if (this->imgui().mouseMoveEvent(event)) {
95  return;
96  }
97  this->Base::mouseMoveEvent(event);
98  }
99 
100  void
101  mouseScrollEvent(MouseScrollEvent& event) override {
102  if (this->imgui().mouseScrollEvent(event)) {
103  return;
104  }
105  this->Base::mouseScrollEvent(event);
106  }
107 
108  void
109  textInputEvent(TextInputEvent& event) override {
110  if (this->imgui().textInputEvent(event)) {
111  return;
112  }
113  this->Base::textInputEvent(event);
114  }
115 
116  inline MagnumImGui& imgui() { return this->_imgui; }
117  inline const MagnumImGui& imgui() const { return this->_imgui; }
118 
119  };
120 
121  }
122 
123 }
124 
125 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9