-
Notifications
You must be signed in to change notification settings - Fork 0
/
Resize Sprite.lua
66 lines (48 loc) · 1.11 KB
/
Resize Sprite.lua
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
if not app.isUIAvailable then return end
if app.activeSprite == nil then
app.alert ("Open a sprite first.")
return
end
local sprite = app.site.sprite
local oldSize = { width = sprite.width, height = sprite.height}
local dialog = Dialog("Resize Sprite")
dialog:label {
label = string.format("Current size: %sx%s", oldSize.width, oldSize.height)
}
dialog:separator()
dialog:number {
id = "width",
label = "Width:"
}
dialog:number {
id = "height",
label = "Height:"
}
dialog:newrow()
dialog:button {
id = "ok",
text = "OK",
onclick = function ()
local newWidth = dialog.data.width
local newHeight = dialog.data.height
app.transaction (
function ()
-- resize sprite
sprite.width = newWidth
sprite.height = newHeight
dialog:close()
-- move cels
for frameIndex, frame in ipairs(sprite.frames) do
for layerIndex, layer in ipairs(sprite.layers) do
local cel = layer:cel(frameIndex)
cel.position = Point (
cel.position.x * (newWidth / oldSize.width),
cel.position.y * (newHeight / oldSize.height)
)
end
end
end
)
end
}
dialog:show()