X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=bigscreen%2Frotatescreen.cpp;h=4fc9fa0903ff50c7247cd02ecf686908698fc1e1;hp=fcc975cbc1ba54a86fa15972a6a5064fe655253c;hb=09ae4d8636130d4c86ab3f8df8f823482f948f97;hpb=0b3bb271ac40b5f8bcfc5a417d4423e92c4483b1 diff --git a/bigscreen/rotatescreen.cpp b/bigscreen/rotatescreen.cpp index fcc975c..4fc9fa0 100644 --- a/bigscreen/rotatescreen.cpp +++ b/bigscreen/rotatescreen.cpp @@ -1,10 +1,12 @@ +/* NOTE: this class will _NOT_ handle resolution changes cleanly. You have been warned. :-) */ + +#include #include #include "rotatescreen.h" RotateScreen::RotateScreen() - : valid(false), current_screen(0), in_fade(false) + : fadefrom_buf(NULL), valid(false), current_screen(0), in_fade(false) { - fadefrom_buf = new unsigned char[800 * 600 * 4]; } RotateScreen::~RotateScreen() @@ -24,15 +26,27 @@ bool RotateScreen::check_invalidated() return false; for (unsigned i = 0; i < subscreens.size(); ++i) { - if (subscreens[i].screen->check_invalidated()) + if (subscreens[i].buf == NULL || subscreens[i].screen->check_invalidated()) return true; } return false; } -void RotateScreen::draw(unsigned char *buf) +void RotateScreen::draw(unsigned char *buf, unsigned width, unsigned height) { + // see line 1 for all of this + if (fadefrom_buf == NULL) { + fadefrom_buf = new unsigned char[width * height * 4]; + } + for (std::vector::iterator i = subscreens.begin(); i != subscreens.end(); ++i) { + if (i->buf == NULL) { + i->buf = new unsigned char[width * height * 4]; + i->screen->draw(i->buf, width, height); + } + } + // end of "line 1"-code :-) + bool force = false; if (subscreens.size() == 0) { @@ -58,9 +72,9 @@ void RotateScreen::draw(unsigned char *buf) in_fade = false; // ugly hack here? :-) - subscreens[current_screen].screen->draw(subscreens[current_screen].buf); + subscreens[current_screen].screen->draw(subscreens[current_screen].buf, width, height); - memcpy(buf, subscreens[current_screen].buf, 800 * 600 * 4); + memcpy(buf, subscreens[current_screen].buf, width * height * 4); } else { // find the fade factors int fr, fg, fb, fa; @@ -80,7 +94,7 @@ void RotateScreen::draw(unsigned char *buf) if (fade_to_new_info && elapsed_fade >= 0.5) { // fade G&B to be = R - for (unsigned i = 0; i < 800 * 600; ++i) { + for (unsigned i = 0; i < width * height; ++i) { dptr[0] = sptr2[0] + (((int(sptr2[2]) - int(sptr2[0])) * fb) >> 8); dptr[1] = sptr2[1] + (((int(sptr2[2]) - int(sptr2[1])) * fg) >> 8); dptr[2] = sptr2[2]; @@ -89,7 +103,7 @@ void RotateScreen::draw(unsigned char *buf) sptr1 += 4, sptr2 += 4, dptr += 4; } } else { - for (unsigned i = 0; i < 800 * 600; ++i) { + for (unsigned i = 0; i < width * height; ++i) { dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * fb) >> 8); dptr[1] = sptr1[1] + (((int(sptr2[1]) - int(sptr1[1])) * fg) >> 8); dptr[2] = sptr1[2] + (((int(sptr2[2]) - int(sptr1[2])) * fr) >> 8); @@ -126,10 +140,11 @@ void RotateScreen::draw(unsigned char *buf) fade_found_start_time = false; fade_to_new_info = force; - memcpy(fadefrom_buf, subscreens[old_current_screen].buf, 800 * 600 * 4); + memcpy(fadefrom_buf, subscreens[old_current_screen].buf, width * height * 4); - if (subscreens[current_screen].screen->check_invalidated()) - subscreens[current_screen].screen->draw(subscreens[current_screen].buf); + if (subscreens[current_screen].screen->check_invalidated()) { + subscreens[current_screen].screen->draw(subscreens[current_screen].buf, width, height); + } } } @@ -170,11 +185,9 @@ bool RotateScreen::can_update() void RotateScreen::add_screen(GenericScreen *screen) { Subscreen ss; - ss.buf = new unsigned char[800 * 600 * 4]; + ss.buf = NULL; ss.screen = screen; - screen->draw(ss.buf); - subscreens.push_back(ss); }