de-duplicate function copy-paste for node color sampling.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 12 Jan 2012 05:46:45 +0000 (05:46 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 12 Jan 2012 05:46:45 +0000 (05:46 +0000)
source/blender/editors/include/ED_image.h
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_image/image_intern.h
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_edit.c

index 27c61e98e21deb8965889fd795ac81dac1d03c91..957b58b141c95213fed7311d081933ca1f309791 100644 (file)
@@ -66,5 +66,8 @@ int ED_space_image_show_uvshadow(struct SpaceImage *sima, struct Object *obedit)
 /* UI level image (texture) updating... render calls own stuff (too) */
 void ED_image_update_frame(const struct Main *mainp, int cfra);
 
+void ED_image_draw_info(struct ARegion *ar, int color_manage, int channels,
+                        int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf);
+
 #endif /* ED_IMAGE_H */
 
index 21a4f35bcb84e79b256abd87b58097b705ba71a2..923bf506b566e3d4e89a9fe49c7b0c7375f555ea 100644 (file)
@@ -110,7 +110,8 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar)
        BKE_image_release_renderresult(scene, ima);
 }
 
-void draw_image_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf)
+/* used by node view too */
+void ED_image_draw_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf)
 {
        char str[256];
        float dx= 6;
index 04156c80c0e4db4ee9e08fb3494bc1d3d33f6efb..29673f7453874e6bdb91695fec6ff7b53ec17b6a 100644 (file)
@@ -55,7 +55,6 @@ void IMAGE_OT_toolbox(struct wmOperatorType *ot);
 
 /* image_draw.c */
 void draw_image_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene);
-void draw_image_info(struct ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4], int *zp, float *zpf);
 void draw_image_grease_pencil(struct bContext *C, short onlyv2d);
 
 /* image_ops.c */
index 2e7fb697c568a18639c9692fd74cc02d957d1a43..999a25f57b5a4f43e388270cdc63d2eced33f0b6 100644 (file)
@@ -1772,7 +1772,7 @@ static void image_sample_draw(const bContext *UNUSED(C), ARegion *ar, void *arg_
        ImageSampleInfo *info= arg_info;
        if(info->draw) {
                /* no color management needed for images (color_manage=0) */
-               draw_image_info(ar, 0, info->channels, info->x, info->y, info->colp, info->colfp, info->zp, info->zfp);
+               ED_image_draw_info(ar, 0, info->channels, info->x, info->y, info->colp, info->colfp, info->zp, info->zfp);
        }
 }
 
index 3f8d9a75244c5311aa7cd79691b4428fbc51813b..7d475973c0936f90b0bfbd97ed738e2e13bab1cf 100644 (file)
@@ -2279,211 +2279,6 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage)
        }
 }
 
