From 9878f02f70ac708f4867a1e5fdd0574a39351a5a Mon Sep 17 00:00:00 2001 From: ge0rdi Date: Sun, 28 May 2023 16:19:13 +0200 Subject: [PATCH] Improve menu animation timing Use steady_clock with 1ms resolution instead of GetTickCount that has typical resolution 10-16ms. This should result in more smooth menu animations. --- Src/StartMenu/StartMenuDLL/MenuPaint.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Src/StartMenu/StartMenuDLL/MenuPaint.cpp b/Src/StartMenu/StartMenuDLL/MenuPaint.cpp index 9481585..d6c3013 100644 --- a/Src/StartMenu/StartMenuDLL/MenuPaint.cpp +++ b/Src/StartMenu/StartMenuDLL/MenuPaint.cpp @@ -19,6 +19,7 @@ #include #include #include +#include static BLENDFUNCTION g_AlphaFunc={AC_SRC_OVER,0,255,AC_SRC_ALPHA}; @@ -3006,6 +3007,8 @@ void CProgramsTree::DrawScrollbarBackground( HDC hdc, int iPartId, int iStateId, void CMenuContainer::AnimateMenu( int flags, int speed, const RECT &rect ) { + using namespace std::chrono; + RECT clipRect=m_bSubMenu?s_MenuLimits:s_MainMenuLimits; bool bUserPic=(!m_bSubMenu && s_bWin7Style && s_UserPicture.m_hWnd && s_UserPictureRect.top(steady_clock::now()-time0).count(); if (dt>speed) break; float f=dt/(float)speed; int alpha=(int)(f*255); @@ -3085,7 +3088,7 @@ void CMenuContainer::AnimateMenu( int flags, int speed, const RECT &rect ) } // animate - int time0=GetTickCount(); + auto time0=steady_clock::now(); int movex=0, movey=0; if (flags&AW_HOR_POSITIVE) { @@ -3111,7 +3114,7 @@ void CMenuContainer::AnimateMenu( int flags, int speed, const RECT &rect ) HRGN clipRgn=CreateRectRgn(clipRect.left-rect.left,clipRect.top-rect.top,clipRect.right-rect.left,clipRect.bottom-rect.top); // clip region in window space while (true) { - int dt=GetTickCount()-time0; + auto dt=duration_cast(steady_clock::now()-time0).count(); if (dt>speed) break; float f=1-dt/(float)speed; f=powf(f,5);