mirror of
https://github.com/mpv-player/mpv
synced 2024-12-20 22:02:59 +00:00
osd: add --osd-bar-align-x/y options to control OSD bar position
This commit is contained in:
parent
e4d52330af
commit
e8181ed9fb
@ -1288,6 +1288,12 @@
|
||||
search for video segments from other files, and will also ignore any
|
||||
chapter order specified for the main file.
|
||||
|
||||
--osd-bar-align-x=<-1..1>
|
||||
Position of the OSD bar. -1 is far left, 0 is centered, 1 is far right.
|
||||
|
||||
--osd-bar-align-y=<-1..1>
|
||||
Position of the OSD bar. -1 is top, 0 is centered, 1 is bottom.
|
||||
|
||||
--osd-back-color=<#RRGGBB>, --sub-text-back-color=<#RRGGBB>
|
||||
See ``--osd-color``. Color used for OSD/sub text background.
|
||||
|
||||
|
@ -499,6 +499,8 @@ const m_option_t common_opts[] = {
|
||||
OPT_INTRANGE("ass-hinting", ass_hinting, 0, 0, 7),
|
||||
OPT_CHOICE("ass-style-override", ass_style_override, 0,
|
||||
({"no", 0}, {"yes", 1})),
|
||||
OPT_FLOATRANGE("osd-bar-align-x", osd_bar_align_x, 0, -1.0, +1.0),
|
||||
OPT_FLOATRANGE("osd-bar-align-y", osd_bar_align_y, 0, -1.0, +1.0),
|
||||
OPT_GENERAL("osd", osd_style, M_OPT_PREFIXED,
|
||||
.type = &m_option_type_subconfig_struct,
|
||||
.priv = (void*)&osd_style_conf),
|
||||
|
@ -117,6 +117,8 @@ typedef struct MPOpts {
|
||||
char **sub_name;
|
||||
char **sub_paths;
|
||||
int sub_auto;
|
||||
float osd_bar_align_x;
|
||||
float osd_bar_align_y;
|
||||
struct osd_style_opts *osd_style;
|
||||
struct osd_style_opts *sub_text_style;
|
||||
float sub_scale;
|
||||
|
@ -155,10 +155,23 @@ static void update_osd(struct osd_state *osd, struct osd_object *obj)
|
||||
talloc_free(text);
|
||||
}
|
||||
|
||||
static int get_align(float val, int res, int *out_margin)
|
||||
{
|
||||
*out_margin = FFMAX(0, (1.0 - fabs(val)) * res / 2);
|
||||
if (fabs(val) < 0.1)
|
||||
return 1; // centered
|
||||
return val > 0 ? 2 : 0; // bottom / top (or right / left)
|
||||
}
|
||||
|
||||
static const int ass_align_x[3] = {1, 2, 3};
|
||||
static const int ass_align_y[3] = {4, 8, 0};
|
||||
|
||||
#define OSDBAR_ELEMS 46
|
||||
|
||||
static void update_progbar(struct osd_state *osd, struct osd_object *obj)
|
||||
{
|
||||
struct MPOpts *opts = osd->opts;
|
||||
|
||||
if (osd->progbar_type < 0) {
|
||||
clear_obj(obj);
|
||||
return;
|
||||
@ -169,8 +182,12 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj)
|
||||
|
||||
ASS_Style *style = obj->osd_track->styles + obj->osd_track->default_style;
|
||||
|
||||
style->Alignment = 10; // all centered
|
||||
style->MarginL = style->MarginR = style->MarginV = 0;
|
||||
int ax = get_align(opts->osd_bar_align_x, obj->osd_track->PlayResX,
|
||||
&style->MarginR);
|
||||
int ay = get_align(opts->osd_bar_align_y, obj->osd_track->PlayResY,
|
||||
&style->MarginV);
|
||||
style->Alignment = ass_align_x[ax] + ass_align_y[ay];
|
||||
style->MarginL = style->MarginR;
|
||||
|
||||
// We need a fixed font size with respect to the OSD width.
|
||||
// Assume the OSD bar takes 2/3 of the OSD width at PlayResY=288 and
|
||||
|
Loading…
Reference in New Issue
Block a user