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, "top5chosenscreen", 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 heading_theme_element = "top5chosensongs.rowheading";
69 std::string songname_theme_element = "top5chosensongs.songname";
70 std::string frequency_theme_element = "top5chosensongs.frequency";
72 // print new entries in red
73 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
74 heading_theme_element = "top5chosensongs.freshrowheading";
75 songname_theme_element = "top5chosensongs.freshsongname";
76 frequency_theme_element = "top5chosensongs.freshfrequency";
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 if (my_draw_text(i->title, NULL, 24.0, songname_theme_element) > SONG_MAX_WIDTH) {
84 my_draw_text(i->shorttitle, buf, 24.0, songname_theme_element, SONG_X, y);
86 my_draw_text(i->title, buf, 24.0, songname_theme_element, SONG_X, y);
89 std::sprintf(str, "%u", i->frequency);
90 width = my_draw_text(str, NULL, 24.0, frequency_theme_element);
91 my_draw_text(str, buf, 24.0, frequency_theme_element, FREQUENCY_X - width/2, y);
98 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
99 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));