forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.h
153 lines (131 loc) · 4.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Aseprite UI Library
// Copyright (C) 2020 Igara Studio S.A.
// 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 "os/font.h"
#include "os/surface.h"
#include "ui/base.h"
#include <string>
#include <vector>
namespace os {
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,
kCapture = 16
};
class IconSurfaceProvider {
public:
virtual os::Surface* iconSurface() const = 0;
};
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; }
os::Surface* icon() const { return m_icon.get(); }
os::Surface* spriteSheet() const { return m_spriteSheet.get(); }
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(const os::SurfaceRef& icon) { m_icon = icon; }
void setSpriteSheet(const os::SurfaceRef& 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;
os::SurfaceRef m_icon;
os::SurfaceRef m_spriteSheet;
gfx::Rect m_spriteBounds;
gfx::Rect m_slicesBounds;
gfx::Point m_offset;
};
typedef std::vector<Layer> Layers;
static gfx::Border UndefinedBorder();
static gfx::Size MinSize();
static gfx::Size MaxSize();
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; }
const gfx::Size& minSize() const { return m_minSize; }
const gfx::Size& maxSize() const { return m_maxSize; }
const gfx::Size& gap() const { return m_gap; }
os::Font* font() const { return m_font.get(); }
const bool mnemonics() const { return m_mnemonics; }
const Layers& layers() const { return m_layers; }
Layers& layers() { 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 setMinSize(const gfx::Size& sz);
void setMaxSize(const gfx::Size& sz);
void setGap(const gfx::Size& value) { m_gap = value; }
void setFont(const os::FontRef& font);
void setMnemonics(const bool enabled) { m_mnemonics = enabled; }
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;
// Min width and height for the widget.
gfx::Size m_minSize;
// Max width and height for the widget.
gfx::Size m_maxSize;
// Grid's columns and rows separation in pixels.
gfx::Size m_gap;
os::FontRef m_font;
bool m_mnemonics;
};
} // namespace ui
#endif