aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/button.cpp
blob: 630c0c39f91b4f6bb34a552b30a68f5e4e8097c9 (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.h"

#include "graph/graph.h"

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

    Button::Button() : Control(true)
    {
        normal_border_border_ = BorderProperty::Create();
        normal_border_border_->SetBrush(CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue)));
        normal_border_border_->SetWidth(2);
        normal_border_border_->SetRadiusX(6);
        normal_border_border_->SetRadiusY(6);

        pressed_border_border_ = BorderProperty::Create();
        pressed_border_border_->SetBrush(CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue)));
        pressed_border_border_->SetWidth(2);
        pressed_border_border_->SetRadiusX(6);
        pressed_border_border_->SetRadiusY(6);

        border_delegate_ = std::make_unique<BorderDelegate>(this, normal_border_border_);
    }

    void Button::OnDraw(ID2D1DeviceContext* device_context)
    {
        Control::OnDraw(device_context);
        border_delegate_->Draw(device_context, GetSize());
    }

    void Button::OnMouseClickBegin(MouseButton button)
    {
        border_delegate_->SetBorderProperty(pressed_border_border_);
        Repaint();
    }

    void Button::OnMouseClickEnd(MouseButton button)
    {
        border_delegate_->SetBorderProperty(normal_border_border_);
        Repaint();
    }
}