-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This script provides script messages and bindings to pan videos and images, making mpv a better image viewer out of the box.
- Loading branch information
1 parent
1c3f092
commit 85a3d2a
Showing
10 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
POSITIONING | ||
=========== | ||
|
||
This script provides key bindings to pan videos and images. | ||
|
||
Script messages and bindings | ||
---------------------------- | ||
|
||
``osd-relative-pan <axis> <amount>`` | ||
Adjust ``--video-align-x`` or ``--video-align-y`` relatively to the OSD | ||
sizes, rather than relatively to the video sizes like the options. This is | ||
useful to pan large images consistently. | ||
|
||
``axis`` can be ``x`` or ``y``, and ``amount`` is a number such that an | ||
amount of 1 scrolls as much as the OSD width or height. | ||
|
||
``drag-to-pan`` | ||
Pan the video while holding a mouse button, relatively to the clicked point in | ||
the OSD. | ||
|
||
``align-to-cursor`` | ||
Pan the video while holding a mouse button, relatively to the whole video. | ||
|
||
``cursor-centric-zoom <zoom>`` | ||
Increase ``--video-zoom`` by ``zoom`` and adjust ``--video-align-x`` and | ||
``--video-align-y`` to shift the OSD towards the position hovered by the | ||
cursor, or the average position of touch points if known. | ||
|
||
Configurable Options | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
``suppress_osd`` | ||
Default: no | ||
|
||
Whether to not print the new value of ``--video-zoom`` when using | ||
``cursor-centric-zoom``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
--[[ | ||
This file is part of mpv. | ||
mpv is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
mpv is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with mpv. If not, see <http://www.gnu.org/licenses/>. | ||
]] | ||
|
||
local options = { | ||
suppress_osd = false, | ||
} | ||
|
||
require "mp.options".read_options(options) | ||
|
||
mp.register_script_message("osd-relative-pan", function (axis, amount) | ||
local dims = mp.get_property_native("osd-dimensions") | ||
local dimension = axis == "x" and dims.w - dims.ml - dims.mr or dims.h - dims.mt - dims.mb | ||
local osd_dimension = axis == "x" and dims.w or dims.h | ||
-- 1 video-align shifts the OSD by (dimension - osd_dimension) / 2 pixels, | ||
-- so the equation to find how much video-align to add to offset the OSD by | ||
-- osd_dimension is: | ||
-- x/1 = osd_dimension / ((dimension - osd_dimension) / 2) | ||
if dimension > osd_dimension then | ||
mp.commandv("add", "video-align-" .. axis, | ||
amount * 2 * osd_dimension / (dimension - osd_dimension)) | ||
end | ||
end) | ||
|
||
mp.add_key_binding(nil, "drag-to-pan", function (t) | ||
if t.event == "up" then | ||
mp.remove_key_binding("drag-to-pan-mouse-move") | ||
return | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
local old_mouse_pos = mp.get_property_native("mouse-pos") | ||
local old_align_x = mp.get_property_native("video-align-x") | ||
local old_align_y = mp.get_property_native("video-align-y") | ||
|
||
mp.add_forced_key_binding("MOUSE_MOVE", "drag-to-pan-mouse-move", function() | ||
local mouse_pos = mp.get_property_native("mouse-pos") | ||
-- 1 video-align shifts the OSD by (dimension - osd_dimension) / 2 pixels, | ||
-- so the equation to find how much video-align to add to offset the OSD | ||
-- by the difference in mouse position is: | ||
-- x/1 = (mouse_pos - old_mouse_pos) / ((dimension - osd_dimension) / 2) | ||
if dims.ml + dims.mr < 0 then | ||
local align = old_align_x + 2 * (mouse_pos.x - old_mouse_pos.x) | ||
/ (dims.ml + dims.mr) | ||
mp.set_property("video-align-x", math.min(1, math.max(align, -1))) | ||
end | ||
if dims.mt + dims.mb < 0 then | ||
local align = old_align_y + 2 * (mouse_pos.y - old_mouse_pos.y) | ||
/ (dims.mt + dims.mb) | ||
mp.set_property("video-align-y", math.min(1, math.max(align, -1))) | ||
end | ||
end) | ||
end, { complex = true }) | ||
|
||
mp.add_key_binding(nil, "align-to-cursor", function (t) | ||
if t.event == "up" then | ||
mp.remove_key_binding("align-to-cursor-mouse-move") | ||
return | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
mp.add_forced_key_binding("MOUSE_MOVE", "align-to-cursor-mouse-move", function() | ||
local mouse_pos = mp.get_property_native("mouse-pos") | ||
if dims.ml + dims.mr < 0 then | ||
mp.set_property("video-align-x", (mouse_pos.x * 2 - dims.w) / dims.w) | ||
end | ||
if dims.mt + dims.mb < 0 then | ||
mp.set_property("video-align-y", (mouse_pos.y * 2 - dims.h) / dims.h) | ||
end | ||
end) | ||
end, { complex = true }) | ||
|
||
mp.register_script_message("cursor-centric-zoom", function (amount) | ||
local command = (options.suppress_osd and "no-osd " or "") .. | ||
"add video-zoom " .. amount .. ";" | ||
|
||
local x, y | ||
local touch_positions = mp.get_property_native("touch-pos") | ||
if next(touch_positions) then | ||
for _, position in pairs(touch_positions) do | ||
x = x + position.x | ||
y = y + position.y | ||
end | ||
x = x / #touch_positions | ||
y = y / #touch_positions | ||
else | ||
local mouse_pos = mp.get_property_native("mouse-pos") | ||
x = mouse_pos.x | ||
y = mouse_pos.y | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
local width = (dims.w - dims.ml - dims.mr) * 2^amount | ||
local height = (dims.h - dims.mt - dims.mb) * 2^amount | ||
|
||
if width > dims.w then | ||
local old_cursor_ml = dims.ml - x | ||
local cursor_ml = old_cursor_ml * 2^amount | ||
local ml = cursor_ml + x | ||
-- video/out/aspect.c:src_dst_split_scaling() defines ml as: | ||
-- ml = (osd-width - width) * (video-align-x + 1) / 2 + pan-x * width | ||
-- So video-align-x is: | ||
local align = 2 * (ml - mp.get_property_native("video-pan-x") * width) | ||
/ (dims.w - width) - 1 | ||
command = command .. "no-osd set video-align-x " .. | ||
math.min(1, math.max(align, -1)) .. ";" | ||
end | ||
|
||
if height > dims.h then | ||
local mt = (dims.mt - y) * 2^amount + y | ||
local align = 2 * (mt - mp.get_property_native("video-pan-y") * height) | ||
/ (dims.h - height) - 1 | ||
command = command .. "no-osd set video-align-y " .. | ||
math.min(1, math.max(align, -1)) | ||
end | ||
|
||
mp.command(command) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters