Patch by GSR #7628, I also added alpha for text background.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 23 Oct 2007 22:51:50 +0000 (22:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 23 Oct 2007 22:51:50 +0000 (22:51 +0000)
The list of changes (some are fixes):
- Properly horizontally centered tags in all fields (bug?).
- File area does not have trailing space and has leading "File " at
start instead (probably a bug).
- Small separation between to time related fields, space saving.
- Removed colons, for consistency and space saving again.
- Frame field is zero aligned for higher visual stability.
- Marker name shows a rarer name, "<none>" (using <> is typical for cases
in which there is nothing: <none>, <empty>, <blank>, etc).
- Top area for misc info that can be really long (file, note and render date).
- Bottom area for more constantly changing but short ones (marker, SMPTE,
frame, camera and scene).
- Only render date moves a line (when note field is not used), and frame one
moves if no SMPTE (still in same line, so no big jump), for extra visual
stability (marker is fixed, assuming most people would show frame and or
SMPTE).
- ISO 8601 date format for render date, localization independant.

Comparision images:
http://www.infernal-iceberg.com/blender/stamp-original.png
http://www.infernal-iceberg.com/blender/stamp-cleanup.png

source/blender/blenkernel/intern/image.c
source/blender/blenloader/intern/readfile.c
source/blender/imbuf/intern/rectop.c
source/blender/src/buttons_scene.c

index 278af464b8208c06f77a775499c3272d7ec2148f..56fd15cedb19ed6bdfe595e586e6ddbba1ae72d0 100644 (file)
@@ -823,16 +823,67 @@ void BKE_stamp(struct ImBuf *ibuf)
        
        IMB_imginfo_change_field (ibuf, "File", G.sce);
        if (G.scene->r.stamp & R_STAMP_DRAW) {
-               x = 1;
-               y = ibuf->y - font_height;
-               sprintf(text, "File: %s", G.sce);
+               /* Top left corner */
+               x = 1; /* Inits for everyone */
+               y = ibuf->y - font_height; /* Also inits for everyone */
+               sprintf(text, "File %s", G.sce);
                text_width = BMF_GetStringWidth(font, text);
                IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-               BMF_DrawStringBuf(font, G.sce, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               x = 1;
+               BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
                y -= font_height+1;
        }
 
+       if (G.scene->r.stamp & R_STAMP_NOTE) {
+               IMB_imginfo_change_field (ibuf, "Note", G.scene->r.stamp_udata);
+               if (G.scene->r.stamp & R_STAMP_DRAW) {
+                       /* Top left corner, below File */
+                       text_width = BMF_GetStringWidth(font, G.scene->r.stamp_udata);
+                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+                       BMF_DrawStringBuf(font, G.scene->r.stamp_udata, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
+                       y -= font_height+1;
+               }
+       }
+       
+       if (G.scene->r.stamp & R_STAMP_DATE) {
+#ifdef WIN32
+               _strdate (sdate);
+               sprintf (infotext, "%s", sdate);
+#else
+               t = time (NULL);
+               tl = localtime (&t);
+               sprintf (infotext, "%04d-%02d-%02d", tl->tm_year+1900, tl->tm_mon+1, tl->tm_mday);
+#endif /* WIN32 */
+               IMB_imginfo_change_field (ibuf, "Date", infotext);
+
+               if (G.scene->r.stamp & R_STAMP_DRAW) {
+                       /* Top left corner, below File (or Note) */
+                       sprintf (text, "Date %s", infotext);
+                       text_width = BMF_GetStringWidth(font, text);
+                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
+               }
+       }
+
+
+       if (G.scene->r.stamp & R_STAMP_MARKER) {
+               TimeMarker *marker = get_frame_marker(CFRA);
+               
+               if (marker) strcpy(infotext, marker->name);
+               else            strcpy(infotext, "<none>");
+               
+               IMB_imginfo_change_field (ibuf, "Marker", infotext);
+               
+               if (G.scene->r.stamp & R_STAMP_DRAW) {
+                       /* Bottom left corner, leaving space for timing */
+                       x = 1;
+                       y = font_height+1;
+                       sprintf (text, "Marker %s", infotext);
+                       text_width = BMF_GetStringWidth(font, text);
+                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
+                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
+               }
+       }
 
        if (G.scene->r.stamp & R_STAMP_TIME) {
                h= m= s= f= 0;
@@ -857,11 +908,14 @@ void BKE_stamp(struct ImBuf *ibuf)
                IMB_imginfo_change_field (ibuf, "Time", infotext);
                
                if (G.scene->r.stamp & R_STAMP_DRAW) {
+                       /* Left bottom corner */
+                       x = 1;
+                       y = 1;
                        sprintf (text, "Time %s", infotext);
                        text_width = BMF_GetStringWidth(font, text);
                        IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-                       x += text_width;
+                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
+                       x += text_width+text_pad;
                }
        }
 
@@ -870,47 +924,35 @@ void BKE_stamp(struct ImBuf *ibuf)
                IMB_imginfo_change_field (ibuf, "Frame", infotext);
 
                if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       sprintf (text, "    Frame %s", infotext);
-                       text_width = BMF_GetStringWidth(font, text);
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-                       x += BMF_GetStringWidth(font, text);
-               }
-       }
-
-       if (G.scene->r.stamp & R_STAMP_DATE) {
-#ifdef WIN32
-               _strdate (sdate);
-               sprintf (infotext, "%s", sdate);
-#else
-               t = time (NULL);
-               tl = localtime (&t);
-               sprintf (infotext, "%02d-%02d-%02d", tl->tm_mon+1, tl->tm_mday, tl->tm_year-100);
-#endif /* WIN32 */
-               IMB_imginfo_change_field (ibuf, "Date", infotext);
+                       char format[32];
 
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       x = 1;
-                       y = 1;
-                       sprintf (text, "Date %s", infotext);
+                       /* First build "Frame %03i" for anims ending in frame 100-999, etc */
+                       sprintf(format, "Frame %%0%di\n", 1 + (int) log10(G.scene->r.efra));
+                       sprintf (text, format, G.scene->r.cfra);
                        text_width = BMF_GetStringWidth(font, text);
+                       /* Left bottom corner (after SMPTE if exists) */
+                       if (!(G.scene->r.stamp & R_STAMP_TIME)) {
+                               x = 1;
+                       }
+                       y = 1;
                        IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-                       x += text_width;
+                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
                }
        }
 
