diff options
Diffstat (limited to 'source')
4 files changed, 49 insertions, 74 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 983cf085e7c..6645015a2b2 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -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) diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 05b1044a964..96916236279 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -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"); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 9377e4d43e3..a15795dc2da 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -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); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 87cf79c540a..120d0a3b10a 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -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"); |