-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathScoreHistogram.cpp
42 lines (34 loc) · 1.15 KB
/
ScoreHistogram.cpp
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
#include "ScoreHistogram.h"
#include "MainFrame.h"
#include "TScorePanel.h"
std::vector<std::tuple<int, float, float, float>> ScoreHistogram::m_scores;
ScoreHistogram::ScoreHistogram( wxWindow* parent )
:
TScoreHistogram( parent )
{
Bind(wxEVT_EVALUATION_UPDATE, &ScoreHistogram::doNewScore, this);
Bind(wxEVT_SET_MOVENUM, [=](wxCommandEvent& event) {
m_DrawPanel->GetEventHandler()->AddPendingEvent(event);
});
wxPersistentRegisterAndRestore(this, "ScoreHistogram");
}
void ScoreHistogram::doNewScore(wxCommandEvent& event) {
if (!event.GetClientData()) return;
auto score_data = reinterpret_cast<std::tuple<int, float, float, float>*>(event.GetClientData());
std::unique_ptr<std::remove_pointer<decltype(score_data)>::type> scores(score_data);
int movenum = std::get<0>(*scores);
auto it = std::find_if(m_scores.begin(), m_scores.end(),
[=](auto const& n) {
return std::get<0>(n) == movenum;
}
);
if (it != m_scores.end()) {
*it = *scores;
} else {
m_scores.push_back(*scores);
}
Refresh();
}
void ScoreHistogram::ClearHistogram() {
m_scores.clear();
}