Repository navigation
Expand file tree
/
Copy pathButtonStyleComponent.h
More file actions
108 lines (88 loc) · 3.41 KB
/
Copy pathButtonStyleComponent.h
File metadata and controls
108 lines (88 loc) · 3.41 KB
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
#pragma once
#include <stdint.h>
#include <deki/Component.h>
#include <deki/assets/AssetRef.h>
#include <deki/reflection/ObjectRef.h>
#include <deki/reflection/Property.h>
#include <deki/Color.h>
#include "Sprite.h"
namespace Deki2D
{
class ButtonComponent;
class SpriteComponent;
enum class ButtonState : uint8_t;
/// How ButtonStyleComponent shows a state change.
enum class ButtonStyleMode : uint8_t
{
ColorTint = 0, // Tint the existing sprite per state
SpriteSwap = 1 // Use a different sprite asset per state
};
/// Visual feedback for a button. Watches the ButtonComponent named by `button`
/// and changes the SpriteComponent named by `sprite` to match its state,
/// either by tinting it (ColorTint) or by swapping its sprite (SpriteSwap).
///
/// Example:
///
/// auto* entity = new Deki::Object("StyledButton");
/// auto* sprite = entity->AddComponent<SpriteComponent>();
/// auto* button = entity->AddComponent<ButtonComponent>();
/// auto* style = entity->AddComponent<ButtonStyleComponent>();
/// style->button.Set(entity); // required
/// style->normalColor = Deki::Color::White;
/// style->pressedColor = Deki::Color(160, 160, 160);
DEKI_CATEGORY("2D")
DEKI_DESCRIPTION("Gives a button its look per state, by tinting or by swapping sprites.")
class ButtonStyleComponent : public Deki::Component
{
public:
// Required
DEKI_EXPORT
DEKI_TOOLTIP("The button whose state drives this styling. Usually the button on the same object.")
Deki::ObjectRef<ButtonComponent> button;
DEKI_EXPORT
DEKI_TOOLTIP("The sprite this styling changes. Usually the sprite on the same object.")
Deki::ObjectRef<SpriteComponent> sprite;
DEKI_EXPORT
DEKI_TOOLTIP("Whether pressing swaps the tint colour or swaps the sprite outright. Colour is cheaper; separate "
"sprites let the shape change.")
ButtonStyleMode transition;
// ColorTint mode colours
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
DEKI_TOOLTIP("Tint while the button is idle.")
Deki::Color normalColor;
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
DEKI_TOOLTIP("Tint while the pointer is over it. On a touch-only device this is rarely seen.")
Deki::Color hoveredColor;
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
DEKI_TOOLTIP("Tint while it is held down. This is the feedback that tells someone the press registered.")
Deki::Color pressedColor;
DEKI_VISIBLE_WHEN(transition, ColorTint)
DEKI_EXPORT
DEKI_TOOLTIP("Tint while the button is disabled. Usually faded or desaturated.")
Deki::Color disabledColor;
// SpriteSwap mode sprites
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
DEKI_TOOLTIP("Sprite while idle, in sprite-swap mode.")
Deki::AssetRef<Sprite> normalSprite;
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
DEKI_TOOLTIP("Sprite while hovered, in sprite-swap mode.")
Deki::AssetRef<Sprite> hoveredSprite;
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
DEKI_TOOLTIP("Sprite while held, in sprite-swap mode.")
Deki::AssetRef<Sprite> pressedSprite;
DEKI_VISIBLE_WHEN(transition, SpriteSwap)
DEKI_EXPORT
DEKI_TOOLTIP("Sprite while disabled, in sprite-swap mode.")
Deki::AssetRef<Sprite> disabledSprite;
ButtonStyleComponent();
void Start() override;
private:
void ApplyState(ButtonState state);
};
} // namespace Deki2D