Metadata:
authorAntony Riakiotakis <kalast@gmail.com>
Tue, 21 Apr 2015 15:15:40 +0000 (17:15 +0200)
committerAntony Riakiotakis <kalast@gmail.com>
Tue, 21 Apr 2015 16:37:06 +0000 (18:37 +0200)
* Theme support for metadata display
* Increase text DPI with scaling.

source/blender/editors/include/UI_resources.h
source/blender/editors/interface/resources.c
source/blender/editors/screen/area.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c

index 3923c5c4432ae20e49871d096a86f96e0f872d58..2b19b6180e5313d86c1cada4aaf2b45ebdfd3509 100644 (file)
@@ -294,7 +294,10 @@ enum {
        TH_INFO_DEBUG_TEXT,
        TH_VIEW_OVERLAY,
        
-       TH_V3D_CLIPPING_BORDER
+       TH_V3D_CLIPPING_BORDER,
+
+       TH_METADATA_BG,
+       TH_METADATA_TEXT
 };
 /* XXX WARNING: previous is saved in file, so do not change order! */
 
index 15e742c930a87a43c966fcea7209d0a9e8423d68..b90c1c1009365dfc96b194fd7a212556e697b5b4 100644 (file)
@@ -569,6 +569,13 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
                                        cp = ts->paint_curve_pivot;
                                        break;
 
+                               case TH_METADATA_BG:
+                                       cp =ts->metadatabg;
+                                       break;
+                               case TH_METADATA_TEXT:
+                                       cp =ts->metadatatext;
+                                       break;
+
                                case TH_UV_OTHERS:
                                        cp = ts->uv_others;
                                        break;
index 1c87d959dc42cc6f30658b19e219429ee51901a7..fff55842f71fce56ef0af8a95451e9c880b8dafe 100644 (file)
@@ -2046,75 +2046,81 @@ const char *meta_data_list[] =
        "Scene"
 };
 
-BLI_INLINE bool metadata_is_valid(ImBuf *ibuf, char *r_str, short index)
+BLI_INLINE bool metadata_is_valid(ImBuf *ibuf, char *r_str, short index, int offset)
 {
-       return (IMB_metadata_get_field(ibuf, meta_data_list[index], r_str, MAX_METADATA_STR) && r_str[0]);
+       return (IMB_metadata_get_field(ibuf, meta_data_list[index], r_str + offset, MAX_METADATA_STR - offset) && r_str[0]);
 }
 
-static void metadata_draw_lines(ImBuf *ibuf, rcti rect, int fontid, const bool is_top)
+static void metadata_draw_imbuf(ImBuf *ibuf, rcti rect, int fontid, const bool is_top, float factor)
 {
        char temp_str[MAX_METADATA_STR];
        int line_width, line_height;
        int ofs_y = 0;
-       short line_index;
        short i;
+       int len;
 
-       for (line_index = 0; line_index < 4 && is_top == true; line_index++) {
-               /* first line */
-               if (line_index == 0) {
-                       int len;
-                       bool do_newline = false;
-                       float height = 0.0;
-                       BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]);
-                       len = strlen(temp_str);
-                       if (metadata_is_valid(ibuf, temp_str + len, 0)) {
-                               BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
-                                            rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
-                               BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
-                               do_newline = true;
-                               height = BLF_height(fontid, temp_str, strlen(temp_str));
-                       }
+       if (is_top) {
+               for (i = 0; i < 4; i++) {
+                       /* first line */
+                       if (i == 0) {
+                               bool do_newline = false;
+                               float height = 0.0;
+                               BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]);
+                               len = strlen(temp_str);
+                               if (metadata_is_valid(ibuf, temp_str, 0, len)) {
+                                       BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
+                                                    rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
+                                       BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+                                       do_newline = true;
+                                       height = BLF_height(fontid, temp_str, strlen(temp_str));
+                               }
 
-                       BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]);
-                       len = strlen(temp_str);
-                       if (metadata_is_valid(ibuf, temp_str + len, 1)) {
+                               BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]);
                                len = strlen(temp_str);
