about summary refs log tree commit diff stats
path: root/src/eye_indicator.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-05-05 15:46:58 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-05-05 15:46:58 -0400
commit149e7c0836927e14a926a952bd1a7f0d1b49e779 (patch)
tree2c7ac89387eb890d3d345217b79929e9a23f4ecf /src/eye_indicator.cpp
parent0dace7831673170bd31eefa6bbe6e705211d3061 (diff)
downloadlingo-ap-tracker-149e7c0836927e14a926a952bd1a7f0d1b49e779.tar.gz
lingo-ap-tracker-149e7c0836927e14a926a952bd1a7f0d1b49e779.tar.bz2
lingo-ap-tracker-149e7c0836927e14a926a952bd1a7f0d1b49e779.zip
Organised repo
Diffstat (limited to 'src/eye_indicator.cpp')
-rw-r--r--src/eye_indicator.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/eye_indicator.cpp b/src/eye_indicator.cpp new file mode 100644 index 0000000..03e234e --- /dev/null +++ b/src/eye_indicator.cpp
@@ -0,0 +1,49 @@
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 event.Skip();
41}
42
43void EyeIndicator::Redraw() {
44 rendered_ =
45 wxBitmap((intended_checked_ ? GetCheckedImage() : GetUncheckedImage())
46 .Scale(GetSize().GetWidth(), GetSize().GetHeight(),
47 wxIMAGE_QUALITY_NORMAL));
48 rendered_checked_ = intended_checked_;
49}