Fix a bug where all new screens would be cycled on start.
[ccbs] / bigscreen / rotatescreen.cpp
index 1dba1cc..ef7fba0 100644 (file)
@@ -32,24 +32,33 @@ bool RotateScreen::check_invalidated()
 void RotateScreen::draw(unsigned char *buf)
 {
        bool force = false;
+
+       if (subscreens.size() == 0) {
+               valid = true;
+               gettimeofday(&last_update, NULL);
+               return;
+       }
        
        // if we're in a fade, complete it before doing anything else
        if (in_fade) {
                struct timeval now;
                gettimeofday(&now, NULL);
 
+               if (!fade_found_start_time) {
+                       fade_found_start_time = true;
+                       fade_started = now;
+               }
+               
                double elapsed_fade = double(now.tv_sec - fade_started.tv_sec) +
                        double(now.tv_usec - fade_started.tv_usec) * 1.0e-6;
-               printf("fade: %f\n", elapsed_fade);
                
-               if (elapsed_fade > 5.0 || (!same_fade && elapsed_fade > 0.5)) {
+               if (elapsed_fade > 5.5 || (!same_fade && elapsed_fade > 0.5)) {
                        in_fade = false;
 
                        // ugly hack here? :-)
                        subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
                        
                        memcpy(buf, subscreens[current_screen].buf, 800 * 600 * 4);
-                       printf("fade done\n");
                } else {
                        // find the fade factors
                        int fr, fg, fb, fa;
@@ -57,12 +66,11 @@ void RotateScreen::draw(unsigned char *buf)
                                if (elapsed_fade < 0.5) {
                                        fr = fg = fb = fa = unsigned(elapsed_fade/0.5 * 256.0);
                                } else {
-                                       fr = fg = fb = fa = unsigned((elapsed_fade-0.5)/4.5 * 256.0);
+                                       fr = fg = fb = fa = unsigned((elapsed_fade-0.5)/5.0 * 256.0);
                                }
                        } else {
                                fr = fg = fb = fa = unsigned(elapsed_fade/0.5 * 256.0);
                        }
-                       printf("%u %u %u %u\n", fr, fg, fb, fa);
 
                        unsigned char *sptr1 = fadefrom_buf;
                        unsigned char *sptr2 = subscreens[current_screen].buf;
@@ -108,12 +116,11 @@ void RotateScreen::draw(unsigned char *buf)
                        gettimeofday(&last_update, NULL);
                }
 
-               if (current_screen != old_current_screen || subscreens[current_screen].screen->check_invalidated()) {
+               if (!valid || current_screen != old_current_screen || subscreens[current_screen].screen->check_invalidated()) {
                        // initialize a fade
                        in_fade = true;
+                       fade_found_start_time = false;
                        same_fade = (current_screen == old_current_screen);
-                       gettimeofday(&fade_started, NULL);
-                       printf("starting fade (same=%u)\n", same_fade);
                        
                        memcpy(fadefrom_buf, subscreens[old_current_screen].buf, 800 * 600 * 4);
 
@@ -146,6 +153,8 @@ void RotateScreen::add_screen(GenericScreen *screen)
        ss.buf = new unsigned char[800 * 600 * 4];
        ss.screen = screen;
 
+       screen->draw(ss.buf);
+       
        subscreens.push_back(ss);
 }