about summary refs log tree commit diff stats
path: root/eye_indicator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'eye_indicator.cpp')
-rw-r--r--eye_indicator.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/eye_indicator.cpp b/eye_indicator.cpp new file mode 100644 index 0000000..c490589 --- /dev/null +++ b/eye_indicator.cpp
@@ -0,0 +1,47 @@
1#include "eye_indicator.h"
2
3EyeIndicator::EyeIndicator(wxWindow* parent) : wxWindow(parent, wxID_ANY) {
4 SetMinSize({32, 32});
5
6 Redraw();
7
8 Bind(wxEVT_PAINT, &EyeIndicator::OnPaint, this);
9}
10
11void EyeIndicator::SetChecked(bool checked) {
12 if (intended_checked_ != checked) {
13 intended_checked_ = checked;
14
15 Redraw();
16 }
17}
18
19const wxImage& EyeIndicator::GetUncheckedImage() {
20 static wxImage* unchecked_image =
21 new wxImage("assets/unchecked.png", wxBITMAP_TYPE_PNG);
22 return *unchecked_image;
23}
24
25const wxImage& EyeIndicator::GetCheckedImage() {
26 static wxImage* checked_image =
27 new wxImage("assets/checked.png", wxBITMAP_TYPE_PNG);
28 return *checked_image;
29}
30
31void EyeIndicator::OnPaint(wxPaintEvent& event) {
32 if (GetSize() != rendered_.GetSize() ||
33 intended_checked_ != rendered_checked_) {
34 Redraw();
35 }
36
37 wxPaintDC dc(this);
38 dc.DrawBitmap(rendered_, 0, 0);
39}
40
41void EyeIndicator::Redraw() {
42 rendered_ =
43 wxBitmap((intended_checked_ ? GetCheckedImage() : GetUncheckedImage())
44 .Scale(GetSize().GetWidth(), GetSize().GetHeight(),
45 wxIMAGE_QUALITY_NORMAL));
46 rendered_checked_ = intended_checked_;
47}