4 #include "top10scorescreen.h"
7 Top10ScoreScreen::Top10ScoreScreen(pqxx::connection &conn, unsigned tournament)
8 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
12 Top10ScoreScreen::~Top10ScoreScreen()
16 bool Top10ScoreScreen::check_invalidated()
20 if (!scores_changed.get_flag())
23 // check that there are indeed changes, otherwise don't bother
24 std::vector<TopScore> scores;
25 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
27 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
28 if (seen_topscore.count(*i) == 0) {
36 void Top10ScoreScreen::draw(unsigned char *buf)
38 scores_changed.reset_flag();
39 memset(buf, 0, 800 * 600 * 4);
41 // fetch the top 10 scores
42 std::vector<TopScore> scores;
43 conn.perform(FetchTopScoresForTournament(tournament, 10, &scores));
46 unsigned width = my_draw_text("Today's top 10 scores", NULL, 40.0);
47 my_draw_text("Today's top 10 scores", buf, 40.0, 800/2 - width/2, 60);
51 my_draw_text("Player", buf, 12.0, 70, 100);
52 my_draw_text("Song", buf, 12.0, 250, 100);
53 my_draw_text("Score", buf, 12.0, 710, 100);
55 unsigned row = 1, y = 140;
56 for (std::vector<TopScore>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
58 unsigned r = 255, g = 255, b = 255;
60 // print new entries in red
61 if (seen_topscore.count(*i) == 0 && seen_topscore.size() > 0) {
65 std::sprintf(str, "%u", row++);
66 unsigned width = my_draw_text(str, NULL, 24.0);
67 my_draw_text(str, buf, 24.0, 30 - width/2, y);
69 my_draw_text(i->nick, buf, 24.0, 70, y, r, g, b);
71 if (my_draw_text(i->title, NULL, 24.0) > 430) {
72 my_draw_text(i->shorttitle, buf, 24.0, 250, y, r, g, b);
74 my_draw_text(i->title, buf, 24.0, 250, y, r, g, b);
77 std::sprintf(str, "%u", i->score);
78 width = my_draw_text(str, NULL, 24.0);
79 my_draw_text(str, buf, 24.0, 728 - width/2, y, r, g, b);
86 seen_topscore.erase(seen_topscore.begin(), seen_topscore.end());
87 std::copy(scores.begin(), scores.end(), std::inserter(seen_topscore, seen_topscore.end()));