ShishGL  1.0
A simple modular cross-platform graphics library
UIWindow.hpp
Go to the documentation of this file.
1 /*============================================================================*/
2 #ifndef SHISHGL_UI_WINDOW_HPP
3 #define SHISHGL_UI_WINDOW_HPP
4 /*============================================================================*/
5 #include <unordered_map>
6 #include <unordered_set>
7 #include <memory>
8 
9 #include "Window.hpp"
10 #include "Style.hpp"
11 #include "Shape2D.hpp"
12 #include "Behavior.hpp"
13 /*============================================================================*/
14 namespace Sh {
15 
16  class UIWindow : public Window {
17  public:
18 
19  enum States {
24  SELECTED
25  };
26 
27  template <int SomeState, typename... Args>
28  UIWindow* applyStyle(Args&&... args);
29 
30  template <typename SomeShape, typename... Args>
31  UIWindow* applyShape(Args&&... args);
32 
33  template <typename SomeBehavior, typename... Args>
34  UIWindow* setBehavior(Args&&... args);
35 
36  [[nodiscard]]
37  int getState() const;
38 
39  void setState(int new_state);
40 
41  [[nodiscard]]
42  bool contains(const Vector2<double>& point) const override;
43 
44  void translate(const Vector2<double>& delta) override {
45  Window::translate(delta);
47  }
48 
49  void setPos(const Vector2<double>& pos) override {
50  Window::setPos(pos);
52  }
53 
54  void setParent(Window* new_parent) override {
55  Window::setParent(new_parent);
57  }
58 
59  [[nodiscard]]
60  Behavior* getBehavior() const {
61  return behavior;
62  }
63 
64  ~UIWindow() override;
65 
66  protected:
67 
68  explicit UIWindow(const Frame& viewport);
69 
70  void onRender() override;
71 
72  using StyleMap = std::unordered_map<int, StylePack>;
73 
74  StyleMap& styles();
75 
76  [[nodiscard]]
77  const Shape2D& shape() const;
78 
79  void notifyBehavior() {
80  if (behavior) {
81  behavior->onTargetUpdate();
82  }
83  }
84 
85  private:
86 
87  int state;
88 
89  StyleMap style_map; // TODO: style set + mask
90 
91  Shape2D* shape_impl;
92 
93  Behavior* behavior;
94 
95  friend class WindowManager;
96 
97  };
98 
99 }
100 /*============================================================================*/
101 #include "UIWindow.ipp"
102 /*============================================================================*/
103 #endif //SHISHGL_UI_WINDOW_HPP
104 /*============================================================================*/
Sh::UIWindow::setState
void setState(int new_state)
Definition: UIWindow.cpp:40
Sh::UIWindow::StyleMap
std::unordered_map< int, StylePack > StyleMap
Definition: UIWindow.hpp:72
Sh::UIWindow::NORMAL
@ NORMAL
Definition: UIWindow.hpp:20
Sh::UIWindow::setPos
void setPos(const Vector2< double > &pos) override
Definition: UIWindow.hpp:49
Sh::UIWindow::HOVER
@ HOVER
Definition: UIWindow.hpp:21
Sh::UIWindow::~UIWindow
~UIWindow() override
Definition: UIWindow.cpp:19
Sh::Shape2D
Definition: Shape2D.hpp:12
Sh::WindowManager
Definition: WindowManager.hpp:13
Sh::UIWindow::contains
bool contains(const Vector2< double > &point) const override
Definition: UIWindow.cpp:62
Sh::UIWindow::HOLD
@ HOLD
Definition: UIWindow.hpp:23
Sh::UIWindow::setParent
void setParent(Window *new_parent) override
Definition: UIWindow.hpp:54
Sh::Window
Definition: Window.hpp:16
Sh::Window::translate
virtual void translate(const Vector2< double > &delta)
Definition: Window.cpp:98
Sh::Frame
Definition: Frame.hpp:9
Sh::UIWindow::translate
void translate(const Vector2< double > &delta) override
Definition: UIWindow.hpp:44
Sh::Vector2< double >
Sh::UIWindow::getState
int getState() const
Definition: UIWindow.cpp:36
Sh::UIWindow::States
States
Definition: UIWindow.hpp:19
Window.hpp
Sh::UIWindow::SELECTED
@ SELECTED
Definition: UIWindow.hpp:24
Sh::UIWindow::applyShape
UIWindow * applyShape(Args &&... args)
Definition: UIWindow.ipp:18
Sh::UIWindow::onRender
void onRender() override
Definition: UIWindow.cpp:46
Sh::UIWindow::styles
StyleMap & styles()
Definition: UIWindow.cpp:30
Style.hpp
Shape2D.hpp
Sh::UIWindow::shape
const Shape2D & shape() const
Definition: UIWindow.cpp:26
Sh::UIWindow::notifyBehavior
void notifyBehavior()
Definition: UIWindow.hpp:79
Sh::UIWindow
Definition: UIWindow.hpp:16
Sh::UIWindow::getBehavior
Behavior * getBehavior() const
Definition: UIWindow.hpp:60
Sh::Window::setPos
virtual void setPos(const Vector2< double > &pos)
Definition: Window.cpp:84
Sh::Window::setParent
virtual void setParent(Window *new_parent)
Definition: Window.cpp:37
Sh
Definition: CoreApplication.hpp:10
Sh::Behavior
Definition: Behavior.hpp:9
Sh::UIWindow::CLICK
@ CLICK
Definition: UIWindow.hpp:22
UIWindow.ipp
Sh::UIWindow::UIWindow
UIWindow(const Frame &viewport)
Definition: UIWindow.cpp:8
Sh::UIWindow::setBehavior
UIWindow * setBehavior(Args &&... args)
Definition: UIWindow.ipp:28
Sh::UIWindow::applyStyle
UIWindow * applyStyle(Args &&... args)
Definition: UIWindow.ipp:10
Sh::Behavior::onTargetUpdate
virtual void onTargetUpdate()
Definition: Behavior.hpp:21
Behavior.hpp