Replace 800x600 width a resolution from a .h file. Lots of positions are still hardco...
authorSteinar H. Gunderson <sesse@samfundet.no>
Tue, 1 Mar 2005 01:59:31 +0000 (01:59 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Tue, 1 Mar 2005 01:59:31 +0000 (01:59 +0000)
bigscreen/ccbs_bigscreen.cpp
bigscreen/fonts.cpp
bigscreen/groupscreen.cpp
bigscreen/resolution.h [new file with mode: 0644]
bigscreen/rotatescreen.cpp
bigscreen/screen.h
bigscreen/splitscreen.cpp
bigscreen/splitscreen.h
bigscreen/top10scorescreen.cpp
bigscreen/top5chosenscreen.cpp

index 0892c16..b183ddd 100644 (file)
@@ -22,7 +22,7 @@ Tournament active_tournament;
 std::vector<SkeletonGroup> active_groups;
 std::vector<GenericScreen *> screens;
 GenericScreen *mainscreen = NULL;
-unsigned char framebuf[800 * 600 * 4], screenbuf[800 * 600 * 4];
+unsigned char framebuf[SCREEN_WIDTH * SCREEN_HEIGHT * 4], screenbuf[SCREEN_WIDTH * SCREEN_HEIGHT * 4];
 
 void init(pqxx::connection &conn)
 {
@@ -57,28 +57,41 @@ void init(pqxx::connection &conn)
                }
        }
 
