Simple GUI Library
fill.h
Go to the documentation of this file.
1/**
2 * @author Nikita Mochalov (github.com/tralf-strues)
3 * @file fill.h
4 * @date 2021-11-05
5 *
6 * @copyright Copyright (c) 2021
7 */
8
9#pragma once
10
11#include <vector>
12#include "sml/math/vec2.h"
13#include "sml/math/rectangle.h"
14#include "sml/graphics_wrapper/texture.h"
15
16namespace Sgl
17{
18 class Fill
19 {
20 public:
21 virtual void fillLine(const Sml::Vec2i& start,
22 const Sml::Vec2i& end,
23 const Sml::Rectangle<int32_t>& targetRegion) const = 0;
24
25 virtual void fillArea(const Sml::Rectangle<int32_t>& area,
26 const Sml::Rectangle<int32_t>& targetRegion) const = 0;
27
28 virtual void fillPoint(const Sml::Vec2i& point,
29 const Sml::Rectangle<int32_t>& targetRegion) const = 0;
30 };
31
32 //------------------------------------------------------------------------------
33 // ColorFill
34 //------------------------------------------------------------------------------
35 class ColorFill : public Fill
36 {
37 public:
38 ColorFill(Sml::Color color = Sml::COLOR_TRANSPARENT);
39
40 virtual void fillLine(const Sml::Vec2i& start,
41 const Sml::Vec2i& end,
42 const Sml::Rectangle<int32_t>& targetRegion) const override;
43
44 virtual void fillArea(const Sml::Rectangle<int32_t>& area,
45 const Sml::Rectangle<int32_t>& targetRegion) const override;
46
47 virtual void fillPoint(const Sml::Vec2i& point,
48 const Sml::Rectangle<int32_t>& targetRegion) const override;
49
50 Sml::Color getColor() const;
51 void setColor(Sml::Color color);
52
53 protected:
54 Sml::Color m_Color;
55 };
56
57 //------------------------------------------------------------------------------
58 // LinearGradientFill
59 //------------------------------------------------------------------------------
60 // TODO:
61 class LinearGradientFill : public Fill
62 {
63 public:
64 static const LinearGradientFill RAINBOX_HORIZONTAL;
65
66 public:
67 class Stop
68 {
69 public:
70 Stop(float offset, Sml::Color color);
71
72 float getOffset() const;
73 const Sml::Vec4f& getColorVector() const;
74 Sml::Color getColor() const;
75
76 bool operator<(const Stop& other) const;
77
78 private:
79 float m_Offset = 0.0; ///< Number ranging from 0 to 1
80 Sml::Vec4f m_Color = Sml::colorToNormalized(Sml::COLOR_TRANSPARENT);
81 };
82
83 enum class Direction
84 {
85 HORIZONTAL,
86 VERTICAL
87 };
88
89 public:
90 LinearGradientFill() = default;
91 LinearGradientFill(const std::initializer_list<Stop>& stops);
92 LinearGradientFill(Direction direction, const std::initializer_list<Stop>& stops);
93
94 void addStop(const Stop& stop);
95
96 void setDirection(Direction direction);
97
98 virtual void fillLine(const Sml::Vec2i& start,
99 const Sml::Vec2i& end,
100 const Sml::Rectangle<int32_t>& targetRegion) const override;
101
102 virtual void fillArea(const Sml::Rectangle<int32_t>& area,
103 const Sml::Rectangle<int32_t>& targetRegion) const override;
104
105 virtual void fillPoint(const Sml::Vec2i& point,
106 const Sml::Rectangle<int32_t>& targetRegion) const override;
107
108 private:
109 std::vector<Stop> m_Stops;
110 Direction m_Direction = Direction::HORIZONTAL;
111 };
112}
Definition: fill.h:19