-
Notifications
You must be signed in to change notification settings - Fork 5
/
Main.cpp
385 lines (320 loc) · 9.63 KB
/
Main.cpp
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# include <Siv3D.hpp> // OpenSiv3D v0.6.5
class ITab
{
public:
ITab(const SizeF& tabSize, const Array<String>& items)
: m_tabSize{ tabSize }
, m_items{ items } {}
virtual ~ITab() = default;
/// @brief すべてのタブを描画します。
/// @param pos タブ描画開始位置
/// @param font テキスト描画に使うフォント(FontMethod::MSDF 設定で作成)
/// @param color アクティブなタブの背景色
/// @param outlineColor タブの枠の色
virtual void draw(const Vec2& pos, const Font& font, const ColorF& color, const ColorF& outlineColor) const = 0;
/// @brief タブの個数を返します。
/// @return タブの個数
virtual size_t getTabCount() const noexcept
{
return m_items.size();
}
/// @brief アクティブなタブのインデックスを返します。
/// @return アクティブなタブのインデックス
virtual size_t getActiveTabIndex() const noexcept
{
return m_activeIndex;
}
/// @brief アクティブなタブを変更します。
/// @param index アクティブにするタブのインデックス
virtual void setActiveTabIndex(size_t index) noexcept
{
assert(index < m_items.size());
m_activeIndex = index;
}
/// @brief タブを左右に移動します。
/// @param offset 左に移動する場合 -1, 右に移動する場合は +1
/// @param wrapAround 端まで到達したときに反対側に戻る場合 true, それ以外の場合は false
virtual void advance(int32 offset, bool wrapAround = false)
{
assert(InRange(offset, -1, 1));
if (offset == -1)
{
if (m_activeIndex == 0)
{
if (wrapAround)
{
m_activeIndex = (m_items.size() - 1);
}
}
else
{
--m_activeIndex;
}
}
else if (offset == 1)
{
if (m_activeIndex == (m_items.size() - 1))
{
if (wrapAround)
{
m_activeIndex = 0;
}
}
else
{
++m_activeIndex;
}
}
}
protected:
SizeF m_tabSize;
Array<String> m_items;
size_t m_activeIndex = 0;
};
class TabA : public ITab
{
public:
TabA(const SizeF& tabSize, const Array<String>& items)
: ITab{ tabSize, items }
{
double posX = 0.0;
for (size_t i = 0; i < items.size(); ++i)
{
m_tabPositions.emplace_back(posX, 0);
posX += (tabSize.x + tabSize.x * 0.14);
}
}
void draw(const Vec2& pos, const Font& font, const ColorF& color, const ColorF& outlineColor) const override
{
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos + m_tabPositions[i]), m_tabSize };
if (i == m_activeIndex)
{
tab.draw(color);
}
else
{
tab.drawFrame(3, 0, outlineColor);
}
}
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos + m_tabPositions[i]), m_tabSize };
font(m_items[i]).drawAt(TextStyle::Shadow(Vec2{ 2.5, 2.5 }, ColorF{ 0.0, 0.6 }), 20, tab.center());
}
}
private:
Array<Vec2> m_tabPositions;
};
class TabB : public ITab
{
public:
TabB(const SizeF& tabSize, const Array<String>& items)
: ITab{ tabSize, items }
{
double posX = 0.0;
for (size_t i = 0; i < items.size(); ++i)
{
m_tabPositions.emplace_back(posX, 0);
posX += (tabSize.x + tabSize.x * 0.14);
}
}
void draw(const Vec2& pos, const Font& font, const ColorF& color, const ColorF& outlineColor) const override
{
const double radius = (m_tabSize.y * 0.25);
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos + m_tabPositions[i]), m_tabSize };
if (i == m_activeIndex)
{
tab.rounded(radius, radius, 0, 0).draw(color);
}
else
{
tab.stretched(-1.5).rounded(radius, radius, 0, 0).drawFrame(3, outlineColor);
}
}
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos + m_tabPositions[i]), m_tabSize };
font(m_items[i]).drawAt(TextStyle::Shadow(Vec2{ 2.5, 2.5 }, ColorF{ 0.0, 0.6 }), 20, tab.center());
}
}
private:
Array<Vec2> m_tabPositions;
};
class TabC : public ITab
{
public:
TabC(const SizeF& tabSize, const Array<String>& items)
: ITab{ tabSize, items } {}
void draw(const Vec2& pos, const Font& font, const ColorF& color, const ColorF& outlineColor) const override
{
constexpr double Thickness = 3.0;
const double radius = (m_tabSize.y * 0.5);
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos.x + i * (m_tabSize.x - Thickness)), pos.y, m_tabSize };
if (i == 0) // ⊂
{
tab.stretched(-Thickness * 0.5).rounded(radius, 0, 0, radius).drawFrame(Thickness, outlineColor);
}
else if (i == (m_items.size() - 1)) // ⊃
{
tab.stretched(-Thickness * 0.5).rounded(0, radius, radius, 0).drawFrame(Thickness, outlineColor);
}
else // □
{
tab.drawFrame(Thickness, 0, outlineColor);
}
}
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos.x + i * (m_tabSize.x - Thickness)), pos.y, m_tabSize };
if (i == m_activeIndex)
{
if (i == 0) // ⊂
{
tab.rounded(radius, 0, 0, radius).draw(color);
}
else if (i == (m_items.size() - 1)) // ⊃
{
tab.rounded(0, radius, radius, 0).draw(color);
}
else // □
{
tab.draw(color);
}
}
}
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos.x + i * (m_tabSize.x - Thickness)), pos.y, m_tabSize };
font(m_items[i]).drawAt(TextStyle::Shadow(Vec2{ 2.5, 2.5 }, ColorF{ 0.0, 0.6 }), 20, tab.center());
}
}
};
class TabD : public ITab
{
public:
TabD(const SizeF& tabSize, const Array<String>& items)
: ITab{ tabSize, items } {}
void draw(const Vec2& pos, const Font& font, const ColorF& color, const ColorF& outlineColor) const override
{
constexpr double Thickness = 3.0;
const double radius = (m_tabSize.y * 0.5);
const double smallRadius = (m_tabSize.y * 0.1);
const double width = ((m_items.size() - 1) * (m_tabSize.x - Thickness) + m_tabSize.x);
RectF{ pos.x, pos.y + 3, width, m_tabSize.y - 6 }.stretched(-Thickness * 0.5).rounded(radius).drawFrame(Thickness, outlineColor);
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab = RectF{ (pos.x + i * (m_tabSize.x - Thickness)), pos.y, m_tabSize.x, m_tabSize.y };
if (i == m_activeIndex)
{
if (i == 0) // ⊂
{
tab.rounded(radius, smallRadius, smallRadius, radius).draw(color);
}
else if (i == (m_items.size() - 1)) // ⊃
{
tab.rounded(smallRadius, radius, radius, smallRadius).draw(color);
}
else // □
{
tab.rounded(smallRadius).draw(color);
}
}
}
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos.x + i * (m_tabSize.x - Thickness)), pos.y, m_tabSize };
font(m_items[i]).drawAt(TextStyle::Shadow(Vec2{ 2.5, 2.5 }, ColorF{ 0.0, 0.6 }), 20, tab.center());
}
}
};
class TabE : public ITab
{
public:
TabE(const SizeF& tabSize, const Array<String>& items)
: ITab{ tabSize, items } {}
void draw(const Vec2& pos, const Font& font, const ColorF& color, const ColorF& outlineColor) const override
{
constexpr double Thickness = 3.0;
const double shear = (m_tabSize.y * 0.2);
const double radius = (m_tabSize.y * 0.5);
const double width = ((m_items.size() - 1) * (m_tabSize.x - Thickness) + m_tabSize.x);
RectF{ pos.x, pos.y + 3, width, m_tabSize.y - 6 }.stretched(-Thickness * 0.5).rounded(radius).drawFrame(Thickness, outlineColor);
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab = RectF{ (pos.x + i * (m_tabSize.x - Thickness)), pos.y, m_tabSize.x, m_tabSize.y };
if (i == m_activeIndex)
{
if (i == 0) // ⊂
{
tab.stretched(0, -shear, 0, 0).rounded(radius, 0, 0, radius).draw(color);
Triangle{ tab.tr().movedBy(-shear, 0), tab.tr().movedBy(shear, 0), tab.br().movedBy(-shear, 0) }.draw(color);
}
else if (i == (m_items.size() - 1)) // ⊃
{
Triangle{ tab.tl().movedBy(shear, 0), tab.bl().movedBy(shear, 0), tab.bl().movedBy(-shear, 0) }.draw(color);
tab.stretched(0, 0, 0, -shear).rounded(0, radius, radius, 0).draw(color);
}
else // □
{
tab.shearedX(shear).draw(color);
}
}
}
for (size_t i = 0; i < m_items.size(); ++i)
{
const RectF tab{ (pos.x + i * (m_tabSize.x - Thickness)), pos.y, m_tabSize };
// 文字を傾かせる
const Transformer2D tr{ Mat3x2::ShearX(0.35).translated(tab.center()) };
font(m_items[i]).drawAt(TextStyle::Shadow(Vec2{ 2.5, 2.5 }, ColorF{ 0.0, 0.6 }), 20, Vec2{ 0, 0 });
}
}
};
void Main()
{
Window::Resize(1280, 720);
const Font font{ FontMethod::MSDF, 48, Typeface::Heavy };
const Array<String> items = { U"ステータス", U"武器", U"装備", U"スキル", U"任務", U"プロフィール" };
constexpr ColorF TabColor{ 0.2, 0.5, 0.9 };
constexpr ColorF TabOutlineColor{ 0.5 };
constexpr ColorF ContentColor{ 0.5 };
TabA tabA{ Size{ 160, 50 }, items };
TabB tabB{ Size{ 160, 50 }, items };
TabC tabC{ Size{ 182, 50 }, items };
TabD tabD{ Size{ 182, 50 }, items };
TabE tabE{ Size{ 182, 50 }, items };
while (System::Update())
{
if (KeyLeft.down())
{
tabA.advance(-1);
tabB.advance(-1);
tabC.advance(-1);
tabD.advance(-1);
tabE.advance(-1);
}
else if (KeyRight.down())
{
tabA.advance(+1);
tabB.advance(+1);
tabC.advance(+1);
tabD.advance(+1);
tabE.advance(+1);
}
tabA.draw(Vec2{ 140, 40 }, font, TabColor, TabOutlineColor);
tabB.draw(Vec2{ 140, 180 }, font, TabColor, TabOutlineColor);
tabC.draw(Vec2{ 140, 310 }, font, TabColor, TabOutlineColor);
tabD.draw(Vec2{ 140, 450 }, font, TabColor, TabOutlineColor);
tabE.draw(Vec2{ 140, 590 }, font, TabColor, TabOutlineColor);
RectF{ 120, 100, 1120, 50 }.draw(ContentColor);
RectF{ 120, 230 - 2, 1120, 50 }.draw(ContentColor);
RectF{ 120, 370, 1120, 50 }.draw(ContentColor);
RectF{ 120, 510, 1120, 50 }.draw(ContentColor);
RectF{ 120, 650, 1120, 50 }.draw(ContentColor);
}
}