Polyphase Game Engine
Loading...
Searching...
No Matches
Slider.h
Go to the documentation of this file.
1#pragma once
2
4
5class Texture;
6class Quad;
7
9{
10public:
11
13
14 virtual void Create() override;
15 virtual void GatherProperties(std::vector<Property>& props) override;
16 virtual void Tick(float deltaTime) override;
17 virtual void PreRender() override;
18
19 void SetValue(float value);
20 float GetValue() const;
21 void SetMinValue(float minValue);
22 float GetMinValue() const;
23 void SetMaxValue(float maxValue);
24 float GetMaxValue() const;
25 void SetStep(float step);
26 float GetStep() const;
27 void SetRange(float minValue, float maxValue);
28
29 void SetBackgroundTexture(Texture* texture);
30 Texture* GetBackgroundTexture();
31 void SetGrabberTexture(Texture* texture);
32 Texture* GetGrabberTexture();
33
34 void SetBackgroundColor(glm::vec4 color);
35 glm::vec4 GetBackgroundColor();
36 void SetGrabberColor(glm::vec4 color);
37 glm::vec4 GetGrabberColor();
38 void SetGrabberHoveredColor(glm::vec4 color);
39 glm::vec4 GetGrabberHoveredColor();
40 void SetGrabberPressedColor(glm::vec4 color);
41 glm::vec4 GetGrabberPressedColor();
42
43 void SetGrabberWidth(float width);
44 float GetGrabberWidth() const;
45 void SetTrackHeight(float height);
46 float GetTrackHeight() const;
47
48 bool IsDragging() const;
49
50 Quad* GetBackground();
51 Quad* GetGrabber();
52
53protected:
54
55 static bool HandlePropChange(Datum* datum, uint32_t index, const void* newValue);
56
57 void UpdateAppearance();
58 void UpdateGrabberPosition();
59 float GetValueFromPosition(float x);
60 float GetValueRatio() const;
61 float SnapToStep(float value);
62
63 // Value
64 float mValue = 0.0f;
65 float mMinValue = 0.0f;
66 float mMaxValue = 1.0f;
67 float mStep = 0.0f;
68
69 // Visual
72 glm::vec4 mBackgroundColor = { 0.3f, 0.3f, 0.3f, 1.0f };
73 glm::vec4 mGrabberColor = { 0.7f, 0.7f, 0.7f, 1.0f };
74 glm::vec4 mGrabberHoveredColor = { 0.8f, 0.8f, 0.8f, 1.0f };
75 glm::vec4 mGrabberPressedColor = { 0.6f, 0.6f, 0.6f, 1.0f };
76 float mGrabberWidth = 20.0f;
77 float mTrackHeight = 8.0f;
78
79 // State
80 bool mDragging = false;
81 bool mGrabberHovered = false;
82
83 // Children
84 Quad* mBackground = nullptr;
85 Quad* mGrabber = nullptr;
86};
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition AssetRef.h:18
Definition Datum.h:164
virtual void Create()
Definition Node.cpp:220
virtual void Tick(float deltaTime)
Definition Node.cpp:558
Definition Quad.h:20
Definition Slider.h:9
DECLARE_NODE(Slider, Widget)
TextureRef mBackgroundTexture
Definition Slider.h:70
TextureRef mGrabberTexture
Definition Slider.h:71
Definition Texture.h:10
Definition Widget.h:53
static bool HandlePropChange(Datum *datum, uint32_t index, const void *newValue)
Definition Widget.cpp:45
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Widget.cpp:115
virtual void PreRender()
Definition Widget.cpp:226