aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/button.cpp
blob: 0422506bf3955338d3a6051e7efae4d15bba8ccb (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
#include "button.hpp"

#include "graph/graph.hpp"

namespace cru::ui::controls
{
    using graph::CreateSolidBrush;

    Button::Button() : Control(true),
        normal_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue))},
        pressed_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue))}
    {
        normal_border_.SetStrokeWidth(2);
        normal_border_.SetRadiusX(6);
        normal_border_.SetRadiusY(6);

        pressed_border_.SetStrokeWidth(2);
        pressed_border_.SetRadiusX(6);
        pressed_border_.SetRadiusY(6);

        SetBordered(true);
        GetBorderProperty() = normal_border_;

        SetCursor(cursors::hand);
    }

    StringView Button::GetControlType() const
    {
        return control_type;
    }

    void Button::OnMouseClickBegin(MouseButton button)
    {
        GetBorderProperty() = pressed_border_;
        InvalidateBorder();
    }

    void Button::OnMouseClickEnd(MouseButton button)
    {
        GetBorderProperty() = normal_border_;
        InvalidateBorder();
    }
}