ShishGL  1.0
A simple modular cross-platform graphics library
Style.hpp
Go to the documentation of this file.
1 /*============================================================================*/
2 #ifndef SHISHGL_STYLE_HPP
3 #define SHISHGL_STYLE_HPP
4 /*============================================================================*/
5 #include <vector>
6 
7 #include "Shape2D.hpp"
8 #include "Frame.hpp"
9 /*============================================================================*/
10 namespace Sh {
11 
12  class Style {
13  public:
14 
15  Style() = default;
16 
17  virtual void apply(Frame& viewport, const Shape2D& shape) = 0;
18 
19  virtual ~Style() = default;
20 
21  };
22 
23  /*-------------------------------------------------------------------------*/
24 
25  class StylePack : public Style {
26  public:
27 
28  StylePack() = default;
29 
30  template <typename... Args>
31  explicit StylePack(Args&&... args) {
32  add(std::forward<Args>(args)...);
33  }
34 
35  void apply(Frame& viewport, const Shape2D& shape) override {
36  for (auto& style : styles) {
37  style->apply(viewport, shape);
38  }
39  }
40 
41  ~StylePack() override {
42  for (auto& style : styles) {
43  delete style;
44  }
45  }
46 
47  template <typename SomeStyle, typename... Args>
48  void add(const SomeStyle& style, Args&&... args) {
49  add(style);
50  add(std::forward<Args>(args)...);
51  }
52 
53  template <typename SomeStyle>
54  void add(const SomeStyle& style) {
55  auto* new_style = new SomeStyle(style);
56  styles.emplace_back(new_style);
57  }
58 
59  private:
60 
61  std::vector<Style*> styles;
62 
63  };
64 
65 }
66 /*============================================================================*/
67 #endif //SHISHGL_STYLE_HPP
68 /*============================================================================*/
Sh::Shape2D
Definition: Shape2D.hpp:12
Sh::StylePack::StylePack
StylePack()=default
Sh::StylePack::~StylePack
~StylePack() override
Definition: Style.hpp:41
Sh::Frame
Definition: Frame.hpp:9
Sh::Style::Style
Style()=default
Sh::StylePack::add
void add(const SomeStyle &style)
Definition: Style.hpp:54
Sh::StylePack
Definition: Style.hpp:25
Sh::StylePack::add
void add(const SomeStyle &style, Args &&... args)
Definition: Style.hpp:48
Shape2D.hpp
Sh::Style
Definition: Style.hpp:12
Sh
Definition: CoreApplication.hpp:10
Frame.hpp
Sh::Style::~Style
virtual ~Style()=default
Sh::StylePack::apply
void apply(Frame &viewport, const Shape2D &shape) override
Definition: Style.hpp:35
Sh::StylePack::StylePack
StylePack(Args &&... args)
Definition: Style.hpp:31
Sh::Style::apply
virtual void apply(Frame &viewport, const Shape2D &shape)=0