[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19083] branches/blender2.5/blender/source /blender: * Added radial control for texture paint ( in both view3d and image)

Nicholas Bishop nicholasbishop at gmail.com
Sun Feb 22 20:31:27 CET 2009


Revision: 19083
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19083
Author:   nicholasbishop
Date:     2009-02-22 20:31:25 +0100 (Sun, 22 Feb 2009)

Log Message:
-----------
* Added radial control for texture paint (in both view3d and image)
* bugfix: for older files, initialize the brush curve on file load

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_brush.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_image.c
    branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_intern.h
    branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_ops.c
    branches/blender2.5/blender/source/blender/editors/sculpt_paint/sculpt.c
    branches/blender2.5/blender/source/blender/editors/space_image/space_image.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_ops.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_brush.h	2009-02-22 15:02:23 UTC (rev 19082)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_brush.h	2009-02-22 19:31:25 UTC (rev 19083)
@@ -85,8 +85,8 @@
 unsigned int *brush_gen_texture_cache(struct Brush *br, int half_side);
 
 /* radial control */
-void brush_radial_control_invoke(struct wmOperator *op, struct Brush *br);
-int brush_radial_control_exec(struct wmOperator *op, struct Brush *br);
+void brush_radial_control_invoke(struct wmOperator *op, struct Brush *br, float size_weight);
+int brush_radial_control_exec(struct wmOperator *op, struct Brush *br, float size_weight);
 
 #endif
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c	2009-02-22 15:02:23 UTC (rev 19082)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c	2009-02-22 19:31:25 UTC (rev 19083)
@@ -1053,13 +1053,13 @@
 	return im;
 }
 
-void brush_radial_control_invoke(wmOperator *op, Brush *br)
+void brush_radial_control_invoke(wmOperator *op, Brush *br, float size_weight)
 {
 	int mode = RNA_int_get(op->ptr, "mode");
 	float original_value= 0;
 
 	if(mode == WM_RADIALCONTROL_SIZE)
-		original_value = br->size;
+		original_value = br->size * size_weight;
 	else if(mode == WM_RADIALCONTROL_STRENGTH)
 		original_value = br->alpha;
 	else if(mode == WM_RADIALCONTROL_ANGLE)
@@ -1069,14 +1069,14 @@
 	op->customdata = brush_gen_radial_control_imbuf(br);
 }
 
-int brush_radial_control_exec(wmOperator *op, Brush *br)
+int brush_radial_control_exec(wmOperator *op, Brush *br, float size_weight)
 {
 	int mode = RNA_int_get(op->ptr, "mode");
 	float new_value = RNA_float_get(op->ptr, "new_value");
 	const float conv = 0.017453293;
 
 	if(mode == WM_RADIALCONTROL_SIZE)
-		br->size = new_value;
+		br->size = new_value * size_weight;
 	else if(mode == WM_RADIALCONTROL_STRENGTH)
 		br->alpha = new_value;
 	else if(mode == WM_RADIALCONTROL_ANGLE)

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-02-22 15:02:23 UTC (rev 19082)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-02-22 19:31:25 UTC (rev 19083)
@@ -109,6 +109,7 @@
 #include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
+#include "BKE_brush.h"
 #include "BKE_cdderivedmesh.h"
 #include "BKE_cloth.h"
 #include "BKE_colortools.h"
@@ -1511,6 +1512,8 @@
 	brush->curve= newdataadr(fd, brush->curve);
 	if(brush->curve)
 		direct_link_curvemapping(fd, brush->curve);
+	else
+		brush_curve_preset(brush, BRUSH_PRESET_SHARP);
 }
 
 static void direct_link_script(FileData *fd, Script *script)

Modified: branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_image.c	2009-02-22 15:02:23 UTC (rev 19082)
+++ branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_image.c	2009-02-22 19:31:25 UTC (rev 19083)
@@ -4759,6 +4759,110 @@
 	RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
 }
 
