Setting clone cursor is now an option for paint operator. This is not
authorAntony Riakiotakis <kalast@gmail.com>
Sun, 17 Mar 2013 03:08:46 +0000 (03:08 +0000)
committerAntony Riakiotakis <kalast@gmail.com>
Sun, 17 Mar 2013 03:08:46 +0000 (03:08 +0000)
too nice but it frees the Ctrl-LClick shortcut and allows us to set
invert mode for other paint tools, such as sharpen vs blur or invert
colour for draw brush. This conflict has existed on GSOC branch, better
resolve now before merging invert functionality.

source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/sculpt_paint/paint_intern.h
source/blender/editors/sculpt_paint/paint_ops.c

index 983cf085e7c513598bf49caa6614e601d8f0aa0b..6645015a2b29228f15da67da0071fc9cde014287 100644 (file)
@@ -371,14 +371,6 @@ static int image_paint_poll(bContext *C)
        return 0;
 }
 
-static int image_paint_3d_poll(bContext *C)
-{
-       if (CTX_wm_region_view3d(C))
-               return image_paint_poll(C);
-       
-       return 0;
-}
-
 static int image_paint_2d_clone_poll(bContext *C)
 {
        Brush *brush = image_paint_brush(C);
@@ -450,7 +442,7 @@ static PaintOperation * texture_paint_init(bContext *C, wmOperator *op, const wm
        Scene *scene = CTX_data_scene(C);
        ToolSettings *settings = scene->toolsettings;
        PaintOperation *pop = MEM_callocN(sizeof(PaintOperation), "PaintOperation"); /* caller frees */
-
+       int mode = RNA_enum_get(op->ptr, "mode");
        view3d_set_viewcontext(C, &pop->vc);
 
        /* TODO Should avoid putting this here. Instead, last position should be requested
@@ -462,7 +454,7 @@ static PaintOperation * texture_paint_init(bContext *C, wmOperator *op, const wm
        /* initialize from context */
        if (CTX_wm_region_view3d(C)) {
                pop->mode = PAINT_MODE_3D_PROJECT;
-               pop->custom_paint = paint_proj_new_stroke(C, OBACT, pop->prevmouse);
+               pop->custom_paint = paint_proj_new_stroke(C, OBACT, pop->prevmouse, mode);
        }
        else {
                pop->mode = PAINT_MODE_2D;
@@ -512,7 +504,7 @@ static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, Po
                BKE_brush_size_set(scene, brush, max_ff(1.0f, startsize * pressure));
 
        if (pop->mode == PAINT_MODE_3D_PROJECT) {
-               redraw = paint_proj_stroke(pop->custom_paint, pop->prevmouse, mouse);
+               redraw = paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse);
        }
        else {
                redraw = paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser);
@@ -599,6 +591,11 @@ static int paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 void PAINT_OT_image_paint(wmOperatorType *ot)
 {
+       static EnumPropertyItem stroke_mode_items[] = {
+               {BRUSH_STROKE_NORMAL, "NORMAL", 0, "Normal", "Apply brush normally"},
+               {BRUSH_STROKE_INVERT, "INVERT", 0, "Invert", "Invert action of brush for duration of stroke"},
+               {0}
+       };
 
        /* identifiers */
        ot->name = "Image Paint";
@@ -615,6 +612,10 @@ void PAINT_OT_image_paint(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
 
+       RNA_def_enum(ot->srna, "mode", stroke_mode_items, BRUSH_STROKE_NORMAL,
+                                "Paint Stroke Mode",
+                                "Action taken when a paint stroke is made");
+
        RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
 }
 
@@ -930,57 +931,6 @@ void PAINT_OT_sample_color(wmOperatorType *ot)
        RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "Cursor location in region coordinates", 0, 16384);
 }
 
-/******************** set clone cursor operator ********************/
-
-static int set_clone_cursor_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene = CTX_data_scene(C);
-       View3D *v3d = CTX_wm_view3d(C);
-       float *cursor = give_cursor(scene, v3d);
-
-       RNA_float_get_array(op->ptr, "location", cursor);
-       
-       ED_area_tag_redraw(CTX_wm_area(C));
-       
-       return OPERATOR_FINISHED;
-}
-
-static int set_clone_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
-{
-       Scene *scene = CTX_data_scene(C);
-       View3D *v3d = CTX_wm_view3d(C);
-       ARegion *ar = CTX_wm_region(C);
-       float location[3];
-
-       view3d_operator_needs_opengl(C);
-
-       if (!ED_view3d_autodist(scene, ar, v3d, event->mval, location))
-               return OPERATOR_CANCELLED;
-
-       RNA_float_set_array(op->ptr, "location", location);
-
-       return set_clone_cursor_exec(C, op);
-}
-
-void PAINT_OT_clone_cursor_set(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Set Clone Cursor";
-       ot->idname = "PAINT_OT_clone_cursor_set";
-       ot->description = "Set the location of the clone cursor";
-       
-       /* api callbacks */
-       ot->exec = set_clone_cursor_exec;
-       ot->invoke = set_clone_cursor_invoke;
-       ot->poll = image_paint_3d_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-       /* properties */
-       RNA_def_float_vector(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Cursor location in world space coordinates", -10000.0f, 10000.0f);
-}
-
 /******************** texture paint toggle operator ********************/
 
 static int texture_paint_toggle_poll(bContext *C)
index 05b1044a96434133adbf5ffee4920d243553f306..96916236279d22638104bcb0493740b68ad1eec1 100644 (file)
@@ -205,7 +205,7 @@ typedef struct ProjPaintState {
        int source; /* PROJ_SRC_**** */
 
        Brush *brush;
-       short tool, blend;
+       short tool, blend, mode;
        int orig_brush_size;
        Object *ob;
        /* end similarities with ImagePaintState */
@@ -4098,7 +4098,7 @@ static int project_paint_op(void *state, const float lastpos[2], const float pos
 }
 
 
-int paint_proj_stroke(void *pps, const int prevmval_i[2], const int mval_i[2])
+int paint_proj_stroke(bContext *C, void *pps, const int prevmval_i[2], const int mval_i[2])
 {
        ProjPaintState *ps = pps;
        int a, redraw;
@@ -4110,6 +4110,22 @@ int paint_proj_stroke(void *pps, const int prevmval_i[2], const int mval_i[2])
        prev_pos[0] = (float)(prevmval_i[0]);
        prev_pos[1] = (float)(prevmval_i[1]);
 
+       /* clone gets special treatment here to avoid going through image initialization */
+       if (ps->tool == PAINT_TOOL_CLONE && ps->mode == BRUSH_STROKE_INVERT) {
+               Scene *scene = ps->scene;
+               View3D *v3d = ps->v3d;
+               float *cursor = give_cursor(scene, v3d);
+
+               view3d_operator_needs_opengl(C);
+
+               if (!ED_view3d_autodist(scene, ps->ar, v3d, mval_i, cursor))
+                       return 0;
+
+               ED_region_tag_redraw(ps->ar);
+
+               return 0;
+       }
+
        for (a = 0; a < ps->image_tot; a++)
                partial_redraw_array_init(ps->projImages[a].partRedrawRect);
 
@@ -4123,12 +4139,13 @@ int paint_proj_stroke(void *pps, const int prevmval_i[2], const int mval_i[2])
 
 
 /* initialize project paint settings from context */
-static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps)
+static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int mode)
 {
        Scene *scene = CTX_data_scene(C);
        ToolSettings *settings = scene->toolsettings;
 
        /* brush */
+       ps->mode = mode;
        ps->brush = paint_brush(&settings->imapaint.paint);
        if (ps->brush) {
                Brush *brush = ps->brush;
@@ -4193,10 +4210,15 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps)
        return;
 }
 
-void *paint_proj_new_stroke(bContext *C, Object *ob, const int mouse[2])
+void *paint_proj_new_stroke(bContext *C, Object *ob, const int mouse[2], int mode)
 {
        ProjPaintState *ps = MEM_callocN(sizeof(ProjPaintState), "ProjectionPaintState");
-       project_state_init(C, ob, ps);
+       project_state_init(C, ob, ps, mode);
+
+       if (ps->tool == PAINT_TOOL_CLONE && mode == BRUSH_STROKE_INVERT) {
+               view3d_operator_needs_opengl(C);
+               return ps;
+       }
 
        /* needed so multiple threads don't try to initialize the brush at once (can leak memory) */
        curvemapping_initialize(ps->brush->curve);
@@ -4232,7 +4254,12 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const int mouse[2])
 void paint_proj_stroke_done(void *pps)
 {
        ProjPaintState *ps = pps;
+       if (ps->tool == PAINT_TOOL_CLONE && ps->mode == BRUSH_STROKE_INVERT) {
+               MEM_freeN(ps);
+               return;
+       }
        BKE_brush_size_set(ps->scene, ps->brush, ps->orig_brush_size);
+
        paint_brush_exit_tex(ps->brush);
 
        project_paint_end(ps);
@@ -4248,7 +4275,7 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
        IDProperty *idgroup;
        IDProperty *view_data = NULL;
 
-       project_state_init(C, OBACT, &ps);
+       project_state_init(C, OBACT, &ps, BRUSH_STROKE_NORMAL);
 
        if (ps.ob == NULL || ps.ob->type != OB_MESH) {
                BKE_report(op->reports, RPT_ERROR, "No active mesh object");
index 9377e4d43e3912d619cb28a2ea7d570798e3075a..a15795dc2da65eee3afda8b423ed25818d74233c 100644 (file)
@@ -133,15 +133,14 @@ void *paint_2d_new_stroke(struct bContext *, struct wmOperator *);
 void paint_2d_redraw(const bContext *C, void *ps, int final);
 void paint_2d_stroke_done(void *ps);
 int paint_2d_stroke(void *ps, const int prev_mval[2], const int mval[2], int eraser);
-void *paint_proj_new_stroke(struct bContext *C, struct Object *ob, const int mouse[2]);
-int paint_proj_stroke(void *ps, const int prevmval_i[2], const int mval_i[2]);
+void *paint_proj_new_stroke(struct bContext *C, struct Object *ob, const int mouse[2], int mode);
+int paint_proj_stroke(struct bContext *C, void *ps, const int prevmval_i[2], const int mval_i[2]);
 void paint_proj_stroke_done(void *ps);
 void paint_brush_init_tex(struct Brush *brush);
 void paint_brush_exit_tex(struct Brush *brush);
 
 void PAINT_OT_grab_clone(struct wmOperatorType *ot);
 void PAINT_OT_sample_color(struct wmOperatorType *ot);
-void PAINT_OT_clone_cursor_set(struct wmOperatorType *ot);
 void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_project_image(struct wmOperatorType *ot);
 void PAINT_OT_image_from_view(struct wmOperatorType *ot);
index 87cf79c540abed7dab78a8f369112cd5634be805..120d0a3b10afd51994c1cf2d2f97bc519abae5b6 100644 (file)
@@ -467,7 +467,6 @@ void ED_operatortypes_paint(void)
        WM_operatortype_append(PAINT_OT_image_paint);
        WM_operatortype_append(PAINT_OT_sample_color);
        WM_operatortype_append(PAINT_OT_grab_clone);
-       WM_operatortype_append(PAINT_OT_clone_cursor_set);
        WM_operatortype_append(PAINT_OT_project_image);
        WM_operatortype_append(PAINT_OT_image_from_view);
 
@@ -768,10 +767,10 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        keymap = WM_keymap_find(keyconf, "Image Paint", 0, 0);
        keymap->poll = image_texture_paint_poll;
 
-       WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
+       RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
+       RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
        WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
-       WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
 
        ed_keymap_paint_brush_switch(keymap, "image_paint");
        ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");