blob: 4cbb4f3730e7df31f307fd433c0fe05f32d85452 (
plain)
| 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
 | #pragma once
// ReSharper disable once CppUnusedIncludeDirective
#include "pre.hpp"
#include "ui/control.hpp"
namespace cru::ui::controls
{
    class ToggleButton : public Control
    {
    public:
        static constexpr auto control_type = L"ToggleButton";
        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;
        StringView GetControlType() const override final;
        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 OnDrawContent(ID2D1DeviceContext* device_context) override;
        void OnMouseClickCore(events::MouseButtonEventArgs& args) override;
        Size OnMeasureContent(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_;
    };
}
 |