-void draw_nodespace_color_info(ARegion *ar, int color_manage, int channels, int x, int y, const char cp[4], const float fp[4])
-{
-       char str[256];
-       float dx= 6;
-       /* text colors */
-       /* XXX colored text not allowed in Blender UI */
-       #if 0
-       unsigned char red[3] = {255, 50, 50};
-       unsigned char green[3] = {0, 255, 0};
-       unsigned char blue[3] = {100, 100, 255};
-       #else
-       unsigned char red[3] = {255, 255, 255};
-       unsigned char green[3] = {255, 255, 255};
-       unsigned char blue[3] = {255, 255, 255};
-       #endif
-       float hue=0, sat=0, val=0, lum=0, u=0, v=0;
-       float col[4], finalcol[4];
-
-       glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-       glEnable(GL_BLEND);
-
-       /* noisy, high contrast make impossible to read if lower alpha is used. */
-       glColor4ub(0, 0, 0, 190);
-       glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
-       glDisable(GL_BLEND);
-
-       BLF_size(blf_mono_font, 11, 72);
-
-       glColor3ub(255, 255, 255);
-       BLI_snprintf(str, sizeof(str), "X:%-4d  Y:%-4d |", x, y);
-       // UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
-       BLF_position(blf_mono_font, dx, 6, 0);
-       BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-       dx += BLF_width(blf_mono_font, str);
-
-       #if 0   /* XXX no Z value in compo backdrop atm */
-       if(zp) {
-               glColor3ub(255, 255, 255);
-               BLI_snprintf(str, sizeof(str), " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-       }
-       if(zpf) {
-               glColor3ub(255, 255, 255);
-               BLI_snprintf(str, sizeof(str), " Z:%-.3f |", *zpf);
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-       }
-       #endif
-
-       if(channels >= 3) {
-               glColor3ubv(red);
-               if (fp)
-                       BLI_snprintf(str, sizeof(str), "  R:%-.4f", fp[0]);
-               else if (cp)
-                       BLI_snprintf(str, sizeof(str), "  R:%-3d", cp[0]);
-               else
-                       BLI_snprintf(str, sizeof(str), "  R:-");
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-               
-               glColor3ubv(green);
-               if (fp)
-                       BLI_snprintf(str, sizeof(str), "  G:%-.4f", fp[1]);
-               else if (cp)
-                       BLI_snprintf(str, sizeof(str), "  G:%-3d", cp[1]);
-               else
-                       BLI_snprintf(str, sizeof(str), "  G:-");
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-               
-               glColor3ubv(blue);
-               if (fp)
-                       BLI_snprintf(str, sizeof(str), "  B:%-.4f", fp[2]);
-               else if (cp)
-                       BLI_snprintf(str, sizeof(str), "  B:%-3d", cp[2]);
-               else
-                       BLI_snprintf(str, sizeof(str), "  B:-");
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-               
-               if(channels == 4) {
-                       glColor3ub(255, 255, 255);
-                       if (fp)
-                               BLI_snprintf(str, sizeof(str), "  A:%-.4f", fp[3]);
-                       else if (cp)
-                               BLI_snprintf(str, sizeof(str), "  A:%-3d", cp[3]);
-                       else
-                               BLI_snprintf(str, sizeof(str), "- ");
-                       BLF_position(blf_mono_font, dx, 6, 0);
-                       BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-                       dx += BLF_width(blf_mono_font, str);
-               }
-       }
-       
-       /* color rectangle */
-       if (channels==1) {
-               if (fp)
-                       col[0] = col[1] = col[2] = fp[0];
-               else if (cp)
-                       col[0] = col[1] = col[2] = (float)cp[0]/255.0f;
-               else
-                       col[0] = col[1] = col[2] = 0.0f;
-       }
-       else if (channels==3) {
-               if (fp)
-                       copy_v3_v3(col, fp);
-               else if (cp) {
-                       col[0] = (float)cp[0]/255.0f;
-                       col[1] = (float)cp[1]/255.0f;
-                       col[2] = (float)cp[2]/255.0f;
-               }
-               else
-                       zero_v3(col);
-       }
-       else if (channels==4) {
-               if (fp)
-                       copy_v4_v4(col, fp);
-               else if (cp) {
-                       col[0] = (float)cp[0]/255.0f;
-                       col[1] = (float)cp[1]/255.0f;
-                       col[2] = (float)cp[2]/255.0f;
-                       col[3] = (float)cp[3]/255.0f;
-               }
-               else
-                       zero_v4(col);
-       }
-       if (color_manage) {
-               linearrgb_to_srgb_v3_v3(finalcol, col);
-               finalcol[3] = col[3];
-       }
-       else {
-               copy_v4_v4(finalcol, col);
-       }
-       glDisable(GL_BLEND);
-       glColor3fv(finalcol);
-       dx += 5;
-       glBegin(GL_QUADS);
-       glVertex2f(dx, 3);
-       glVertex2f(dx, 17);
-       glVertex2f(dx+30, 17);
-       glVertex2f(dx+30, 3);
-       glEnd();
-       dx += 35;
-
-       glColor3ub(255, 255, 255);
-       if(channels == 1) {
-               if (fp) {
-                       rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
-                       rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v);
-               }
-               else if (cp) {
-                       rgb_to_hsv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &hue, &sat, &val);
-                       rgb_to_yuv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &lum, &u, &v);
-               }
-               
-               BLI_snprintf(str, sizeof(str), "V:%-.4f", val);
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-
-               BLI_snprintf(str, sizeof(str), "   L:%-.4f", lum);
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-       }
-       else if(channels >= 3) {
-               if (fp) {
-                       rgb_to_hsv(fp[0], fp[1], fp[2], &hue, &sat, &val);
-                       rgb_to_yuv(fp[0], fp[1], fp[2], &lum, &u, &v);
-               }
-               else if (cp) {
-                       rgb_to_hsv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &hue, &sat, &val);
-                       rgb_to_yuv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &lum, &u, &v);
-               }
-
-               BLI_snprintf(str, sizeof(str), "H:%-.4f", hue);
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-
-               BLI_snprintf(str, sizeof(str), "  S:%-.4f", sat);
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-
-               BLI_snprintf(str, sizeof(str), "  V:%-.4f", val);
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-
-               BLI_snprintf(str, sizeof(str), "   L:%-.4f", lum);
-               BLF_position(blf_mono_font, dx, 6, 0);
-               BLF_draw_ascii(blf_mono_font, str, sizeof(str));
-               dx += BLF_width(blf_mono_font, str);
-       }
-
-       (void)dx;
-}
-
 #if 0
 /* note: needs to be userpref or opengl profile option */
 static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode)
index 190f22dd60873b65100f4b2a92423fe05182c214..5beac4ea212b3b966fb3f8ffe378d0645e3c0a24 100644 (file)
@@ -71,6 +71,7 @@
 #include "IMB_imbuf_types.h"
 
 #include "ED_node.h"
+#include "ED_image.h"
 #include "ED_screen.h"
 #include "ED_space_api.h"
 #include "ED_render.h"
@@ -1343,8 +1344,10 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
 {
        ImageSampleInfo *info= arg_info;
 
-       draw_nodespace_color_info(ar, (CTX_data_scene(C)->r.color_mgt_flag & R_COLOR_MANAGEMENT), info->channels,
-                                                         info->x, info->y, info->col, info->colf);
+       ED_image_draw_info(ar, (CTX_data_scene(C)->r.color_mgt_flag & R_COLOR_MANAGEMENT), info->channels,
+                          info->x, info->y, info->col, info->colf,
+                          NULL, NULL /* zbuf - unused for nodes */
+                          );
 }
 
 static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)