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