#include "GlobalFunc.h" #include "T2BitImage.h" #include "T2DlgItemAnimation.h" #include "T2ImageObj.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif T2DlgItemAnimation::T2DlgItemAnimation(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) : T2DlgItem(inDoc, inImageObj, inPalette) { mBitImage = NULL; mImageObj = NULL; mStartFrame = 0; mDelay = 500; mTimerCreated = false; } /*virtual*/ T2DlgItemAnimation::~T2DlgItemAnimation() { if (mBitImage) delete mBitImage; if (mImageObj) delete mImageObj; } /*virtual*/ BOOL T2DlgItemAnimation::OnT2DlgItemEraseBkgnd(CDC* pDC) { CRect rect; GetClientRect(rect); int save = pDC->SaveDC(); pDC->SelectPalette(mPalette, false); pDC->RealizePalette(); if (mImageObj) { int objID; retry: objID = mImageObj->FindObject("ANIM", mCurrentFrame); if (objID == -1) { mCurrentFrame = mStartFrame; goto retry; } mImageObj->DrawObject(pDC, objID, rect); } pDC->RestoreDC(save); return true; } void T2DlgItemAnimation::SetAnimation(HINSTANCE inModule, int inResID, int unk) { if (mBitImage) delete mBitImage; if (mImageObj) delete mImageObj; #line 60 mBitImage = new T2BitImage(GetWorldModuleHandle(), inResID, true); mImageObj = new T2ImageObj; mImageObj->AddObject(GetWorldModuleHandle(), inResID, mBitImage); mStartFrame = 0; mCurrentFrame = 0; } void T2DlgItemAnimation::SetAnimationParam(int inDelay, int inStartFrame) { mDelay = inDelay; mStartFrame = inStartFrame; if (mTimerCreated) { KillTimer(100); SetTimer(100, mDelay, NULL); } } /*virtual*/ int T2DlgItemAnimation::OnT2DlgItemCreate(CREATESTRUCT*) { SetTimer(100, mDelay, NULL); mTimerCreated = true; return 0; } /*virtual*/ void T2DlgItemAnimation::OnT2Close() { KillTimer(100); mTimerCreated = false; } /*virtual*/ void T2DlgItemAnimation::OnT2Timer(UINT id) { if (id == 100) { mCurrentFrame++; InvalidateRect(NULL); } else { T2DlgItem::OnT2Timer(id); } }