Commit: e614dca234b63571d39b9b2b8b6de36128e3cc21
Author: Antony Riakiotakis
Date: Mon Mar 10 23:49:14 2014 +0200
https://developer.blender.org/rBe614dca234b63571d39b9b2b8b6de36128e3cc21
Make palette sampling more stable. It was possible to sample too many
palette colors just by hovering the pen over the screen.
===================================================================
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/intern/paint.c
M source/blender/editors/sculpt_paint/paint_image.c
M source/blender/editors/sculpt_paint/paint_intern.h
M source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h
b/source/blender/blenkernel/BKE_paint.h
index 002e287..a5ba888 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -98,6 +98,8 @@ void BKE_paint_set_overlay_override(enum OverlayFlags flag);
void BKE_free_palette(struct Palette *palette);
struct Palette *BKE_palette_add(struct Main *bmain, const char *name);
struct PaletteColor *BKE_palette_color_add(struct Palette *palette);
+struct PaletteColor *BKE_palette_color_get_last(struct Palette *palette);
+bool BKE_palette_is_empty(const struct Palette *palette);
void BKE_palette_remove_color (struct Palette *palette, struct PaletteColor
*colour);
void BKE_paint_init(struct Paint *p, const char col[3]);
diff --git a/source/blender/blenkernel/intern/paint.c
b/source/blender/blenkernel/intern/paint.c
index 4729d0b..711f595 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -311,6 +311,17 @@ PaletteColor *BKE_palette_color_add(Palette *palette)
return color;
}
+struct PaletteColor *BKE_palette_color_get_last(struct Palette *palette)
+{
+ return palette->colors.last;
+}
+
+bool BKE_palette_is_empty(const struct Palette *palette)
+{
+ return BLI_listbase_is_empty(&palette->colors);
+}
+
+
/* are we in vertex paint or weight pain face select mode? */
bool BKE_paint_select_face_test(Object *ob)
{
diff --git a/source/blender/editors/sculpt_paint/paint_image.c
b/source/blender/editors/sculpt_paint/paint_image.c
index fd0d6d7..de53186 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1253,7 +1253,8 @@ static int sample_color_exec(bContext *C, wmOperator *op)
RNA_int_get_array(op->ptr, "location", location);
use_palette = RNA_boolean_get(op->ptr, "palette");
- paint_sample_color(C, ar, location[0], location[1], mode ==
PAINT_TEXTURE_PROJECTIVE, use_palette);
+
+ paint_sample_color(C, ar, location[0], location[1], mode ==
PAINT_TEXTURE_PROJECTIVE, use_palette, false);
if (show_cursor) {
paint->flags |= PAINT_SHOW_BRUSH;
@@ -1289,7 +1290,7 @@ static int sample_color_invoke(bContext *C, wmOperator
*op, const wmEvent *event
WM_redraw_windows(C);
RNA_int_set_array(op->ptr, "location", event->mval);
- paint_sample_color(C, ar, event->mval[0], event->mval[1], mode ==
PAINT_TEXTURE_PROJECTIVE, false);
+ paint_sample_color(C, ar, event->mval[0], event->mval[1], mode ==
PAINT_TEXTURE_PROJECTIVE, false, false);
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
@@ -1304,7 +1305,6 @@ static int sample_color_modal(bContext *C, wmOperator
*op, const wmEvent *event)
PaintMode mode = BKE_paintmode_get_active_from_context(C);
if ((event->type == data->event_type) && (event->val == KM_RELEASE)) {
- Paint *paint = BKE_paint_get_active_from_context(C);
ScrArea *sa = CTX_wm_area(C);
if (data->show_cursor) {
@@ -1312,7 +1312,6 @@ static int sample_color_modal(bContext *C, wmOperator
*op, const wmEvent *event)
}
if (data->sample_palette) {
- Brush *brush = BKE_paint_brush(paint);
copy_v3_v3(brush->rgb, data->initcolor);
RNA_boolean_set(op->ptr, "palette", true);
}
@@ -1327,17 +1326,16 @@ static int sample_color_modal(bContext *C, wmOperator
*op, const wmEvent *event)
{
ARegion *ar = CTX_wm_region(C);
RNA_int_set_array(op->ptr, "location", event->mval);
- paint_sample_color(C, ar, event->mval[0],
event->mval[1], mode == PAINT_TEXTURE_PROJECTIVE, data->sample_palette);
+ paint_sample_color(C, ar, event->mval[0],
event->mval[1], mode == PAINT_TEXTURE_PROJECTIVE, data->sample_palette,
data->sample_palette);
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
break;
}
case LEFTMOUSE:
if (event->val == KM_PRESS) {
+ ARegion *ar = CTX_wm_region(C);
RNA_int_set_array(op->ptr, "location",
event->mval);
- RNA_boolean_set(op->ptr, "palette", true);
- sample_color_exec(C, op);
- RNA_boolean_set(op->ptr, "palette", false);
+ paint_sample_color(C, ar, event->mval[0],
event->mval[1], mode == PAINT_TEXTURE_PROJECTIVE, true, false);
if (!data->sample_palette) {
data->sample_palette = true;
sample_color_update_header(data, C);
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h
b/source/blender/editors/sculpt_paint/paint_intern.h
index 634944d..4c5cc16 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -211,7 +211,7 @@ int imapaint_pick_face(struct ViewContext *vc, const int
mval[2], unsigned int *
void imapaint_pick_uv(struct Scene *scene, struct Object *ob, unsigned int
faceindex, const int xy[2], float uv[2]);
void brush_drawcursor_texpaint_uvsculpt(struct bContext *C, int x, int y, void
*customdata);
-void paint_sample_color(bContext *C, struct ARegion *ar, int x, int y, bool
texpaint_proj, bool palette);
+void paint_sample_color(bContext *C, struct ARegion *ar, int x, int y, bool
texpaint_proj, bool palette, bool use_last);
void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
void PAINT_OT_face_select_linked(struct wmOperatorType *ot);
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c
b/source/blender/editors/sculpt_paint/paint_utils.c
index 0273d2a..39ac7d1 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -390,7 +390,7 @@ void flip_v3_v3(float out[3], const float in[3], const char
symm)
}
/* used for both 3d view and image window */
-void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool
texpaint_proj, bool use_palette) /* frontbuf */
+void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool
texpaint_proj, bool use_palette, bool use_last)
{
Paint *paint = BKE_paint_get_active_from_context(C);
Palette *palette = BKE_paint_palette(paint);
@@ -489,8 +489,12 @@ void paint_sample_color(bContext *C, ARegion *ar, int x,
int y, bool texpaint_pr
}
cp = (unsigned char *)&col;
- if (use_palette && palette) {
- PaletteColor *color = BKE_palette_color_add(palette);
+ if (use_palette) {
+ PaletteColor *color;
+ if (use_last && !BKE_palette_is_empty(palette))
+ color = BKE_palette_color_get_last(palette);
+ else
+ color = BKE_palette_color_add(palette);
rgb_uchar_to_float(color->rgb, cp);
} else if (br) {
rgb_uchar_to_float(br->rgb, cp);
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs