Skip to content
Snippets Groups Projects
Commit 393c978b authored by Pullusb's avatar Pullusb
Browse files

GPencil Tools: timeline scrub frame snapping option

Add an addon-preference option to always snap on keyframes while scrubbing (Disabled by defaut).
Invert the behavior of the snap modifier key. Disabled if there isn't any keyframe.

fix: carriage return at the end of rotate_canvas.py
parent 32adcd8c
Branches
Tags
No related merge requests found
...@@ -21,7 +21,7 @@ bl_info = { ...@@ -21,7 +21,7 @@ bl_info = {
"name": "Grease Pencil Tools", "name": "Grease Pencil Tools",
"description": "Extra tools for Grease Pencil", "description": "Extra tools for Grease Pencil",
"author": "Samuel Bernou, Antonio Vazquez, Daniel Martinez Lara, Matias Mendiola", "author": "Samuel Bernou, Antonio Vazquez, Daniel Martinez Lara, Matias Mendiola",
"version": (1, 3, 2), "version": (1, 3, 3),
"blender": (2, 91, 0), "blender": (2, 91, 0),
"location": "Sidebar > Grease Pencil > Grease Pencil Tools", "location": "Sidebar > Grease Pencil > Grease Pencil Tools",
"warning": "", "warning": "",
......
...@@ -258,4 +258,4 @@ def register(): ...@@ -258,4 +258,4 @@ def register():
def unregister(): def unregister():
for cls in reversed(classes): for cls in reversed(classes):
bpy.utils.unregister_class(cls) bpy.utils.unregister_class(cls)
\ No newline at end of file
...@@ -122,6 +122,7 @@ class GPTS_OT_time_scrub(bpy.types.Operator): ...@@ -122,6 +122,7 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
self.current_area = context.area self.current_area = context.area
self.key = prefs.keycode self.key = prefs.keycode
self.evaluate_gp_obj_key = prefs.evaluate_gp_obj_key self.evaluate_gp_obj_key = prefs.evaluate_gp_obj_key
self.always_snap = prefs.always_snap
self.dpi = context.preferences.system.dpi self.dpi = context.preferences.system.dpi
self.ui_scale = context.preferences.system.ui_scale self.ui_scale = context.preferences.system.ui_scale
...@@ -191,13 +192,14 @@ class GPTS_OT_time_scrub(bpy.types.Operator): ...@@ -191,13 +192,14 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
if frame.frame_number not in self.pos: if frame.frame_number not in self.pos:
self.pos.append(frame.frame_number) self.pos.append(frame.frame_number)
if not ob or not self.pos:
# Add start and end to snap on # Disable inverted behavior if no frame to snap
self.always_snap = False
# Also snap on play bounds (sliced off for keyframe display) # Also snap on play bounds (sliced off for keyframe display)
self.pos += [self.f_start, self.f_end] self.pos += [self.f_start, self.f_end]
# Disable Onion skin # Disable Onion skin
self.active_space_data = context.space_data self.active_space_data = context.space_data
self.onion_skin = None self.onion_skin = None
...@@ -389,8 +391,14 @@ class GPTS_OT_time_scrub(bpy.types.Operator): ...@@ -389,8 +391,14 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
if self.snap_alt and event.alt: if self.snap_alt and event.alt:
mod_snap = True mod_snap = True
if self.snap_on or mod_snap: ## Snapping
self.new_frame = nearest(self.pos, self.new_frame) if self.always_snap:
# inverted snapping behavior
if not self.snap_on and not mod_snap:
self.new_frame = nearest(self.pos, self.new_frame)
else:
if self.snap_on or mod_snap:
self.new_frame = nearest(self.pos, self.new_frame)
# frame range restriction # frame range restriction
if self.lock_range: if self.lock_range:
...@@ -492,6 +500,11 @@ class GPTS_timeline_settings(bpy.types.PropertyGroup): ...@@ -492,6 +500,11 @@ class GPTS_timeline_settings(bpy.types.PropertyGroup):
description="Shortcut to trigger the scrub in viewport during press", description="Shortcut to trigger the scrub in viewport during press",
default="MIDDLEMOUSE") default="MIDDLEMOUSE")
always_snap: BoolProperty(
name="Always Snap",
description="Always snap to keys if any, modifier is used deactivate the snapping\nDisabled if no keyframe found",
default=False)
use_in_timeline_editor: BoolProperty( use_in_timeline_editor: BoolProperty(
name="Shortcut in timeline editors", name="Shortcut in timeline editors",
description="Add the same shortcut to scrub in timeline editor windows", description="Add the same shortcut to scrub in timeline editor windows",
...@@ -649,7 +662,11 @@ def draw_ts_pref(prefs, layout): ...@@ -649,7 +662,11 @@ def draw_ts_pref(prefs, layout):
else: else:
box.label(text='[ NOW TYPE KEY OR CLICK TO USE, WITH MODIFIER ]') box.label(text='[ NOW TYPE KEY OR CLICK TO USE, WITH MODIFIER ]')
snap_text = 'Snap to keyframes: ' if prefs.always_snap:
snap_text = 'Disable keyframes snap: '
else:
snap_text = 'Keyframes snap: '
snap_text += 'Left Mouse' if prefs.keycode == 'RIGHTMOUSE' else 'Right Mouse' snap_text += 'Left Mouse' if prefs.keycode == 'RIGHTMOUSE' else 'Right Mouse'
if not prefs.use_ctrl: if not prefs.use_ctrl:
snap_text += ' or Ctrl' snap_text += ' or Ctrl'
...@@ -662,6 +679,7 @@ def draw_ts_pref(prefs, layout): ...@@ -662,6 +679,7 @@ def draw_ts_pref(prefs, layout):
box.label( box.label(
text="Recommended to choose at least one modifier to combine with clicks (default: Ctrl+Alt)", icon="ERROR") text="Recommended to choose at least one modifier to combine with clicks (default: Ctrl+Alt)", icon="ERROR")
box.prop(prefs, 'always_snap')
box.prop(prefs, 'use_in_timeline_editor', box.prop(prefs, 'use_in_timeline_editor',
text='Add same shortcut to scrub within timeline editors') text='Add same shortcut to scrub within timeline editors')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment