Skip to content

Commit 9878f02

Browse files
committed
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.
1 parent 9c14933 commit 9878f02

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Src/StartMenu/StartMenuDLL/MenuPaint.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <dwmapi.h>
2020
#include <algorithm>
2121
#include <math.h>
22+
#include <chrono>
2223

2324
static BLENDFUNCTION g_AlphaFunc={AC_SRC_OVER,0,255,AC_SRC_ALPHA};
2425

@@ -3006,6 +3007,8 @@ void CProgramsTree::DrawScrollbarBackground( HDC hdc, int iPartId, int iStateId,
30063007

30073008
void CMenuContainer::AnimateMenu( int flags, int speed, const RECT &rect )
30083009
{
3010+
using namespace std::chrono;
3011+
30093012
RECT clipRect=m_bSubMenu?s_MenuLimits:s_MainMenuLimits;
30103013

30113014
bool bUserPic=(!m_bSubMenu && s_bWin7Style && s_UserPicture.m_hWnd && s_UserPictureRect.top<s_UserPictureRect.bottom);
@@ -3030,10 +3033,10 @@ void CMenuContainer::AnimateMenu( int flags, int speed, const RECT &rect )
30303033
}
30313034

30323035
// animate
3033-
int time0=GetTickCount();
3036+
auto time0=steady_clock::now();
30343037
while (true)
30353038
{
3036-
int dt=GetTickCount()-time0;
3039+
auto dt=duration_cast<milliseconds>(steady_clock::now()-time0).count();
30373040
if (dt>speed) break;
30383041
float f=dt/(float)speed;
30393042
int alpha=(int)(f*255);
@@ -3085,7 +3088,7 @@ void CMenuContainer::AnimateMenu( int flags, int speed, const RECT &rect )
30853088
}
30863089

30873090
// animate
3088-
int time0=GetTickCount();
3091+
auto time0=steady_clock::now();
30893092
int movex=0, movey=0;
30903093
if (flags&AW_HOR_POSITIVE)
30913094
{
@@ -3111,7 +3114,7 @@ void CMenuContainer::AnimateMenu( int flags, int speed, const RECT &rect )
31113114
HRGN clipRgn=CreateRectRgn(clipRect.left-rect.left,clipRect.top-rect.top,clipRect.right-rect.left,clipRect.bottom-rect.top); // clip region in window space
31123115
while (true)
31133116
{
3114-
int dt=GetTickCount()-time0;
3117+
auto dt=duration_cast<milliseconds>(steady_clock::now()-time0).count();
31153118
if (dt>speed) break;
31163119
float f=1-dt/(float)speed;
31173120
f=powf(f,5);

0 commit comments

Comments
 (0)