Add a better framework for showing what's changed.
[ccbs] / bigscreen / fonts.cpp
index e65e356..2a7d274 100644 (file)
@@ -68,7 +68,9 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, in
 
                                unsigned char *dst = buf + dsty * 800*4 + (x + xpos + slot->bitmap_left)*4;
                                unsigned char *src = bm->buffer + y * bm->width;
 
                                unsigned char *dst = buf + dsty * 800*4 + (x + xpos + slot->bitmap_left)*4;
                                unsigned char *src = bm->buffer + y * bm->width;
-                               for (xx = 0; xx < bm->width; xx++) {
+
+                               int width = (x + xpos + slot->bitmap_left + bm->width >= 800) ? (799 - x - xpos - slot->bitmap_left) : bm->width;
+                               for (xx = 0; xx < width; xx++) {
                                        *dst = (*dst * (256-*src) + r * *src) >> 8;
                                        *dst++;
                                        *dst = (*dst * (256-*src) + g * *src) >> 8;
                                        *dst = (*dst * (256-*src) + r * *src) >> 8;
                                        *dst++;
                                        *dst = (*dst * (256-*src) + g * *src) >> 8;
@@ -86,3 +88,31 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, in
 
        return x;
 }
 
        return x;
 }
+
+void my_draw_text_deferred(std::vector<TextDefer> &td, const widestring &str, double size, int xpos, int ypos)
+{
+       TextDefer newtd;
+       newtd.str = str;
+       newtd.size = size;
+       newtd.xpos = xpos;
+       newtd.ypos = ypos;
+       td.push_back(newtd);
+}
+
+void draw_all_deferred_text(unsigned char *buf, std::vector<TextDefer> &current, std::vector<TextDefer> &old)
+{
+       for (unsigned i = 0; i < current.size(); ++i) {
+               int r, g, b;
+               if (i < old.size() && current[i].str != old[i].str) {
+                       // changed text
+                       r = 255;
+                       g = 0;
+                       b = 0;
+               } else {
+                       r = g = b = 255;
+               }       
+               
+               my_draw_text(current[i].str, buf, current[i].size, current[i].xpos, current[i].ypos, r, g, b);
+       }
+}
+