-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHighscoreWindow.cpp
71 lines (55 loc) · 1.62 KB
/
HighscoreWindow.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
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
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <sstream>
#include "GameWindow.h"
#include "HighscoreWindow.h"
// コンストラクタ
HighscoreWindow::HighscoreWindow(GameWindow *g) :
Fl_Window(400, 140, "Highscores"), game(g)
{
set_modal();
begin();
label = new Fl_Box(20, 20, 120, 60);
label->label("Beginner:\nIntermediate:\nAdvanced:");
label->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
score = new Fl_Box(160, 20, 60, 60, "");
score->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
name = new Fl_Box(240, 20, 140, 60, "");
name->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
clear = new Fl_Button(60, 100, 140, 25, "Clear Highscore");
clear->callback(cb_clear, this);
ok = new Fl_Button(260, 100, 80, 25, "OK");
ok->callback(cb_close, this);
ok->take_focus();
update_score();
end();
show();
}
// 表示を更新
void HighscoreWindow::update_score()
{
std::ostringstream str1;
str1 << game->sfile.beg_score.score << "\n"
<< game->sfile.int_score.score << "\n"
<< game->sfile.adv_score.score;
score->copy_label(str1.str().c_str());
std::ostringstream str2;
str2 << game->sfile.beg_score.name << "\n"
<< game->sfile.int_score.name << "\n"
<< game->sfile.adv_score.name;
name->copy_label(str2.str().c_str());
}
// コールバック(close)
void HighscoreWindow::cb_close(Fl_Widget *w, void *p)
{
HighscoreWindow *hw = static_cast<HighscoreWindow*>(p);
hw->hide();
}
// コールバック(clear)
void HighscoreWindow::cb_clear(Fl_Widget *w, void *p)
{
HighscoreWindow *hw = static_cast<HighscoreWindow*>(p);
hw->game->reset_score();
hw->update_score();
}