forked from sabrogden/Ditto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaveAnimation.cpp
112 lines (91 loc) · 2.4 KB
/
SaveAnimation.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "stdafx.h"
#include ".\saveanimation.h"
#include "PerfTimer.h"
CSaveAnimation::CSaveAnimation(void)
{
m_dLeftPercent = 0;
m_dTopPercent = 0;
m_dRightPercent = 0;
m_dBottomPercent = 0;
m_dSpeed = 40;
}
CSaveAnimation::~CSaveAnimation(void)
{
}
void CSaveAnimation::DoAnimation(CRect crStart, CRect crEnd, CWnd *pWnd)
{
m_crStart = crStart;
m_crEnd = crEnd;
long lMaxDist = GetMaxDistance();
GetPercentages(lMaxDist);
CDC* pDC = pWnd->GetDC();
CRect crCur(m_crStart);
CRect crPrev(-1, -1, -1, -1);
MSG msg;
double dCurLeft = crCur.left;
double dCurTop = crCur.top;
double dCurRight = crCur.right;
double dCurBottom = crCur.bottom;
CPerfTimer Timer;
for(int i = 0; i < lMaxDist/m_dSpeed; i++)
{
//don't do the first time
if(i > 0)
{
//wait 20ms between paints
while(Timer.Elapsedms() < 10)
{
Sleep(1);
}
//Remove the old focus rect
pDC->DrawFocusRect(crPrev);
}
Timer.Start(TRUE);
pDC->DrawFocusRect(crCur);
crPrev = crCur;
dCurLeft -= m_dLeftPercent * m_dSpeed;
dCurTop -= m_dTopPercent * m_dSpeed;
dCurRight -= m_dRightPercent * m_dSpeed;
dCurBottom -= m_dBottomPercent * m_dSpeed;
crCur.left = (int)dCurLeft;
crCur.top = (int)dCurTop;
crCur.right = (int)dCurRight;
crCur.bottom = (int)dCurBottom;
while (PeekMessage(&msg, pWnd->m_hWnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
//Draw one more time to remove the last focus rect
pDC->DrawFocusRect(crPrev);
while (PeekMessage(&msg, pWnd->m_hWnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
pWnd->ReleaseDC(pDC);
}
long CSaveAnimation::GetMaxDistance()
{
long lMax = 0;
if(abs(m_crStart.left - m_crEnd.left) > lMax)
lMax = abs(m_crStart.left - m_crEnd.left);
if(abs(m_crStart.top - m_crEnd.top) > lMax)
lMax = abs(m_crStart.top - m_crEnd.top);
if(abs(m_crStart.right - m_crEnd.right) > lMax)
lMax = abs(m_crStart.right - m_crEnd.right);
if(abs(m_crStart.bottom - m_crEnd.bottom) > lMax)
lMax = abs(m_crStart.bottom - m_crEnd.bottom);
return lMax;
}
void CSaveAnimation::GetPercentages(long lMaxDist)
{
if(lMaxDist > 0)
{
m_dLeftPercent = (m_crStart.left - m_crEnd.left) / (double)lMaxDist;
m_dTopPercent = (m_crStart.top - m_crEnd.top) / (double)lMaxDist;
m_dRightPercent = (m_crStart.right - m_crEnd.right) / (double)lMaxDist;
m_dBottomPercent = (m_crStart.bottom - m_crEnd.bottom) / (double)lMaxDist;
}
}