]> git.sesse.net Git - ccbs/blobdiff - bigscreen/ccbs_bigscreen.cpp
Move most of the resolution settings to the config file.
[ccbs] / bigscreen / ccbs_bigscreen.cpp
index 05b32b89cec2b341630eeada909ee718bc0cd149..eeee86cefa4bf318806be01e7fe80cd0f282345e 100644 (file)
@@ -26,7 +26,7 @@ Tournament active_tournament;
 std::vector<SkeletonGroup> active_groups;
 std::vector<GenericScreen *> screens;
 GenericScreen *mainscreen = NULL;
-unsigned char framebuf[SCREEN_WIDTH * SCREEN_HEIGHT * 4], screenbuf[SCREEN_WIDTH * SCREEN_HEIGHT * 4];
+unsigned char *framebuf, *screenbuf;
 bool quit_requested = false;
 
 void init(pqxx::connection &conn)
@@ -137,7 +137,7 @@ void init(pqxx::connection &conn)
 #endif
 }
 
-void main_loop(pqxx::connection &conn)
+void main_loop(pqxx::connection &conn, unsigned screen_width, unsigned screen_height)
 {
        if (active_tournament.id == -1) {
                // No active tournament, sleep a second or so and exit
@@ -146,17 +146,17 @@ void main_loop(pqxx::connection &conn)
        }
 
        if (mainscreen && mainscreen->check_invalidated()) {
-               if (screen->pitch == SCREEN_WIDTH * 4) {
+               if (screen->pitch == screen_width * 4) {
                        SDL_LockSurface(screen);
-                       mainscreen->draw((unsigned char *)screen->pixels, SCREEN_WIDTH, SCREEN_HEIGHT);
+                       mainscreen->draw((unsigned char *)screen->pixels, screen_width, screen_height);
                        SDL_UnlockSurface(screen);
                } else {
-                       mainscreen->draw(framebuf, SCREEN_WIDTH, SCREEN_HEIGHT);
+                       mainscreen->draw(framebuf, screen_width, screen_height);
                        SDL_LockSurface(screen);
-                       for (unsigned y = 0; y < SCREEN_HEIGHT; ++y) {
-                               unsigned char *sptr = framebuf + y * SCREEN_WIDTH * 4;
+                       for (unsigned y = 0; y < screen_height; ++y) {
+                               unsigned char *sptr = framebuf + y * screen_width * 4;
                                unsigned char *dptr = (unsigned char *)screen->pixels + y * screen->pitch;
-                               memcpy(dptr, sptr, SCREEN_WIDTH * 4);
+                               memcpy(dptr, sptr, screen_width * 4);
                        }
                        SDL_UnlockSurface(screen);
                }
@@ -183,21 +183,29 @@ void handle_events()
 
 int main(int argc, char **argv)
 {
+       init_theme();
+       unsigned screen_width = atoi(get_theme_config("screen", "width").c_str());
+       unsigned screen_height = atoi(get_theme_config("screen", "height").c_str());
+       bool use_lcd = atoi(get_theme_config("screen", "fullscreen").c_str());
+
        SDL_Init(SDL_INIT_VIDEO);
-#if USE_FULLSCREEN
-       screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF | SDL_FULLSCREEN);
-       SDL_ShowCursor(SDL_DISABLE);
-#else
-       screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF);
-#endif
+       if (use_lcd) {
+               screen = SDL_SetVideoMode(screen_width, screen_height, 32, SDL_DOUBLEBUF | SDL_FULLSCREEN);
+               SDL_ShowCursor(SDL_DISABLE);
+       } else {
+               screen = SDL_SetVideoMode(screen_width, screen_height, 32, SDL_DOUBLEBUF);
+       }
        if (screen == NULL) {
                fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
                exit(1);
        }
+
+       framebuf = new unsigned char[screen_width * screen_height * 4];
+       screenbuf = new unsigned char[screen_width * screen_height * 4];
        
        try {
-               init_theme();
                init_freetype();
+               set_screen_size(screen_width, screen_height);
                pqxx::connection conn("dbname=ccbs host=www.positivegaming.com user=ccbs password=GeT|>>B_");
                FlagTrigger tournament_changed(conn, "active_tournament");
                FlagTrigger rounds_changed(conn, "active_groups");
@@ -209,7 +217,7 @@ int main(int argc, char **argv)
                        rounds_changed.reset_flag();
                        init(conn);
                        do {
-                               main_loop(conn);
+                               main_loop(conn, screen_width, screen_height);
                                conn.get_notifs();
                                handle_events();
                        } while (!tournament_changed.get_flag() && !rounds_changed.get_flag() && !quit_requested);