[Bf-blender-cvs] [aaa0383] soc-2013-paint: Paint Curves:
Antony Riakiotakis
noreply at git.blender.org
Mon Jul 14 14:00:53 CEST 2014
Commit: aaa0383ef3b509d09df8aa5f5f6843fbf0f0aa93
Author: Antony Riakiotakis
Date: Mon Jul 14 15:00:34 2014 +0300
https://developer.blender.org/rBaaa0383ef3b509d09df8aa5f5f6843fbf0f0aa93
Paint Curves:
* Change behaviour of selection - selecting in empty space now will not
clear selection. This leads to:
* Improved behaviour of right click translate. Now even dragging in
empty space will drag correctly.
===================================================================
M source/blender/editors/sculpt_paint/paint_curve.c
M source/blender/editors/sculpt_paint/paint_image_2d.c
M source/blender/editors/sculpt_paint/paint_intern.h
M source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c
index 99d7463..2b7dee1 100644
--- a/source/blender/editors/sculpt_paint/paint_curve.c
+++ b/source/blender/editors/sculpt_paint/paint_curve.c
@@ -363,7 +363,7 @@ void PAINTCURVE_OT_delete_point(wmOperatorType *ot)
}
-static void paintcurve_point_select(bContext *C, wmOperator *op, const int loc[2],
+static bool paintcurve_point_select(bContext *C, wmOperator *op, const int loc[2],
bool handle, bool toggle, bool extend)
{
wmWindow *window = CTX_wm_window(C);
@@ -373,20 +373,21 @@ static void paintcurve_point_select(bContext *C, wmOperator *op, const int loc[2
PaintCurve *pc;
PaintCurvePoint *pcp;
int i;
- char select = 0;
const float loc_fl[2] = {UNPACK2(loc)};
pc = br->paint_curve;
if (!pc)
- return;
+ return false;
paintcurve_undo_begin(C, op, pc);
pcp = pc->points;
if (toggle) {
+ char select = 0;
bool selected = false;
+
for (i = 0; i < pc->tot_points; i++) {
if (pcp[i].bez.f1 || pcp[i].bez.f2 || pcp[i].bez.f3) {
selected = true;
@@ -397,45 +398,95 @@ static void paintcurve_point_select(bContext *C, wmOperator *op, const int loc[2
if (!selected) {
select = SELECT;
}
- }
- if (!extend) {
- /* first clear selection from all bezier handles */
for (i = 0; i < pc->tot_points; i++) {
- pcp[i].bez.f1 = pcp[i].bez.f2 = pcp[i].bez.f3 = select;
+ pc->points[i].bez.f1 = pc->points[i].bez.f2 = pc->points[i].bez.f3 = select;
}
}
+ else {
+#define SEL_F1 (1 << 0)
+#define SEL_F2 (1 << 1)
+#define SEL_F3 (1 << 2)
+ int selflag;
+ bool selected = false;
- if (!toggle) {
for (i = 0; i < pc->tot_points; i++, pcp++) {
/* shift means constrained editing so exclude center handles from collision detection */
if (!handle) {
if (len_manhattan_v2v2(loc_fl, pcp->bez.vec[1]) < PAINT_CURVE_SELECT_THRESHOLD) {
- pcp->bez.f2 ^= SELECT;
+ if (extend)
+ pcp->bez.f2 ^= SELECT;
+ else
+ pcp->bez.f2 = SELECT;
pc->add_index = i + 1;
+ selflag = SEL_F2;
break;
}
}
if (len_manhattan_v2v2(loc_fl, pcp->bez.vec[0]) < PAINT_CURVE_SELECT_THRESHOLD) {
- pcp->bez.f1 ^= SELECT;
+ if (extend)
+ pcp->bez.f1 ^= SELECT;
+ else
+ pcp->bez.f1 = SELECT;
pc->add_index = i + 1;
+ selflag = SEL_F1;
if (handle)
pcp->bez.h1 = HD_ALIGN;
break;
}
if (len_manhattan_v2v2(loc_fl, pcp->bez.vec[2]) < PAINT_CURVE_SELECT_THRESHOLD) {
- pcp->bez.f3 ^= SELECT;
+ if (extend)
+ pcp->bez.f3 ^= SELECT;
+ else
+ pcp->bez.f3 = SELECT;
pc->add_index = i + 1;
+ selflag = SEL_F3;
if (handle)
pcp->bez.h2 = HD_ALIGN;
break;
}
}
+
+ selected = (i != pc->tot_points);
+
+ /* clear selection for unselected points if not extending and if a point has been selected */
+ if (!extend && selected) {
+ for (i = 0; i < pc->tot_points; i++) {
+ if ((pc->points + i) == pcp) {
+ switch (selflag) {
+ case SEL_F1:
+ pc->points[i].bez.f2 = pc->points[i].bez.f3 = 0;
+ break;
+ case SEL_F2:
+ pc->points[i].bez.f1 = pc->points[i].bez.f3 = 0;
+ break;
+ case SEL_F3:
+ pc->points[i].bez.f1 = pc->points[i].bez.f2 = 0;
+ break;
+ default:
+ /* shouldn't happen */
+ break;
+ }
+ }
+ else {
+ pc->points[i].bez.f1 = pc->points[i].bez.f2 = pc->points[i].bez.f3 = 0;
+ }
+ }
+ }
+
+#undef SEL_F1
+#undef SEL_F2
+#undef SEL_F3
+
+ if (!selected)
+ return false;
}
WM_paint_cursor_tag_redraw(window, ar);
+
+ return true;
}
@@ -445,9 +496,13 @@ static int paintcurve_select_point_invoke(bContext *C, wmOperator *op, const wmE
bool handle = RNA_boolean_get(op->ptr, "handle");
bool toggle = RNA_boolean_get(op->ptr, "toggle");
bool extend = RNA_boolean_get(op->ptr, "extend");
- paintcurve_point_select(C, op, loc, handle, toggle, extend);
- RNA_int_set_array(op->ptr, "location", loc);
- return OPERATOR_FINISHED;
+ if (paintcurve_point_select(C, op, loc, handle, toggle, extend)) {
+ RNA_int_set_array(op->ptr, "location", loc);
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
}
static int paintcurve_select_point_exec(bContext *C, wmOperator *op)
@@ -459,8 +514,8 @@ static int paintcurve_select_point_exec(bContext *C, wmOperator *op)
bool toggle = RNA_boolean_get(op->ptr, "toggle");
bool extend = RNA_boolean_get(op->ptr, "extend");
RNA_int_get_array(op->ptr, "location", loc);
- paintcurve_point_select(C, op, loc, handle, toggle, extend);
- return OPERATOR_FINISHED;
+ if (paintcurve_point_select(C, op, loc, handle, toggle, extend))
+ return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 1392620..d394d6d 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -1306,15 +1306,15 @@ void paint_2d_stroke_done(void *ps)
}
static void paint_2d_fill_add_pixel_byte(
- const int i, const int j, ImBuf *ibuf, BLI_Stack *stack, BLI_bitmap *touched,
+ const int x_px, const int y_px, ImBuf *ibuf, BLI_Stack *stack, BLI_bitmap *touched,
const float color[4], float threshold_sq)
{
int coordinate;
- if (i >= ibuf->x || i < 0 || j >= ibuf->y || j < 0)
+ if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0)
return;
- coordinate = j * ibuf->x + i;
+ coordinate = y_px * ibuf->x + x_px;
if (!BLI_BITMAP_TEST(touched, coordinate)) {
float color_f[4];
@@ -1329,15 +1329,15 @@ static void paint_2d_fill_add_pixel_byte(
}
static void paint_2d_fill_add_pixel_float(
- const int i, const int j, ImBuf *ibuf, BLI_Stack *stack, BLI_bitmap *touched,
+ const int x_px, const int y_px, ImBuf *ibuf, BLI_Stack *stack, BLI_bitmap *touched,
const float color[4], float threshold_sq)
{
int coordinate;
- if (i >= ibuf->x || i < 0 || j >= ibuf->y || j < 0)
+ if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0)
return;
- coordinate = j * ibuf->x + i;
+ coordinate = y_px * ibuf->x + x_px;
if (!BLI_BITMAP_TEST(touched, coordinate)) {
if (compare_len_squared_v3v3(ibuf->rect_float + 4 * coordinate, color, threshold_sq)) {
@@ -1359,7 +1359,7 @@ void paint_2d_bucket_fill(
ImagePaintState *s = ps;
ImBuf *ibuf;
- int i, j;
+ int x_px, y_px;
unsigned int color_b;
float color_f[4];
float strength = br ? br->alpha : 1.0f;
@@ -1392,18 +1392,18 @@ void paint_2d_bucket_fill(
ED_imapaint_dirty_region(ima, ibuf, 0, 0, ibuf->x, ibuf->y);
if (do_float) {
- for (; i < ibuf->x; i++) {
- for (j = 0; j < ibuf->y; j++) {
- blend_color_mix_float(ibuf->rect_float + 4 * (j * ibuf->x + i),
- ibuf->rect_float + 4 * (j * ibuf->x + i), color_f);
+ for (; x_px < ibuf->x; x_px++) {
+ for (y_px = 0; y_px < ibuf->y; y_px++) {
+ blend_color_mix_float(ibuf->rect_float + 4 * (y_px * ibuf->x + x_px),
+ ibuf->rect_float + 4 * (y_px * ibuf->x + x_px), color_f);
}
}
}
else {
- for (; i < ibuf->x; i++) {
- for (j = 0; j < ibuf->y; j++) {
- blend_color_mix_byte((unsigned char *)(ibuf->rect + j * ibuf->x + i),
- (unsigned char *)(ibuf->rect + j * ibuf->x + i), (unsigned char *)&color_b);
+ for (; x_px < ibuf->x; x_px++) {
+ for (y_px = 0; y_px < ibuf->y; y_px++) {
+ blend_color_mix_byte((unsigned char *)(ibuf->rect + y_px * ibuf->x + x_px),
+ (unsigned char *)(ibuf->rect + y_px * ibuf->x + x_px), (unsigned char *)&color_b);
}
}
}
@@ -1422,10 +1422,10 @@ void paint_2d_bucket_fill(
UI_view2d_region_to_view(s->v2d, mouse_init[0], mouse_init[1], &image_init[0], &image_init[1]);
- i = image_init[0] * ibuf->x;
- j = image_init[1] * ibuf->y;
+ x_px = image_init[0] * ibuf->x;
+ y_px = image_init[1] * ibuf->y;
- if (i >= ibuf->x || i < 0 || j > ibuf->y || j < 0) {
+ if (x_px >= ibuf->x || x_px < 0 || y_px > ibuf->y || y_px < 0) {
BKE_image_release_ibuf(ima, ibuf, NULL);
return;
}
@@ -1436,7 +1436,7 @@ void paint_2d_bucket_fill(
stack = BLI_stack_new(sizeof(int), __func__);
touched = BLI_BITMAP_NEW(ibuf->x * ibuf->y, "bucket_fill_bitmap");
- coordinate = (j * ibuf->x + i);
+ coordinate = (y_px * ibuf->x + x_px);
if (do_float) {
copy_v4_v4(pixel_color, ibuf->rect_float + 4 * coordinate);
@@ -1458,26 +1458,26 @@ void paint_2d_bucket_fill(
color_f, br->blend);
/* reconstruct the coordinates here */
- i = coordinate % width;
- j = coordinate / width;
-
- paint_2d_fill_add_pixel_float(i - 1, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
- paint_2d_fill_add_pixel_float(i - 1, j, ibuf, stack, touched, pixel_color, threshold_sq);
- paint_2d_fill_add_pixel_float(i - 1, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
- paint_2d_fill_add_pixel_float(i, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
- paint_2d_fill_add_pixel_float(i, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
- paint_2d_fill_add_pixel_float(i + 1, j - 1, ibuf, stack, touched, pixel_color, threshold_sq);
- paint_2d_fill_add_pixel_float(i + 1, j, ibuf, stack, touched, pixel_color, threshold_sq);
- paint_2d_fill_add_pixel_float(i + 1, j + 1, ibuf, stack, touched, pixel_color, threshold_sq);
-
- if (i > maxx)
- maxx = i;
- if (i < minx)
- minx = i;
- if (j > maxy)
- maxy = j;
- if (i > miny)
- miny = j;
+ x_px = coordinate % width;
+ y_px = coordinate / width;
+
+ paint_2d_fill_add_pixel_float(x_px - 1, y_px - 1, ibuf, stack, touched, pixel_color, threshold_sq);
+ paint_2d_fill_add_pixel_float(x_px - 1, y_px, ibuf, stack, touched, pixel_color, threshold_sq);
+ paint_2d_fill_add_pixel_float(x_px - 1, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq);
+ paint_2d_fill_add_pixel_float(x_px, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq);
+ paint_2d_fil
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list