forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.h
176 lines (147 loc) · 6 KB
/
theme.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Aseprite UI Library
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UI_THEME_H_INCLUDED
#define UI_THEME_H_INCLUDED
#pragma once
#include "gfx/border.h"
#include "gfx/color.h"
#include "gfx/rect.h"
#include "gfx/size.h"
#include "ui/base.h"
#include "ui/cursor_type.h"
#include "ui/style.h"
#include "ui/scale.h"
namespace gfx {
class Region;
}
namespace os {
class Font;
class Surface;
}
namespace ui {
class Cursor;
class Graphics;
class PaintEvent;
class SizeHintEvent;
class Widget;
class Theme;
void set_theme(Theme* theme, const int uiscale);
Theme* get_theme();
inline int CALC_FOR_CENTER(int p, int s1, int s2) {
return (p/guiscale() + (s1/guiscale())/2 - (s2/guiscale())/2)*guiscale();
}
struct PaintWidgetPartInfo {
gfx::Color bgColor;
int styleFlags; // ui::Style::Layer flags
const std::string* text;
int mnemonic;
os::Surface* icon;
PaintWidgetPartInfo();
PaintWidgetPartInfo(const Widget* widget);
static int getStyleFlagsForWidget(const Widget* widget);
};
class Theme {
friend void set_theme(Theme* theme, const int uiscale);
public:
Theme();
virtual ~Theme();
virtual os::Font* getDefaultFont() const = 0;
virtual os::Font* getWidgetFont(const Widget* widget) const = 0;
virtual ui::Cursor* getStandardCursor(CursorType type) = 0;
virtual void initWidget(Widget* widget) = 0;
virtual void getWindowMask(Widget* widget, gfx::Region& region) = 0;
virtual void setDecorativeWidgetBounds(Widget* widget);
virtual int getScrollbarSize() = 0;
virtual gfx::Size getEntryCaretSize(Widget* widget) = 0;
virtual void paintEntry(PaintEvent& ev) = 0;
virtual void paintListBox(PaintEvent& ev) = 0;
virtual void paintMenu(PaintEvent& ev) = 0;
virtual void paintMenuItem(PaintEvent& ev) = 0;
virtual void paintSlider(PaintEvent& ev) = 0;
virtual void paintComboBoxEntry(PaintEvent& ev) = 0;
virtual void paintTextBox(PaintEvent& ev) = 0;
virtual void paintViewViewport(PaintEvent& ev) = 0;
virtual void paintWidgetPart(Graphics* g,
const Style* style,
const gfx::Rect& bounds,
const PaintWidgetPartInfo& info);
// Default implementation to draw widgets with new ui::Styles
virtual void paintWidget(Graphics* g,
const Widget* widget,
const Style* style,
const gfx::Rect& bounds);
virtual void paintScrollBar(Graphics* g,
const Widget* widget,
const Style* style,
const Style* thumbStyle,
const gfx::Rect& bounds,
const gfx::Rect& thumbBounds);
virtual void paintTooltip(Graphics* g,
const Widget* widget,
const Style* style,
const Style* arrowStyle,
const gfx::Rect& bounds,
const int arrowAlign,
const gfx::Rect& target);
void paintTextBoxWithStyle(Graphics* g,
const Widget* widget);
virtual gfx::Size calcSizeHint(const Widget* widget,
const Style* style);
virtual gfx::Border calcBorder(const Widget* widget,
const Style* style);
virtual void calcSlices(const Widget* widget,
const Style* style,
gfx::Size& topLeft,
gfx::Size& center,
gfx::Size& bottomRight);
virtual void calcTextInfo(const Widget* widget,
const Style* style,
const gfx::Rect& bounds,
gfx::Rect& textBounds, int& textAlign);
virtual gfx::Color calcBgColor(const Widget* widget,
const Style* style);
virtual gfx::Size calcMinSize(const Widget* widget,
const Style* style);
virtual gfx::Size calcMaxSize(const Widget* widget,
const Style* style);
static void drawSlices(Graphics* g,
os::Surface* sheet,
const gfx::Rect& rc,
const gfx::Rect& sprite,
const gfx::Rect& slices,
const gfx::Color color,
const bool drawCenter = true);
static void drawTextBox(Graphics* g, const Widget* textbox,
int* w, int* h, gfx::Color bg, gfx::Color fg);
static ui::Style* getDefaultStyle() { return &m_defaultStyle; }
protected:
virtual void onRegenerateTheme() = 0;
private:
void regenerateTheme();
void paintLayer(Graphics* g,
const Style* style,
const Style::Layer& layer,
const std::string& text,
const int mnemonic,
os::Surface* icon,
gfx::Rect& rc,
gfx::Color& bgColor);
void measureLayer(const Widget* widget,
const Style* style,
const Style::Layer& layer,
gfx::Border& borderHint,
gfx::Rect& textHint, int& textAlign,
gfx::Size& iconHint, int& iconAlign);
void calcWidgetMetrics(const Widget* widget,
const Style* style,
gfx::Size& sizeHint,
gfx::Border& borderHint,
gfx::Rect& textHint, int& textAlign);
static ui::Style m_defaultStyle;
};
} // namespace ui
#endif