Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2013-04-14 13:43:12 +0400
committerAntony Riakiotakis <kalast@gmail.com>2013-04-14 13:43:12 +0400
commit1e839ec8bc4e8b13787e6ca47c20118ce65d94e8 (patch)
tree9875fc5fa7050c56c0c1a9546e82751041345f8e /source/blender/editors/sculpt_paint/paint_ops.c
parent4d0c576f4e27a1b4ca35f6d73ef06527b5985fd8 (diff)
Texture stencil:
Robustness: Avoid translating the stencil outside the active area. Helps to avoid losing the stencil somewhere in bitspace. Usability: Take image repeat mapping and scaling into account when fitting stencil aspect. Togglable by operator properties.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_ops.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 0fe60813fd1..8c2bdc526d8 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -468,6 +468,7 @@ typedef struct {
float init_rot;
float init_angle;
float lenorig;
+ float area_size[2];
StencilControlMode mode;
StencilConstraint constrain_mode;
Brush *br;
@@ -480,6 +481,7 @@ static int stencil_control_invoke(bContext *C, wmOperator *op, const wmEvent *ev
Brush *br = BKE_paint_brush(paint);
float mdiff[2];
float mvalf[2] = {event->mval[0], event->mval[1]};
+ ARegion *ar = CTX_wm_region(C);
StencilControlData *scd = MEM_mallocN(sizeof(StencilControlData), "stencil_control");
@@ -493,6 +495,8 @@ static int stencil_control_invoke(bContext *C, wmOperator *op, const wmEvent *ev
scd->init_angle = atan2(mdiff[1], mdiff[0]);
scd->mode = RNA_enum_get(op->ptr, "mode");
scd->event_type = event->type;
+ scd->area_size[0] = ar->winx;
+ scd->area_size[1] = ar->winy;
op->customdata = scd;
WM_event_add_modal_handler(C, op);
@@ -515,6 +519,8 @@ static int stencil_control_cancel(bContext *UNUSED(C), wmOperator *op)
static void stencil_control_calculate(StencilControlData *scd, const int *mval)
{
+ #define PIXEL_MARGIN 5
+
float mdiff[2];
float mvalf[2] = {mval[0], mval[1]};
switch (scd->mode) {
@@ -522,6 +528,14 @@ static void stencil_control_calculate(StencilControlData *scd, const int *mval)
sub_v2_v2v2(mdiff, mvalf, scd->init_mouse);
add_v2_v2v2(scd->br->stencil_pos, scd->init_spos,
mdiff);
+ CLAMP(scd->br->stencil_pos[0],
+ -scd->br->stencil_dimension[0] + PIXEL_MARGIN,
+ scd->area_size[0] + scd->br->stencil_dimension[0] - PIXEL_MARGIN);
+
+ CLAMP(scd->br->stencil_pos[1],
+ -scd->br->stencil_dimension[1] + PIXEL_MARGIN,
+ scd->area_size[1] + scd->br->stencil_dimension[1] - PIXEL_MARGIN);
+
break;
case STENCIL_SCALE:
{
@@ -637,11 +651,13 @@ static void BRUSH_OT_stencil_control(wmOperatorType *ot)
}
-static int stencil_fit_image_aspect_exec(bContext *C, wmOperator *UNUSED(op))
+static int stencil_fit_image_aspect_exec(bContext *C, wmOperator *op)
{
Paint *paint = BKE_paint_get_active_from_context(C);
Brush *br = BKE_paint_brush(paint);
Tex *tex = (br)? br->mtex.tex : NULL;
+ bool use_scale = RNA_boolean_get(op->ptr, "use_scale");
+ bool use_repeat = RNA_boolean_get(op->ptr, "use_repeat");
if (tex && tex->type == TEX_IMAGE && tex->ima) {
float aspx, aspy;
@@ -649,6 +665,16 @@ static int stencil_fit_image_aspect_exec(bContext *C, wmOperator *UNUSED(op))
float orig_area, stencil_area, factor;
ED_image_get_uv_aspect(ima, NULL, &aspx, &aspy);
+ if (use_scale) {
+ aspx *= br->mtex.size[0];
+ aspy *= br->mtex.size[1];
+ }
+
+ if (use_repeat && tex->extend == TEX_REPEAT) {
+ aspx *= tex->xrepeat;
+ aspy *= tex->yrepeat;
+ }
+
orig_area = aspx * aspy;
stencil_area = br->stencil_dimension[0] * br->stencil_dimension[1];
@@ -658,6 +684,8 @@ static int stencil_fit_image_aspect_exec(bContext *C, wmOperator *UNUSED(op))
br->stencil_dimension[1] = factor * aspy;
}
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+
return OPERATOR_FINISHED;
}
@@ -674,7 +702,10 @@ static void BRUSH_OT_stencil_fit_image_aspect(wmOperatorType *ot)
ot->poll = stencil_control_poll;
/* flags */
- ot->flag = 0;
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_boolean(ot->srna, "use_repeat", 1, "Use Repeat", "Use repeat mapping values");
+ RNA_def_boolean(ot->srna, "use_scale", 1, "Use Scale", "Use texture scale values");
}