Skip to content

Commit

Permalink
Danmaku mask follow the video mirror setting
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Dec 10, 2023
1 parent f3f17ac commit 1df6a1f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions wiliwili/include/view/mpv_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ class MPVCore : public brls::Singleton<MPVCore> {
// 默认的音量
inline static int VIDEO_VOLUME = 100;

// 是否镜像视频
inline static bool VIDEO_MIRROR = false;

private:
mpv_handle *mpv = nullptr;
mpv_render_context *mpv_context = nullptr;
Expand Down
7 changes: 3 additions & 4 deletions wiliwili/source/fragment/player_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,11 @@ void PlayerSetting::setupCommonSetting() {
});

/// Player mirror
static bool videoMirror = false;
btnMirror->init("wiliwili/player/setting/common/mirror"_i18n, videoMirror,
btnMirror->init("wiliwili/player/setting/common/mirror"_i18n, MPVCore::VIDEO_MIRROR,
[](bool value) {
videoMirror = !videoMirror;
MPVCore::VIDEO_MIRROR = !MPVCore::VIDEO_MIRROR;
MPVCore::instance().command_async(
"set", "vf", videoMirror ? "hflip" : "");
"set", "vf", MPVCore::VIDEO_MIRROR ? "hflip" : "");
});

/// Player Highlight progress bar
Expand Down
6 changes: 6 additions & 0 deletions wiliwili/source/view/danmaku_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ void DanmakuCore::draw(NVGcontext *vg, float x, float y, float width,
}

// 设置遮罩
if (MPVCore::VIDEO_MIRROR) {
nvgSave(vg);
nvgTranslate(vg, width + x + x, 0);
nvgScale(vg, -1, 1);
}
nvgBeginPath(vg);
float drawHeight = height, drawWidth = width;
float drawX = x, drawY = y;
Expand All @@ -333,6 +338,7 @@ void DanmakuCore::draw(NVGcontext *vg, float x, float y, float width,
#else
nvgStencil(vg);
#endif
if (MPVCore::VIDEO_MIRROR) nvgRestore(vg);
}
#endif /* BOREALIS_USE_OPENGL */
skip_mask:
Expand Down

0 comments on commit 1df6a1f

Please sign in to comment.