Paint: update shortcut detection for new logic

This commit is contained in:
2018-11-07 10:54:14 +11:00
parent 87a6aab251
commit 895295a9f0
4 changed files with 52 additions and 42 deletions

View File

@@ -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

View File

@@ -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] = "";

View File

@@ -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(

View File

@@ -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;