-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zooming in on a specific part of the canvas from a script #4722
Comments
I actually found a solution to my own problem, it was a combination of a zoom and scroll. Here's a sample function that can scroll to a slice with a little heuristic for calculating an appropriate zoom: function ScrollToSlice(slice, autoZoom)
-- Center the canvas first
app.command.ScrollCenter()
local sliceCenterX = slice.bounds.x + slice.bounds.width / 2
local sliceCenterY = slice.bounds.y + slice.bounds.height / 2
local centerX = slice.sprite.width / 2
local centerY = slice.sprite.height / 2
if sliceCenterX < centerX then
app.command.Scroll {
direction = "left",
units = "zoomed-pixel",
quantity = tostring(centerX - sliceCenterX)
}
else
app.command.Scroll {
direction = "right",
units = "zoomed-pixel",
quantity = tostring(sliceCenterX - centerX)
}
end
if sliceCenterY < centerY then
app.command.Scroll {
direction = "up",
units = "zoomed-pixel",
quantity = tostring(centerY - sliceCenterY)
}
else
app.command.Scroll {
direction = "down",
units = "zoomed-pixel",
quantity = tostring(sliceCenterY - centerY)
}
end
if autoZoom then
local sizes = {
64, 48, 32, 24, 16, 12, 8, 6, 5, 4, 3, 2, 1, 0.5, 0.333, 0.25, 0.20,
0.167, 0.125 -- There are a few skipped zoom options
}
for _, size in ipairs(sizes) do
-- The window width and height percentages are just heuristic values to make the zoom not bee too harsh
if slice.bounds.width * size < app.window.width * 0.8 and
slice.bounds.height * size < app.window.height * 0.6 then
app.command.Zoom {
percentage = tostring(size * 100),
focus = "center"
}
break
end
end
end
end |
@thkwznk we'll add |
@dacap It should be more than enough, just knowing the zoom value will allow for restoting zoom after moving the view. |
This is purely a feature request, ot seems that there's no working option to zoom in on a specific part of a canvas using the Lua API.
The
Zoom
command doesn't allow for specifing a point to zoom to (or from) other then the center. And theapp.useTool
method for thezoom
tool produces no results (in the v1.3.9-2).The text was updated successfully, but these errors were encountered: