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) {
70 std::string theme_element = "data";
71 std::string heading_theme_element = "rowheading";
73 // print new entries in red
74 if (seen_topscore.count(*i) == 0 && seen_topscore.size() > 0) {
75 theme_element = "freshdata";
76 heading_theme_element = "freshrowheading";
79 std::sprintf(str, "%u", row++);
80 unsigned width = my_draw_text(str, NULL, 24.0, heading_theme_element);
81 my_draw_text(str, buf, 24.0, heading_theme_element, RANK_X - width/2, y);
83 my_draw_text(i->nick, buf, 24.0, theme_element, PLAYER_X, y);
85 if (my_draw_text(i->title, NULL, 24.0, theme_element) > SONG_MAX_WIDTH &&
86 !i->shorttitle.empty()) {
87 my_draw_text(i->shorttitle, buf, 24.0, theme_element, SONG_X, y);
89 my_draw_text(i->title, buf, 24.0, theme_element, SONG_X, y);
92 std::sprintf(str, "%u", i->score);
93 width = my_draw_text(str, NULL, 24.0, theme_element);
94 my_draw_text(str, buf, 24.0, theme_element, SCORE_X - width/2, y);
101 seen_topscore.erase(seen_topscore.begin(), seen_topscore.end());
102 std::copy(scores.begin(), scores.end(), std::inserter(seen_topscore, seen_topscore.end()));
105 int Top10ScoreScreen::get_priority()