4 #include "resolution.h"
5 #include "top10scorescreen.h"
12 #define SCORE_X (LOGICAL_SCREEN_WIDTH - 72)
13 #define SONG_MAX_WIDTH (LOGICAL_SCREEN_WIDTH - 480)
15 Top10ScoreScreen::Top10ScoreScreen(pqxx::connection &conn, unsigned tournament)
16 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
20 Top10ScoreScreen::~Top10ScoreScreen()
24 bool Top10ScoreScreen::check_invalidated()
28 if (!scores_changed.get_flag())
30 scores_changed.reset_flag();
32 // check that there are indeed changes, otherwise don't bother
33 std::vector<TopScore> scores;
34 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
36 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
37 if (seen_topscore.count(*i) == 0) {
46 void Top10ScoreScreen::draw(unsigned char *buf, unsigned width, unsigned height)
48 scores_changed.reset_flag();
49 fill_background(buf, "top10scorescreen", width, height);
50 set_screen_size(width, height);
52 // fetch the top 10 scores
53 std::vector<TopScore> scores;
54 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
57 unsigned width = my_draw_text("Today's top 10 scores", NULL, 40.0, "mainheading");
58 my_draw_text("Today's top 10 scores", buf, 40.0, "mainheading", LOGICAL_SCREEN_WIDTH/2 - width/2, 60);
62 my_draw_text("Player", buf, 12.0, "columnheading", PLAYER_X, 100);
63 my_draw_text("Song", buf, 12.0, "columnheading", SONG_X, 100);
64 width = my_draw_text("Score", NULL, 12.0, "columnheading");
65 my_draw_text("Score", buf, 12.0, "columnheading", SCORE_X - width/2, 100);
67 unsigned row = 1, y = 140;
68 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
77 std::string heading_theme_element = "top10scores.rowheading" + suffix;
78 std::string nick_theme_element = "top10scores.nick" + suffix;
79 std::string songname_theme_element = "top10scores.songname" + suffix;
80 std::string frequency_theme_element = "top10scores.frequency" + suffix;
82 // print new entries in red
83 if (seen_topscore.count(*i) == 0 && seen_topscore.size() > 0) {
84 heading_theme_element = "top10scores.freshrowheading" + suffix;
85 nick_theme_element = "top10scores.freshnick" + suffix;
86 songname_theme_element = "top10scores.freshsongname" + suffix;
87 frequency_theme_element = "top10scores.freshfrequency" + suffix;
90 std::sprintf(str, "%u", row++);
91 unsigned width = my_draw_text(str, NULL, 24.0, heading_theme_element);
92 my_draw_text(str, buf, 24.0, heading_theme_element, RANK_X - width/2, y);
94 my_draw_text(i->nick, buf, 24.0, nick_theme_element, PLAYER_X, y);
96 if (my_draw_text(i->title, NULL, 24.0, songname_theme_element) > SONG_MAX_WIDTH &&
97 !i->shorttitle.empty()) {
98 my_draw_text(i->shorttitle, buf, 24.0, songname_theme_element, SONG_X, y);
100 my_draw_text(i->title, buf, 24.0, songname_theme_element, SONG_X, y);
103 std::sprintf(str, "%u", i->score);
104 width = my_draw_text(str, NULL, 24.0, frequency_theme_element);
105 my_draw_text(str, buf, 24.0, frequency_theme_element, SCORE_X - width/2, y);
112 seen_topscore.erase(seen_topscore.begin(), seen_topscore.end());
113 std::copy(scores.begin(), scores.end(), std::inserter(seen_topscore, seen_topscore.end()));
116 int Top10ScoreScreen::get_priority()