From 29f27b9a81e8272768096971d35062cb2fa4c7d2 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 19 Nov 2023 17:04:36 +0800 Subject: [PATCH] polish render code --- include/player.h | 5 ++-- include/window.h | 4 +-- resources/icon.png | Bin 14277 -> 14786 bytes source/player.cpp | 61 +++++++++++++++++++++--------------------- source/window.cpp | 65 +++++++++++++++++++++------------------------ 5 files changed, 64 insertions(+), 71 deletions(-) diff --git a/include/player.h b/include/player.h index 35160ac..2969ced 100644 --- a/include/player.h +++ b/include/player.h @@ -24,6 +24,8 @@ #include "helpers/nfd.h" #include "helpers/utils.h" +#define PLAYER_NAME "ImPlay" + namespace ImPlay { class Player { public: @@ -63,7 +65,7 @@ class Player { void writeMpvConf(); void draw(); - void drawLogo(); + void drawVideo(); void execute(int n_args, const char **args_); void openFileDlg(NFD::Filters filters, bool append = false); @@ -99,7 +101,6 @@ class Player { virtual void SetWindowPos(int x, int y) = 0; virtual void GetWindowSize(int *w, int *h) = 0; virtual void SetWindowSize(int w, int h) = 0; - virtual std::string GetWindowTitle() = 0; virtual void SetWindowTitle(std::string) = 0; virtual void SetWindowAspectRatio(int num, int den) = 0; virtual bool GetWindowMaximized() = 0; diff --git a/include/window.h b/include/window.h index a8f53c4..237a93c 100644 --- a/include/window.h +++ b/include/window.h @@ -24,6 +24,7 @@ class Window : Player { void run(); private: + void initGLFW(); void wakeup(); void updateCursor(); @@ -33,7 +34,6 @@ class Window : Player { void sendKeyEvent(std::string key, bool action); void translateMod(std::vector &keys, int mods); - GLFWwindow *createWindow(); void installCallbacks(GLFWwindow *target); GLFWmonitor *getMonitor(GLFWwindow *target); @@ -54,7 +54,6 @@ class Window : Player { void SetWindowPos(int x, int y) override; void GetWindowSize(int *w, int *h) override; void SetWindowSize(int w, int h) override; - std::string GetWindowTitle() override; void SetWindowTitle(std::string title) override; void SetWindowAspectRatio(int num, int den) override; bool GetWindowMaximized() override; @@ -65,7 +64,6 @@ class Window : Player { void SetWindowFullscreen(bool fs) override; void SetWindowShouldClose(bool c) override; - std::string title = "ImPlay"; GLFWwindow *window = nullptr; bool ownCursor = true; double lastInputAt = 0; diff --git a/resources/icon.png b/resources/icon.png index 888ef4b348d877f9245f3737bf1f7770b5335680..ea3cc63101dfb1cef9b5c6ad997356bcbb3ae799 100644 GIT binary patch literal 14786 zcmeHud0dR^`~Oo(=rAoRTZ^Qj)!JT@qeYeqB_tCfTXovC&N!iIlXB>2n{a5OB#KfK z+9VZ4T8C*>TBdcXX`bKpJj40m^ZDoZ|M!oB*Lm*cy080M-q-uOC(PQ?eBpv+3lIcZ zXtB*?4}u87KLwF_bK$SCa}Cq**Ze=W9q>dDQAzAS0VFcbiS&>YJpLyPAf3gBL}$sXJ2Fg(;+z8I;bO-%MTkTiD!x7Kb{HHuvm2 z8#8zQwkmOn(J#u&l&H^<4Qu9Xu#u``T~Ur&veNdca}g=_mSx-5+(|v{{Jup!le0a~ z+kCSNvPWLH6$yGKW`MkFuJ0)#fpkj()Zov>VxsV;a4AS{ERX~Lv^M^~|NY-O85rjw zQPsM3L(yVmW$8uPF3g-~4AuU2#XD^#-rC*|cUT-Mq!nw3i;Kt6Dn(gNSJSw=ZRwId z!TnVuon)usS53^|{)q8ehA4kF!Fl$2w216<49zE>oDAA}b> znD7p62%dVTnK^lnY_d9tH&@UAb% zC);DMPG(lFSA3YeP32RIJcZd3oUO8BdrjNQj;m!dL0#$zBNUiO;!lhgHa6|b?8&~- zdi}{Ml@S5)rc<4MU1Xc~+TgchXqC3Bb9K8U<2r*5$90rc!ebA<{mx zCtBr+gMVbC9nw&onQ7lx&dxRnu(l~SD4wObCb8f6E;1_@Fm8LxpRu1mV>(Q~TI^bM zW@Xlap-fM1{fD%IK^f(NAXW4}LNzmEzSxflnt2LX@1B~De4MIttv0;U=qCB%+;CJi zvFccur#yo*9VBgDJO^nI4iY^kFmK6yVMpHB`I&BlXDJVn-}%i0;0k2RI=__d+Mjjv;(1(4g} z#TRpsISr=;IOS8B(R;i_O}f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Sx3xb6Bwy)$Dmz^U*Gb4?&|K z1KTF%Kh`LUzHsl}F4g`L1JyQUStx$6>heQNAk0L)+(Dd+-%hOTb0zdJ@eG;7aJgY` z;jjB(0*Q#~#nn914ISD!T1pY4)nsXI^DrFPo!=A{XLm(`pEWlts+ItY{}U zXTN{=4C%bYj`1ax1#pZ>DX2RV83DgUa_|lJt%|N1Q!-I%vXHP{V7E7iJ`mhRvWv*_MFbTy^qf}gXNX4YvwKgT_IbL0%&|`eGb0SeRVIHd z22?~Iz&nHW*2aV9Dr{MW3lsG$kE>uGiXf{Z&7fzVNryKl*|~HVnZ%7JA6~l1&#TF@ za-Rp~2I38ud!k-Gul_Zpz0o7=P4%%I9Uz&$<74|{BThFpE)$TkRYYViP-pS$SsSwk zqg>Xu)5llHo^ojk?UTWxnrrOGN9D1z4LkNcKWzq=JnxYgSGA2io>P%cyhYl6d5r2(_0F=WsbOmKh1Lr!2N| zpEz2ol=q?Gt<8e>B8cpJByzj`b_e63d-?UGVnTAb+WdRbpN;Ll4p`OuTe)A4*1x%V zi|uK`-}dSRk_>^gGfO8oIfFT1Q|QZYapMf+@ksNK|L_0k|BXpp>t7o=-#5YxH+GBV L4vT^f2haRJxG{@# diff --git a/source/player.cpp b/source/player.cpp index 567e5a1..5332b16 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -77,7 +77,7 @@ bool Player::init(std::map &options) { } void Player::draw() { - drawLogo(); + drawVideo(); about->draw(); debug->draw(); @@ -90,16 +90,18 @@ void Player::draw() { drawDialog(); } -void Player::drawLogo() { - if (logoTexture == nullptr || mpv->forceWindow || !idle) return; +void Player::drawVideo() { + auto vp = ImGui::GetMainViewport(); + auto drawList = ImGui::GetBackgroundDrawList(vp); - ImGuiViewport *vp = ImGui::GetMainViewport(); - const float width = std::min(vp->WorkSize.x, vp->WorkSize.y) * 0.1f; - const ImVec2 delta(width, width); - const ImVec2 center = vp->GetCenter(); - ImRect bb(center - delta, center + delta); - - ImGui::GetBackgroundDrawList(vp)->AddImage(logoTexture, bb.Min, bb.Max); + if (!idle) { + ImTextureID texture = reinterpret_cast(static_cast(tex)); + drawList->AddImage(texture, vp->WorkPos, vp->WorkPos + vp->WorkSize); + } else if (logoTexture != nullptr && !mpv->forceWindow) { + const ImVec2 center = vp->GetWorkCenter(); + const ImVec2 delta(64, 64); + drawList->AddImage(logoTexture, center - delta, center + delta); + } } void Player::render() { @@ -132,16 +134,9 @@ void Player::render() { } #endif - if (!idle) { - ImGuiViewport *vp = ImGui::GetMainViewport(); - ImTextureID texture = reinterpret_cast(static_cast(tex)); - ImGui::GetBackgroundDrawList(vp)->AddImage(texture, vp->Pos, vp->Pos + vp->Size); - } - draw(); ImGui::Render(); - const auto targetFps = config->Data.Interface.Fps; { ContextGuard guard(this); GetFramebufferSize(&width, &height); @@ -151,14 +146,19 @@ void Player::render() { glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - SetSwapInterval(targetFps > 60 ? 0 : 1); + SetSwapInterval(config->Data.Interface.Fps > 60 ? 0 : 1); SwapBuffers(); mpv->reportSwap(); + + if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + } } // limit fps while player idle static double time = 0; - double targetDelta = 1.0f / targetFps; + double targetDelta = 1.0f / config->Data.Interface.Fps; if (idle || mpv->pause) { double delta = time - ImGui::GetTime(); if (delta > 0 && delta < targetDelta) @@ -167,14 +167,6 @@ void Player::render() { time = ImGui::GetTime(); } time += targetDelta; - - if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { - ImGui::UpdatePlatformWindows(); - - std::lock_guard lock(contextLock); - ImGui::RenderPlatformWindowsDefault(); - DeleteContext(); - } } void Player::renderVideo() { @@ -330,9 +322,14 @@ void Player::onIconifyEvent(bool iconified) { void Player::onSizeEvent(int w, int h) { bool m = GetWindowMaximized(); if (maximized != m) mpv->property("window-maximized", m ? "yes" : "no"); + auto g = ImGui::GetCurrentContext(); + if (g != nullptr && !g->WithinFrameScope) render(); } -void Player::onPosEvent(int x, int y) {} +void Player::onPosEvent(int x, int y) { + auto g = ImGui::GetCurrentContext(); + if (g != nullptr && !g->WithinFrameScope) render(); +} void Player::onCursorEvent(double x, double y) { std::string xs = std::to_string((int)x); @@ -395,7 +392,7 @@ void Player::initObservers() { mpv->observeProperty("idle-active", [this](int flag) { idle = static_cast(flag); if (idle) { - SetWindowTitle(GetWindowTitle()); + SetWindowTitle(PLAYER_NAME); SetWindowAspectRatio(-1, -1); } }); @@ -453,7 +450,7 @@ void Player::writeMpvConf() { std::filesystem::create_directories(scrips); std::filesystem::create_directories(scriptOpts); - + auto oscLua = scrips / "osc.lua"; if (!std::filesystem::exists(oscLua)) { @@ -665,7 +662,9 @@ void Player::drawOpenURL() { } void Player::drawDialog() { - if (m_dialog) ImGui::OpenPopup(m_dialog_title.c_str()); + if (!m_dialog) return; + ImGui::OpenPopup(m_dialog_title.c_str()); + ImGui::SetNextWindowSize(ImVec2(scaled(30), 0), ImGuiCond_Always); ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetWorkCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); if (ImGui::BeginPopupModal(m_dialog_title.c_str(), &m_dialog, ImGuiWindowFlags_NoMove)) { diff --git a/source/window.cpp b/source/window.cpp index 7bcfbe5..d5f4059 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -18,16 +18,9 @@ namespace ImPlay { Window::Window(Config* config) : Player(config) { - glfwSetErrorCallback( - [](int error, const char* desc) { fmt::print(fg(fmt::color::red), "GLFW [{}]: {}\n", error, desc); }); -#ifdef GLFW_PATCHED - glfwInitHint(GLFW_WIN32_MESSAGES_IN_FIBER, GLFW_TRUE); -#endif - if (!glfwInit()) throw std::runtime_error("Failed to initialize GLFW!"); - - window = createWindow(); + initGLFW(); + window = glfwCreateWindow(1280, 720, PLAYER_NAME, nullptr, nullptr); if (window == nullptr) throw std::runtime_error("Failed to create window!"); - glfwSetWindowSizeLimits(window, 640, 480, GLFW_DONT_CARE, GLFW_DONT_CARE); installCallbacks(window); initGui(); @@ -42,6 +35,33 @@ Window::~Window() { glfwTerminate(); } +void Window::initGLFW() { + glfwSetErrorCallback( + [](int error, const char* desc) { fmt::print(fg(fmt::color::red), "GLFW [{}]: {}\n", error, desc); }); +#ifdef GLFW_PATCHED + glfwInitHint(GLFW_WIN32_MESSAGES_IN_FIBER, GLFW_TRUE); +#endif + if (!glfwInit()) throw std::runtime_error("Failed to initialize GLFW!"); + +#if defined(IMGUI_IMPL_OPENGL_ES3) + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); +#elif defined(__APPLE__) + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#else + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#endif + glfwWindowHint(GLFW_AUTO_ICONIFY, GLFW_FALSE); + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); +} + bool Window::init(OptionParser& parser) { mpv->wakeupCb() = [this](Mpv* ctx) { wakeup(); }; mpv->updateCb() = [this](Mpv* ctx) { @@ -131,27 +151,6 @@ void Window::updateCursor() { ImGui::SetMouseCursor(cursor ? ImGuiMouseCursor_Arrow : ImGuiMouseCursor_None); } -GLFWwindow* Window::createWindow() { -#if defined(IMGUI_IMPL_OPENGL_ES3) - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); - glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); -#elif defined(__APPLE__) - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -#else - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -#endif - glfwWindowHint(GLFW_AUTO_ICONIFY, GLFW_FALSE); - glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); - return glfwCreateWindow(640, 480, title.c_str(), nullptr, nullptr); -} - void Window::installCallbacks(GLFWwindow* target) { glfwSetWindowUserPointer(target, this); @@ -171,12 +170,10 @@ void Window::installCallbacks(GLFWwindow* target) { glfwSetWindowSizeCallback(target, [](GLFWwindow* window, int w, int h) { auto win = static_cast(glfwGetWindowUserPointer(window)); win->onSizeEvent(w, h); - win->render(); }); glfwSetWindowPosCallback(target, [](GLFWwindow* window, int x, int y) { auto win = static_cast(glfwGetWindowUserPointer(window)); win->onPosEvent(x, y); - win->render(); }); glfwSetCursorEnterCallback(target, [](GLFWwindow* window, int entered) { auto win = static_cast(glfwGetWindowUserPointer(window)); @@ -194,7 +191,7 @@ void Window::installCallbacks(GLFWwindow* target) { #endif win->onCursorEvent(x, y); #ifdef GLFW_PATCHED - if (win->mpv->allowDrag() && win->height - y > 150) { // 150: height of the OSC bar + if (win->mpv->allowDrag() && win->height - y > 280) { // 280: height of the OSC bar if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) glfwDragWindow(window); } #endif @@ -305,8 +302,6 @@ void Window::GetWindowSize(int* w, int* h) { glfwGetWindowSize(window, w, h); } void Window::SetWindowSize(int w, int h) { glfwSetWindowSize(window, w, h); } -std::string Window::GetWindowTitle() { return title; } - void Window::SetWindowTitle(std::string title) { glfwSetWindowTitle(window, title.c_str()); } void Window::SetWindowAspectRatio(int num, int den) { glfwSetWindowAspectRatio(window, num, den); }