diff options
author | crupest <crupest@outlook.com> | 2018-09-25 13:37:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-25 13:37:33 +0800 |
commit | ccbc293c0158d4450c0db344474193f17925403f (patch) | |
tree | 1ecde3132b3299ab2f272f541a76bced67f983b1 /src/ui/controls/toggle_button.h | |
parent | 184c3b2b39d3fa34f9349a7d7fbebe49bc62f7fc (diff) | |
parent | ea4b0966d8eb5a8e76dfbe4d833a07a4797a3284 (diff) | |
download | cru-ccbc293c0158d4450c0db344474193f17925403f.tar.gz cru-ccbc293c0158d4450c0db344474193f17925403f.tar.bz2 cru-ccbc293c0158d4450c0db344474193f17925403f.zip |
Merge branch 'master' into issue4-dev
Diffstat (limited to 'src/ui/controls/toggle_button.h')
-rw-r--r-- | src/ui/controls/toggle_button.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/ui/controls/toggle_button.h b/src/ui/controls/toggle_button.h new file mode 100644 index 00000000..d496f21a --- /dev/null +++ b/src/ui/controls/toggle_button.h @@ -0,0 +1,61 @@ +#pragma once + +#include "ui/control.h" + +namespace cru::ui::controls +{ + class ToggleButton : public Control + { + public: + static ToggleButton* Create() + { + return new ToggleButton(); + } + + protected: + ToggleButton(); + + public: + ToggleButton(const ToggleButton& other) = delete; + ToggleButton(ToggleButton&& other) = delete; + ToggleButton& operator=(const ToggleButton& other) = delete; + ToggleButton& operator=(ToggleButton&& other) = delete; + ~ToggleButton() override = default; + + bool IsPointInside(const Point& point) override; + + bool GetState() const + { + return state_; + } + + void SetState(bool state); + + void Toggle(); + + public: + events::ToggleEvent toggle_event; + + protected: + virtual void OnToggle(events::ToggleEventArgs& args); + + protected: + void OnDraw(ID2D1DeviceContext* device_context) override; + + void OnMouseClickCore(events::MouseButtonEventArgs& args) override; + + Size OnMeasure(const Size& available_size) override; + + private: + void RaiseToggleEvent(bool new_state); + + private: + bool state_ = false; + + float current_circle_position_; + + Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> frame_path_; + Microsoft::WRL::ComPtr<ID2D1Brush> on_brush_; + Microsoft::WRL::ComPtr<ID2D1Brush> off_brush_; + }; +} |