UI: only reset eyedropper on cancel when set
authorCampbell Barton <ideasman42@gmail.com>
Thu, 17 Jan 2019 22:31:39 +0000 (09:31 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 17 Jan 2019 22:31:39 +0000 (09:31 +1100)
source/blender/editors/interface/interface_eyedropper_color.c
source/blender/editors/interface/interface_eyedropper_colorband.c
source/blender/editors/interface/interface_eyedropper_depth.c

index 322d368..9448585 100644 (file)
@@ -71,6 +71,7 @@ typedef struct Eyedropper {
        int index;
        bool is_undo;
 
+       bool is_set;
        float init_col[3]; /* for resetting on cancel */
 
        bool  accum_start; /* has mouse been pressed */
@@ -212,6 +213,7 @@ static void eyedropper_color_set(bContext *C, Eyedropper *eye, const float col[3
        }
 
        RNA_property_float_set_array(&eye->ptr, eye->prop, col_conv);
+       eye->is_set = true;
 
        RNA_property_update(C, &eye->ptr, eye->prop);
 }
@@ -245,7 +247,9 @@ static void eyedropper_color_sample(bContext *C, Eyedropper *eye, int mx, int my
 static void eyedropper_cancel(bContext *C, wmOperator *op)
 {
        Eyedropper *eye = op->customdata;
-       eyedropper_color_set(C, eye, eye->init_col);
+       if (eye->is_set) {
+               eyedropper_color_set(C, eye, eye->init_col);
+       }
        eyedropper_exit(C, op);
 }
 
index dd4524c..805e117 100644 (file)
@@ -73,6 +73,7 @@ typedef struct EyedropperColorband {
        PointerRNA ptr;
        PropertyRNA *prop;
        bool is_undo;
+       bool is_set;
 } EyedropperColorband;
 
 /* For user-data only. */
@@ -132,6 +133,7 @@ static void eyedropper_colorband_sample_point(bContext *C, EyedropperColorband *
                eye->color_buffer_len += 1;
                eye->last_x = mx;
                eye->last_y = my;
+               eye->is_set = true;
        }
 }
 
@@ -172,14 +174,17 @@ static void eyedropper_colorband_apply(bContext *C, wmOperator *op)
        /* Always filter, avoids noise in resulting color-band. */
        bool filter_samples = true;
        BKE_colorband_init_from_table_rgba(eye->color_band, eye->color_buffer, eye->color_buffer_len, filter_samples);
+       eye->is_set = true;
        RNA_property_update(C, &eye->ptr, eye->prop);
 }
 
 static void eyedropper_colorband_cancel(bContext *C, wmOperator *op)
 {
        EyedropperColorband *eye = op->customdata;
-       *eye->color_band = eye->init_color_band;
-       RNA_property_update(C, &eye->ptr, eye->prop);
+       if (eye->is_set) {
+               *eye->color_band = eye->init_color_band;
+               RNA_property_update(C, &eye->ptr, eye->prop);
+       }
        eyedropper_colorband_exit(C, op);
 }
 
index 4d0a95a..1634e7c 100644 (file)
@@ -69,6 +69,7 @@ typedef struct DepthDropper {
        PropertyRNA *prop;
        bool is_undo;
 
+       bool is_set;
        float init_depth; /* for resetting on cancel */
 
        bool  accum_start; /* has mouse been presed */
@@ -219,6 +220,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx,
 static void depthdropper_depth_set(bContext *C, DepthDropper *ddr, const float depth)
 {
        RNA_property_float_set(&ddr->ptr, ddr->prop, depth);
+       ddr->is_set = true;
        RNA_property_update(C, &ddr->ptr, ddr->prop);
 }
 
@@ -255,7 +257,9 @@ static void depthdropper_depth_sample_accum(bContext *C, DepthDropper *ddr, int
 static void depthdropper_cancel(bContext *C, wmOperator *op)
 {
        DepthDropper *ddr = op->customdata;
-       depthdropper_depth_set(C, ddr, ddr->init_depth);
+       if (ddr->is_set) {
+               depthdropper_depth_set(C, ddr, ddr->init_depth);
+       }
        depthdropper_exit(C, op);
 }