Fix annotate tool in the 3D view

We can't share tools between space-types since they contain keymaps
that store the space type.
This commit is contained in:
Campbell Barton 2018-08-23 20:25:25 +10:00
parent 32f3ecf701
commit 73f90b2505

@ -196,92 +196,98 @@ class _defs_view3d_generic:
),
)
def _defs_annotate_factory():
class _defs_annotate:
@staticmethod
def draw_settings_common(context, layout, tool):
ts = context.tool_settings
class _defs_annotate:
@staticmethod
def draw_settings_common(context, layout, tool):
ts = context.tool_settings
space_type = tool.space_type
if space_type == 'VIEW_3D':
layout.separator()
space_type = tool.space_type
if space_type == 'VIEW_3D':
layout.separator()
row = layout.row(align=True)
row.prop(ts, "annotation_stroke_placement_view3d", text="Placement")
if ts.gpencil_stroke_placement_view3d == 'CURSOR':
row.prop(ts.gpencil_sculpt, "lockaxis")
elif ts.gpencil_stroke_placement_view3d in {'SURFACE', 'STROKE'}:
row.prop(ts, "use_gpencil_stroke_endpoints")
row = layout.row(align=True)
row.prop(ts, "annotation_stroke_placement_view3d", text="Placement")
if ts.gpencil_stroke_placement_view3d == 'CURSOR':
row.prop(ts.gpencil_sculpt, "lockaxis")
elif ts.gpencil_stroke_placement_view3d in {'SURFACE', 'STROKE'}:
row.prop(ts, "use_gpencil_stroke_endpoints")
@ToolDef.from_fn
def scribble():
def draw_settings(context, layout, tool):
_defs_annotate.draw_settings_common(context, layout, tool)
@ToolDef.from_fn
def scribble():
def draw_settings(context, layout, tool):
_defs_annotate.draw_settings_common(context, layout, tool)
return dict(
text="Annotate",
icon="ops.gpencil.draw",
cursor='PAINT_BRUSH',
keymap=(
("gpencil.annotate",
dict(mode='DRAW', wait_for_input=False),
dict(type='EVT_TWEAK_A', value='ANY')),
),
draw_settings=draw_settings,
)
return dict(
text="Annotate",
icon="ops.gpencil.draw",
cursor='PAINT_BRUSH',
keymap=(
("gpencil.annotate",
dict(mode='DRAW', wait_for_input=False),
dict(type='EVT_TWEAK_A', value='ANY')),
),
draw_settings=draw_settings,
)
@ToolDef.from_fn
def line():
def draw_settings(context, layout, tool):
_defs_annotate.draw_settings_common(context, layout, tool)
@ToolDef.from_fn
def line():
def draw_settings(context, layout, tool):
_defs_annotate.draw_settings_common(context, layout, tool)
return dict(
text="Draw Line",
icon="ops.gpencil.draw.line",
cursor='CROSSHAIR',
keymap=(
("gpencil.annotate",
dict(mode='DRAW_STRAIGHT', wait_for_input=False),
dict(type='EVT_TWEAK_A', value='ANY')),
),
draw_settings=draw_settings,
)
return dict(
text="Draw Line",
icon="ops.gpencil.draw.line",
cursor='CROSSHAIR',
keymap=(
("gpencil.annotate",
dict(mode='DRAW_STRAIGHT', wait_for_input=False),
dict(type='EVT_TWEAK_A', value='ANY')),
),
draw_settings=draw_settings,
)
@ToolDef.from_fn
def poly():
def draw_settings(context, layout, tool):
_defs_annotate.draw_settings_common(context, layout, tool)
@ToolDef.from_fn
def poly():
def draw_settings(context, layout, tool):
_defs_annotate.draw_settings_common(context, layout, tool)
return dict(
text="Draw Polygon",
icon="ops.gpencil.draw.poly",
cursor='CROSSHAIR',
keymap=(
("gpencil.annotate",
dict(mode='DRAW_POLY', wait_for_input=False),
dict(type='ACTIONMOUSE', value='PRESS')),
),
draw_settings=draw_settings,
)
return dict(
text="Draw Polygon",
icon="ops.gpencil.draw.poly",
cursor='CROSSHAIR',
keymap=(
("gpencil.annotate",
dict(mode='DRAW_POLY', wait_for_input=False),
dict(type='ACTIONMOUSE', value='PRESS')),
),
draw_settings=draw_settings,
)
@ToolDef.from_fn
def eraser():
def draw_settings(context, layout, tool):
# TODO: Move this setting to toolsettings
user_prefs = context.user_preferences
layout.prop(user_prefs.edit, "grease_pencil_eraser_radius", text="Radius")
@ToolDef.from_fn
def eraser():
def draw_settings(context, layout, tool):
# TODO: Move this setting to toolsettings
user_prefs = context.user_preferences
layout.prop(user_prefs.edit, "grease_pencil_eraser_radius", text="Radius")
return dict(
text="Eraser",
icon="ops.gpencil.draw.eraser",
cursor='CROSSHAIR', # XXX: Always show brush circle when enabled
keymap=(
("gpencil.annotate",
dict(mode='ERASER', wait_for_input=False),
dict(type='ACTIONMOUSE', value='PRESS')),
),
draw_settings=draw_settings,
)
return dict(
text="Eraser",
icon="ops.gpencil.draw.eraser",
cursor='CROSSHAIR', # XXX: Always show brush circle when enabled
keymap=(
("gpencil.annotate",
dict(mode='ERASER', wait_for_input=False),
dict(type='ACTIONMOUSE', value='PRESS')),
),
draw_settings=draw_settings,
)
return _defs_annotate
# Needed so annotation gets a keymap per space type.
_defs_annotate_image = _defs_annotate_factory()
_defs_annotate_view3d = _defs_annotate_factory()
class _defs_transform:
@ -1473,10 +1479,10 @@ class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel):
_tools_annotate = (
(
_defs_annotate.scribble,
_defs_annotate.line,
_defs_annotate.poly,
_defs_annotate.eraser,
_defs_annotate_image.scribble,
_defs_annotate_image.line,
_defs_annotate_image.poly,
_defs_annotate_image.eraser,
),
)
@ -1543,10 +1549,10 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
_tools_annotate = (
(
_defs_annotate.scribble,
_defs_annotate.line,
_defs_annotate.poly,
_defs_annotate.eraser,
_defs_annotate_view3d.scribble,
_defs_annotate_view3d.line,
_defs_annotate_view3d.poly,
_defs_annotate_view3d.eraser,
),
_defs_view3d_generic.ruler,
)