-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasedWindow.cpp
More file actions
128 lines (115 loc) · 4.27 KB
/
BasedWindow.cpp
File metadata and controls
128 lines (115 loc) · 4.27 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "pch.h"
#include "BasedWindow.h"
constexpr wxWindowID ID_RESULT = 900;
BasedWindow::BasedWindow()
: wxFrame(NULL, wxID_ANY, "Based")
, m_scores{ 0 }
, m_but{ nullptr }
, m_butState{ false }
, m_board{ "bingo_politics.png", wxBITMAP_TYPE_PNG }
{
InitMenu();
ParseBingo(m_board);
wxFlexGridSizer* fgs = new wxFlexGridSizer(18, 17, 0, 0);
int id = 0;
for(int i = 0; i < 17; ++i) {
for(int j = 0; j < 17; ++j) {
m_but[i][j] = new wxBitmapButton(this, id++, m_bitmaps[i][j]);
fgs->Add(m_but[i][j], 1, wxEXPAND | wxALL, 0);
Bind(wxEVT_BUTTON, &BasedWindow::OnPress, this, id - 1);
}
}
fgs->Add(new wxButton(this, ID_RESULT, "Get score"));
SetSizer(fgs);
Fit();
Center();
}
void BasedWindow::ParseBingo(wxImage& img) {
double width = double(img.GetWidth()) / 17.0;
double height = double(img.GetHeight()) / 17.0;
for(int i = 1; i <= 17; ++i) {
for(int j = 1; j <= 17; ++j) {
auto sub = img.GetSubImage(
{
wxPoint{int((j-1) * width), int((i-1) * height)},
wxPoint{int(j * width), int(i * height)},
});
sub.Rescale(100, 100, wxIMAGE_QUALITY_HIGH);
m_bitmaps[i-1][j-1] = sub;
}
}
}
constexpr inline static std::array<std::array<int,17>,17> scores{
{
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, 2, 2, -1, 2, 2, 1, 0, 2, 2, -1 },
{ -1, -1, -1, -1, -1, -1, 2, 1, 2, 2, 2, 2, 2, 2, 2, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, -1, 2, -1, 1, -1, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, 2, 2, 1, 2, 2, 2, 2, 2, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 2, -1, 2, 2, 2, 1, -1 },
{ -1, -1, -1, 2, -1, -1, -1, -1, 0, 2, 2, 2, 1, 1, 2, 1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 1, -1, 2, 1, 2, -1 },
{ -1, -1, -1, 2, -1, 2, 2, 0, 0, 0, 1, 2, 2, 2, 1, 1, -1 },
{ -1, -1, -1, -1, -1, -1, 1, -1, 0, 2, 0, 1, 2, 1, 2, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 2, -1, 2, 2, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, 1, 1, -1, 1, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 1, 1, -1, 1, 0, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, -1, -1, -1, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, 1, 1, -1, -1, 2, -1 },
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }
}
};
constexpr static int GetSum() {
int sum = 0;
for(auto& arr : scores) {
for(auto& val : arr) {
if(val > 0) {
sum += val;
}
}
}
return sum;
}
void BasedWindow::OnPress(wxCommandEvent& event) {
auto id = event.GetId();
auto ind1 = id / 17;
auto ind2 = id % 17;
if(!m_butState[ind1][ind2]) {
m_scores += scores[ind1][ind2];
m_but[ind1][ind2]->SetBitmap(
m_bitmaps[ind1][ind2].Scale(75, 75, wxIMAGE_QUALITY_HIGH)
);
} else {
m_scores -= scores[ind1][ind2];
m_but[ind1][ind2]->SetBitmap(m_bitmaps[ind1][ind2]);
}
m_butState[ind1][ind2] = !m_butState[ind1][ind2];
}
void BasedWindow::OnGetResult(wxCommandEvent& event) {
wxString disp;
if(m_scores > 0) {
disp= wxString::Format(
"Your based score is: %d / %d",
m_scores, GetSum()
);
} else if(m_scores < 0) {
disp = wxString::Format("You are very cringe. Based score of: %d", m_scores);
} else {
disp = "True neutral";
}
wxMessageBox(disp, "Results");
}
void BasedWindow::InitMenu() {
wxMenu* menuFile = new wxMenu();
menuFile->Append(wxID_EXIT);
wxMenuBar* menuBar = new wxMenuBar();
menuBar->Append(menuFile, "&File");
SetMenuBar(menuBar);
CreateStatusBar();
SetStatusText("How based are you?");
Bind(wxEVT_MENU, [&](wxCommandEvent&) { Close(true); });
}
BEGIN_EVENT_TABLE(BasedWindow, wxFrame)
EVT_BUTTON(ID_RESULT, BasedWindow::OnGetResult)
END_EVENT_TABLE()