summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
Diffstat (limited to 'player')
-rw-r--r--player/lua.c36
-rw-r--r--player/lua/osc.lua39
2 files changed, 40 insertions, 35 deletions
diff --git a/player/lua.c b/player/lua.c
index 9fe1d0deca..04c7dbb977 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -974,17 +974,7 @@ static int script_set_osd_ass(lua_State *L)
return 0;
}
-static int script_get_osd_resolution(lua_State *L)
-{
- struct MPContext *mpctx = get_mpctx(L);
- int w, h;
- osd_object_get_resolution(mpctx->osd, OSDTYPE_EXTERNAL, &w, &h);
- lua_pushnumber(L, w);
- lua_pushnumber(L, h);
- return 2;
-}
-
-static int script_get_screen_size(lua_State *L)
+static int script_get_osd_size(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_EXTERNAL);
@@ -996,7 +986,7 @@ static int script_get_screen_size(lua_State *L)
return 3;
}
-static int script_get_screen_margins(lua_State *L)
+static int script_get_osd_margins(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_EXTERNAL);
@@ -1012,10 +1002,8 @@ static int script_get_mouse_pos(lua_State *L)
struct MPContext *mpctx = get_mpctx(L);
int px, py;
mp_input_get_mouse_pos(mpctx->input, &px, &py);
- double sw, sh;
- osd_object_get_scale_factor(mpctx->osd, OSDTYPE_EXTERNAL, &sw, &sh);
- lua_pushnumber(L, px * sw);
- lua_pushnumber(L, py * sh);
+ lua_pushnumber(L, px);
+ lua_pushnumber(L, py);
return 2;
}
@@ -1030,14 +1018,11 @@ static int script_input_set_section_mouse_area(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
- double sw, sh;
- osd_object_get_scale_factor(mpctx->osd, OSDTYPE_EXTERNAL, &sw, &sh);
-
char *section = (char *)luaL_checkstring(L, 1);
- int x0 = sw ? luaL_checkinteger(L, 2) / sw : 0;
- int y0 = sh ? luaL_checkinteger(L, 3) / sh : 0;
- int x1 = sw ? luaL_checkinteger(L, 4) / sw : 0;
- int y1 = sh ? luaL_checkinteger(L, 5) / sh : 0;
+ int x0 = luaL_checkinteger(L, 2);
+ int y0 = luaL_checkinteger(L, 3);
+ int x1 = luaL_checkinteger(L, 4);
+ int y1 = luaL_checkinteger(L, 5);
mp_input_set_section_mouse_area(mpctx->input, section, x0, y0, x1, y1);
return 0;
}
@@ -1266,9 +1251,8 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(raw_observe_property),
FN_ENTRY(raw_unobserve_property),
FN_ENTRY(set_osd_ass),
- FN_ENTRY(get_osd_resolution),
- FN_ENTRY(get_screen_size),
- FN_ENTRY(get_screen_margins),
+ FN_ENTRY(get_osd_size),
+ FN_ENTRY(get_osd_margins),
FN_ENTRY(get_mouse_pos),
FN_ENTRY(get_time),
FN_ENTRY(input_set_section_mouse_area),
diff --git a/player/lua/osc.lua b/player/lua/osc.lua
index 24afeef970..f3beee85dd 100644
--- a/player/lua/osc.lua
+++ b/player/lua/osc.lua
@@ -99,6 +99,27 @@ local state = {
-- Helperfunctions
--
+-- scale factor for translating between real and virtual ASS coordinates
+function get_virt_scale_factor()
+ local w, h = mp.get_osd_size()
+ if w <= 0 or h <= 0 then
+ return 0, 0
+ end
+ return osc_param.playresx / w, osc_param.playresy / h
+end
+
+-- return mouse position in virtual ASS coordinates (playresx/y)
+function get_virt_mouse_pos()
+ local sx, sy = get_virt_scale_factor()
+ local x, y = mp.get_mouse_pos()
+ return x * sx, y * sy
+end
+
+function set_virt_mouse_area(x0, y0, x1, y1, name)
+ local sx, sy = get_virt_scale_factor()
+ mp.set_mouse_area(x0 * sx, y0 * sy, x1 * sx, y1 * sy)
+end
+
function scale_value(x0, x1, y0, y1, val)
local m = (y1 - y0) / (x1 - x0)
local b = y0 - (m * x0)
@@ -141,7 +162,7 @@ function mouse_hit(element)
end
function mouse_hit_coords(bX1, bY1, bX2, bY2)
- local mX, mY = mp.get_mouse_pos()
+ local mX, mY = get_virt_mouse_pos()
return (mX >= bX1 and mX <= bX2 and mY >= bY1 and mY <= bY2)
end
@@ -182,7 +203,7 @@ end
-- get value at current mouse position
function get_slider_value(element)
- return get_slider_value_at(element, mp.get_mouse_pos())
+ return get_slider_value_at(element, get_virt_mouse_pos())
end
function countone(val)
@@ -589,7 +610,7 @@ function render_elements(master_ass)
end
elem_ass:new_event()
- elem_ass:pos(mp.get_mouse_pos(), ty)
+ elem_ass:pos(get_virt_mouse_pos(), ty)
elem_ass:an(an)
elem_ass:append(slider_lo.tooltip_style)
elem_ass:append(tooltiplabel)
@@ -1298,7 +1319,7 @@ function osc_init()
-- set canvas resolution according to display aspect and scaling setting
local baseResY = 720
- local display_w, display_h, display_aspect = mp.get_screen_size()
+ local display_w, display_h, display_aspect = mp.get_osd_size()
local scale = 1
if (mp.get_property("video") == "no") then -- dummy/forced window
@@ -1718,8 +1739,8 @@ end
function render()
msg.debug("rendering")
- local current_screen_sizeX, current_screen_sizeY, aspect = mp.get_screen_size()
- local mouseX, mouseY = mp.get_mouse_pos()
+ local current_screen_sizeX, current_screen_sizeY, aspect = mp.get_osd_size()
+ local mouseX, mouseY = get_virt_mouse_pos()
local now = mp.get_time()
-- check if display changed, if so request reinit
@@ -1782,7 +1803,7 @@ function render()
--mouse show/hide area
for k,cords in pairs(osc_param.areas["showhide"]) do
- mp.set_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide")
+ set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide")
end
do_enable_keybindings()
@@ -1791,7 +1812,7 @@ function render()
for _,cords in ipairs(osc_param.areas["input"]) do
if state.osc_visible then -- activate only when OSC is actually visible
- mp.set_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "input")
+ set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "input")
end
if state.osc_visible ~= state.input_enabled then
if state.osc_visible then
@@ -1887,7 +1908,7 @@ function process_event(source, what)
state.mouse_down_counter = 0
elseif source == "mouse_move" then
- local mouseX, mouseY = mp.get_mouse_pos()
+ local mouseX, mouseY = get_virt_mouse_pos()
if (user_opts.minmousemove == 0) or
(not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and
((math.abs(mouseX - state.last_mouseX) >= user_opts.minmousemove)