-
Notifications
You must be signed in to change notification settings - Fork 8
/
ui_panels.py
71 lines (55 loc) · 2.78 KB
/
ui_panels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# SPDX-FileCopyrightText: 2020-2023 Blender Foundation
#
# SPDX-License-Identifier: GPL-3.0-or-later
import bpy
class GP_PT_sidebarPanel(bpy.types.Panel):
bl_label = "Grease Pencil Tools"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Grease Pencil"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
# Box deform ops
self.layout.operator_context = 'INVOKE_DEFAULT'
layout.operator('view3d.gp_box_deform', icon ="MOD_MESHDEFORM")
# Straight line ops
layout.operator('gpencil.straight_stroke', icon ="CURVE_PATH")
# Expose native view operators
row = layout.row(align=True)
row.operator('view3d.zoom_camera_1_to_1', text = 'Zoom 1:1', icon = 'ZOOM_PREVIOUS')
row.operator('view3d.view_center_camera', text = 'Zoom Fit', icon = 'FULLSCREEN_ENTER')
# Rotation save/load
row = layout.row(align=True)
row.operator('view3d.rotate_canvas_reset', text = 'Reset Rotation', icon = 'FILE_REFRESH')
row.operator('view3d.rotate_canvas_set', text = 'Save Rotation', icon = 'DRIVER_ROTATIONAL_DIFFERENCE')
# View flip
if context.scene.camera and context.scene.camera.scale.x < 0:
row = layout.row(align=True)
row.operator('view3d.camera_flip_x', text = 'Camera Mirror Flip', icon = 'MOD_MIRROR')
row.label(text='', icon='LOOP_BACK')
else:
layout.operator('view3d.camera_flip_x', text = 'Camera Mirror Flip', icon = 'MOD_MIRROR')
def menu_boxdeform_entry(self, context):
"""Transform shortcut to append in existing menu"""
layout = self.layout
obj = bpy.context.object
if obj and obj.type == 'GREASEPENCIL' and context.mode in {'OBJECT', 'EDIT_GREASE_PENCIL', 'PAINT_GREASE_PENCIL'}:
self.layout.operator_context = 'INVOKE_DEFAULT'
layout.operator('view3d.gp_box_deform', text='Box Deform')
def menu_stroke_entry(self, context):
layout = self.layout
if context.mode in {'EDIT_GREASE_PENCIL', 'PAINT_GREASE_PENCIL'}:
self.layout.operator_context = 'INVOKE_DEFAULT'
layout.operator('gpencil.straight_stroke', text='Straight Stroke')
def register():
bpy.utils.register_class(GP_PT_sidebarPanel)
## VIEW3D_MT_edit_gpencil.append# Grease pencil menu
bpy.types.VIEW3D_MT_transform_object.append(menu_boxdeform_entry)
bpy.types.VIEW3D_MT_transform.append(menu_boxdeform_entry)
bpy.types.VIEW3D_MT_edit_greasepencil_stroke.append(menu_stroke_entry)
def unregister():
bpy.types.VIEW3D_MT_transform_object.remove(menu_boxdeform_entry)
bpy.types.VIEW3D_MT_transform.remove(menu_boxdeform_entry)
bpy.types.VIEW3D_MT_edit_greasepencil_stroke.remove(menu_stroke_entry)
bpy.utils.unregister_class(GP_PT_sidebarPanel)