?? animeffect.cpp
字號(hào):
/*
Modified by 徐景周 2000.12
Modify by dsfy 2002.9
Modify by Lorndragon 2003.7 -- MFC to SDK
功能:對(duì)話框動(dòng)畫效果顯示
*/
//////////////////////////////////////////////////////////////////////
#define _ANIM_INTERNAL_
//#include "stdafx.h"
#include "AnimEffect.h"
#include <math.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define FIXED_SHIFT 16
#define FIXED int
typedef struct tag_MATRIXF {
FIXED fM11;
FIXED fM12;
int iM13;
FIXED fM21;
FIXED fM22;
int iM23;
int iM31;
int iM32;
int iM33;
} MATRIXF;
const FIXED fixed1= 1 << FIXED_SHIFT;
const MATRIXF matrix1 = { fixed1, 0, 0, 0, fixed1, 0, 0, 0, 1 };
const POINT point0 = { 0, 0 };
int fixedMul(int iMultiplicand, FIXED fMultiplier);
FIXED fixedDiv(int iNumerator, int iDenominator);
POINT operator*( const POINT &point, const MATRIXF &matrix);
MATRIXF operator*( const MATRIXF &matrix1, const MATRIXF &matrix2);
MATRIXF mix( const MATRIXF &matrix1, const MATRIXF &matrix2, FIXED fMix);
POINT mix( const POINT &point1, const POINT &point2, FIXED fMix);
MATRIXF scaleMatrix( FIXED scaleX, FIXED scaleY, POINT ptOrg = point0 );
MATRIXF rotateMatrix( FIXED angle, POINT ptOrg = point0 );
MATRIXF offsetMatrix( int offsetX, int offsetY );
BOOL efSpinFrame( AnimData *pAnimData );
BOOL efVortexFrames( AnimData *pAnimData );
BOOL efScatterGatherFrames( AnimData *pAnimData );
BOOL efSpikeFrames( AnimData *pAnimData );
BOOL efFireworxFrames( AnimData *pAnimData );
inline POINT operator+(POINT &point1, POINT &point2)
{
POINT ptResult;
ptResult.x = point1.x + point2.x;
ptResult.y = point1.y + point2.y;
return ptResult;
}
inline POINT operator-(POINT &point1, POINT &point2)
{
POINT ptResult;
ptResult.x = point1.x - point2.x;
ptResult.y = point1.y - point2.y;
return ptResult;
}
inline MATRIXF& operator *=(MATRIXF &matrix1, const MATRIXF &matrix2)
{
return matrix1 = matrix1*matrix2;
}
void drawBox( HDC hDC, POINT &ptCenter, POINT &ptRelRightTop );
void drawPoly( HDC hDC, POINT *pPts, DWORD dwPoints );
//畫動(dòng)態(tài)變化的方框線
void AnimEffect::DrawWireRects(LPRECT lprcFrom, LPRECT lprcTo, UINT nMilliSecSpeed)
{
const int nNumSteps = 10;
GdiFlush();
Sleep(50); // Let the desktop window sort itself out
// if hwnd is null - "you have the CON".
HDC hDC = GetDC(NULL);
// Pen size, urmmm not too thick
HPEN hPen = CreatePen(PS_SOLID, 2, RGB(12,240,44));
int nMode = SetROP2(hDC, R2_NOT);
HPEN hOldPen = (HPEN) SelectObject(hDC, hPen);
for (int i = 0; i < nNumSteps; i++)
{
double dFraction = (double) i / (double) nNumSteps;
RECT transition;
transition.left = lprcFrom->left + (int)((lprcTo->left - lprcFrom->left) * dFraction);
transition.right = lprcFrom->right + (int)((lprcTo->right - lprcFrom->right) * dFraction);
transition.top = lprcFrom->top + (int)((lprcTo->top - lprcFrom->top) * dFraction);
transition.bottom = lprcFrom->bottom + (int)((lprcTo->bottom - lprcFrom->bottom) * dFraction);
POINT pt[5];
pt[0].x = transition.left;
pt[0].y = transition.top;
pt[1].x = transition.right;
pt[1].y = transition.top;
pt[2].x = transition.right;
pt[2].y = transition.bottom;
pt[3].x = transition.left;
pt[3].y = transition.bottom;
pt[4].x = transition.left;
pt[4].y = transition.top;
// We use Polyline because we can determine our own pen size
// Draw Sides
Polyline(hDC,pt,5);
GdiFlush();
Sleep(50);
// Sleep(1000);
// UnDraw Sides
Polyline(hDC,pt,5);
GdiFlush();
}
SetROP2(hDC, nMode);
SelectObject(hDC, hOldPen);
ReleaseDC(NULL,hDC);
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
AnimEffect::AnimEffect()
{
m_hDC = GetDC(NULL);
m_hPen = CreatePen( PS_SOLID, 1, RGB(12,240,44) );
Defaults();
}
AnimEffect::~AnimEffect()
{
DeleteObject( m_hPen );
ReleaseDC( NULL, m_hDC );
}
void AnimEffect::Defaults()
{
m_rcScreen.left = 0; m_rcScreen.top = 0;
m_rcScreen.right = GetSystemMetrics(SM_CXFULLSCREEN);
m_rcScreen.bottom = GetSystemMetrics(SM_CYFULLSCREEN);
m_iAfterimages = 1;//6;
m_iTotalSteps = 20;//50;
m_iDelay = 1;//5;
Effect( Random );
}
void AnimEffect::Setup(int iSteps, int iAfterimages, int iDelay)
{
if (iSteps > 255) iSteps = 255;
else if (iSteps < 1) iSteps = 1;
m_iTotalSteps = iSteps;
if (iAfterimages > 32) iAfterimages = 32;
m_iAfterimages = iAfterimages;
if (iDelay > 100) iDelay = 100;
else if (iDelay < 0) iDelay = 0;
}
void AnimEffect::Effect( EffectType effect )
{
switch ( effect ) {
case Random:
break;
case Spin:
m_iParameter = 360;
break;
case Vortex:
m_iParameter = 180;
break;
case ScatterGather:
m_iParameter = 4;
break;
case Spike:
m_iParameter = 180;
break;
case Fireworks:
m_iParameter = 360;
break;
}
m_Effect = effect;
}
void AnimEffect::ChooseFunc()
{
bool bRandom = false;
if (m_Effect == Random) {
bRandom = true;
Effect((EffectType)(rand() % 5));
}
switch (m_Effect) {
case Spin:
m_Func = efSpinFrame;
break;
case Vortex:
m_Func = efVortexFrames;
break;
case ScatterGather:
m_Func = efScatterGatherFrames;
break;
case Spike:
m_Func = efSpikeFrames;
break;
case Fireworks:
m_Func = efFireworxFrames;
break;
default:
m_Func = 0;
}
if (bRandom) {
m_Effect = Random;
}
}
void AnimEffect::Open( const RECT &rcWnd )
{
HPEN oldpen;
int oldrop2;
AnimData ad;
oldpen = (HPEN)SelectObject(m_hDC, m_hPen);
oldrop2= SetROP2(m_hDC, R2_NOT);
ChooseFunc();
ad.bOpen = TRUE;
ad.hDC = m_hDC;
ad.iAfterimages = m_iAfterimages;
ad.iTotalSteps = m_iTotalSteps;
ad.rcWnd = rcWnd;
ad.ptCenter.x = rcWnd.left + (rcWnd.right - rcWnd.left ) / 2 ; // - rcWnd.top ;
ad.ptCenter.y = rcWnd.top + (rcWnd.bottom - rcWnd.top) /2 ;
ad.ptRelRightTop.x = rcWnd.right - ad.ptCenter.x;
ad.ptRelRightTop.y = rcWnd.top - ad.ptCenter.y;
ad.iParameter = m_iParameter;
Animate(ad);
Sleep(1);
SetROP2(m_hDC, oldrop2);
SelectObject(m_hDC, oldpen);
}
void AnimEffect::Close( const RECT &rcWnd )
{
HPEN oldpen;
int oldrop2;
AnimData ad;
oldpen = (HPEN)SelectObject(m_hDC, m_hPen);
oldrop2= SetROP2(m_hDC, R2_NOT);
ChooseFunc();
ad.bOpen = FALSE;
ad.hDC = m_hDC;
ad.iAfterimages = m_iAfterimages;
ad.iTotalSteps = m_iTotalSteps;
ad.rcWnd = rcWnd;
ad.ptCenter.x = rcWnd.left + (rcWnd.right - rcWnd.left ) / 2;
ad.ptCenter.y = rcWnd.top + (rcWnd.bottom - rcWnd.top) /2;
ad.ptRelRightTop.x = rcWnd.right - ad.ptCenter.x;
ad.ptRelRightTop.y = rcWnd.top - ad.ptCenter.y;
ad.iParameter = m_iParameter;
Animate(ad);
SetROP2(m_hDC, oldrop2);
SelectObject(m_hDC, oldpen);
}
void AnimEffect::Animate(AnimData &animData)
{
animData.animType = AnimInit;
m_Func(&animData);
if (animData.bOpen) {
for(int frame=0;frame < animData.iTotalSteps+animData.iAfterimages;frame++) {
// draw
if (frame < animData.iTotalSteps) {
animData.animType = AnimDraw;
animData.iStep = frame;
m_Func( &animData );
GdiFlush();
}
Sleep(20);
// erase
if (frame >= animData.iAfterimages){
animData.animType = AnimErase;
animData.iStep = frame - animData.iAfterimages;
m_Func( &animData );
GdiFlush();
}
}
} else {
for(int frame=animData.iTotalSteps+animData.iAfterimages-1;frame >= 0 ;frame--) {
// draw
if (frame >= animData.iAfterimages) {
animData.animType = AnimDraw;
animData.iStep = frame - animData.iAfterimages;
m_Func( &animData );
GdiFlush();
}
Sleep(20);
// erase
if (frame < animData.iTotalSteps) {
animData.animType = AnimErase;
animData.iStep = frame;
m_Func( &animData );
GdiFlush();
}
}
}
animData.animType = AnimTerm;
m_Func(&animData);
}
//////////////////////////////////////////////////////////////////////
// Supp. functions
//////////////////////////////////////////////////////////////////////
int fixedMul(int iMultiplicand, FIXED fMultiplier)
{
return MulDiv(iMultiplicand, fMultiplier, 65536);
}
FIXED fixedDiv(int iNumerator, int iDenominator)
{
if ( iNumerator == 0 || iDenominator == 0) return 0;
return MulDiv(65536,iNumerator,iDenominator);
}
POINT operator*( const POINT &point, const MATRIXF &matrix)
{
POINT ptResult;
ptResult.x = fixedMul(point.x, matrix.fM11) + fixedMul(point.y,matrix.fM21) + matrix.iM31;
ptResult.y = fixedMul(point.x, matrix.fM12) + fixedMul(point.y,matrix.fM22) + matrix.iM32;
return ptResult;
}
MATRIXF operator*( const MATRIXF &m1, const MATRIXF &m2)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -