Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-07 02:54:14 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-07 02:54:56 +0300
commit895295a9f0cb85c7c48c395621b9c9d7e5fc78a3 (patch)
treef9621ae96c65433301ba2a8ba401d43ad0df68d4 /source
parent87a6aab2518ed391c755e3e7aeae9692f25569ae (diff)
Paint: update shortcut detection for new logic
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c32
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/rna_access.c15
3 files changed, 30 insertions, 18 deletions
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;