aboutsummaryrefslogtreecommitdiff
path: root/Src/auth/Loginbox/animation.cpp
blob: 6ec82225d9ca4a9c0f54567557d5466fa7e00ae4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "./animation.h"
#include "./common.h"

BOOL Animation_Initialize(ANIMATIONDATA *animation, UINT durationMs)
{
	if (NULL == animation)
		return FALSE;
	
	if (FALSE == QueryPerformanceFrequency(&animation->frequency))
		return FALSE;

	QueryPerformanceCounter(&animation->completion);
	animation->completion.QuadPart += animation->frequency.QuadPart*durationMs/1000LL;
	return TRUE;
}

BOOL Animation_BeginStep(ANIMATIONDATA *animation)
{
	if (NULL == animation || FALSE == QueryPerformanceCounter(&animation->stepBegin))
		return FALSE;

	return TRUE;
}

BOOL Animation_EndStep(ANIMATIONDATA *animation, size_t stepsRemaining)
{
	if (NULL == animation || FALSE == QueryPerformanceCounter(&animation->stepEnd))
		return FALSE;
	
	if (0 == stepsRemaining || animation->stepEnd.QuadPart >= animation->completion.QuadPart)
		return TRUE;
			
	LARGE_INTEGER sleep;
	sleep.QuadPart = (animation->completion.QuadPart - animation->stepEnd.QuadPart) -
						(stepsRemaining * (animation->stepEnd.QuadPart - animation->stepBegin.QuadPart));
	
	if (stepsRemaining > 1)
		sleep.QuadPart /= (stepsRemaining -1);

	if (sleep.QuadPart <= 0)
		return TRUE;
							
	sleep.QuadPart += animation->stepEnd.QuadPart;
	do
	{
		SleepEx(0, FALSE);
		QueryPerformanceCounter(&animation->stepEnd);
	} while(sleep.QuadPart > animation->stepEnd.QuadPart);
								
	return TRUE;
}

BOOL Animation_SetWindowPos(HWND hwnd, INT x, INT y, INT cx, INT cy, UINT flags, HDC hdc, INT contextX, INT contextY)
{
	if (NULL == hwnd || 
		FALSE == SetWindowPos(hwnd, NULL, x, y, cx, cy, 
					flags | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOCOPYBITS))
	{
		return FALSE;
	}
	
	UINT windowStyle = GetWindowStyle(hwnd);
	
	POINT origPoint;
	SetViewportOrgEx(hdc, contextX, contextY, &origPoint);
	if (0 == (WS_VISIBLE & windowStyle))
		SetWindowLongPtr(hwnd, GWL_STYLE, windowStyle | WS_VISIBLE);

	if (FALSE == LoginBox_PrintWindow(hwnd, hdc, 0))
		SendMessage(hwnd, WM_PRINT, (WPARAM)hdc, (LPARAM)(PRF_CLIENT | PRF_ERASEBKGND | PRF_CHILDREN | PRF_NONCLIENT));
							
	if (0 == (WS_VISIBLE & windowStyle))
		SetWindowLongPtr(hwnd, GWL_STYLE, windowStyle & ~WS_VISIBLE);

	SetViewportOrgEx(hdc, origPoint.x, origPoint.y, NULL);
	return TRUE;
}