+static int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
+{
+	RegionView3D *rv3d= CTX_wm_region_view3d(C);
+
+	if(!rv3d) {
+		SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
+		ARegion *ar= CTX_wm_region(C);
+		
+		ED_space_image_zoom(sima, ar, zoomx, zoomy);
+
+		return 1;
+	}
+
+	*zoomx = *zoomy = 1;
+
+	return 0;
+}
+
+/************************ cursor drawing *******************************/
+
+static void brush_drawcursor(bContext *C, int x, int y, void *customdata)
+{
+	Brush *brush= image_paint_brush(C);
+
+	if(brush) {
+		float zoomx, zoomy;
+		glPushMatrix();
+
+		glTranslatef((float)x, (float)y, 0.0f);
+
+		if(get_imapaint_zoom(C, &zoomx, &zoomy))
+			glScalef(zoomx, zoomy, 1.0f);
+
+		glColor4ub(255, 255, 255, 128);
+		glEnable( GL_LINE_SMOOTH );
+		glEnable(GL_BLEND);
+		glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size*0.5f, 40);
+		glDisable(GL_BLEND);
+		glDisable( GL_LINE_SMOOTH );
+		
+		glPopMatrix();
+	}
+}
+
+static void toggle_paint_cursor(bContext *C, int enable)
+{
+	ToolSettings *settings= CTX_data_scene(C)->toolsettings;
+
+	if(settings->imapaint.paintcursor && !enable) {
+		WM_paint_cursor_end(CTX_wm_manager(C), settings->imapaint.paintcursor);
+		settings->imapaint.paintcursor = NULL;
+	}
+	else if(enable)
+		settings->imapaint.paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, brush_drawcursor, NULL);
+}
+
+/* ************ image paint radial control *************/
+static int paint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	float zoom;
+	ToolSettings *ts = CTX_data_scene(C)->toolsettings;
+	get_imapaint_zoom(C, &zoom, &zoom);
+	toggle_paint_cursor(C, !ts->imapaint.paintcursor);
+	brush_radial_control_invoke(op, ts->imapaint.brush, 0.5 * zoom);
+	return WM_radial_control_invoke(C, op, event);
+}
+
+static int paint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+	ToolSettings *ts = CTX_data_scene(C)->toolsettings;
+	int ret = WM_radial_control_modal(C, op, event);
+	if(ret != OPERATOR_RUNNING_MODAL)
+	        toggle_paint_cursor(C, !ts->imapaint.paintcursor);
+	return ret;
+}
+
+static int paint_radial_control_exec(bContext *C, wmOperator *op)
+{
+	float zoom;
+	int ret;
+	char str[256];
+	get_imapaint_zoom(C, &zoom, &zoom);
+	ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->imapaint.brush, 2.0 / zoom);
+	WM_radial_control_string(op, str, 256);
+
+	return ret;
+}
+
+void PAINT_OT_image_paint_radial_control(wmOperatorType *ot)
+{
+	WM_OT_radial_control_partial(ot);
+
+	ot->name= "Image Paint Radial Control";
+	ot->idname= "PAINT_OT_image_paint_radial_control";
+
+	ot->invoke= paint_radial_control_invoke;
+	ot->modal= paint_radial_control_modal;
+	ot->exec= paint_radial_control_exec;
+	ot->poll= image_paint_poll;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 /************************ grab clone operator ************************/
 
 typedef struct GrabClone {
@@ -4962,50 +5066,6 @@
 	RNA_def_float_vector(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Cursor location in world space coordinates.", -10000.0f, 10000.0f);
 }
 
-/************************ cursor drawing *******************************/
-
-static void brush_drawcursor(bContext *C, int x, int y, void *customdata)
-{
-	Brush *brush= image_paint_brush(C);
-	RegionView3D *rv3d= CTX_wm_region_view3d(C);
-
-	if(brush) {
-		glPushMatrix();
-
-		glTranslatef((float)x, (float)y, 0.0f);
-
-		if(!rv3d) {
-			SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C);
-			ARegion *ar= CTX_wm_region(C);
-			float zoomx, zoomy;
-
-			ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
-			glScalef(zoomx, zoomy, 1.0f);
-		}
-		
-		glColor4ub(255, 255, 255, 128);
-		glEnable( GL_LINE_SMOOTH );
-		glEnable(GL_BLEND);
-		glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size*0.5f, 40);
-		glDisable(GL_BLEND);
-		glDisable( GL_LINE_SMOOTH );
-		
-		glPopMatrix();
-	}
-}
-
-static void toggle_paint_cursor(bContext *C, int enable)
-{
-	ToolSettings *settings= CTX_data_scene(C)->toolsettings;
-
-	if(settings->imapaint.paintcursor && !enable) {
-		WM_paint_cursor_end(CTX_wm_manager(C), settings->imapaint.paintcursor);
-		settings->imapaint.paintcursor = NULL;
-	}
-	else if(enable)
-		settings->imapaint.paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, brush_drawcursor, NULL);
-}
-
 /******************** texture paint toggle operator ********************/
 
 static int texture_paint_toggle_poll(bContext *C)
@@ -5076,3 +5136,45 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* ************ texture paint radial control *************/
+static int texture_paint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	ToolSettings *ts = CTX_data_scene(C)->toolsettings;
+	toggle_paint_cursor(C, !ts->imapaint.paintcursor);
+	brush_radial_control_invoke(op, ts->imapaint.brush, 0.5);
+	return WM_radial_control_invoke(C, op, event);
+}
+
+static int texture_paint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+	ToolSettings *ts = CTX_data_scene(C)->toolsettings;
+	int ret = WM_radial_control_modal(C, op, event);
+	if(ret != OPERATOR_RUNNING_MODAL)
+		toggle_paint_cursor(C, !ts->imapaint.paintcursor);
+	return ret;
+}
+
+static int texture_paint_radial_control_exec(bContext *C, wmOperator *op)
+{
+	int ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->imapaint.brush, 2);
+	char str[256];
+	WM_radial_control_string(op, str, 256);
+
+	return ret;
+}
+
+void PAINT_OT_texture_paint_radial_control(wmOperatorType *ot)
+{
+	WM_OT_radial_control_partial(ot);
+
+	ot->name= "Texture Paint Radial Control";
+	ot->idname= "PAINT_OT_texture_paint_radial_control";
+
+	ot->invoke= texture_paint_radial_control_invoke;
+	ot->modal= texture_paint_radial_control_modal;
+	ot->exec= texture_paint_radial_control_exec;
+	ot->poll= texture_paint_toggle_poll;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}

Modified: branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_intern.h	2009-02-22 15:02:23 UTC (rev 19082)
+++ branches/blender2.5/blender/source/blender/editors/sculpt_paint/paint_intern.h	2009-02-22 19:31:25 UTC (rev 19083)
@@ -47,10 +47,12 @@
 
 /* paint_image.c */
 void PAINT_OT_image_paint(struct wmOperatorType *ot);
+void PAINT_OT_image_paint_radial_control(struct wmOperatorType *ot);
 void PAINT_OT_grab_clone(struct wmOperatorType *ot);
 void PAINT_OT_sample_color(struct wmOperatorType *ot);
 void PAINT_OT_set_clone_cursor(struct wmOperatorType *ot);
 void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
+void PAINT_OT_texture_paint_radial_control(struct wmOperatorType *ot);
 
 /* paint_utils.c */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list