Implement Canvas Size feature

This commit is contained in:
2024-05-20 23:53:16 +09:00
parent 9913ae8c35
commit a580a4e137
3 changed files with 168 additions and 3 deletions
+93 -1
View File
@@ -1,5 +1,5 @@
'''
Copyright (C) 2021 - 2023 Akaneyu
Copyright (C) 2021 - 2024 Akaneyu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -199,6 +199,90 @@ class IMAGE_EDITOR_PLUS_OT_scale_dialog(bpy.types.Operator):
row.column()
row.prop(self, 'reset', text='Reset', toggle=True)
def reset_canvas_size_properties(self, context):
if self.reset:
self.width = self.original_width
self.height = self.original_height
self.expand_from_center = False
self.use_background_color = False
self.reset = False
class IMAGE_EDITOR_PLUS_OT_change_canvas_size_dialog(bpy.types.Operator):
"""Change the canvas size"""
bl_idname = 'image_editor_plus.change_canvas_size_dialog'
bl_label = "Canvas Size"
reset: bpy.props.BoolProperty(options={'SKIP_SAVE'}, update=reset_canvas_size_properties)
width: bpy.props.IntProperty(name='Width',
min=1, options={'SKIP_SAVE'})
height: bpy.props.IntProperty(name='Height',
min=1, options={'SKIP_SAVE'})
expand_from_center: bpy.props.BoolProperty(name='Expand from Center', default=False)
use_background_color: bpy.props.BoolProperty(name='Use Background Color', default=False)
original_width: bpy.props.IntProperty()
original_height: bpy.props.IntProperty()
def invoke(self, context, event):
wm = context.window_manager
img = context.area.spaces.active.image
if not img:
return {'CANCELLED'}
width, height = img.size
self.original_width = width
self.original_height = height
self.width = width
self.height = height
return wm.invoke_props_dialog(self)
def execute(self, context):
width = self.width
height = self.height
if width < 1:
width = 1
if height < 1:
height = 1
bpy.ops.image_editor_plus.change_canvas_size('EXEC_DEFAULT', False,
width=width, height=height, expand_from_center=self.expand_from_center,
use_background_color=self.use_background_color)
return {'FINISHED'}
def draw(self, context):
layout = self.layout
row = layout.row()
row = layout.split(align=True)
row.alignment = 'RIGHT'
row.label(text='Width')
row.prop(self, 'width', text='')
row = layout.split(align=True)
row.alignment = 'RIGHT'
row.label(text='Height')
row.prop(self, 'height', text='')
row = layout.split(align=True)
row.column()
row.prop(self, 'expand_from_center')
row = layout.split(align=True)
row.column()
row.prop(self, 'use_background_color')
row = layout.split(align=True)
row.column()
row = layout.split(factor=0.7)
row.column()
row.prop(self, 'reset', text='Reset', toggle=True)
def preview_offset_properties(self, context):
if self.preview:
update_offset_properties(self, context)
@@ -1261,6 +1345,9 @@ class IMAGE_EDITOR_PLUS_MT_transform_menu(bpy.types.Menu):
op = layout.operator(IMAGE_EDITOR_PLUS_OT_scale_dialog.bl_idname, text='Scale...',
icon_value=get_icon_id('scale'))
op = layout.operator(IMAGE_EDITOR_PLUS_OT_change_canvas_size_dialog.bl_idname, text='Canvas Size...',
icon_value=get_icon_id('scale'))
class IMAGE_EDITOR_PLUS_MT_transform_layer_menu(bpy.types.Menu):
bl_idname = "IMAGE_EDITOR_PLUS_MT_transform_layer_menu"
bl_label = "Transform Layer"
@@ -1536,6 +1623,11 @@ class IMAGE_EDITOR_PLUS_PT_transform_panel(bpy.types.Panel):
op = row.operator(IMAGE_EDITOR_PLUS_OT_scale_dialog.bl_idname, text='Scale...',
icon_value=get_icon_id('scale'))
row = layout.row()
op = row.operator(IMAGE_EDITOR_PLUS_OT_change_canvas_size_dialog.bl_idname,
text='Canvas Size...',
icon_value=get_icon_id('scale'))
class IMAGE_EDITOR_PLUS_PT_transform_layer_panel(bpy.types.Panel):
bl_label = "Transform Layer"
bl_space_type = "IMAGE_EDITOR"