4 #include "resolution.h"
5 #include "top10scorescreen.h"
11 #define SCORE_X (LOGICAL_SCREEN_WIDTH - 72)
12 #define SONG_MAX_WIDTH (LOGICAL_SCREEN_WIDTH - 480)
14 Top10ScoreScreen::Top10ScoreScreen(pqxx::connection &conn, unsigned tournament)
15 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
19 Top10ScoreScreen::~Top10ScoreScreen()
23 bool Top10ScoreScreen::check_invalidated()
27 if (!scores_changed.get_flag())
29 scores_changed.reset_flag();
31 // check that there are indeed changes, otherwise don't bother
32 std::vector<TopScore> scores;
33 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
35 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
36 if (seen_topscore.count(*i) == 0) {
45 void Top10ScoreScreen::draw(unsigned char *buf, unsigned width, unsigned height)
47 scores_changed.reset_flag();
48 memset(buf, 0, width * height * 4);
49 set_screen_size(width, height);
51 // fetch the top 10 scores
52 std::vector<TopScore> scores;
53 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
56 unsigned width = my_draw_text("Today's top 10 scores", NULL, 40.0);
57 my_draw_text("Today's top 10 scores", buf, 40.0, LOGICAL_SCREEN_WIDTH/2 - width/2, 60);
61 my_draw_text("Player", buf, 12.0, PLAYER_X, 100);
62 my_draw_text("Song", buf, 12.0, SONG_X, 100);
63 width = my_draw_text("Score", NULL, 12.0);
64 my_draw_text("Score", buf, 12.0, SCORE_X - width/2, 100);
66 unsigned row = 1, y = 140;
67 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
69 unsigned r = 255, g = 255, b = 255;
71 // print new entries in red
72 if (seen_topscore.count(*i) == 0 && seen_topscore.size() > 0) {
76 std::sprintf(str, "%u", row++);
77 unsigned width = my_draw_text(str, NULL, 24.0);
78 my_draw_text(str, buf, 24.0, RANK_X - width/2, y);
80 my_draw_text(i->nick, buf, 24.0, PLAYER_X, y, r, g, b);
82 if (my_draw_text(i->title, NULL, 24.0) > SONG_MAX_WIDTH &&
83 !i->shorttitle.empty()) {
84 my_draw_text(i->shorttitle, buf, 24.0, SONG_X, y, r, g, b);
86 my_draw_text(i->title, buf, 24.0, SONG_X, y, r, g, b);
89 std::sprintf(str, "%u", i->score);
90 width = my_draw_text(str, NULL, 24.0);
91 my_draw_text(str, buf, 24.0, SCORE_X - width/2, y, r, g, b);
98 seen_topscore.erase(seen_topscore.begin(), seen_topscore.end());
99 std::copy(scores.begin(), scores.end(), std::inserter(seen_topscore, seen_topscore.end()));
102 int Top10ScoreScreen::get_priority()