-                               line_width = BLF_width(fontid, temp_str, len);
-                               BLF_position(fontid, rect.xmax - line_width - (0.2f * U.widget_unit),
-                                            rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
-                               BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
-                               do_newline = true;
-                               height = max_ff(BLF_height(fontid, temp_str, len), height);
-                       }
+                               if (metadata_is_valid(ibuf, temp_str, 1, len)) {
+                                       len = strlen(temp_str);
+                                       line_width = BLF_width(fontid, temp_str, len);
+                                       BLF_position(fontid, rect.xmax - line_width - (0.2f * U.widget_unit),
+                                                    rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y), 0.0f);
+                                       BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+                                       do_newline = true;
+                                       height = max_ff(BLF_height(fontid, temp_str, len), height);
+                               }
 
-                       if (do_newline)
-                               ofs_y += (height + (0.2f * U.widget_unit));
-               }
-               else if (line_index == 1) {
-                       if (metadata_is_valid(ibuf, temp_str, line_index + 1)) {
-                               BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
-                                            rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
-                               BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
-                               ofs_y += (BLF_height(fontid, temp_str, strlen(temp_str)) + (0.2f * U.widget_unit));
+                               if (do_newline)
+                                       ofs_y += (height + (0.2f * U.widget_unit));
                        }
-               }
-               else {
-                       if (metadata_is_valid(ibuf, temp_str, line_index + 1)) {
-                               BLF_position(fontid, rect.xmax + (0.2f * U.widget_unit),
-                                            rect.ymax - (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
-                               BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
-                               ofs_y += (BLF_height(fontid, temp_str, strlen(temp_str)) + (0.2f * U.widget_unit));
+                       else if (i == 1) {
+                               BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]);
+                               len = strlen(temp_str);
+                               if (metadata_is_valid(ibuf, temp_str, i + 1, len)) {
+                                       BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit),
+                                                    rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
+                                       BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+                                       ofs_y += (BLF_height(fontid, temp_str, strlen(temp_str)) + (0.2f * U.widget_unit));
+                               }
+                       }
+                       else {
+                               BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]);
+                               len = strlen(temp_str);
+                               if (metadata_is_valid(ibuf, temp_str, i + 1, len)) {
+                                       BLF_position(fontid, rect.xmax + (0.2f * U.widget_unit),
+                                                    rect.ymax - factor * (1.5f * U.widget_unit - UI_UNIT_Y) - ofs_y, 0.0f);
+                                       BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
+                                       ofs_y += (BLF_height(fontid, temp_str, strlen(temp_str)) + (0.2f * U.widget_unit));
+                               }
                        }
                }
        }
