[Bf-extensions-cvs] [3c6e9c26] master: GPencil Tools: code cleanup
Pullusb
noreply at git.blender.org
Sun Jan 24 19:44:17 CET 2021
Commit: 3c6e9c26bc6b35399dfbc38c3116b1375fa6f53c
Author: Pullusb
Date: Sun Jan 24 19:43:41 2021 +0100
Branches: master
https://developer.blender.org/rBA3c6e9c26bc6b35399dfbc38c3116b1375fa6f53c
GPencil Tools: code cleanup
Remove _wip_ comments on timeline_scrub.py file
===================================================================
M greasepencil_tools/__init__.py
M greasepencil_tools/timeline_scrub.py
===================================================================
diff --git a/greasepencil_tools/__init__.py b/greasepencil_tools/__init__.py
index abc7a033..e5135422 100644
--- a/greasepencil_tools/__init__.py
+++ b/greasepencil_tools/__init__.py
@@ -21,7 +21,7 @@ bl_info = {
"name": "Grease Pencil Tools",
"description": "Extra tools for Grease Pencil",
"author": "Samuel Bernou, Antonio Vazquez, Daniel Martinez Lara, Matias Mendiola",
-"version": (1, 2, 0),
+"version": (1, 2, 1),
"blender": (2, 91, 0),
"location": "Sidebar > Grease Pencil > Grease Pencil Tools",
"warning": "",
diff --git a/greasepencil_tools/timeline_scrub.py b/greasepencil_tools/timeline_scrub.py
index 7a783e0b..bd7edebe 100644
--- a/greasepencil_tools/timeline_scrub.py
+++ b/greasepencil_tools/timeline_scrub.py
@@ -36,17 +36,6 @@ from bpy.props import (BoolProperty,
PointerProperty,
EnumProperty)
-""" bl_info = {
- "name": "Viewport Scrub Timeline",
- "description": "Scrub on timeline from viewport and snap to nearest keyframe",
- "author": "Samuel Bernou",
- "version": (0, 7, 5),
- "blender": (2, 91, 0),
- "location": "View3D > shortcut key chosen in addon prefs",
- "warning": "",
- "doc_url": "https://github.com/Pullusb/scrub_timeline",
- "category": "Object"}
- """
def nearest(array, value):
'''
@@ -61,8 +50,6 @@ def draw_callback_px(self, context):
'''Draw callback use by modal to draw in viewport'''
if context.area != self.current_area:
return
- ## lines and shaders
- # 50% alpha, 2 pixel width line
# text
font_id = 0
@@ -71,13 +58,13 @@ def draw_callback_px(self, context):
bgl.glEnable(bgl.GL_BLEND)
bgl.glLineWidth(1)
- # - # Draw HUD
+ # Draw HUD
if self.use_hud_time_line:
shader.bind()
shader.uniform_float("color", self.color_timeline)
self.batch_timeline.draw(shader)
- # - # Display keyframes
+ # Display keyframes
if self.use_hud_keyframes:
if self.keyframe_aspect == 'LINE':
bgl.glLineWidth(3)
@@ -85,29 +72,14 @@ def draw_callback_px(self, context):
shader.uniform_float("color", self.color_timeline)
self.batch_keyframes.draw(shader)
else:
- # - # Display keyframe as diamonds
bgl.glLineWidth(1)
shader.bind()
shader.uniform_float("color", self.color_timeline)
- # shader.uniform_float("color", list(self.color_timeline[:3]) + [1]) # timeline color full opacity
- # shader.uniform_float("color", (0.8, 0.8, 0.8, 0.8)) # grey
- # shader.uniform_float("color", (0.9, 0.69, 0.027, 1.0)) # yellow-ish
- # shader.uniform_float("color",(1.0, 0.515, 0.033, 1.0)) # orange 'selected keyframe'
self.batch_keyframes.draw(shader)
- # - # Display init frame text (under playhead)
- # if self.use_hud_frame_init: # propertie not existing currently
- # blf.position(font_id, self.init_mouse_x,
- # self.init_mouse_y - (60 *self.ui_scale), 0)
- # blf.size(font_id, 16, self.dpi)
- # blf.color(font_id, *self.color_timeline)
- # blf.draw(font_id, f'{self.init_frame:.0f}')
-
- # - # Show current frame line
+ # Show current frame line
bgl.glLineWidth(1)
if self.use_hud_playhead:
- # -# old full height playhead
- # playhead = [(self.cursor_x, 0), (self.cursor_x, context.area.height)]
playhead = [(self.cursor_x, self.my + self.playhead_size/2),
(self.cursor_x, self.my - self.playhead_size/2)]
batch = batch_for_shader(shader, 'LINES', {"pos": playhead})
@@ -118,20 +90,18 @@ def draw_callback_px(self, context):
# restore opengl defaults
bgl.glDisable(bgl.GL_BLEND)
- # - # Display current frame text
+ # Display current frame text
blf.color(font_id, *self.color_text)
if self.use_hud_frame_current:
blf.position(font_id, self.mouse[0]+10, self.mouse[1]+10, 0)
- # Id, Point size of the font, dots per inch value to use for drawing.
- blf.size(font_id, 30, self.dpi) # 72
+ blf.size(font_id, 30, self.dpi)
blf.draw(font_id, f'{self.new_frame:.0f}')
- # - # Display frame offset text
+ # Display frame offset text
if self.use_hud_frame_offset:
blf.position(font_id, self.mouse[0]+10,
self.mouse[1]+(40*self.ui_scale), 0)
blf.size(font_id, 16, self.dpi)
- # blf.color(font_id, *self.color_text)
sign = '+' if self.offset > 0 else ''
blf.draw(font_id, f'{sign}{self.offset:.0f}')
@@ -148,10 +118,6 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
def invoke(self, context, event):
prefs = get_addon_prefs().ts
- # Gpencil contexts : ('PAINT_GPENCIL', 'EDIT_GPENCIL')
- # if context.space_data.type != 'VIEW_3D':
- # self.report({'WARNING'}, "Work only in Viewport")
- # return {'CANCELLED'}
self.current_area = context.area
self.key = prefs.keycode
@@ -174,17 +140,15 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
self.lines_size = prefs.lines_size
self.px_step = prefs.pixel_step
- # global keycode
- # self.key = keycode
self.snap_on = False
self.mouse = (event.mouse_region_x, event.mouse_region_y)
- self.init_mouse_x = self.cursor_x = event.mouse_region_x # event.mouse_x
+ self.init_mouse_x = self.cursor_x = event.mouse_region_x
# self.init_mouse_y = event.mouse_region_y # only to display init frame text
self.init_frame = self.new_frame = context.scene.frame_current
self.offset = 0
self.pos = []
- # Snap touch control
+ # Snap control
self.snap_ctrl = not prefs.use_ctrl
self.snap_shift = not prefs.use_shift
self.snap_alt = not prefs.use_alt
@@ -218,7 +182,7 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
if frame.frame_number not in self.pos:
self.pos.append(frame.frame_number)
- # - Add start and end to snap on
+ # Add start and end to snap on
if context.scene.use_preview_range:
play_bounds = [context.scene.frame_preview_start,
context.scene.frame_preview_end]
@@ -242,8 +206,6 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
return {'RUNNING_MODAL'}
# - HUD params
-
- # line_height = 25 # px
width = context.area.width
right = int((width - self.init_mouse_x) / self.px_step)
left = int(self.init_mouse_x / self.px_step)
@@ -262,15 +224,16 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
bound_h = key_height + 19
bound_bracket_l = self.px_step/2
- self.my = my = event.mouse_region_y # event.mouse_y
+ self.my = my = event.mouse_region_y
self.hud_lines = []
- # - # frame marks
+
+ # frame marks
for x in hud_pos_x:
self.hud_lines.append((x, my - (frame_height/2)))
self.hud_lines.append((x, my + (frame_height/2)))
- # - # init frame mark
+ # init frame mark
self.hud_lines += [(self.init_mouse_x, my - (init_height/2)),
(self.init_mouse_x, my + (init_height/2))]
@@ -281,7 +244,7 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
end_x = self.init_mouse_x + \
(play_bounds[1] - self.init_frame) * self.px_step
- # - # start
+ # start
up = (start_x, my - (bound_h/2))
dn = (start_x, my + (bound_h/2))
self.hud_lines.append(up)
@@ -292,7 +255,7 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
self.hud_lines.append(dn)
self.hud_lines.append((dn[0] + bound_bracket_l, dn[1]))
- # - # end
+ # end
up = (end_x, my - (bound_h/2))
dn = (end_x, my + (bound_h/2))
self.hud_lines.append(up)
@@ -303,20 +266,15 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
self.hud_lines.append(dn)
self.hud_lines.append((dn[0] - bound_bracket_l, dn[1]))
- # - # Horizontal line
+ # Horizontal line
self.hud_lines += [(0, my), (width, my)]
- # - #other method with cutted H line
- # leftmost = self.init_mouse_x - (left*self.px_step)
- # rightmost = self.init_mouse_x + (right*self.px_step)
- # self.hud_lines += [(leftmost, my), (rightmost, my)]
-
- # - # Prepare batchs to draw static parts
+ # Prepare batchs to draw static parts
shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR') # initiate shader
self.batch_timeline = batch_for_shader(
shader, 'LINES', {"pos": self.hud_lines})
- # - # keyframe display
+ # keyframe display
if self.keyframe_aspect == 'LINE':
key_lines = []
# Slice off position of start/end frame added last (in list for snapping)
@@ -331,7 +289,7 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
else:
# diamond and square
- # keysize = 6 # 5 for square, 4 or 6 for diamond
+ # keysize5 for square, 4 or 6 for diamond
keysize = 6 if self.keyframe_aspect == 'DIAMOND' else 5
upper = 0
@@ -369,7 +327,6 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
self._handle = bpy.types.SpaceView3D.draw_handler_add(
draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
- # - # VSE disabling hud : Doesn't get right coordinates in preview window
elif context.space_data.type == 'SEQUENCE_EDITOR':
self.viewtype = bpy.types.SpaceSequenceEditor
self.spacetype = 'PREVIEW'
@@ -398,10 +355,8 @@ class GPTS_OT_time_scrub(bpy.types.Operator):
# - calculate frame offset from pixel offset
# - get mouse.x and add it to initial frame num
self.mouse = (event.mouse_region_x, event.mouse_region_y)
- # self.mouse = (event.mouse_x, event.mouse_y)
px_offset = (event.mouse_region_x - self.init_mouse_x)
- # int to overt
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list