summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-03-07 22:20:51 +0100
committerwm4 <wm4@nowhere>2016-03-07 22:22:18 +0100
commit5fa45fb5641c95a5dc65faac2087d842333b5425 (patch)
tree0807f5cff191b18427b36ebf5d30de25620ae033
parentb7617f42d873adceebd3904d906e4eff818240ed (diff)
downloadmpv-5fa45fb5641c95a5dc65faac2087d842333b5425.tar.bz2
mpv-5fa45fb5641c95a5dc65faac2087d842333b5425.tar.xz
osd, lua: remove weird OSD scaling
Do not scale OSD mouse input to the ASS OSD script resolution. The original idea of this mechanism was that the user doesn't have to care about the actual resolution of anything, and can just use the OSD resolution consistently. But this made things worse. Remove the implicit scaling, and always use the screen resolution. (Except with --vo=xv, where additional scaling is forced upon everything.) Drop get_osd_resolution(). There is no replacement. Rename get_screen_size() and get_screen_margins() to use "osd" instead of "screen". For anything but --vo=xv these are equivalent, but with --vo=xv the OSD resolution has additional implicit scaling. Add code to osc.lua which emulates the old behavior. Note that none of the changed functions were public API, so implicit breakage of scripts which used it is just going to happen.
-rw-r--r--player/lua.c36
-rw-r--r--player/lua/osc.lua39
-rw-r--r--sub/osd.c15
-rw-r--r--sub/osd.h7
-rw-r--r--sub/osd_dummy.c7
-rw-r--r--sub/osd_libass.c10
6 files changed, 40 insertions, 74 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)
diff --git a/sub/osd.c b/sub/osd.c
index 81cfb7daa6..a9bc035c73 100644
--- a/sub/osd.c
+++ b/sub/osd.c
@@ -422,21 +422,6 @@ bool osd_query_and_reset_want_redraw(struct osd_state *osd)
return r;
}
-// Scale factor to translate OSD coordinates to what the obj uses internally.
-// osd_coordinates * (sw, sh) = obj_coordinates
-void osd_object_get_scale_factor(struct osd_state *osd, int obj,
- double *sw, double *sh)
-{
- int nw, nh;
- osd_object_get_resolution(osd, obj, &nw, &nh);
- pthread_mutex_lock(&osd->lock);
- int vow = osd->objs[obj]->vo_res.w;
- int voh = osd->objs[obj]->vo_res.h;
- pthread_mutex_unlock(&osd->lock);
- *sw = vow ? nw / (double)vow : 0;
- *sh = voh ? nh / (double)voh : 0;
-}
-
struct mp_osd_res osd_get_vo_res(struct osd_state *osd, int obj)
{
pthread_mutex_lock(&osd->lock);
diff --git a/sub/osd.h b/sub/osd.h
index 4e18ce7f7c..c066b09645 100644
--- a/sub/osd.h
+++ b/sub/osd.h
@@ -190,9 +190,6 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
struct mp_image_params;
struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p);
-void osd_object_get_scale_factor(struct osd_state *osd, int obj,
- double *sw, double *sh);
-
struct mp_osd_res osd_get_vo_res(struct osd_state *osd, int obj);
void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
@@ -211,8 +208,4 @@ void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function);
extern const char *const osd_ass_0;
extern const char *const osd_ass_1;
-// defined in backend, but locks if required
-void osd_object_get_resolution(struct osd_state *osd, int obj,
- int *out_w, int *out_h);
-
#endif /* MPLAYER_SUB_H */
diff --git a/sub/osd_dummy.c b/sub/osd_dummy.c
index 5c50569dd6..1982870248 100644
--- a/sub/osd_dummy.c
+++ b/sub/osd_dummy.c
@@ -26,10 +26,3 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
{
*out_imgs = (struct sub_bitmaps) {0};
}
-
-void osd_object_get_resolution(struct osd_state *osd, int obj,
- int *out_w, int *out_h)
-{
- *out_w = 0;
- *out_h = 0;
-}
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index eed2822380..cd28396746 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -477,13 +477,3 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
&obj->parts_cache, out_imgs);
talloc_steal(obj, obj->parts_cache);
}
-
-void osd_object_get_resolution(struct osd_state *osd, int obj,
- int *out_w, int *out_h)
-{
- pthread_mutex_lock(&osd->lock);
- struct osd_object *osd_obj = osd->objs[obj];
- *out_w = osd_obj->osd_track ? osd_obj->osd_track->PlayResX : 0;
- *out_h = osd_obj->osd_track ? osd_obj->osd_track->PlayResY : 0;
- pthread_mutex_unlock(&osd->lock);
-}