Fix #23652: texture paint RMB would translate the object after sampling
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 16 Sep 2010 21:03:07 +0000 (21:03 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 16 Sep 2010 21:03:07 +0000 (21:03 +0000)
color, made sample a modal operator now to solve this. It's an indirect
solution, but couldn't think of anything better, and it's useful to have
anyway.

source/blender/editors/sculpt_paint/paint_image.c

index 3f1a5af76b1ff16558be0af02d84ebb9a350c9e9..e7a06f27f67db88449780f469861cab4ed3526d1 100644 (file)
@@ -5135,11 +5135,40 @@ static int sample_color_invoke(bContext *C, wmOperator *op, wmEvent *event)
        ARegion *ar= CTX_wm_region(C);
        int location[2];
 
-       location[0]= event->x - ar->winrct.xmin;
-       location[1]= event->y - ar->winrct.ymin;
-       RNA_int_set_array(op->ptr, "location", location);
+       if(ar) {
+               location[0]= event->x - ar->winrct.xmin;
+               location[1]= event->y - ar->winrct.ymin;
+               RNA_int_set_array(op->ptr, "location", location);
 
-       return sample_color_exec(C, op);
+               sample_color_exec(C, op);
+       }
+
+       WM_event_add_modal_handler(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+static int sample_color_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       ARegion *ar= CTX_wm_region(C);
+       int location[2];
+
+       switch(event->type) {
+               case LEFTMOUSE:
+               case RIGHTMOUSE: // XXX hardcoded
+                       return OPERATOR_FINISHED;
+               case MOUSEMOVE:
+                       if(ar) {
+                               location[0]= event->x - ar->winrct.xmin;
+                               location[1]= event->y - ar->winrct.ymin;
+                               RNA_int_set_array(op->ptr, "location", location);
+
+                               sample_color_exec(C, op);
+                       }
+                       break;
+       }
+
+       return OPERATOR_RUNNING_MODAL;
 }
 
 void PAINT_OT_sample_color(wmOperatorType *ot)
@@ -5151,6 +5180,7 @@ void PAINT_OT_sample_color(wmOperatorType *ot)
        /* api callbacks */
        ot->exec= sample_color_exec;
        ot->invoke= sample_color_invoke;
+       ot->modal= sample_color_modal;
        ot->poll= image_paint_poll;
 
        /* flags */