4 #include "resolution.h"
5 #include "top10scorescreen.h"
8 Top10ScoreScreen::Top10ScoreScreen(pqxx::connection &conn, unsigned tournament)
9 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
13 Top10ScoreScreen::~Top10ScoreScreen()
17 bool Top10ScoreScreen::check_invalidated()
21 if (!scores_changed.get_flag())
24 // check that there are indeed changes, otherwise don't bother
25 std::vector<TopScore> scores;
26 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
28 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
29 if (seen_topscore.count(*i) == 0) {
37 void Top10ScoreScreen::draw(unsigned char *buf)
39 scores_changed.reset_flag();
40 memset(buf, 0, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
42 // fetch the top 10 scores
43 std::vector<TopScore> scores;
44 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
47 unsigned width = my_draw_text("Today's top 10 scores", NULL, 40.0);
48 my_draw_text("Today's top 10 scores", buf, 40.0, SCREEN_WIDTH/2 - width/2, 60);
52 my_draw_text("Player", buf, 12.0, 70, 100);
53 my_draw_text("Song", buf, 12.0, 250, 100);
54 my_draw_text("Score", buf, 12.0, 710, 100);
56 unsigned row = 1, y = 140;
57 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
59 unsigned r = 255, g = 255, b = 255;
61 // print new entries in red
62 if (seen_topscore.count(*i) == 0 && seen_topscore.size() > 0) {
66 std::sprintf(str, "%u", row++);
67 unsigned width = my_draw_text(str, NULL, 24.0);
68 my_draw_text(str, buf, 24.0, 30 - width/2, y);
70 my_draw_text(i->nick, buf, 24.0, 70, y, r, g, b);
72 if (my_draw_text(i->title, NULL, 24.0) > 430) {
73 my_draw_text(i->shorttitle, buf, 24.0, 250, y, r, g, b);
75 my_draw_text(i->title, buf, 24.0, 250, y, r, g, b);
78 std::sprintf(str, "%u", i->score);
79 width = my_draw_text(str, NULL, 24.0);
80 my_draw_text(str, buf, 24.0, 728 - width/2, y, r, g, b);
87 seen_topscore.erase(seen_topscore.begin(), seen_topscore.end());
88 std::copy(scores.begin(), scores.end(), std::inserter(seen_topscore, seen_topscore.end()));
91 int Top10ScoreScreen::get_priority()