From 5ae75d5dc841a6fa33b8ead55bc6fbe89bb8b767 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 16 Sep 2010 21:03:07 +0000 Subject: [PATCH] Fix #23652: texture paint RMB would translate the object after sampling 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. --- .../editors/sculpt_paint/paint_image.c | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 3f1a5af76b1..e7a06f27f67 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -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 */