mirror of https://github.com/mpv-player/mpv
core: use floats for OSD bar percentage display
Use floats instead of integers in the range 0-100. Currently, the OSD is currently made up of 46 elements so no change should be visible, but rendering of the bar will be changed later to use vector drawings (using pixel coordinates) instead of glyphs. This commit is for preparation.
This commit is contained in:
parent
72bdc5d3af
commit
f143eec611
|
@ -282,6 +282,7 @@ int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts);
|
||||||
double get_time_length(struct MPContext *mpctx);
|
double get_time_length(struct MPContext *mpctx);
|
||||||
double get_current_time(struct MPContext *mpctx);
|
double get_current_time(struct MPContext *mpctx);
|
||||||
int get_percent_pos(struct MPContext *mpctx);
|
int get_percent_pos(struct MPContext *mpctx);
|
||||||
|
double get_current_pos_ratio(struct MPContext *mpctx);
|
||||||
int get_current_chapter(struct MPContext *mpctx);
|
int get_current_chapter(struct MPContext *mpctx);
|
||||||
char *chapter_display_name(struct MPContext *mpctx, int chapter);
|
char *chapter_display_name(struct MPContext *mpctx, int chapter);
|
||||||
char *chapter_name(struct MPContext *mpctx, int chapter);
|
char *chapter_name(struct MPContext *mpctx, int chapter);
|
||||||
|
|
|
@ -1460,8 +1460,8 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, bool full)
|
||||||
static void add_seek_osd_messages(struct MPContext *mpctx)
|
static void add_seek_osd_messages(struct MPContext *mpctx)
|
||||||
{
|
{
|
||||||
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) {
|
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) {
|
||||||
set_osd_bar(mpctx, OSD_BAR_SEEK, "Position", 0, 100,
|
set_osd_bar(mpctx, OSD_BAR_SEEK, "Position", 0, 1,
|
||||||
get_percent_pos(mpctx));
|
av_clipf(get_current_pos_ratio(mpctx), 0, 1));
|
||||||
}
|
}
|
||||||
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) {
|
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) {
|
||||||
mp_osd_msg_t *msg = add_osd_msg(mpctx, OSD_MSG_TEXT, 1,
|
mp_osd_msg_t *msg = add_osd_msg(mpctx, OSD_MSG_TEXT, 1,
|
||||||
|
@ -1500,7 +1500,8 @@ static void update_osd_msg(struct MPContext *mpctx)
|
||||||
struct osd_state *osd = mpctx->osd;
|
struct osd_state *osd = mpctx->osd;
|
||||||
|
|
||||||
add_seek_osd_messages(mpctx);
|
add_seek_osd_messages(mpctx);
|
||||||
update_osd_bar(mpctx, OSD_BAR_SEEK, 0, 100, get_percent_pos(mpctx));
|
update_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1,
|
||||||
|
av_clipf(get_current_pos_ratio(mpctx), 0, 1));
|
||||||
|
|
||||||
// Look if we have a msg
|
// Look if we have a msg
|
||||||
mp_osd_msg_t *msg = get_osd_msg(mpctx);
|
mp_osd_msg_t *msg = get_osd_msg(mpctx);
|
||||||
|
@ -2980,33 +2981,33 @@ static double get_start_time(struct MPContext *mpctx)
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_percent_pos(struct MPContext *mpctx)
|
// Return playback position in 0.0-1.0 ratio, or -1 if unknown.
|
||||||
|
double get_current_pos_ratio(struct MPContext *mpctx)
|
||||||
{
|
{
|
||||||
struct demuxer *demuxer = mpctx->demuxer;
|
struct demuxer *demuxer = mpctx->demuxer;
|
||||||
if (!demuxer)
|
if (!demuxer)
|
||||||
return 0;
|
return -1;
|
||||||
int ans = 0;
|
double ans = -1;
|
||||||
double start = get_start_time(mpctx);
|
double start = get_start_time(mpctx);
|
||||||
double len = get_time_length(mpctx);
|
double len = get_time_length(mpctx);
|
||||||
double pos = get_current_time(mpctx);
|
double pos = get_current_time(mpctx);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
ans = (pos - start) / len * 100;
|
ans = av_clipf((pos - start) / len, 0, 1);
|
||||||
} else {
|
} else {
|
||||||
int len = (demuxer->movi_end - demuxer->movi_start) / 100;
|
int len = (demuxer->movi_end - demuxer->movi_start);
|
||||||
int64_t pos = demuxer->filepos > 0 ?
|
int64_t pos = demuxer->filepos > 0 ?
|
||||||
demuxer->filepos : stream_tell(demuxer->stream);
|
demuxer->filepos : stream_tell(demuxer->stream);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
ans = (pos - demuxer->movi_start) / len;
|
ans = av_clipf((double)(pos - demuxer->movi_start) / len, 0, 1);
|
||||||
else
|
|
||||||
ans = 0;
|
|
||||||
}
|
}
|
||||||
if (ans < 0)
|
|
||||||
ans = 0;
|
|
||||||
if (ans > 100)
|
|
||||||
ans = 100;
|
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_percent_pos(struct MPContext *mpctx)
|
||||||
|
{
|
||||||
|
return av_clip(get_current_pos_ratio(mpctx) * 100, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
// -2 is no chapters, -1 is before first chapter
|
// -2 is no chapters, -1 is before first chapter
|
||||||
int get_current_chapter(struct MPContext *mpctx)
|
int get_current_chapter(struct MPContext *mpctx)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue