]> git.sesse.net Git - ccbs/commitdiff
Move most of the resolution settings to the config file.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 18 Feb 2012 22:30:30 +0000 (23:30 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 18 Feb 2012 22:30:30 +0000 (23:30 +0100)
bigscreen/ccbs_bigscreen.cpp
bigscreen/fonts.cpp
bigscreen/resolution.h
bigscreen/theme.config
bigscreen/theme.h

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);
index 0381157c687097dfe59642deb976b301b23c42a5..bbc4c1a0d4305e5133c7626d8ace838435080439 100644 (file)
@@ -60,7 +60,7 @@ void init_freetype()
 }
 
 // this should really be done somehow else :-)
-static unsigned screen_width = SCREEN_WIDTH, screen_height = SCREEN_HEIGHT;
+static unsigned screen_width, screen_height;
 void set_screen_size(unsigned width, unsigned height)
 {
        screen_width = width;
@@ -75,6 +75,7 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, co
        int r = atoi(get_theme_config(theme_element, "red").c_str());
        int g = atoi(get_theme_config(theme_element, "green").c_str());
        int b = atoi(get_theme_config(theme_element, "blue").c_str());
+       bool use_lcd = atoi(get_theme_config("screen", "lcd").c_str());
 
        // Find font faces.
        std::vector<FT_Face> fonts;
@@ -101,12 +102,13 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, co
                        if (glyph_index == 0)
                                continue;
 
-#if SCREEN_LCD
-                       if (FT_Load_Glyph(*j, glyph_index, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD))
-#else
-                       if (FT_Load_Glyph(*j, glyph_index, FT_LOAD_RENDER))
-#endif
-                               throw std::runtime_error("Couldn't load glyph");
+                       if (use_lcd) {
+                               if (FT_Load_Glyph(*j, glyph_index, FT_LOAD_RENDER | FT_LOAD_TARGET_LCD))
+                                       throw std::runtime_error("Couldn't load glyph");
+                       } else {
+                               if (FT_Load_Glyph(*j, glyph_index, FT_LOAD_RENDER))
+                                       throw std::runtime_error("Couldn't load glyph");
+                       }
                        slot = (*j)->glyph;
                        break;
                }
@@ -124,38 +126,33 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, co
                                if (dsty < 0 || dsty > signed(screen_height-1)) continue;
 
                                unsigned char *dst = buf + dsty * screen_width*4 + (x + xpos + slot->bitmap_left)*4;
-#if SCREEN_LCD
-                               unsigned char *src = bm->buffer + y * bm->pitch;
-                               int width = (x + xpos + slot->bitmap_left + bm->width/3 >= signed(screen_width)) ? ((screen_width-1) - x - xpos - slot->bitmap_left) : bm->width/3;
-#else
                                unsigned char *src = bm->buffer + y * bm->pitch;
-                               int width = (x + xpos + slot->bitmap_left + bm->width >= signed(screen_width)) ? ((screen_width-1) - x - xpos - slot->bitmap_left) : bm->width;
-#endif
-
-#if SCREEN_LCD
-                               for (xx = 0; xx < width; xx++) {
-                                       *dst = (*dst * (256-src[2]) + b * src[2]) >> 8;
-                                       ++dst;
-                                       *dst = (*dst * (256-src[1]) + g * src[1]) >> 8;
-                                       ++dst;
-                                       *dst = (*dst * (256-src[0]) + r * src[0]) >> 8;
-                                       ++dst;
-                                       *dst++ = 0;
-
-                                       src += 3;
-                               }
-#else
-                               for (xx = 0; xx < width; xx++) {
-                                       *dst = (*dst * (256-*src) + b * *src) >> 8;
-                                       ++dst;
-                                       *dst = (*dst * (256-*src) + g * *src) >> 8;
-                                       ++dst;
-                                       *dst = (*dst * (256-*src) + r * *src) >> 8;
-                                       ++dst;
-                                       *dst++ = 0;
-                                       ++src;
+                               if (use_lcd) {
+                                       int width = (x + xpos + slot->bitmap_left + bm->width/3 >= signed(screen_width)) ? ((screen_width-1) - x - xpos - slot->bitmap_left) : bm->width/3;
+                                       for (xx = 0; xx < width; xx++) {
+                                               *dst = (*dst * (256-src[2]) + b * src[2]) >> 8;
+                                               ++dst;
+                                               *dst = (*dst * (256-src[1]) + g * src[1]) >> 8;
+                                               ++dst;
+                                               *dst = (*dst * (256-src[0]) + r * src[0]) >> 8;
+                                               ++dst;
+                                               *dst++ = 0;
+
+                                               src += 3;
+                                       }
+                               } else {
+                                       int width = (x + xpos + slot->bitmap_left + bm->width >= signed(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;
+                                               *dst = (*dst * (256-*src) + g * *src) >> 8;
+                                               ++dst;
+                                               *dst = (*dst * (256-*src) + r * *src) >> 8;
+                                               ++dst;
+                                               *dst++ = 0;
+                                               ++src;
+                                       }
                                }
-#endif
                        }
                }
 
index 01a299c3a4e467478c148829096ada0a790e5eb4..6898112b239cdbc642fe2c4e5bbc0c7196effb33 100644 (file)
@@ -1,19 +1,6 @@
 #ifndef _RESOLUTION_H
 #define _RESOLUTION_H 1
 
-#define SCREEN_WIDTH 1024
-#define SCREEN_HEIGHT 768
-#define SCREEN_LCD 1
-
-#define USE_FULLSCREEN 0
 #define USE_SPLITSCREEN 1
 
-/*
- * This is used in the screens, mostly for historical reasons (they were
- * first hard-coded to 800x600, and changing them to be resolution-independent
- * is not a project for today).
- */
-#define LOGICAL_SCREEN_WIDTH 800
-#define LOGICAL_SCREEN_HEIGHT 600
-
 #endif /* !defined(_RESOLUTION_H) */
index cdf7abcef31ee96c2803ab6cc68cf92192f043c0..bee59aa21525a2ef3c9f1092a7b0687014d44715 100644 (file)
@@ -1,3 +1,16 @@
+# Screen mode.
+screen.width=1024
+screen.height=768
+screen.lcd=1        # subpixel font rendering
+screen.fullscreen=0
+
+# This is used in the screens, mostly for historical reasons (they were
+# first hard-coded to 800x600, and changing them to be resolution-independent
+# is not a project for today).
+screen.logical_width=800
+screen.logical_height=600
+
+# Theme.
 default.font=/usr/share/fonts/truetype/msttcorefonts/Georgia.ttf;/usr/share/fonts/truetype/freefont/FreeSerif.ttf;arialuni.ttf
 default.red=255
 default.green=255
index 1b0e33ec4c6af146ed730709c59fdc13182ce158..2c873841f4ec56d10b3cfc981ff00300d0213f8f 100644 (file)
@@ -7,4 +7,7 @@ void init_theme();
 std::string get_theme_config(const std::string &key, const std::string subkey);
 void fill_background(unsigned char *buf, unsigned width, unsigned height);
 
+#define LOGICAL_SCREEN_WIDTH (atoi(get_theme_config("screen", "logical_width").c_str()))
+#define LOGICAL_SCREEN_HEIGHT (atoi(get_theme_config("screen", "logical_height").c_str()))
+
 #endif