-       RotateScreen *aux_screen = new RotateScreen();
-       screens.push_back(aux_screen);
-       
-       conn.perform(FetchAuxilliaryScreens(&aux_screens));
-       for (std::vector<widestring>::const_iterator i = aux_screens.begin(); i != aux_screens.end(); ++i) {
-               if (*i == widestring("top10scores")) {
-                       aux_screen->add_screen(new Top10ScoreScreen(conn, active_tournament.id));
-                       continue;
-               }
-               if (*i == widestring("top5chosen")) {
-                       aux_screen->add_screen(new Top5ChosenScreen(conn, active_tournament.id));
-                       continue;
+       // show auxilliary screens if we have zero, two or three other screens going
+       if (screens.size() < 4 && screens.size() != 1) {
+               RotateScreen *aux_screen = new RotateScreen();
+               screens.push_back(aux_screen);
+               
+               conn.perform(FetchAuxilliaryScreens(&aux_screens));
+               for (std::vector<widestring>::const_iterator i = aux_screens.begin(); i != aux_screens.end(); ++i) {
+                       if (*i == widestring("top10scores")) {
+                               aux_screen->add_screen(new Top10ScoreScreen(conn, active_tournament.id));
+                               continue;
+                       }
+                       if (*i == widestring("top5chosen")) {
+                               aux_screen->add_screen(new Top5ChosenScreen(conn, active_tournament.id));
+                               continue;
+                       }
+                       std::fprintf(stderr, "Foobarbaz?\n");
                }
-               std::fprintf(stderr, "Foobarbaz?\n");
-       }
 
-       // add all finished screens to the auxilliary screens
-       std::vector<SkeletonGroup> finished_groups;
-       conn.perform(FetchListOfFinishedGroups(active_tournament.id, &finished_groups));
-               
-       for (std::vector<SkeletonGroup>::const_iterator i = finished_groups.begin(); i != finished_groups.end(); ++i) {
-               aux_screen->add_screen(new GroupScreen(conn, i->tournament, i->round, i->parallel, 0, 1));
+               /*
+                * If we still have room, make yet another rotational screen with
+                * results from previous groups -- otherwise tack them onto the end
+                * of the auxilliary screens.
+                */
+               RotateScreen *finished_groups_screen = aux_screen;
+               if (screens.size() < 4 && screens.size() != 1) {
+                       finished_groups_screen = new RotateScreen();
+                       screens.push_back(finished_groups_screen);
+               }
+                       
+               std::vector<SkeletonGroup> finished_groups;
+               conn.perform(FetchListOfFinishedGroups(active_tournament.id, &finished_groups));
+                       
+               for (std::vector<SkeletonGroup>::const_iterator i = finished_groups.begin(); i != finished_groups.end(); ++i) {
+                       finished_groups_screen->add_screen(new GroupScreen(conn, i->tournament, i->round, i->parallel, 0, 1));
+               }
        }
        
        // hack
@@ -114,7 +127,7 @@ void main_loop(pqxx::connection &conn)
 
 int main(int argc, char **argv)
 {
-       ptc_open("CCBS bigscreen", 800, 600);
+       ptc_open("CCBS bigscreen", SCREEN_WIDTH, SCREEN_HEIGHT);
        
        try {
                init_freetype();
index 8ba809f..af9a936 100644 (file)
@@ -1,6 +1,7 @@
 #include <vector>
 #include <stdexcept>
 #include "fonts.h"
+#include "resolution.h"
 
 std::vector<FT_Face> fonts;
 
@@ -64,12 +65,12 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, in
                        for (y = 0; y < bm->rows; y++) {
                                int xx;
                                int dsty = ypos - slot->bitmap_top + y;
-                               if (dsty < 0 || dsty > 599) continue;
+                               if (dsty < 0 || dsty > (SCREEN_HEIGHT-1)) continue;
 
-                               unsigned char *dst = buf + dsty * 800*4 + (x + xpos + slot->bitmap_left)*4;
+                               unsigned char *dst = buf + dsty * SCREEN_WIDTH*4 + (x + xpos + slot->bitmap_left)*4;
                                unsigned char *src = bm->buffer + y * bm->width;
 
-                               int width = (x + xpos + slot->bitmap_left + bm->width >= 800) ? (799 - x - xpos - slot->bitmap_left) : bm->width;
+                               int width = (x + xpos + slot->bitmap_left + bm->width >= SCREEN_WIDTH) ? ((SCREEN_WIDTH-1) - x - xpos - slot->bitmap_left) : bm->width;
                                for (xx = 0; xx < width; xx++) {
                                        *dst = (*dst * (256-*src) + b * *src) >> 8;
                                        *dst++;
index 8d408ec..222db23 100644 (file)
@@ -2,6 +2,7 @@
 #include <algorithm>
 #include <map>
 
+#include "resolution.h"
 #include "groupscreen.h"
 #include "fetch_group.h"
 #include "fetch_max_score_for_songs.h"
@@ -53,7 +54,7 @@ void GroupScreen::draw(unsigned char *buf)
        conn.perform(FetchGroup(tournament, round, parallel, &group));
        gettimeofday(&last_updated, NULL);
 
-       memset(buf, 0, 800 * 600 * 4);
+       memset(buf, 0, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
 
        // main heading
        char heading[64];
@@ -73,7 +74,7 @@ void GroupScreen::draw(unsigned char *buf)
 
        {
                unsigned width = my_draw_text(heading, NULL, 40.0);
-               my_draw_text_deferred(td, heading, 40.0, 800/2 - width/2, 60);
+               my_draw_text_deferred(td, heading, 40.0, SCREEN_WIDTH/2 - width/2, 60);
        }
        
        // Find out how wide each column has to be. First try unlimited width (ie.
@@ -346,11 +347,11 @@ void GroupScreen::draw(unsigned char *buf)
        if (next_song != NULL) {
                widestring text = widestring("Next player: ") + next_player->nick;
                unsigned this_width = my_draw_text(text, NULL, 24.0);
-               my_draw_text(text, buf, 24.0, 400 - this_width/2, 420);
+               my_draw_text(text, buf, 24.0, (SCREEN_WIDTH/2) - this_width/2, 420);
 
                if (next_song->song.id != -1) {
                        this_width = my_draw_text(next_song->song.title, NULL, 20.0);
-                       my_draw_text(next_song->song.title, buf, 20.0, 400 - this_width/2, 457);
+                       my_draw_text(next_song->song.title, buf, 20.0, (SCREEN_WIDTH/2) - this_width/2, 457);
 
                        Highscore hs;
                        conn.perform(FetchHighscore(next_song->song.id, &hs));
@@ -359,7 +360,7 @@ void GroupScreen::draw(unsigned char *buf)
                                text = widestring("High score: ") + widestring(pqxx::to_string(hs.score)) +
                                        widestring(", by ") + hs.nick + widestring(" in ") + hs.tournament_name;
                                this_width = my_draw_text(text, NULL, 16.0);
-                               my_draw_text(text, buf, 16.0, 400 - this_width/2, 487);
+                               my_draw_text(text, buf, 16.0, (SCREEN_WIDTH/2) - this_width/2, 487);
                        }
                }
 
@@ -456,7 +457,7 @@ void GroupScreen::draw(unsigned char *buf)
                                if (lead_need > 0) {
                                        text = widestring("Needs to lead: ") + widestring(pqxx::to_string(lead_need));
                                        this_width = my_draw_text(text, NULL, 18.0);
-                                       my_draw_text(text, buf, 18.0, 400 - this_width/2, y);
+                                       my_draw_text(text, buf, 18.0, (SCREEN_WIDTH/2) - this_width/2, y);
 
                                        y += 30;
                                }
@@ -469,7 +470,7 @@ void GroupScreen::draw(unsigned char *buf)
                                        text = widestring("Needs to win: ") + widestring(pqxx::to_string(win_need));
 
                                        this_width = my_draw_text(text, NULL, 18.0);
-                                       my_draw_text(text, buf, 18.0, 400 - this_width/2, y);
+                                       my_draw_text(text, buf, 18.0, (SCREEN_WIDTH/2) - this_width/2, y);
 
                                        y += 30;
                                }
@@ -488,7 +489,7 @@ void GroupScreen::draw(unsigned char *buf)
                                        }
                                        
                                        this_width = my_draw_text(text, NULL, 18.0);
-                                       my_draw_text(text, buf, 18.0, 400 - this_width/2, y);
+                                       my_draw_text(text, buf, 18.0, (SCREEN_WIDTH/2) - this_width/2, y);
                                
                                        y += 30;
                                }
diff --git a/bigscreen/resolution.h b/bigscreen/resolution.h
new file mode 100644 (file)
index 0000000..0bbddf3
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _RESOLUTION_H
+#define _RESOLUTION_H 1
+
+#define SCREEN_WIDTH 800
+#define SCREEN_HEIGHT 600
+
+#endif /* !defined(_RESOLUTION_H) */
index fcc975c..78a0e78 100644 (file)
@@ -4,7 +4,7 @@
 RotateScreen::RotateScreen()
        : valid(false), current_screen(0), in_fade(false)
 {
-       fadefrom_buf = new unsigned char[800 * 600 * 4];
+       fadefrom_buf = new unsigned char[SCREEN_WIDTH * SCREEN_HEIGHT * 4];
 }
 
 RotateScreen::~RotateScreen()
@@ -60,7 +60,7 @@ void RotateScreen::draw(unsigned char *buf)
                        // ugly hack here? :-)
                        subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
                        
-                       memcpy(buf, subscreens[current_screen].buf, 800 * 600 * 4);
+                       memcpy(buf, subscreens[current_screen].buf, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
                } else {
                        // find the fade factors
                        int fr, fg, fb, fa;
@@ -80,7 +80,7 @@ void RotateScreen::draw(unsigned char *buf)
 
                        if (fade_to_new_info && elapsed_fade >= 0.5) {
                                // fade G&B to be = R
-                               for (unsigned i = 0; i < 800 * 600; ++i) {
+                               for (unsigned i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; ++i) {
                                        dptr[0] = sptr2[0] + (((int(sptr2[2]) - int(sptr2[0])) * fb) >> 8);
                                        dptr[1] = sptr2[1] + (((int(sptr2[2]) - int(sptr2[1])) * fg) >> 8);
                                        dptr[2] = sptr2[2];
@@ -89,7 +89,7 @@ void RotateScreen::draw(unsigned char *buf)
                                        sptr1 += 4, sptr2 += 4, dptr += 4;
                                }
                        } else {
-                               for (unsigned i = 0; i < 800 * 600; ++i) {
+                               for (unsigned i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; ++i) {
                                        dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * fb) >> 8);
                                        dptr[1] = sptr1[1] + (((int(sptr2[1]) - int(sptr1[1])) * fg) >> 8);
                                        dptr[2] = sptr1[2] + (((int(sptr2[2]) - int(sptr1[2])) * fr) >> 8);
@@ -126,7 +126,7 @@ void RotateScreen::draw(unsigned char *buf)
                        fade_found_start_time = false;
                        fade_to_new_info = force;
                        
-                       memcpy(fadefrom_buf, subscreens[old_current_screen].buf, 800 * 600 * 4);
+                       memcpy(fadefrom_buf, subscreens[old_current_screen].buf, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
 
                        if (subscreens[current_screen].screen->check_invalidated())
                                subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
@@ -170,7 +170,7 @@ bool RotateScreen::can_update()
 void RotateScreen::add_screen(GenericScreen *screen)
 {
        Subscreen ss;
-       ss.buf = new unsigned char[800 * 600 * 4];
+       ss.buf = new unsigned char[SCREEN_WIDTH * SCREEN_HEIGHT * 4];
        ss.screen = screen;
 
        screen->draw(ss.buf);
index b35e3af..e519279 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _SCREEN_H
 #define _SCREEN_H 1
 
+#include "resolution.h"
+
 // arf, Screen conflicts with X11
 class GenericScreen {
 protected:
index 10e3197..9d569b1 100644 (file)
@@ -9,10 +9,10 @@ SplitScreen::SplitScreen(GenericScreen *s1, GenericScreen *s2, GenericScreen *s3
        subscreens[2] = s3;
        subscreens[3] = s4;
 
-       memset(subbufs[0], 0, 800*600*4);
-       memset(subbufs[1], 0, 800*600*4);
-       memset(subbufs[2], 0, 800*600*4);
-       memset(subbufs[3], 0, 800*600*4);
+       memset(subbufs[0], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
+       memset(subbufs[1], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
+       memset(subbufs[2], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
+       memset(subbufs[3], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
 }
 
 SplitScreen::~SplitScreen()
@@ -41,27 +41,27 @@ void SplitScreen::draw(unsigned char *buf)
        }
        
        downscale_2x2(buf, subbufs[0]);
-       downscale_2x2(buf + 400 * 4, subbufs[1]);
-       downscale_2x2(buf + 800 * 300 * 4, subbufs[2]);
-       downscale_2x2(buf + 800 * 300 * 4 + 400 * 4, subbufs[3]); 
+       downscale_2x2(buf + (SCREEN_WIDTH/2) * 4, subbufs[1]);
+       downscale_2x2(buf + SCREEN_WIDTH * (SCREEN_HEIGHT/2) * 4, subbufs[2]);
+       downscale_2x2(buf + SCREEN_WIDTH * (SCREEN_HEIGHT/2) * 4 + (SCREEN_WIDTH/2) * 4, subbufs[3]); 
 
        // make divider lines
-       unsigned char *ptr = buf + 300 * 800 * 4;
-       for (unsigned x = 0; x < 800; ++x) {
+       unsigned char *ptr = buf + (SCREEN_HEIGHT/2) * SCREEN_WIDTH * 4;
+       for (unsigned x = 0; x < SCREEN_WIDTH; ++x) {
                *ptr++ = 255;
                *ptr++ = 255;
                *ptr++ = 255;
                *ptr++ = 0;
        }
        
-       ptr = buf + 400 * 4;
-       for (unsigned y = 0; y < 600; ++y) {
+       ptr = buf + (SCREEN_WIDTH/2) * 4;
+       for (unsigned y = 0; y < SCREEN_HEIGHT; ++y) {
                ptr[0] = 255;
                ptr[1] = 255;
                ptr[2] = 255;
                ptr[3] = 0;
 
-               ptr += 800 * 4;
+               ptr += SCREEN_WIDTH * 4;
        }
        
        valid = true;
@@ -70,12 +70,12 @@ void SplitScreen::draw(unsigned char *buf)
 // simple box filter (blah)
 void SplitScreen::downscale_2x2(unsigned char *dst, unsigned char *src)
 {
-       for (unsigned y = 0; y < 300; ++y) {
-               unsigned char *sptr1 = src + (y*2) * 800 * 4;
-               unsigned char *sptr2 = src + (y*2+1) * 800 * 4;
-               unsigned char *dptr = dst + y * 800 * 4;
+       for (unsigned y = 0; y < (SCREEN_HEIGHT/2); ++y) {
+               unsigned char *sptr1 = src + (y*2) * SCREEN_WIDTH * 4;
+               unsigned char *sptr2 = src + (y*2+1) * SCREEN_WIDTH * 4;
+               unsigned char *dptr = dst + y * SCREEN_WIDTH * 4;
                
-               for (unsigned x = 0; x < 400; ++x) {
+               for (unsigned x = 0; x < (SCREEN_WIDTH/2); ++x) {
                        *dptr++ = (sptr1[0] + sptr1[4] + sptr2[0] + sptr2[4]) >> 2;  // red
                        *dptr++ = (sptr1[1] + sptr1[5] + sptr2[1] + sptr2[5]) >> 2;  // green
                        *dptr++ = (sptr1[2] + sptr1[6] + sptr2[2] + sptr2[6]) >> 2;  // blue
index 3b0616c..bf68b82 100644 (file)
@@ -6,7 +6,7 @@
 /* A 4x4 split class */
 class SplitScreen : public GenericScreen {
 private:
-       unsigned char subbufs[4][800 * 600 * 4];
+       unsigned char subbufs[4][SCREEN_WIDTH * SCREEN_HEIGHT * 4];
        GenericScreen *subscreens[4];
        bool valid;
 
index 6ae58fd..d4453d8 100644 (file)
@@ -1,6 +1,7 @@
 #include <cstdio>
 #include <algorithm>
 
+#include "resolution.h"
 #include "top10scorescreen.h"
 #include "fonts.h"
 
@@ -36,7 +37,7 @@ bool Top10ScoreScreen::check_invalidated()
 void Top10ScoreScreen::draw(unsigned char *buf)
 {
        scores_changed.reset_flag();
-       memset(buf, 0, 800 * 600 * 4);
+       memset(buf, 0, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
 
        // fetch the top 10 scores
        std::vector<TopScore> scores;
@@ -44,7 +45,7 @@ void Top10ScoreScreen::draw(unsigned char *buf)
 
        {
                unsigned width = my_draw_text("Today's top 10 scores", NULL, 40.0);
-               my_draw_text("Today's top 10 scores", buf, 40.0, 800/2 - width/2, 60);
+               my_draw_text("Today's top 10 scores", buf, 40.0, SCREEN_WIDTH/2 - width/2, 60);
        }
 
        // simple headings
index cbb4455..321005c 100644 (file)
@@ -1,6 +1,7 @@
 #include <cstdio>
 #include <algorithm>
 
+#include "resolution.h"
 #include "top5chosenscreen.h"
 #include "fonts.h"
 
@@ -36,7 +37,7 @@ bool Top5ChosenScreen::check_invalidated()
 void Top5ChosenScreen::draw(unsigned char *buf)
 {
        scores_changed.reset_flag();
-       memset(buf, 0, 800 * 600 * 4);
+       memset(buf, 0, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
 
        // fetch the top 5 chosen songs
        std::vector<TopChosen> scores;
@@ -44,7 +45,7 @@ void Top5ChosenScreen::draw(unsigned char *buf)
 
        {
                unsigned width = my_draw_text("Today's top 5 chosen songs", NULL, 40.0);
-               my_draw_text("Today's top 5 chosen songs", buf, 40.0, 800/2 - width/2, 60);
+               my_draw_text("Today's top 5 chosen songs", buf, 40.0, SCREEN_WIDTH/2 - width/2, 60);
        }
 
        // simple headings