]> git.sesse.net Git - ccbs/blob - bigscreen/splitscreen.cpp
Move the theming out to a runtime-read config file. Opens, among others, for differen...
[ccbs] / bigscreen / splitscreen.cpp
1 /* NOTE: this class will _NOT_ handle resolution changes cleanly. You have been warned. :-) */
2
3 #include <cstring>
4 #include <cstdlib>
5 #include "splitscreen.h"
6 #include "theme.h"
7
8 SplitScreen::SplitScreen(GenericScreen *s1, GenericScreen *s2, GenericScreen *s3, GenericScreen *s4)
9         : valid(false)
10 {
11         subscreens[0] = s1;
12         subscreens[1] = s2;
13         subscreens[2] = s3;
14         subscreens[3] = s4;
15
16         for (unsigned i = 0; i < 4; ++i)
17                 subbufs[i] = NULL;
18 }
19
20 SplitScreen::~SplitScreen()
21 {
22 }
23
24 bool SplitScreen::check_invalidated()
25 {
26         if (!valid)
27                 return true;
28         
29         for (unsigned i = 0; i < 4; ++i) {
30                 if (subscreens[i] && subscreens[i]->check_invalidated())
31                         return true;
32         }
33
34         return false;
35 }
36
37 void SplitScreen::draw(unsigned char *buf, unsigned width, unsigned height)
38 {
39         for (unsigned i = 0; i < 4; ++i) {
40                 if (subbufs[i] == NULL) {  // see line 1
41                         subbufs[i] = new unsigned char[width/2 * height/2 * 4];
42                         memset(subbufs[i], 0, width/2 * height/2 * 4);
43                 }
44                 if (subscreens[i] && subscreens[i]->check_invalidated()) {
45                         subscreens[i]->draw(subbufs[i], width/2, height/2);
46                 }
47         }
48         
49         copy_subscreen(buf, subbufs[0], width, height);
50         copy_subscreen(buf + (width/2) * 4, subbufs[1], width, height);
51         copy_subscreen(buf + width * (height/2) * 4, subbufs[2], width, height);
52         copy_subscreen(buf + width * (height/2) * 4 + (width/2) * 4, subbufs[3], width, height); 
53         
54         // make divider lines
55         int r = atoi(get_theme_config("divider", "red").c_str());
56         int g = atoi(get_theme_config("divider", "green").c_str());
57         int b = atoi(get_theme_config("divider", "blue").c_str());
58
59         unsigned char *ptr = buf + (height/2) * width * 4;
60         for (unsigned x = 0; x < width; ++x) {
61                 *ptr++ = b;
62                 *ptr++ = g;
63                 *ptr++ = r;
64                 *ptr++ = 0;
65         }
66         
67         ptr = buf + (width/2) * 4;
68         for (unsigned y = 0; y < height; ++y) {
69                 ptr[0] = b;
70                 ptr[1] = g;
71                 ptr[2] = r;
72                 ptr[3] = 0;
73
74                 ptr += width * 4;
75         }
76         
77         valid = true;
78 }
79
80 void SplitScreen::copy_subscreen(unsigned char *dst, unsigned char *src, unsigned width, unsigned height)
81 {
82         for (unsigned y = 0; y < height/2; ++y) {
83                 unsigned char *sptr = src + y * width/2 * 4;
84                 unsigned char *dptr = dst + y * width * 4;
85
86                 memcpy(dptr, sptr, width/2 * 4);
87         }
88 }
89