Skip to content

Commit

Permalink
options: move OSD bar opts to a separate struct
Browse files Browse the repository at this point in the history
Move them to a suboption so the suboption prefix can be
used.
  • Loading branch information
na-na-hi authored and kasper93 committed Nov 18, 2024
1 parent e056ad3 commit 8612f80
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 34 deletions.
18 changes: 1 addition & 17 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,31 +390,15 @@ const struct m_sub_options mp_subtitle_shared_sub_opts = {

const struct m_sub_options mp_osd_render_sub_opts = {
.opts = (const struct m_option[]){
{"osd-bar-align-x", OPT_FLOAT(osd_bar_align_x), M_RANGE(-1.0, +1.0)},
{"osd-bar-align-y", OPT_FLOAT(osd_bar_align_y), M_RANGE(-1.0, +1.0)},
{"osd-bar-w", OPT_FLOAT(osd_bar_w), M_RANGE(1, 100)},
{"osd-bar-h", OPT_FLOAT(osd_bar_h), M_RANGE(0.1, 50)},
{"osd-bar-outline-size", OPT_FLOAT(osd_bar_outline_size), M_RANGE(0, 1000.0)},
{"osd-bar-border-size", OPT_ALIAS("osd-bar-outline-size")},
{"osd-bar-marker-scale", OPT_FLOAT(osd_bar_marker_scale), M_RANGE(0, 100.0)},
{"osd-bar-marker-min-size", OPT_FLOAT(osd_bar_marker_min_size), M_RANGE(0, 1000.0)},
{"osd-bar-marker-style", OPT_CHOICE(osd_bar_marker_style,
{"none", 0}, {"triangle", 1}, {"line", 2})},
{"osd", OPT_SUBSTRUCT(osd_style, osd_style_conf)},
{"osd-bar", OPT_SUBSTRUCT(osd_bar_style, osd_bar_style_conf)},
{"osd-scale", OPT_FLOAT(osd_scale), M_RANGE(0, 100)},
{"osd-scale-by-window", OPT_BOOL(osd_scale_by_window)},
{"force-rgba-osd-rendering", OPT_BOOL(force_rgba_osd)},
{0}
},
.size = sizeof(OPT_BASE_STRUCT),
.defaults = &(OPT_BASE_STRUCT){
.osd_bar_align_y = 0.5,
.osd_bar_w = 75.0,
.osd_bar_h = 3.125,
.osd_bar_outline_size = 0.5,
.osd_bar_marker_scale = 1.3,
.osd_bar_marker_min_size = 1.6,
.osd_bar_marker_style = 1,
.osd_scale = 1,
.osd_scale_by_window = true,
},
Expand Down
9 changes: 1 addition & 8 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,10 @@ struct mp_subtitle_shared_opts {
};

struct mp_osd_render_opts {
float osd_bar_align_x;
float osd_bar_align_y;
float osd_bar_w;
float osd_bar_h;
float osd_bar_outline_size;
float osd_bar_marker_scale;
float osd_bar_marker_min_size;
int osd_bar_marker_style;
float osd_scale;
bool osd_scale_by_window;
struct osd_style_opts *osd_style;
struct osd_bar_style_opts *osd_bar_style;
bool force_rgba_osd;
};

Expand Down
31 changes: 31 additions & 0 deletions sub/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,37 @@ const struct m_sub_options sub_style_conf = {
.change_flags = UPDATE_OSD,
};

#undef OPT_BASE_STRUCT
#define OPT_BASE_STRUCT struct osd_bar_style_opts
static const m_option_t bar_style_opts[] = {
{"align-x", OPT_FLOAT(align_x), M_RANGE(-1.0, +1.0)},
{"align-y", OPT_FLOAT(align_y), M_RANGE(-1.0, +1.0)},
{"w", OPT_FLOAT(w), M_RANGE(1, 100)},
{"h", OPT_FLOAT(h), M_RANGE(0.1, 50)},
{"outline-size", OPT_FLOAT(outline_size), M_RANGE(0, 1000.0)},
{"border-size", OPT_ALIAS("osd-bar-outline-size")},
{"marker-scale", OPT_FLOAT(marker_scale), M_RANGE(0, 100.0)},
{"marker-min-size", OPT_FLOAT(marker_min_size), M_RANGE(0, 1000.0)},
{"marker-style", OPT_CHOICE(marker_style,
{"none", 0}, {"triangle", 1}, {"line", 2})},
{0}
};

const struct m_sub_options osd_bar_style_conf = {
.opts = bar_style_opts,
.size = sizeof(struct osd_bar_style_opts),
.defaults = &(const struct osd_bar_style_opts){
.align_y = 0.5,
.w = 75.0,
.h = 3.125,
.outline_size = 0.5,
.marker_scale = 1.3,
.marker_min_size = 1.6,
.marker_style = 1,
},
.change_flags = UPDATE_OSD,
};

bool osd_res_equals(struct mp_osd_res a, struct mp_osd_res b)
{
return a.w == b.w && a.h == b.h && a.ml == b.ml && a.mt == b.mt
Expand Down
12 changes: 12 additions & 0 deletions sub/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,20 @@ struct osd_style_opts {
char *fonts_dir;
};

struct osd_bar_style_opts {
float align_x;
float align_y;
float w;
float h;
float outline_size;
float marker_scale;
float marker_min_size;
int marker_style;
};

extern const struct m_sub_options osd_style_conf;
extern const struct m_sub_options sub_style_conf;
extern const struct m_sub_options osd_bar_style_conf;

struct osd_state;
struct osd_object;
Expand Down
18 changes: 9 additions & 9 deletions sub/osd_libass.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ static void get_osd_bar_box(struct osd_state *osd, struct osd_object *obj,
// and each bar ass event gets its own opaque box - breaking the bar.
style->BorderStyle = 1; // outline

*o_w = track->PlayResX * (opts->osd_bar_w / 100.0);
*o_h = track->PlayResY * (opts->osd_bar_h / 100.0);
*o_w = track->PlayResX * (opts->osd_bar_style->w / 100.0);
*o_h = track->PlayResY * (opts->osd_bar_style->h / 100.0);

style->Outline = opts->osd_bar_outline_size;
style->Outline = opts->osd_bar_style->outline_size;
// Rendering with shadow is broken (because there's more than one shape)
style->Shadow = 0;
style->Blur = 0;
Expand All @@ -392,8 +392,8 @@ static void get_osd_bar_box(struct osd_state *osd, struct osd_object *obj,

*o_border = style->Outline;

*o_x = get_align(opts->osd_bar_align_x, track->PlayResX, *o_w, *o_border);
*o_y = get_align(opts->osd_bar_align_y, track->PlayResY, *o_h, *o_border);
*o_x = get_align(opts->osd_bar_style->align_x, track->PlayResX, *o_w, *o_border);
*o_y = get_align(opts->osd_bar_style->align_y, track->PlayResY, *o_h, *o_border);
}

static void update_progbar(struct osd_state *osd, struct osd_object *obj)
Expand Down Expand Up @@ -470,13 +470,13 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj)
ass_draw_rect_ccw(d, 0, 0, width, height);

// chapter marks
if (osd->opts->osd_bar_marker_style) {
if (osd->opts->osd_bar_style->marker_style) {
for (int n = 0; n < obj->progbar_state.num_stops; n++) {
float s = obj->progbar_state.stops[n] * width;
float size = MPMAX(border * osd->opts->osd_bar_marker_scale,
osd->opts->osd_bar_marker_min_size);
float size = MPMAX(border * osd->opts->osd_bar_style->marker_scale,
osd->opts->osd_bar_style->marker_min_size);

if (osd->opts->osd_bar_marker_style == 2 &&
if (osd->opts->osd_bar_style->marker_style == 2 &&
s > size / 2 && s < width - size / 2)
{ // line
ass_draw_rect_cw(d, s - size / 2, 0, s + size / 2, height);
Expand Down

0 comments on commit 8612f80

Please sign in to comment.