From: Steinar H. Gunderson Date: Sat, 18 Feb 2012 22:30:30 +0000 (+0100) Subject: Move most of the resolution settings to the config file. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=2b2861e26f123a07b2794d4a66b6e62868b288d1 Move most of the resolution settings to the config file. --- diff --git a/bigscreen/ccbs_bigscreen.cpp b/bigscreen/ccbs_bigscreen.cpp index 05b32b8..eeee86c 100644 --- a/bigscreen/ccbs_bigscreen.cpp +++ b/bigscreen/ccbs_bigscreen.cpp @@ -26,7 +26,7 @@ Tournament active_tournament; std::vector active_groups; std::vector 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); diff --git a/bigscreen/fonts.cpp b/bigscreen/fonts.cpp index 0381157..bbc4c1a 100644 --- a/bigscreen/fonts.cpp +++ b/bigscreen/fonts.cpp @@ -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 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 } } diff --git a/bigscreen/resolution.h b/bigscreen/resolution.h index 01a299c..6898112 100644 --- a/bigscreen/resolution.h +++ b/bigscreen/resolution.h @@ -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) */ diff --git a/bigscreen/theme.config b/bigscreen/theme.config index cdf7abc..bee59aa 100644 --- a/bigscreen/theme.config +++ b/bigscreen/theme.config @@ -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 diff --git a/bigscreen/theme.h b/bigscreen/theme.h index 1b0e33e..2c87384 100644 --- a/bigscreen/theme.h +++ b/bigscreen/theme.h @@ -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