[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58405] branches/soc-2013-paint/source/ blender/editors/sculpt_paint/paint_image.c: Improve texture sampling.

Antony Riakiotakis kalast at gmail.com
Fri Jul 19 14:45:43 CEST 2013


Revision: 58405
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58405
Author:   psy-fi
Date:     2013-07-19 12:45:43 +0000 (Fri, 19 Jul 2013)
Log Message:
-----------
Improve texture sampling. Don't revert the brush colour at end of
operation if the operation is used once for sampling palettes (though
the brush colour still changes during operator operation to display the
colour sampled). Also added area message describing use (possibly could
be used for value display too).

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-07-19 12:39:58 UTC (rev 58404)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-07-19 12:45:43 UTC (rev 58405)
@@ -1028,8 +1028,29 @@
 typedef struct {
 	bool show_cursor;
 	short event_type;
+	float initcolor[3];
+	bool sample_palette;
 }	SampleColorData;
 
+
+#define HEADER_LENGTH 150
+static void sample_color_update_header(SampleColorData *data, bContext *C)
+{
+	static char str[] = "Sample color for %s";
+
+	char msg[HEADER_LENGTH];
+	ScrArea *sa = CTX_wm_area(C);
+
+	if (sa) {
+		BLI_snprintf(msg, HEADER_LENGTH, str,
+		             !data->sample_palette?
+		             "brush. Use Left Click to sample for palette instead" :
+		             "palette. Use Left Click to sample more colors");
+		ED_area_headerprint(sa, msg);
+	}
+}
+#undef HEADER_LENGTH
+
 static int sample_color_exec(bContext *C, wmOperator *op)
 {
 	Brush *brush = image_paint_brush(C);
@@ -1049,13 +1070,17 @@
 static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	Paint *paint = &(CTX_data_tool_settings(C)->imapaint.paint);
+	Brush *brush = BKE_paint_brush(paint);
 	SampleColorData *data = MEM_mallocN(sizeof(SampleColorData), "sample color custom data");
 	data->event_type = event->type;
 	data->show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
-
+	copy_v3_v3(data->initcolor, brush->rgb);
+	data->sample_palette = false;
 	op->customdata = data;
 	paint->flags &= ~PAINT_SHOW_BRUSH;
 
+	sample_color_update_header(data, C);
+
 	WM_event_add_modal_handler(C, op);
 
 	RNA_int_set_array(op->ptr, "location", event->mval);
@@ -1068,12 +1093,23 @@
 static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	SampleColorData *data = op->customdata;
+
 	if ((event->type == data->event_type) && (event->val == KM_RELEASE)) {
 		Paint *paint = &(CTX_data_tool_settings(C)->imapaint.paint);
+		ScrArea *sa = CTX_wm_area(C);
+
 		if(data->show_cursor) {
 			paint->flags |= PAINT_SHOW_BRUSH;
 		}
+
+		if (data->sample_palette) {
+			Brush *brush = BKE_paint_brush(paint);
+			copy_v3_v3(brush->rgb, data->initcolor);
+			RNA_boolean_set(op->ptr, "palette", true);
+		}
 		MEM_freeN(data);
+		ED_area_headerprint(sa, NULL);
+
 		return OPERATOR_FINISHED;
 	}
 
@@ -1085,9 +1121,14 @@
 
 		case LEFTMOUSE:
 			if (event->val == KM_PRESS) {
+				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);
+				if (!data->sample_palette) {
+					data->sample_palette = true;
+					sample_color_update_header(data, C);
+				}
 			}
 			break;
 	}




More information about the Bf-blender-cvs mailing list