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)
#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
}
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);
}
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");
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);
}
// 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;
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;
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;
}
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
}
}
#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) */
+# 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
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