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())
30 // check that there are indeed changes, otherwise don't bother
31 std::vector<TopScore> scores;
32 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
34 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
35 if (seen_topscore.count(*i) == 0) {
43 void Top10ScoreScreen::draw(unsigned char *buf, unsigned width, unsigned height)
45 scores_changed.reset_flag();
46 memset(buf, 0, width * height * 4);
47 set_screen_size(width, height);
49 // fetch the top 10 scores
50 std::vector<TopScore> scores;
51 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
54 unsigned width = my_draw_text("Today's top 10 scores", NULL, 40.0);
55 my_draw_text("Today's top 10 scores", buf, 40.0, LOGICAL_SCREEN_WIDTH/2 - width/2, 60);
59 my_draw_text("Player", buf, 12.0, PLAYER_X, 100);
60 my_draw_text("Song", buf, 12.0, SONG_X, 100);
61 my_draw_text("Score", buf, 12.0, SCORE_X - 18, 100);
63 unsigned row = 1, y = 140;
64 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
66 unsigned r = 255, g = 255, b = 255;
68 // print new entries in red
69 if (seen_topscore.count(*i) == 0 && seen_topscore.size() > 0) {
73 std::sprintf(str, "%u", row++);
74 unsigned width = my_draw_text(str, NULL, 24.0);
75 my_draw_text(str, buf, 24.0, RANK_X - width/2, y);
77 my_draw_text(i->nick, buf, 24.0, PLAYER_X, y, r, g, b);
79 if (my_draw_text(i->title, NULL, 24.0) > SONG_MAX_WIDTH &&
80 !i->shorttitle.empty()) {
81 my_draw_text(i->shorttitle, buf, 24.0, SONG_X, y, r, g, b);
83 my_draw_text(i->title, buf, 24.0, SONG_X, y, r, g, b);
86 std::sprintf(str, "%u", i->score);
87 width = my_draw_text(str, NULL, 24.0);
88 my_draw_text(str, buf, 24.0, SCORE_X - width/2, y, r, g, b);
95 seen_topscore.erase(seen_topscore.begin(), seen_topscore.end());
96 std::copy(scores.begin(), scores.end(), std::inserter(seen_topscore, seen_topscore.end()));
99 int Top10ScoreScreen::get_priority()