[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27342] trunk/blender: improve brush size keys so they dont change by 20 each time ( bad for small brushes), added wm.context_scale_int() operator.

Campbell Barton ideasman42 at gmail.com
Tue Mar 9 00:34:38 CET 2010


Revision: 27342
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27342
Author:   campbellbarton
Date:     2010-03-09 00:34:38 +0100 (Tue, 09 Mar 2010)

Log Message:
-----------
improve brush size keys so they dont change by 20 each time (bad for small brushes), added wm.context_scale_int() operator.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/wm.py
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c

Modified: trunk/blender/release/scripts/op/wm.py
===================================================================
--- trunk/blender/release/scripts/op/wm.py	2010-03-08 22:52:39 UTC (rev 27341)
+++ trunk/blender/release/scripts/op/wm.py	2010-03-08 23:34:38 UTC (rev 27342)
@@ -100,6 +100,42 @@
     execute = execute_context_assign
 
 
+class WM_OT_context_scale_int(bpy.types.Operator): # same as enum
+    '''Scale an int context value.'''
+    bl_idname = "wm.context_scale_int"
+    bl_label = "Context Set"
+    bl_options = {'UNDO'}
+
+    path = rna_path_prop
+    value = FloatProperty(name="Value", description="Assign value", default=1.0)
+    always_step = BoolProperty(name="Always Step",
+        description="Always adjust the value by a minimum of 1 when 'value' is not 1.0.",
+        default=True)
+
+    def execute(self, context):
+        if context_path_validate(context, self.properties.path) is Ellipsis:
+            return {'PASS_THROUGH'}
+
+        value = self.properties.value
+        path = self.properties.path
+
+        if value == 1.0: # nothing to do
+            return {'CANCELLED'}
+
+        if getattr(self.properties, "always_step", False):
+            if value > 1.0:
+                add = "1"
+                func = "max"
+            else:
+                add = "-1"
+                func = "min"
+            exec("context.%s = %s(round(context.%s * value), context.%s + %s)" % (path, func, path, path, add))
+        else:
+            exec("context.%s *= value" % self.properties.path)
+
+        return {'FINISHED'}
+
+
 class WM_OT_context_set_float(bpy.types.Operator): # same as enum
     '''Set a context value.'''
     bl_idname = "wm.context_set_float"
@@ -510,6 +546,7 @@
 
     WM_OT_context_set_boolean,
     WM_OT_context_set_int,
+    WM_OT_context_scale_int,
     WM_OT_context_set_float,
     WM_OT_context_set_string,
     WM_OT_context_set_enum,

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2010-03-08 22:52:39 UTC (rev 27341)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2010-03-08 23:34:38 UTC (rev 27342)
@@ -184,15 +184,13 @@
 {
 	wmKeyMapItem *kmi;
 	
-	kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", LEFTBRACKETKEY, KM_PRESS, 0, 0);
+	kmi= WM_keymap_add_item(keymap, "WM_OT_context_scale_int", LEFTBRACKETKEY, KM_PRESS, 0, 0);
 	RNA_string_set(kmi->ptr, "path", path);
-	RNA_int_set(kmi->ptr, "value", -20);
-	RNA_boolean_set(kmi->ptr, "relative", 1);
+	RNA_float_set(kmi->ptr, "value", 0.9);
 	
-	kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
+	kmi= WM_keymap_add_item(keymap, "WM_OT_context_scale_int", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
 	RNA_string_set(kmi->ptr, "path", path);
-	RNA_int_set(kmi->ptr, "value", 20);
-	RNA_boolean_set(kmi->ptr, "relative", 1);
+	RNA_float_set(kmi->ptr, "value", 10.0/9.0); // 1.1111....
 }	
 
 void ED_keymap_paint(wmKeyConfig *keyconf)





More information about the Bf-blender-cvs mailing list