GPencil Tools: Canvas rotation fixes

- Changed canvas rotation reset method (was hard to trigger with a tablet pen).
- Default angle steps increased to 15 degrees.
- HUD now appear only in active viewport as it should
This commit is contained in:
Samuel Bernou 2021-02-10 21:52:30 +01:00
parent e5a2d98c82
commit 32adcd8c59
3 changed files with 12 additions and 6 deletions

View File

@ -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, 3, 1),
"version": (1, 3, 2),
"blender": (2, 91, 0),
"location": "Sidebar > Grease Pencil > Grease Pencil Tools",
"warning": "",

View File

@ -128,9 +128,9 @@ class GreasePencilAddonPrefs(bpy.types.AddonPreferences):
rc_angle_step: FloatProperty(
name="Angle Steps",
description="Step the rotation using this angle when using rotate canvas step modifier",
default=0.0872664600610733, # 5
default=0.2617993877991494, # 15
min=0.01745329238474369, # 1
max=3.1415927410125732, # # 180
max=3.1415927410125732, # 180
soft_min=0.01745329238474369, # 1
soft_max=1.5707963705062866, # 90
step=10, precision=1, subtype='ANGLE', unit='ROTATION')
@ -153,7 +153,7 @@ class GreasePencilAddonPrefs(bpy.types.AddonPreferences):
row.label(text='Box Deform:')
row.operator("wm.call_menu", text="", icon='QUESTION').name = "GPT_MT_box_deform_doc"
box.prop(self, "use_clic_drag")
# box.separator()
box.prop(self, "default_deform_type")
box.label(text="Deformer type can be changed during modal with 'M' key, this is for default behavior", icon='INFO')
@ -204,7 +204,7 @@ class GreasePencilAddonPrefs(bpy.types.AddonPreferences):
draw_ts_pref(prefs.ts, box)
# def box_deform_tuto(layout):
class GPT_MT_box_deform_doc(bpy.types.Menu):
# bl_idname = "OBJECT_MT_custom_menu"
bl_label = "Box Deform Infos Sheet"

View File

@ -5,6 +5,7 @@ import math
import mathutils
from bpy_extras.view3d_utils import location_3d_to_region_2d
from bpy.props import BoolProperty, EnumProperty
from time import time
## draw utils
import gpu
import bgl
@ -25,6 +26,8 @@ def step_value(value, step):
def draw_callback_px(self, context):
# 50% alpha, 2 pixel width line
if context.area != self.current_area:
return
shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
bgl.glEnable(bgl.GL_BLEND)
bgl.glLineWidth(2)
@ -116,7 +119,8 @@ class RC_OT_RotateCanvas(bpy.types.Operator):
context.space_data.region_3d.view_rotation = rot.to_quaternion()
if event.type in {'RIGHTMOUSE', 'LEFTMOUSE', 'MIDDLEMOUSE'} and event.value == 'RELEASE':
if not self.angle:
# Trigger reset : Less than 150ms and less than 2 degrees move
if time() - self.timer < 0.15 and abs(math.degrees(self.angle)) < 2:
# self.report({'INFO'}, 'Reset')
aim = context.space_data.region_3d.view_rotation @ mathutils.Vector((0.0, 0.0, 1.0))#view vector
z_up_quat = aim.to_track_quat('Z','Y')#track Z, up Y
@ -143,6 +147,7 @@ class RC_OT_RotateCanvas(bpy.types.Operator):
return {'RUNNING_MODAL'}
def invoke(self, context, event):
self.current_area = context.area
prefs = get_addon_prefs()
self.hud = prefs.canvas_use_hud
self.angle = 0.0
@ -190,6 +195,7 @@ class RC_OT_RotateCanvas(bpy.types.Operator):
# round to closer degree and convert back to radians
self.snap_step = math.radians(round(math.degrees(prefs.rc_angle_step)))
self.timer = time()
args = (self, context)
if self.hud:
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL')