From 65869589b6bc0caf9a08a10415a18dc563a447cf Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Wed, 6 Mar 2013 22:54:44 +0000 Subject: Support position jittering on new texpaint code using the stroke system. --- source/blender/blenkernel/BKE_paint.h | 11 +++++ source/blender/blenkernel/intern/paint.c | 49 ++++++++++++++++++++++ source/blender/editors/sculpt_paint/paint_image.c | 6 +-- .../editors/sculpt_paint/paint_image_proj.c | 12 +++--- source/blender/editors/sculpt_paint/paint_stroke.c | 3 +- 5 files changed, 71 insertions(+), 10 deletions(-) diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 211b6189fa8..98184bfa65d 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -54,6 +54,16 @@ extern const char PAINT_CURSOR_VERTEX_PAINT[3]; extern const char PAINT_CURSOR_WEIGHT_PAINT[3]; extern const char PAINT_CURSOR_TEXTURE_PAINT[3]; +typedef enum { + PAINT_SCULPT, + PAINT_VERTEX, + PAINT_WEIGHT, + PAINT_TEXTURE_PROJECTIVE, + PAINT_TEXTURE_2D, + PAINT_SCULPT_UV, + PAINT_INVALID +} PaintMode; + void BKE_paint_init(struct Paint *p, const char col[3]); void BKE_paint_free(struct Paint *p); void BKE_paint_copy(struct Paint *src, struct Paint *tar); @@ -61,6 +71,7 @@ void BKE_paint_copy(struct Paint *src, struct Paint *tar); /* TODO, give these BKE_ prefix too */ struct Paint *paint_get_active(struct Scene *sce); struct Paint *paint_get_active_from_context(const struct bContext *C); +PaintMode paintmode_get_active_from_context(const struct bContext *C); struct Brush *paint_brush(struct Paint *paint); void paint_brush_set(struct Paint *paint, struct Brush *br); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index d34d5eaa250..a001a13d000 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -137,6 +137,55 @@ Paint *paint_get_active_from_context(const bContext *C) return NULL; } +PaintMode paintmode_get_active_from_context(const bContext *C) +{ + Scene *sce = CTX_data_scene(C); + SpaceImage *sima; + + if (sce) { + ToolSettings *ts = sce->toolsettings; + Object *obact = NULL; + + if (sce->basact && sce->basact->object) + obact = sce->basact->object; + + if ((sima = CTX_wm_space_image(C)) != NULL) { + if (obact && obact->mode == OB_MODE_EDIT) { + if (sima->mode == SI_MODE_PAINT) + return PAINT_TEXTURE_2D; + else if (ts->use_uv_sculpt) + return PAINT_SCULPT_UV; + } + else { + return PAINT_TEXTURE_2D; + } + } + else if (obact) { + switch (obact->mode) { + case OB_MODE_SCULPT: + return PAINT_SCULPT; + case OB_MODE_VERTEX_PAINT: + return PAINT_VERTEX; + case OB_MODE_WEIGHT_PAINT: + return PAINT_WEIGHT; + case OB_MODE_TEXTURE_PAINT: + return PAINT_TEXTURE_PROJECTIVE; + case OB_MODE_EDIT: + if (ts->use_uv_sculpt) + return PAINT_SCULPT_UV; + else + return PAINT_TEXTURE_2D; + } + } + else { + /* default to image paint */ + return PAINT_TEXTURE_2D; + } + } + + return PAINT_INVALID; +} + Brush *paint_brush(Paint *p) { return p ? p->brush : NULL; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index a99f82058b8..63a111c9165 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -4936,14 +4936,14 @@ static int image_paint_2d_clone_poll(bContext *C) /************************ paint operator ************************/ -typedef enum PaintMode { +typedef enum TexPaintMode { PAINT_MODE_2D, PAINT_MODE_3D, PAINT_MODE_3D_PROJECT -} PaintMode; +} TexPaintMode; typedef struct PaintOperation { - PaintMode mode; + TexPaintMode mode; BrushPainter *painter; ImagePaintState s; diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 47654fc32fd..bb05fbcb315 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -4803,13 +4803,13 @@ static int image_paint_poll(bContext *C) /************************ paint operator ************************/ -typedef enum PaintMode { +typedef enum TexPaintMode { PAINT_MODE_2D, PAINT_MODE_3D_PROJECT -} PaintMode; +} TexPaintMode; typedef struct PaintOperation { - PaintMode mode; + TexPaintMode mode; BrushPainter *painter; ImagePaintState s; @@ -5060,10 +5060,10 @@ static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, Po mouse[1] = (int)(mousef[1]); pressure = RNA_float_get(itemptr, "pressure"); - if (pop->first) - project_paint_begin_clone(&pop->ps, mouse); - if (pop->mode == PAINT_MODE_3D_PROJECT) { + if (pop->first) + project_paint_begin_clone(&pop->ps, mouse); + redraw = project_paint_stroke(&pop->ps, pop->prevmouse, mouse, pressure); pop->prevmouse[0] = mouse[0]; pop->prevmouse[1] = mouse[1]; diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index a44702bd125..287bd723534 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -143,6 +143,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev { Scene *scene = CTX_data_scene(C); Paint *paint = paint_get_active_from_context(C); + PaintMode mode = paintmode_get_active_from_context(C); Brush *brush = paint_brush(paint); PaintStroke *stroke = op->customdata; float mouse_out[2]; @@ -156,7 +157,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev /* TODO: as sculpt and other paint modes are unified, this * separation will go away */ - if (stroke->vc.obact->sculpt) { + if (ELEM(mode, PAINT_SCULPT, PAINT_TEXTURE_PROJECTIVE)) { float delta[2]; BKE_brush_jitter_pos(scene, brush, mouse_in, mouse_out); -- cgit v1.2.3