[Bf-blender-cvs] [895295a9f0c] blender2.8: Paint: update shortcut detection for new logic

Campbell Barton noreply at git.blender.org
Wed Nov 7 00:56:21 CET 2018


Commit: 895295a9f0cb85c7c48c395621b9c9d7e5fc78a3
Author: Campbell Barton
Date:   Wed Nov 7 10:54:14 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB895295a9f0cb85c7c48c395621b9c9d7e5fc78a3

Paint: update shortcut detection for new logic

===================================================================

M	release/scripts/startup/bl_ui/space_toolsystem_common.py
M	source/blender/editors/interface/interface_region_tooltip.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_access.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index 138f69860a6..f23b76c5911 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -811,30 +811,28 @@ def keymap_from_context(context, space_type):
                 if kmi_found is None:
                     if item.data_block:
                         # PAINT_OT_brush_select
-                        brush = bpy.data.brushes.get(item.data_block)
-                        if brush is not None:
-                            mode = context.active_object.mode
-                            attr_op, attr_brush = {
-                                'SCULPT': ("sculpt_tool", "sculpt_tool"),
-                                'WEIGHT_PAINT': ("weight_paint_tool", "weight_tool"),
-                                'VERTEX_PAINT': ("vertex_paint_tool", "vertex_tool"),
-                                'TEXTURE_PAINT': ("texture_paint_tool", "image_tool"),
-                            }.get(mode, (None, None))
-                            if attr_op is not None:
-                                kmi_hack_brush_select_properties.paint_mode = mode
-                                setattr(kmi_hack_brush_select_properties, attr_op, getattr(brush, attr_brush))
-                                kmi_found = wm.keyconfigs.find_item_from_operator(
-                                    idname="paint.brush_select",
-                                    context='INVOKE_REGION_WIN',
-                                    properties=kmi_hack_brush_select_properties,
-                                )[1]
-                            elif mode == 'GPENCIL_PAINT':
-                                # TODO: gpencil.brush_select
-                                # By default no keys are mapped to this, pass.
-                                pass
-                            else:
-                                print("Unsupported mode:", mode)
-                            del mode, attr_op, attr_brush
+                        mode = context.active_object.mode
+                        attr = {
+                            'SCULPT': "sculpt_tool",
+                            'WEIGHT_PAINT': "weight_paint_tool",
+                            'VERTEX_PAINT': "vertex_paint_tool",
+                            'TEXTURE_PAINT': "texture_paint_tool",
+                        }.get(mode, (None, None))
+                        if attr is not None:
+                            kmi_hack_brush_select_properties.paint_mode = mode
+                            setattr(kmi_hack_brush_select_properties, attr, item.data_block)
+                            kmi_found = wm.keyconfigs.find_item_from_operator(
+                                idname="paint.brush_select",
+                                context='INVOKE_REGION_WIN',
+                                properties=kmi_hack_brush_select_properties,
+                            )[1]
+                        elif mode == 'GPENCIL_PAINT':
+                            # TODO: gpencil.brush_select
+                            # By default no keys are mapped to this, pass.
+                            pass
+                        else:
+                            print("Unsupported mode:", mode)
+                        del mode, attr
 
             else:
                 kmi_found = None
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 4e1218c3b2f..6d3ba95fda5 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -56,6 +56,7 @@
 #include "BKE_context.h"
 #include "BKE_screen.h"
 #include "BKE_library.h"
+#include "BKE_paint.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -457,42 +458,37 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
 		}
 
 		if (shortcut == NULL) {
-			int mode = CTX_data_mode_enum(C);
+			ePaintMode paint_mode = BKE_paintmode_get_active_from_context(C);
 			const char *tool_attr = NULL;
-			uint tool_offset = 0;
 
-			switch (mode) {
-				case CTX_MODE_SCULPT:
+			switch (paint_mode) {
+				case ePaintSculpt:
 					tool_attr = "sculpt_tool";
-					tool_offset = offsetof(Brush, sculpt_tool);
 					break;
-				case CTX_MODE_PAINT_VERTEX:
+				case ePaintVertex:
 					tool_attr = "vertex_paint_tool";
-					tool_offset = offsetof(Brush, vertexpaint_tool);
 					break;
-				case CTX_MODE_PAINT_WEIGHT:
+				case ePaintWeight:
 					tool_attr = "weight_paint_tool";
-					tool_offset = offsetof(Brush, weightpaint_tool);
 					break;
-				case CTX_MODE_PAINT_TEXTURE:
+				case ePaintTexture2D:
+				case ePaintTextureProjective:
 					tool_attr = "texture_paint_tool";
-					tool_offset = offsetof(Brush, imagepaint_tool);
+					paint_mode = ePaintTextureProjective;
 					break;
 				default:
 					break;
 			}
 
 			if (tool_attr != NULL) {
-				struct Main *bmain = CTX_data_main(C);
-				Brush *brush = (Brush *)BKE_libblock_find_name(bmain, ID_BR, tool_name);
-				if (brush) {
-					Object *ob = CTX_data_active_object(C);
+				const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
+				const int i = RNA_enum_from_name(items, tool_name);
+				if (i != -1) {
 					wmOperatorType *ot = WM_operatortype_find("paint.brush_select", true);
-
 					PointerRNA op_props;
 					WM_operator_properties_create_ptr(&op_props, ot);
-					RNA_enum_set(&op_props, "paint_mode", ob->mode);
-					RNA_enum_set(&op_props, tool_attr, *(((char *)brush) + tool_offset));
+					RNA_enum_set(&op_props, "paint_mode", paint_mode);
+					RNA_enum_set(&op_props, tool_attr, items[i].value);
 
 					/* Check for direct access to the tool. */
 					char shortcut_brush[128] = "";
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 2c0d647332c..2f4d999c4fb 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -877,6 +877,7 @@ bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r
 bool RNA_enum_description(const EnumPropertyItem *item, const int value, const char **description);
 int  RNA_enum_from_value(const EnumPropertyItem *item, const int value);
 int  RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier);
+int  RNA_enum_from_name(const EnumPropertyItem *item, const char *name);
 unsigned int RNA_enum_items_count(const EnumPropertyItem *item);
 
 void RNA_property_enum_items_ex(
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 3cc99571ccf..33246ba4a30 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1665,6 +1665,21 @@ int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifie
 	return -1;
 }
 
+/**
+ * Take care using this with translated enums,
+ * prefer #RNA_enum_from_identifier where possible.
+ */
+int RNA_enum_from_name(const EnumPropertyItem *item, const char *name)
+{
+	int i = 0;
+	for (; item->identifier; item++, i++) {
+		if (item->identifier[0] && STREQ(item->name, name)) {
+			return i;
+		}
+	}
+	return -1;
+}
+
 int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
 {
 	int i = 0;



More information about the Bf-blender-cvs mailing list