From 8a0869bc8a821fd69fe04146f414a55181a2b14b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 19 Feb 2012 18:41:33 +0100 Subject: [PATCH] Add theme support for drawing rectangles in the background. --- bigscreen/theme.config | 9 +++++++++ bigscreen/theme.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/bigscreen/theme.config b/bigscreen/theme.config index fc03f3a..2c65bd9 100644 --- a/bigscreen/theme.config +++ b/bigscreen/theme.config @@ -48,3 +48,12 @@ divider.blue=127 # available elements: background.groupscreen, background.top5chosenscreen, background.top10scorescreen, mainheading, (fresh)columnheading, randomsongname, nextsonginfo, need, divider # available elements that also have .odd and .even: rowheading, (fresh)score, (fresh)chosensongname, (fresh)totalscore, (fresh)rank + +## How to draw rectangles in the background (up to ten, numbered 0-9): +# background.groupscreen.rect1.x0=0 +# background.groupscreen.rect1.y0=80 +# background.groupscreen.rect1.x1=800 +# background.groupscreen.rect1.y1=110 +# background.groupscreen.rect1.red=63 +# background.groupscreen.rect1.green=63 +# background.groupscreen.rect1.blue=63 diff --git a/bigscreen/theme.cpp b/bigscreen/theme.cpp index fb6f770..0b51fe2 100644 --- a/bigscreen/theme.cpp +++ b/bigscreen/theme.cpp @@ -5,6 +5,8 @@ #include #include +#include "theme.h" + std::map config; void read_config(const char *filename) @@ -92,4 +94,30 @@ void fill_background(unsigned char *buf, const std::string &screen_name, unsigne *ptr++ = bg_r; *ptr++ = 0; } + + for (unsigned i = 0; i < 10; ++i) { + char rectkey[1024]; + snprintf(rectkey, sizeof(rectkey), "background.%s.rect%u", screen_name.c_str(), i); + if (get_theme_config(rectkey, "x0").empty()) { + continue; + } + + int x0 = std::max(atoi(get_theme_config(rectkey, "x0").c_str()) * width / LOGICAL_SCREEN_WIDTH, 0); + int y0 = std::max(atoi(get_theme_config(rectkey, "y0").c_str()) * height / LOGICAL_SCREEN_HEIGHT, 0); + int x1 = std::min(atoi(get_theme_config(rectkey, "x1").c_str()) * width / LOGICAL_SCREEN_WIDTH, width); + int y1 = std::min(atoi(get_theme_config(rectkey, "y1").c_str()) * height / LOGICAL_SCREEN_HEIGHT, height); + int r = atoi(get_theme_config(rectkey, "red").c_str()); + int g = atoi(get_theme_config(rectkey, "green").c_str()); + int b = atoi(get_theme_config(rectkey, "blue").c_str()); + + for (int y = y0; y < y1; ++y) { + unsigned char *ptr = buf + (y * width + x0) * 4; + for (int x = x0; x < x1; ++x) { + *ptr++ = b; + *ptr++ = g; + *ptr++ = r; + *ptr++ = 0; + } + } + } } -- 2.39.2