+
        if (G.scene->r.stamp & R_STAMP_CAMERA) {
                sprintf(infotext, ((Camera *) G.scene->camera)->id.name+2);
                IMB_imginfo_change_field (ibuf, "Camera", infotext);
 
                if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       sprintf (text, "Camera: %s", infotext);
+                       sprintf (text, "Camera %s", infotext);
                        text_width = BMF_GetStringWidth(font, text);
+                       /* Center of bottom edge */
                        x = (ibuf->x/2) - (BMF_GetStringWidth(font, text)/2);
                        y = 1;
                        IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
+                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
                }
        }
 
@@ -919,41 +961,13 @@ void BKE_stamp(struct ImBuf *ibuf)
                IMB_imginfo_change_field (ibuf, "Scene", infotext);
 
                if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       sprintf (text, "Scene: %s", infotext);
+                       sprintf (text, "Scene %s", infotext);
                        text_width = BMF_GetStringWidth(font, text);
+                       /* Bottom right corner */
                        x = ibuf->x - (BMF_GetStringWidth(font, text)+1+text_pad);
+                       y = 1;
                        IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               }
-       }
-       
-       if (G.scene->r.stamp & R_STAMP_NOTE) {
-               IMB_imginfo_change_field (ibuf, "Note", G.scene->r.stamp_udata);
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       x = 1;
-                       y = font_height+1;
-                       text_width = BMF_GetStringWidth(font, G.scene->r.stamp_udata);
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, G.scene->r.stamp_udata, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
-               }
-       }
-       
-       if (G.scene->r.stamp & R_STAMP_MARKER) {
-               TimeMarker *marker = get_frame_marker(CFRA);
-               
-               if (marker) strcpy(infotext, marker->name);
-               else            strcpy(infotext, "None");
-               
-               IMB_imginfo_change_field (ibuf, "Marker", infotext);
-               
-               if (G.scene->r.stamp & R_STAMP_DRAW) {
-                       sprintf (text, "Marker: %s", infotext);
-                       x = 1;
-                       y = ibuf->y - (font_height+1)*3;
-                       text_width = BMF_GetStringWidth(font, text);
-                       IMB_rectfill_area(ibuf, G.scene->r.bg_stamp, x-1, y-1, x+text_width+text_pad+1, y+font_height+1);
-                       BMF_DrawStringBuf(font, text, x, y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
+                       BMF_DrawStringBuf(font, text, x+(text_pad/2), y, G.scene->r.fg_stamp, (unsigned char *)ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y);
                }
        }
 }
