-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeumorphismUI.hpp
583 lines (489 loc) · 20.9 KB
/
NeumorphismUI.hpp
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
//
// NeumorphismUI
//
// ver.0.1.1
//
// (C) YotioSoft 2020-2021
//
#ifndef NeumorphismUI_hpp
#define NeumorphismUI_hpp
#include <Siv3D.hpp> // OpenSiv3D v0.6.0 or later
#define DEFAULT_BACKGROUND_COLOR Color(224, 229, 236)
#define DEFAULT_SHADOW_COLOR Color(163, 177, 198)
#define DEFAULT_LIGHT_COLOR Color(255, 255, 255)
namespace NeumorphismUI {
// 角丸長方形スイッチ
void RectSwitch(int argPositionX, int argPositionY,
int argSizeX, int argSizeY,
bool& argVar,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
Mat3x2 mat;
RoundRect switchRect(argPositionX, argPositionY, argSizeX, argSizeY, argRadius);
// マウスオーバー時にマウスポインタを変更
if (switchRect.mouseOver()) {
Cursor::RequestStyle(CursorStyle::Hand);
}
// クリックされたら状態を切り替え
bool isClicked = switchRect.leftClicked();
if (isClicked) {
argVar = !argVar;
}
// ONの時の表示
if (argVar) {
switchRect.drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Scale(0.9, Point(argPositionX+argSizeX/2, argPositionY+argSizeY/2));
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX+argSizeX/2, argPositionY+argSizeY/2, argPushedFontColor);
}
}
}
// OFFの時の表示
else {
switchRect.drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Identity();
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX+argSizeX/2, argPositionY+argSizeY/2, argFontColor);
}
}
}
}
void RectSwitch(Vec2 argPosition,
int argSizeX, int argSizeY,
bool& argVar,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
RectSwitch(argPosition.x, argPosition.y, argSizeX, argSizeY, argVar, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argRadius, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
void RectSwitch(int argPositionX, int argPositionY,
Vec2 argSize,
bool& argVar,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
RectSwitch(argPositionX, argPositionY, argSize.x, argSize.y, argVar, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argRadius, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
void RectSwitch(Vec2 argPosition,
Vec2 argSize,
bool& argVar,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
RectSwitch(argPosition.x, argPosition.y, argSize.x, argSize.y, argVar, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argRadius, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
// 角丸長方形ボタン
int RectButton(int argPositionX, int argPositionY,
int argSizeX, int argSizeY,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
Mat3x2 mat;
RoundRect buttonRect(argPositionX, argPositionY, argSizeX, argSizeY, argRadius);
// マウスオーバー時にマウスポインタを変更
if (buttonRect.mouseOver()) {
Cursor::RequestStyle(CursorStyle::Hand);
}
bool clicked = buttonRect.leftClicked();
// 押下時の表示
if (buttonRect.leftPressed()) {
buttonRect.drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Scale(0.9, Point(argPositionX+argSizeX/2, argPositionY+argSizeY/2));
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX+argSizeX/2, argPositionY+argSizeY/2, argPushedFontColor);
}
}
}
// 押下時以外の表示
else {
buttonRect.drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Identity();
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX+argSizeX/2, argPositionY+argSizeY/2, argFontColor);
}
}
}
return clicked;
}
int RectButton(Vec2 argPosition,
int argSizeX, int argSizeY,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
return RectButton(argPosition.x, argPosition.y, argSizeX, argSizeY, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argRadius, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
int RectButton(int argPositionX, int argPositionY,
Vec2 argSize,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
return RectButton(argPositionX, argPositionY, argSize.x, argSize.y, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argRadius, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
int RectButton(Vec2 argPosition,
Vec2 argSize,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argRadius = 10, int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
return RectButton(argPosition.x, argPosition.y, argSize.x, argSize.y, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argRadius, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
// 丸型スイッチ
void CircleSwitch(int argPositionX, int argPositionY,
int argSize,
bool& argVar,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
Mat3x2 mat;
Circle switchCircle(argPositionX, argPositionY, argSize);
// マウスオーバー時にマウスポインタを変更
if (switchCircle.mouseOver()) {
Cursor::RequestStyle(CursorStyle::Hand);
}
// クリックされたら状態を切り替え
bool isClicked = switchCircle.leftClicked();
if (isClicked) {
argVar = !argVar;
}
// ONの時の表示
if (argVar) {
switchCircle.drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Scale(0.9, Point(argPositionX, argPositionY));
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX, argPositionY, argPushedFontColor);
}
}
}
// OFFの時の表示
else {
switchCircle.drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Identity();
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX, argPositionY, argFontColor);
}
}
}
}
void CircleSwitch(Vec2 argPosition,
int argSize,
bool& argVar,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
CircleSwitch(argPosition.x, argPosition.y, argSize, argVar, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
// 丸型ボタン
int CircleButton(int argPositionX, int argPositionY,
int argSize,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
Mat3x2 mat;
Circle buttonCircle(argPositionX, argPositionY, argSize);
// マウスオーバー時にマウスポインタを変更
if (buttonCircle.mouseOver()) {
Cursor::RequestStyle(CursorStyle::Hand);
}
bool clicked = buttonCircle.leftClicked();
// 押下時の表示
if (buttonCircle.leftPressed()) {
buttonCircle.drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Scale(0.9, Point(argPositionX, argPositionY));
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX, argPositionY, argPushedFontColor);
}
}
}
// 押下時以外の表示
else {
buttonCircle.drawShadow(argLowerShadowPosOffset, argBlurSize, argShadowSize, argDarkColor).drawShadow(argUpperShadowPosOffset, argBlurSize, argShadowSize, argLightColor).draw(argBackgroundColor);
mat = Mat3x2::Identity();
if (!argFont.isEmpty()) {
{
// 座標変換行列を適用
const Transformer2D t(mat, TransformCursor::No);
argFont(argStr).drawAt(argPositionX, argPositionY, argFontColor);
}
}
}
return clicked;
}
int CircleButton(Vec2 argPosition,
int argSize,
String argStr, Font& argFont,
Color argBackgroundColor = DEFAULT_BACKGROUND_COLOR, Color argDarkColor = DEFAULT_SHADOW_COLOR, Color argLightColor = DEFAULT_LIGHT_COLOR,
Color argFontColor = Palette::Gray, Color argPushedFontColor = Palette::Gray,
int argBlurSize = 16, int argShadowSize = 2,
Vec2 argUpperShadowPosOffset = {-4, -4}, Vec2 argLowerShadowPosOffset = {4, 4})
{
return CircleButton(argPosition.x, argPosition.y, argSize, argStr, argFont, argBackgroundColor, argDarkColor, argLightColor, argFontColor, argPushedFontColor, argBlurSize, argShadowSize, argUpperShadowPosOffset, argLowerShadowPosOffset);
}
// スライドスイッチ
class SlideSwitch {
public:
SlideSwitch(bool argVar, int argPositionX, int argPositionY, int argSizeW, int argSizeH) {
init(argVar, argPositionX, argPositionY, argSizeW, argSizeH);
}
SlideSwitch(bool argVar, int argPositionX, int argPositionY, Vec2 argSize) {
init(argVar, argPositionX, argPositionY, argSize.x, argSize.y);
}
SlideSwitch(bool argVar, Vec2 argPosition, int argSizeW, int argSizeH) {
init(argVar, argPosition.x, argPosition.y, argSizeW, argSizeH);
}
SlideSwitch(bool argVar, Vec2 argPosition, Vec2 argSize) {
init(argVar, argPosition.x, argPosition.y, argSize.x, argSize.y);
}
bool draw() {
switchRect
.drawShadow(lowerShadowPosOffset, blurSize, shadowSize, darkShadow)
.drawShadow(upperShadowPosOffset, blurSize, shadowSize, lightShadow)
.draw(background); // スイッチの外枠
innerSliderRect
.drawShadow(upperShadowPosOffset, blurSize, shadowSize, darkShadow)
.drawShadow(lowerShadowPosOffset, blurSize, shadowSize, lightShadow)
.draw(background); // スイッチの内枠
knobCircle = Circle(position.x+10/2+knobX, position.y+10/2+(size.y-10)/2, (size.y-10/2)/2);
knobCircle.drawShadow(Vec2{0, 0}, blurSize, shadowSize, darkShadow);
barRect = RoundRect(position.x+10/2, position.y+10/2, knobX, size.y-10, size.y/2);
barRect.draw(Color(52, 152, 219));
knobCircle.draw(background);
// マウスオーバー時にマウスポインタを変更
if (knobCircle.mouseOver() || barRect.mouseOver() || innerSliderRect.mouseOver()) {
Cursor::RequestStyle(CursorStyle::Hand);
}
// 押されたら状態変更
if (knobCircle.leftClicked() || barRect.leftClicked() || innerSliderRect.leftClicked()) {
b = !b;
sliding = true;
slidingCount = 0.0;
}
// スライド中の動作
if (sliding) {
slidingCount += 0.1;
if (slidingCount > Math::Pi/2) {
sliding = false;
}
else {
if (b) {
knobX = sin(slidingCount)*(size.x-10);
}
else {
knobX = (size.x-10) - sin(slidingCount)*(size.x-10);
}
}
}
return b;
}
private:
bool b;
bool sliding;
Vec2 upperShadowPosOffset;
Vec2 lowerShadowPosOffset;
int blurSize;
int shadowSize;
Vec2 position;
Size size;
Color background;
Color darkShadow;
Color lightShadow;
RoundRect switchRect;
RoundRect innerSliderRect;
RoundRect barRect;
Circle knobCircle;
int knobX;
double slidingCount;
// コンストラクタから呼び出す
void init(bool argBool, int argPositionX, int argPositionY, int argSizeW, int argSizeH) {
upperShadowPosOffset = {-4, -4};
lowerShadowPosOffset = {4, 4};
blurSize = 16;
shadowSize = 2;
b = argBool;
position.x = argPositionX;
position.y = argPositionY;
size.x = argSizeW;
size.y = argSizeH;
background = Color(224, 229, 236);
darkShadow = Color(163, 177, 198);
lightShadow = Color(255, 255, 255);
sliding = false;
knobX = b*(argSizeW-10);
switchRect = RoundRect(position, size, size.y/2);
innerSliderRect = RoundRect(position.x+10/2, position.y+10/2, size.x-10, size.y-10, (size.y-10)/2);
}
};
// スライダー
class Slider {
public:
Slider(double argVar, int argPositionX, int argPositionY, int argSizeW, int argSizeH) {
init(argVar, argPositionX, argPositionY, argSizeW, argSizeH);
}
Slider(double argVar, int argPositionX, int argPositionY, Vec2 argSize) {
init(argVar, argPositionX, argPositionY, argSize.x, argSize.y);
}
Slider(double argVar, Vec2 argPosition, int argSizeW, int argSizeH) {
init(argVar, argPosition.x, argPosition.y, argSizeW, argSizeH);
}
Slider(double argVar, Vec2 argPosition, Vec2 argSize) {
init(argVar, argPosition.x, argPosition.y, argSize.x, argSize.y);
}
double draw() {
sliderRect
.drawShadow(lowerShadowPosOffset, blurSize, shadowSize, darkShadow)
.drawShadow(upperShadowPosOffset, blurSize, shadowSize, lightShadow)
.draw(background); // スイッチの外枠
innerSliderRect
.drawShadow(upperShadowPosOffset, blurSize, shadowSize, darkShadow)
.drawShadow(lowerShadowPosOffset, blurSize, shadowSize, lightShadow)
.draw(background); // スイッチの内枠
knobCircle = Circle(position.x+10/2+knobX, position.y+10/2+(size.y-10)/2, (size.y-10/2)/2);
knobCircle.drawShadow(Vec2{0, 0}, blurSize, shadowSize, darkShadow);
barRect = RoundRect(position.x+10/2, position.y+10/2, knobX, size.y-10, size.y/2);
barRect.draw(Color(52, 152, 219));
knobCircle.draw(background);
// マウスオーバー時にマウスポインタを変更
if (knobCircle.mouseOver() || barRect.mouseOver() || innerSliderRect.mouseOver()) {
Cursor::RequestStyle(CursorStyle::Hand);
}
// クリックされたら状態変更
if (knobCircle.leftPressed() || barRect.leftPressed() || innerSliderRect.leftPressed() || knobClicked) {
if (knobCircle.leftPressed()) {
knobClicked = true;
}
// マウスがクリックされっぱなしのときにスライドし続ける
if (barRect.leftPressed() || innerSliderRect.leftPressed()) {
beforeX = knobX;
clickedX = Cursor::Pos().x-position.x+10/2;
sliding = true;
slidingCount = 0.0;
}
value = (Cursor::Pos().x-position.x-10/2)/(size.x-10);
if (value > 1.0) {
value = 1.0;
}
if (value < 0.0) {
value = 0.0;
}
}
if (knobClicked && !MouseL.pressed()) {
knobClicked = false;
}
// スライド中の動作
if (sliding) {
slidingCount += 0.2;
if (slidingCount > Math::Pi/2) {
slidingCount = 0;
sliding = false;
}
else {
if (beforeX > clickedX) {
knobX = beforeX - sin(slidingCount)*(beforeX-clickedX+(size.y-10)/2);
}
else {
knobX = beforeX + sin(slidingCount)*(clickedX-beforeX-(size.y-10)/2);
}
}
}
if (knobClicked) {
knobX = value*(size.x-10);
}
return value;
}
private:
RoundRect sliderRect;
RoundRect innerSliderRect;
RoundRect barRect;
Circle knobCircle;
bool knobClicked;
bool sliding;
double value;
Vec2 upperShadowPosOffset;
Vec2 lowerShadowPosOffset;
int blurSize;
int shadowSize;
Vec2 position;
Size size;
Color background;
Color darkShadow;
Color lightShadow;
int knobX;
int clickedX;
int beforeX;
double slidingCount;
// コンストラクタから呼び出す
void init(double argRet, int argPositionX, int argPositionY, int argSizeW, int argSizeH) {
upperShadowPosOffset = {-4, -4};
lowerShadowPosOffset = {4, 4};
blurSize = 16;
shadowSize = 2;
value = argRet;
position.x = argPositionX;
position.y = argPositionY;
size.x = argSizeW;
size.y = argSizeH;
background = Color(224, 229, 236);
darkShadow = Color(163, 177, 198);
lightShadow = Color(255, 255, 255);
sliderRect = RoundRect(argPositionX, argPositionY, argSizeW, argSizeH, argSizeH/2);
innerSliderRect = RoundRect(argPositionX+10/2, argPositionY+10/2, argSizeW-10, argSizeH-10, (argSizeH-10)/2);
knobClicked = false;
sliding = false;
knobX = (size.x-10)*value;
}
};
}
#endif /* NeumorphismUI_hpp */