1 | // Aseprite UI Library |
2 | // Copyright (C) 2020 Igara Studio S.A. |
3 | // Copyright (C) 2017 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifndef UI_STYLE_H_INCLUDED |
9 | #define UI_STYLE_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "gfx/border.h" |
13 | #include "gfx/color.h" |
14 | #include "gfx/point.h" |
15 | #include "gfx/rect.h" |
16 | #include "gfx/size.h" |
17 | #include "os/font.h" |
18 | #include "os/surface.h" |
19 | #include "ui/base.h" |
20 | |
21 | #include <string> |
22 | #include <vector> |
23 | |
24 | namespace os { |
25 | class Font; |
26 | class Surface; |
27 | } |
28 | |
29 | namespace ui { |
30 | |
31 | class Style { |
32 | public: |
33 | class Layer { |
34 | public: |
35 | enum class Type { |
36 | kNone, |
37 | kBackground, |
38 | kBackgroundBorder, |
39 | kBorder, |
40 | kIcon, |
41 | kText, |
42 | kNewLayer, |
43 | }; |
44 | |
45 | // Flags (in which state the widget must be to show this layer) |
46 | enum { |
47 | kMouse = 1, |
48 | kFocus = 2, |
49 | kSelected = 4, |
50 | kDisabled = 8, |
51 | }; |
52 | |
53 | Layer() |
54 | : m_type(Type::kNone) |
55 | , m_flags(0) |
56 | , m_align(CENTER | MIDDLE) |
57 | , m_color(gfx::ColorNone) |
58 | , m_icon(nullptr) |
59 | , m_spriteSheet(nullptr) |
60 | , m_offset(0, 0) { |
61 | } |
62 | |
63 | Type type() const { return m_type; } |
64 | int flags() const { return m_flags; } |
65 | int align() const { return m_align; } |
66 | |
67 | gfx::Color color() const { return m_color; } |
68 | os::Surface* icon() const { return m_icon.get(); } |
69 | os::Surface* spriteSheet() const { return m_spriteSheet.get(); } |
70 | const gfx::Rect& spriteBounds() const { return m_spriteBounds; } |
71 | const gfx::Rect& slicesBounds() const { return m_slicesBounds; } |
72 | const gfx::Point& offset() const { return m_offset; } |
73 | |
74 | void setType(const Type type) { m_type = type; } |
75 | void setFlags(const int flags) { m_flags = flags; } |
76 | void setAlign(const int align) { m_align = align; } |
77 | void setColor(gfx::Color color) { m_color = color; } |
78 | void setIcon(const os::SurfaceRef& icon) { m_icon = icon; } |
79 | void setSpriteSheet(const os::SurfaceRef& spriteSheet) { m_spriteSheet = spriteSheet; } |
80 | void setSpriteBounds(const gfx::Rect& bounds) { m_spriteBounds = bounds; } |
81 | void setSlicesBounds(const gfx::Rect& bounds) { m_slicesBounds = bounds; } |
82 | void setOffset(const gfx::Point& offset) { m_offset = offset; } |
83 | |
84 | private: |
85 | Type m_type; |
86 | int m_flags; |
87 | int m_align; |
88 | gfx::Color m_color; |
89 | os::SurfaceRef m_icon; |
90 | os::SurfaceRef m_spriteSheet; |
91 | gfx::Rect m_spriteBounds; |
92 | gfx::Rect m_slicesBounds; |
93 | gfx::Point m_offset; |
94 | }; |
95 | |
96 | typedef std::vector<Layer> Layers; |
97 | |
98 | static gfx::Border UndefinedBorder(); |
99 | |
100 | Style(const Style* base); |
101 | |
102 | const std::string& id() const { return m_id; } |
103 | const gfx::Border& margin() const { return m_margin; } |
104 | const gfx::Border& border() const { return m_border; } |
105 | const gfx::Border& padding() const { return m_padding; } |
106 | os::Font* font() const { return m_font.get(); } |
107 | const Layers& layers() const { return m_layers; } |
108 | Layers& layers() { return m_layers; } |
109 | |
110 | void setId(const std::string& id) { m_id = id; } |
111 | void setMargin(const gfx::Border& value) { m_margin = value; } |
112 | void setBorder(const gfx::Border& value) { m_border = value; } |
113 | void setPadding(const gfx::Border& value) { m_padding = value; } |
114 | void setFont(const os::FontRef& font); |
115 | void addLayer(const Layer& layer); |
116 | |
117 | private: |
118 | std::string m_id; // Just for debugging purposes |
119 | Layers m_layers; |
120 | int m_insertionPoint; |
121 | gfx::Border m_margin; |
122 | gfx::Border m_border; |
123 | gfx::Border m_padding; |
124 | os::FontRef m_font; |
125 | }; |
126 | |
127 | } // namespace ui |
128 | |
129 | #endif |
130 | |