4 #include "resolution.h"
5 #include "top5chosenscreen.h"
11 #define FREQUENCY_X (LOGICAL_SCREEN_WIDTH - 55)
12 #define SONG_MAX_WIDTH (LOGICAL_SCREEN_WIDTH - 190)
14 Top5ChosenScreen::Top5ChosenScreen(pqxx::connection &conn, unsigned tournament)
15 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
19 Top5ChosenScreen::~Top5ChosenScreen()
23 bool Top5ChosenScreen::check_invalidated()
27 if (!scores_changed.get_flag())
29 scores_changed.reset_flag();
31 // check that there are indeed changes, otherwise don't bother
32 std::vector<TopChosen> scores;
33 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
35 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
36 if (seen_topchosen.count(*i) == 0) {
45 void Top5ChosenScreen::draw(unsigned char *buf, unsigned width, unsigned height)
47 scores_changed.reset_flag();
48 fill_background(buf, width, height);
49 set_screen_size(width, height);
51 // fetch the top 5 chosen songs
52 std::vector<TopChosen> scores;
53 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
56 unsigned width = my_draw_text("Today's top 5 chosen songs", NULL, 40.0, "mainheading");
57 my_draw_text("Today's top 5 chosen songs", buf, 40.0, "mainheading", LOGICAL_SCREEN_WIDTH/2 - width/2, 60);
61 my_draw_text("Song", buf, 12.0, "columnheading", SONG_X, 100);
62 width = my_draw_text("Frequency", NULL, 12.0, "columnheading");
63 my_draw_text("Frequency", buf, 12.0, "columnheading", FREQUENCY_X - width/2, 100);
65 unsigned row = 1, y = 140;
66 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
68 std::string theme_element = "data";
69 std::string heading_theme_element = "rowheading";
71 // print new entries in red
72 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
73 theme_element = "freshdata";
74 heading_theme_element = "freshrowheading";
77 std::sprintf(str, "%u", row++);
78 unsigned width = my_draw_text(str, NULL, 24.0, heading_theme_element);
79 my_draw_text(str, buf, 24.0, heading_theme_element, RANK_X - width/2, y);
81 if (my_draw_text(i->title, NULL, 24.0, theme_element) > SONG_MAX_WIDTH) {
82 my_draw_text(i->shorttitle, buf, 24.0, theme_element, SONG_X, y);
84 my_draw_text(i->title, buf, 24.0, theme_element, SONG_X, y);
87 std::sprintf(str, "%u", i->frequency);
88 width = my_draw_text(str, NULL, 24.0, theme_element);
89 my_draw_text(str, buf, 24.0, theme_element, FREQUENCY_X - width/2, y);
96 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
97 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));