📄 chanim.cpp
字号:
delete pch;
}
}
return this;
}
bool ChAnimView::AddAnchor( ChAnimAnchor* pAnchor, bool boolPutInPending )
{
// set back ptr; need for notification decency
pAnchor->SetView(this);
// Add to the rect anchor list, or try to add to a cast member
if( pAnchor->GetType() == ChAnimAnchor::rect )
{
ChAnimAnchor** ppExisting;
if (ppExisting = m_Anchors.Find(pAnchor->GetId()))
{
//delete *ppExisting;
m_Anchors.Delete(pAnchor->GetId());
}
m_Anchors.Insert(pAnchor->GetId(), pAnchor);
}
else
{
// find the cast member
ChAnimCastMember * pCast = FindChar( pAnchor->GetHotCastId() );
if (pCast)
{
pCast->SetAnchor( pAnchor );
}
else if (boolPutInPending)
{
if(!m_pCastAnchors)
{
m_pCastAnchors = new ChPtrList<ChAnimAnchor>;
}
if(m_pCastAnchors->IsEmpty() || !(m_pCastAnchors->Find( pAnchor )))
{
m_pCastAnchors->AddHead( pAnchor );
}
return false; // not added; put on pending list
}
else return false; // don't put on pending, nothing done
}
return true;
}
bool ChAnimView::DeleteAnchor( const chuint32 luId )
{
ChAnimAnchor** ppExisting;
if (ppExisting = m_Anchors.Find(luId))
{
delete *ppExisting;
m_Anchors.Delete(luId);
}
return true;
}
bool ChAnimView::DeleteAnchors( )
{
m_Anchors.Erase(); // destruct method should delete anchors
return true;
}
void ChAnimView::LoadAnchors(const string& strFilename) // Go away???
{
ifstream anchorFile( strFilename );
//ChAnimParser parser( this, (iostream *)(&anchorFile), pInfo->GetHTTPConn() );
ChAnimParser parser( this, (iostream *)(&anchorFile), 0, "");
bool boolSuccess = !parser.interpret(); // try new parser 1=> failed
ASSERT(boolSuccess); // rude, but only for debugging CAML
#if 0 // old format - not supported anymore
{
chuint32 id;
chuint32 hotCastid;
CRect rcHot;
chuint32 castId;
string strHint;
chuint32 lCursor;
ChAnimAnchor::type theType;
chint32 lStartCell;
chint32 tmp;
anchorFile.seekg(0, ios::beg);
anchorFile >> tmp;
theType = (ChAnimAnchor::type)tmp;
while (theType)
{
switch (theType)
{
case ChAnimAnchor::rect:
{
anchorFile >> id;
anchorFile >> rcHot.left >> rcHot.top;
anchorFile >> rcHot.right >> rcHot.bottom;
anchorFile.eatwhite();
anchorFile.get(); // first quote
anchorFile.get((strHint.GetBuffer(200)), 200, '"');
strHint.ReleaseBuffer();
anchorFile.get(); // last quote
ChAnimAnchor *pAnchor = new ChAnimAnchor(id, rcHot);
anchorFile >> lCursor >> castId >> lStartCell;
pAnchor->SetHint(strHint);
pAnchor->SetCast(castId);
pAnchor->SetStartFrame(lStartCell);
pAnchor->SetCursorId(lCursor);
AddAnchor(pAnchor);
break;
}
case ChAnimAnchor::cast:
{
anchorFile >> id;
anchorFile >> hotCastid;
anchorFile.eatwhite();
anchorFile.get(); // first quote
anchorFile.get((strHint.GetBuffer(200)), 200, '"');
strHint.ReleaseBuffer();
anchorFile.get(); // last quote
ChAnimAnchor *pAnchor = new ChAnimAnchor(id, hotCastid);
anchorFile >> lCursor >> castId >> lStartCell;
pAnchor->SetHint(strHint);
pAnchor->SetCast(castId);
pAnchor->SetStartFrame(lStartCell);
pAnchor->SetCursorId(lCursor);
AddAnchor(pAnchor);
break;
}
}
anchorFile >> tmp;
theType = (ChAnimAnchor::type)tmp;
}
}
#endif // 0 for old format
}
void ChAnimView::OnTimer(UINT nIDEvent)
{
OnTick();
}
void ChAnimView::OnDestroy()
{
ChGraphicView::OnDestroy();
if (m_uiTimer) KillTimer(1);
}
void ChAnimView::OnLButtonDown(UINT nFlags, CPoint pt)
{
ChAnimAnchor *pHit;
if (pHit = FindAnchor(pt))
{
pHit->Notify(pt);
}
}
void ChAnimView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ChGraphicView::OnLButtonUp(nFlags, point);
}
void ChAnimView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//ChGraphicView::OnMouseMove(nFlags, point);
}
BOOL ChAnimView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if(HTCLIENT == nHitTest)
{
POINT point;
::GetCursorPos( &point );
ScreenToClient( &point );
return SetCursor( point );
}
else return ChGraphicView::OnSetCursor(pWnd, nHitTest, message);
}
BOOL ChAnimView::SetCursor( POINT& pointInClient )
{
HCURSOR hCursor = GetCursor(m_cursorId);
ChAnimAnchor *pHit = 0;
chuint32 anchorId = 0; // compare this to last anchor with hint displayed
pHit = FindAnchor( pointInClient );
if (pHit)
{
hCursor = GetCursor(pHit->GetCursorId());
anchorId = pHit->GetId();
}
else
{
anchorId = 0;
}
::SetCursor(hCursor);
if (anchorId != m_anchorId)
{
string strHint = "";
if(anchorId)
{
strHint = pHit->GetHint();
}
((CFrameWnd*)(AfxGetMainWnd()))->SetMessageText(LPCTSTR(strHint));
m_anchorId = anchorId;
}
return true;
//return ChGraphicView::OnSetCursor(pWnd, nHitTest, message);
}
void ChAnimView::UpdateAnchorList()
{ // !!!!!!!!!!!!!!!!!
if ( m_pCastAnchors )
{
ChPosition pos = m_pCastAnchors->GetHeadPosition();
while (pos)
{
ChPosition oldPos = pos;
ChAnimAnchor* pAnchor = m_pCastAnchors->GetNext(pos);
if (AddAnchor( pAnchor, false))
{
m_pCastAnchors->Remove( oldPos );
}
}
if(m_pCastAnchors->IsEmpty())
{
delete m_pCastAnchors;
m_pCastAnchors = 0;
}
}
}
// Important! pt is in window coords (not scrolled)
ChAnimAnchor *ChAnimView::FindAnchor( const CPoint & pt )
{
CPoint pointInView = GetDeviceScrollPosition( ) + CSize(pt); // now it's in view coords
ChAnimAnchor *pHit = 0, *pTry;
if (m_pCastAnchors) UpdateAnchorList(); // make sure all anchors are
// associated with chars, if possible
// first try the sprite/char type of anchors
// by walking the sprite list.
// If the sprite has an anchor, hittest it
POSITION pos = m_spriteList.GetHeadPosition();
CPhasedSprite *pSprite;
while (pos)
{
pSprite = (CPhasedSprite *)(m_spriteList.GetNext(pos));
pTry = pSprite->GetCast()->GetAnchor(); // any sprite on list -MUST- have a
// cast member, but not necessarily an
// anchor.
if (pTry)
{
if(pSprite->HitTest(pointInView))
{
pHit = pTry;
break;
}
}
}
if (!pHit) // no hit in sprites
{
m_HitFinder.Initialize(pointInView);
m_Anchors.Infix( m_HitFinder );
pHit = m_HitFinder.GetHit();
// Optimization trick; force this node to front, so we find faster
if (pHit)
{
m_Anchors.Find(pHit->GetId());
}
}
return pHit;
}
/*----------------------------------------------------------------------------
ChAnimAnchor class
----------------------------------------------------------------------------*/
ChAnimAnchor::ChAnimAnchor() :
m_id( 0 ),
m_rcHot( 0, 0, 0, 0 ),
m_cursor( CH_CURSOR_PICK ),
m_type( rect ),
m_pView( 0 ),
m_pHotCast( 0 ),
m_hotCastId( 0 ),
m_pCast( 0 ),
m_castId( 0 ),
m_lStartCell( 0 )
{
}
ChAnimAnchor::ChAnimAnchor( chuint32 id, CRect& rcHot ) :
m_id( id ),
m_rcHot( rcHot ),
m_cursor( CH_CURSOR_PICK ),
m_type( rect ),
m_pView( 0 ),
m_pHotCast( 0 ),
m_hotCastId( 0 ),
m_pCast( 0 ),
m_castId( 0 ),
m_lStartCell( 0 )
{
}
ChAnimAnchor::ChAnimAnchor( chuint32 id, chuint32 hotCastId ) :
m_id( id ),
m_rcHot( 0, 0, 0, 0 ),
m_cursor( CH_CURSOR_PICK ),
m_type( cast ),
m_pView( 0 ),
m_pHotCast( 0 ),
m_hotCastId( hotCastId ),
m_pCast( 0 ),
m_castId( 0 ),
m_lStartCell( 0 )
{
}
ChAnimAnchor::~ChAnimAnchor()
{
m_pCast = 0;
m_castId = 0;
}
bool ChAnimAnchor::Notify( CPoint& pt )
{
ChAnimCastMember *pCast = GetCast();
if (pCast)
{
// default is to toggle animation
pCast->Animate(!(pCast->IsAnimating()));
pCast->SetCell(m_lStartCell);
}
Post(pt); // needs to be here in case they delete us during post
return true; // did something
}
bool ChAnimAnchor::Post(CPoint &point)
{
//ChAnchorEventMsg msg( m_id, point );
//m_pModule->Post(event);
//m_pModule->Post(CH_MSG_ANCHOR_EVENT, 1, m_id);
//ChCore::GetCore()->DispatchMsg( m_moduleId, msg ); // client only right now
if( !m_strCmdArg.IsEmpty())
{
bool boolProcessed;
ChCmdMsg msg( m_strCmdArg );
m_pView->GetCmdHookMgr()->Dispatch( msg, boolProcessed );
}
return true;
}
ChAnimCastMember * ChAnimAnchor::GetCast()
{
if ( m_pCast ) return m_pCast;
else if (m_castId)
{
// ask the view to find it based on id, and cache it for future
return( m_pCast = m_pView->FindChar(m_castId) );
}
return 0;
}
void ChAnimAnchor::SetCursor( string& cursorName )
{
chuint32 id = CH_CURSOR_STD_PTR;
for (int j = 0;aChAnimPointerNames[j].key; j++)
{
if (!cursorName.CompareNoCase(aChAnimPointerNames[j].strStr))
{
id = aChAnimPointerNames[j].key;
break;
}
}
SetCursorId(id);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -