Tuesday merger of bf-blender into orange branch.
[blender-staging.git] / source / blender / src / editsima.c
index eca241c155f42d3e4c8a11007b120d1075b3651a..2cef54283168d354226846b5111bf9865f87e2de 100644 (file)
@@ -59,6 +59,7 @@
 #include "DNA_image_types.h"
 #include "DNA_object_types.h" // only for uvedit_selectionCB() (struct Object)
 
+#include "BKE_colortools.h"
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_mesh.h"
@@ -84,6 +85,8 @@
 #include "BDR_editobject.h"
 #include "BDR_unwrapper.h"
 
+#include "BMF_Api.h"
+
 #include "blendef.h"
 #include "mydevice.h"
 
@@ -1395,3 +1398,97 @@ int minmax_tface_uv(float *min, float *max)
        return sel;
 }
 
+static void sima_show_info(int x, int y, char *cp, float *fp, unsigned int *zp)
+{
+       short ofs;
+       char str[256];
+       
+       ofs= sprintf(str, "X: %d Y: %d ", x, y);
+       if(cp)
+               ofs+= sprintf(str+ofs, "| R: %d G: %d B: %d A: %d ", cp[0], cp[1], cp[2], cp[3]);
+       if(fp)
+               ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f A: %.3f ", fp[0], fp[1], fp[2], fp[3]);
+       if(zp)
+               ofs+= sprintf(str+ofs, "| Z: %x ", *zp);
+       
+       glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+       glEnable(GL_BLEND);
+       
+       glColor4f(.0,.0,.0,.25);
+       glRectf(0.0, 0.0, curarea->winx, 30.0);
+       glDisable(GL_BLEND);
+       
+       glColor3ub(255, 255, 255);
+       glRasterPos2i(10, 10);
+       
+       BMF_DrawString(G.fonts, str);
+
+}
+
+void sima_sample_color(void)
+{
+       ImBuf *ibuf;
+       float fx, fy;
+       short mval[2], mvalo[2], firsttime=1;
+       
+       if(G.sima->image==NULL) return;
+       if(G.sima->image->ibuf==NULL) return;
+       ibuf= G.sima->image->ibuf;
+       
+       calc_image_view(G.sima, 'f');
+       getmouseco_areawin(mvalo);
+       
+       while(get_mbut() & L_MOUSE) {
+               
+               getmouseco_areawin(mval);
+               if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || firsttime) {
+                       firsttime= 0;
+                       areamouseco_to_ipoco(G.v2d, mval, &fx, &fy);
+                       
+                       if(fx>=0.0 && fy>=0.0 && fx<1.0 && fy<1.0) {
+                               float *fp= NULL;
+                               unsigned int *zp= NULL;
+                               char *cp= NULL;
+                               
+                               int x= (int) (fx*ibuf->x);
+                               int y= (int) (fy*ibuf->y);
+                               
+                               if(x>=ibuf->x) x= ibuf->x-1;
+                               if(y>=ibuf->y) y= ibuf->y-1;
+                               
+                               if(ibuf->rect) {
+                                       cp= (char *)(ibuf->rect + y*ibuf->x + x);
+                               }
+                               if(ibuf->zbuf) {
+                                       zp= ibuf->zbuf + y*ibuf->x + x;
+                               }
+                               if(ibuf->rect_float) {
+                                       fp= (ibuf->rect_float + 4*(y*ibuf->x + x));
+                                       
+                                       if(G.sima->cumap) {
+                                               if(G.qual & LR_CTRLKEY) {
+                                                       curvemapping_set_black_white(G.sima->cumap, NULL, fp);
+                                                       curvemapping_do_image(G.sima->cumap, G.sima->image);
+                                               }
+                                               else if(G.qual & LR_SHIFTKEY) {
+                                                       curvemapping_set_black_white(G.sima->cumap, fp, NULL);
+                                                       curvemapping_do_image(G.sima->cumap, G.sima->image);
+                                               }
+                                       }
+                               }
+                               
+                               scrarea_do_windraw(curarea);
+                               myortho2(-0.375, curarea->winx-0.375, -0.375, curarea->winy-0.375);
+                               glLoadIdentity();
+                               sima_show_info(x, y, cp, fp, zp);
+                               screen_swapbuffers();
+                       }
+                       
+               }
+               BIF_wait_for_statechange();
+       }
+       
+       scrarea_queue_winredraw(curarea);
+}
+
+