index 0b8500e6228d19c67ce8462091cd4ef8732eb479..fc5214572f48b9041132588c33134afe107b0643 100644 (file)
@@ -6781,6 +6781,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                Scene *sce;
                for(sce= main->scene.first; sce; sce=sce->id.next) {
                        sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8;
+                       sce->r.fg_stamp[3] = 1.0; /* dont use text alpha yet */
+                       sce->r.bg_stamp[3] = 0.25; /* make sure the background has full alpha */
                }
        }
 
index 55cd4b9b6a1f846bda14d32b881037ffdf8b77a5..591ab066c57f1297aec36e4770574dc57d112f44 100644 (file)
@@ -524,7 +524,7 @@ void IMB_rectfill(struct ImBuf *drect, float col[4])
 void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2)
 {
        int i, j;
-       
+       float a, ai;
        if ((!ibuf) || (!col))
                return;
        
@@ -538,6 +538,9 @@ void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, i
        if (y1>y2) SWAP(int,y1,y2);
        if (x1==x2 || y1==y2) return;
        
+       a = col[3];
+       ai = 1-a;
+       
        if (ibuf->rect) {
                unsigned char *img, *pixel; 
                unsigned char chr, chg, chb;
@@ -550,9 +553,16 @@ void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, i
                for (j = 0; j < y2-y1; j++) {
                        for (i = 0; i < x2-x1; i++) {
                                pixel = img + 4 * (((y1 + j) * ibuf->x) + (x1 + i));
-                               pixel[0] = chr;
-                               pixel[1] = chg;
-                               pixel[2] = chb;
+                               if (a == 1.0) {
+                                       pixel[0] = chr;
+                                       pixel[1] = chg;
+                                       pixel[2] = chb;
+                               } else {
+                                       pixel[0] = (char)((chr*a) + (pixel[0]*ai));
+                                       pixel[1] = (char)((chg*a) + (pixel[1]*ai));
+                                       pixel[2] = (char)((chb*a) + (pixel[2]*ai));
+                               }
+                               
                        }
                }
        }
@@ -563,9 +573,15 @@ void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, i
                for (j = 0; j < y2-y1; j++) {
                        for (i = 0; i < x2-x1; i++) {
                                pixel = img + 4 * (((y1 + j) * ibuf->x) + (x1 + i));
-                               pixel[0] = col[0];
-                               pixel[1] = col[1];
-                               pixel[2] = col[2];
+                               if (a == 1.0) {
+                                       pixel[0] = col[0];
+                                       pixel[1] = col[1];
+                                       pixel[2] = col[2];
+                               } else {
+                                       pixel[0] = (col[0]*a) + (pixel[0]*ai);
+                                       pixel[1] = (col[1]*a) + (pixel[1]*ai);
+                                       pixel[2] = (col[2]*a) + (pixel[2]*ai);
+                               }
                        }
                }
        }
index d61268b20642387de0e6e2d91aa0d55d45eb12bf..7232698a7a88b5e90f08ded98102bacb17ba213a 100644 (file)
@@ -1570,12 +1570,14 @@ static void render_panel_stamp(void)
                        
                        /* draw fg/bg next to the scene */
                        yofs -= 25;
-                       uiDefBut(block, LABEL, 0, "Text Color", xofs+110, yofs, 80, 19, 0, 0, 0, 0, 0, "");
-                       uiDefBut(block, LABEL, 0, "Background", xofs+205, yofs, 80, 19, 0, 0, 0, 0, 0, "");
+                       uiDefBut(block, LABEL, B_NOP, "Text Color", xofs+110, yofs, 80, 19, 0, 0, 0, 0, 0, "");
+                       uiDefBut(block, LABEL, B_NOP, "Background", xofs+205, yofs, 80, 19, 0, 0, 0, 0, 0, "");
                        yofs -= 20;
                        uiDefButF(block, COL, B_NOP, "", xofs+110, yofs, 90, 19, G.scene->r.fg_stamp, 0, 0, 0, 0, "Foreground text color");
                        uiDefButF(block, COL, B_NOP, "", xofs+210, yofs, 90, 19, G.scene->r.bg_stamp, 0, 0, 0, 0, "Background color");
-                       yofs += 75;
+                       yofs -= 30;
+                       uiDefButF(block, NUMSLI, B_NOP, "A", xofs+110, yofs, 180, 19, &G.scene->r.bg_stamp[3], 0, 1.0, 0, 0, "Alpha for text background");
+                       yofs += 105;
                } else {
                        yofs += 30;
                }