-
-       if (is_top == false) {
+       else {
                int ofs_x = 0;
                for (i = 5; i < 10; i++) {
-                       if (metadata_is_valid(ibuf, temp_str, i)) {
+                       BLI_snprintf(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]);
+                       len = strlen(temp_str);
+                       if (metadata_is_valid(ibuf, temp_str, i, len)) {
                                line_height = BLF_height(fontid, temp_str, strlen(temp_str));
                                BLF_position(fontid, rect.xmin + (0.2f * U.widget_unit) + ofs_x,
-                                            rect.ymin - line_height + (1.5f * U.widget_unit), 0.0f);
+                                            rect.ymin - line_height + factor * (1.5f * U.widget_unit), 0.0f);
                                BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX);
        
                                ofs_x += BLF_width(fontid, temp_str, strlen(temp_str)) + UI_UNIT_X;
@@ -2131,14 +2137,14 @@ static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top)
 
        if (is_top) {
                for (i = 0; i < 5 ; i++) {
-                       if (metadata_is_valid(ibuf, str, i)) {
+                       if (metadata_is_valid(ibuf, str, i, 0)) {
                                height += BLF_height(fontid, str, strlen(str));
                        }
                }
        }
        else {
                for (i = 5; i < 10; i++) {
-                       if (metadata_is_valid(ibuf, str, i)) {
+                       if (metadata_is_valid(ibuf, str, i, 0)) {
                                height += BLF_height(fontid, str, strlen(str));
                        }
                }
@@ -2173,14 +2179,15 @@ void ED_region_image_metadata_draw(ARegion *ar, ImBuf *ibuf, float zoomx, float
        glTranslatef(x, y, 0.0f);
        glScalef(zoomx, zoomy, 1.0f);
 
+       BLF_size(fontid, style->widgetlabel.points, U.dpi * zoomy);
+
        /* *** upper box*** */
 
        /* get needed box height */
        box_y = metadata_box_height_get(ibuf, fontid, true);
 
        if (box_y) {
-               glColor3f(0.1f, 0.1f, 0.1f);
-               //glColor3f(1.0f, 0.15f, 0.8f); /* Pinkyfied version for Pablo */
+               UI_ThemeColor(TH_METADATA_BG);
 
                /* set up rect */
                BLI_rcti_init(&rect, 0, ibuf->x, ibuf->y, ibuf->y + box_y);
@@ -2190,9 +2197,8 @@ void ED_region_image_metadata_draw(ARegion *ar, ImBuf *ibuf, float zoomx, float
                BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
                BLF_enable(fontid, BLF_CLIPPING);
 
-               glColor3f(1.0f, 1.0f, 1.0f);
-
-               metadata_draw_lines(ibuf, rect, fontid, true);
+               UI_ThemeColor(TH_TEXT_HI);
+               metadata_draw_imbuf(ibuf, rect, fontid, true, zoomy);
 
                BLF_disable(fontid, BLF_CLIPPING);
        }
@@ -2203,8 +2209,7 @@ void ED_region_image_metadata_draw(ARegion *ar, ImBuf *ibuf, float zoomx, float
        box_y = metadata_box_height_get(ibuf, fontid, false);
 
        if (box_y) {
-               glColor3f(0.1f, 0.1f, 0.1f);
-               //glColor3f(1.0f, 0.15f, 0.8f); /* Pinkyfied version for Pablo */
+               UI_ThemeColor(TH_METADATA_BG);
 
                /* set up box rect */
                BLI_rcti_init(&rect, 0, ibuf->x, -box_y, 0);
@@ -2214,9 +2219,8 @@ void ED_region_image_metadata_draw(ARegion *ar, ImBuf *ibuf, float zoomx, float
                BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
                BLF_enable(fontid, BLF_CLIPPING);
 
-               glColor3f(1.0f, 1.0f, 1.0f);
-
-               metadata_draw_lines(ibuf, rect, fontid, false);
+               UI_ThemeColor(TH_TEXT_HI);
+               metadata_draw_imbuf(ibuf, rect, fontid, false, zoomy);
 
                BLF_disable(fontid, BLF_CLIPPING);
        }
index afa1f03a8cad6a2dfc645ddb528adc2255a74da1..e0b51a1b25b0e2350a197c50792930a2f46a79fb 100644 (file)
@@ -338,6 +338,9 @@ typedef struct ThemeSpace {
 
        char paint_curve_pivot[4];
        char paint_curve_handle[4];
+
+       char metadatabg[4];
+       char metadatatext[4];
 } ThemeSpace;
 
 
index b5ce031dd8031a6bde6f9ad773bdb42780f6f464..58f355bdf528b8edeb039f8be58bc474355ebd03 100644 (file)
@@ -2386,6 +2386,18 @@ static void rna_def_userdef_theme_space_image(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Current Frame", "");
        RNA_def_property_update(prop, 0, "rna_userdef_update");
 
+       prop = RNA_def_property(srna, "metadatabg", PROP_FLOAT, PROP_COLOR_GAMMA);
+       RNA_def_property_float_sdna(prop, NULL, "metadatabg");
+       RNA_def_property_array(prop, 3);
+       RNA_def_property_ui_text(prop, "Metadata Background", "");
+       RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+       prop = RNA_def_property(srna, "metadatatext", PROP_FLOAT, PROP_COLOR_GAMMA);
+       RNA_def_property_float_sdna(prop, NULL, "metadatatext");
+       RNA_def_property_array(prop, 3);
+       RNA_def_property_ui_text(prop, "Metadata Text", "");
+       RNA_def_property_update(prop, 0, "rna_userdef_update");
+
        rna_def_userdef_theme_spaces_curves(srna, false, false, false, true);
 
        rna_def_userdef_theme_spaces_paint_curves(srna);