[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39076] branches/soc-2011-onion/source/ blender/editors/sculpt_paint/paint_uv.c: smooth brush

Antony Riakiotakis kalast at gmail.com
Fri Aug 5 18:40:50 CEST 2011


Revision: 39076
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39076
Author:   psy-fi
Date:     2011-08-05 16:40:49 +0000 (Fri, 05 Aug 2011)
Log Message:
-----------
smooth brush
============
-Implemented almost every operator related stuff using texture_paint paradigm. This brush will not require fancy functionality so keeping this simple for now. "little ducks" test phrase is now printed when painting, pending actual implementatio. Next commit will most likely incorporate farsthary's relaxation code adapted for UVs.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c	2011-08-05 16:29:38 UTC (rev 39075)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_uv.c	2011-08-05 16:40:49 UTC (rev 39076)
@@ -1,5 +1,5 @@
 /*
- * $Id$
+ * $Id: paint_uv.c 39020 2011-08-04 13:55:38Z psy-fi $
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -51,6 +51,7 @@
 #include "BKE_context.h"
 #include "BKE_paint.h"
 #include "BKE_main.h"
+#include "BKE_depsgraph.h"
 
 #include "ED_sculpt.h"
 #include "ED_screen.h"
@@ -70,63 +71,100 @@
 //#include <stdio.h>
 #include <stddef.h>
 
+typedef struct SmoothBrushData{
+	/* Timer to be used for airbrush-type brush */
+	wmTimer *timer;
+}SmoothBrushData;
 
-static int uv_smooth_stroke_test_start(const bContext *C, struct PaintStroke *stroke)
-{
-	/* Always succeed */
-	return 1;
-}
 
-static void uv_smooth_stroke_start(const bContext *C, struct PaintStroke *stroke)
+static void uv_smooth_stroke_apply(bContext *C, wmOperator *op, wmEvent *event)
 {
-
+	printf("little ducks\n");
 }
 
-static void uv_smooth_stroke_update_step(const bContext *C, struct PaintStroke *stroke)
-{
 
-}
-
-static void uv_smooth_stroke_apply(const struct bContext *C, struct PaintStroke *stroke)
+static void uv_smooth_stroke_exit(bContext *C, wmOperator *op)
 {
-	printf("little ducks\n");
+	SmoothBrushData *data = op->customdata;
+	if(data->timer){
+		WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), data->timer);
+	}
+	MEM_freeN(data);
+	op->customdata = NULL;
 }
 
-static void uv_smooth_stroke_done(const struct bContext *C, struct PaintStroke *stroke)
+static int uv_smooth_stroke_init(bContext *UNUSED(C), wmOperator *op)
 {
-
+	SmoothBrushData *data = MEM_mallocN(sizeof(*data), "UV Smooth Brush Data");
+	if(data)
+	{
+		op->customdata = data;
+		return 1;
+	}
+	else
+		return 0;
 }
 
 static int uv_smooth_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-	paint_stroke_new(
-		C,
-		op,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		uv_smooth_stroke_test_start,
-		uv_smooth_stroke_start,
-		paint_cursor,
-		uv_smooth_stroke_update_step,
-		NULL,
-		paint_init_params,
-		paint_update_params,
-		NULL,
-		uv_smooth_stroke_apply,
-		uv_smooth_stroke_done,
-		event->type);
+	SmoothBrushData *data;
 
-	return paint_stroke_invoke(C, op, event);
+	if(!uv_smooth_stroke_init(C, op)) {
+		return OPERATOR_CANCELLED;
+	}
+
+	uv_smooth_stroke_apply(C, op, event);
+
+	data = op->customdata;
+	data->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
+	if(!data->timer){
+		uv_smooth_stroke_exit(C, op);
+		return OPERATOR_CANCELLED;
+	}
+	WM_event_add_modal_handler(C, op);
+
+	return OPERATOR_RUNNING_MODAL;
 }
 
 static int uv_smooth_stroke_exec(bContext *C, wmOperator *op)
 {
-	printf("little ducks\n");
+	if(!uv_smooth_stroke_init(C, op)) {
+		return OPERATOR_CANCELLED;
+	}
+//	uv_smooth_stroke_apply(C, op, event);
+
+	uv_smooth_stroke_exit(C, op);
 	return OPERATOR_FINISHED;
 }
 
+static int uv_smooth_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+	SmoothBrushData *data = (SmoothBrushData *)op->customdata;
+	Object *obedit = CTX_data_edit_object(C);
+
+	switch(event->type) {
+		case LEFTMOUSE:
+		case MIDDLEMOUSE:
+		case RIGHTMOUSE: // XXX hardcoded
+			uv_smooth_stroke_exit(C, op);
+			return OPERATOR_FINISHED;
+		case MOUSEMOVE:
+		case INBETWEEN_MOUSEMOVE:
+			uv_smooth_stroke_apply(C, op, event);
+			break;
+		case TIMER:
+			if(event->customdata == data->timer)
+				uv_smooth_stroke_apply(C, op, event);
+			break;
+		default:
+			return OPERATOR_RUNNING_MODAL;
+	}
+
+	ED_region_tag_redraw(CTX_wm_region(C));
+	DAG_id_tag_update(obedit->data, 0);
+	return OPERATOR_RUNNING_MODAL;
+}
+
 void PAINT_OT_uv_smooth_stroke(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -137,12 +175,11 @@
 	/* api callbacks */
 	ot->invoke = uv_smooth_stroke_invoke;
 	ot->exec = uv_smooth_stroke_exec;
-	ot->modal = paint_stroke_modal;
+	ot->modal = uv_smooth_stroke_modal;
 	ot->poll = uv_smooth_poll;
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 
-	paint_stroke_def_properties(ot, 0, 0, 0, NULL);
 	/* props */
 }




More information about the Bf-blender-cvs mailing list