chanim.h

来自「Windows上的MUD客户端程序」· C头文件 代码 · 共 467 行 · 第 1/2 页

H
467
字号
		bool	IsVisible() { return m_boolVisible; }
		chuint32 GetId() { return m_id; };			// tag for external reference
		void Animate( bool boolRun = true );
		bool IsAnimating( ) {return !m_boolFrozen; };
		void SetDraggable( bool boolDraggable = true ) { m_boolDraggable = boolDraggable;};
		bool IsDraggable( ) {return m_boolDraggable; };

		void SetCell( chint32 iCell );
		//virtual void Serialize( ChArchive& ar ) const;
		virtual void Read( istream& strm );
		void SetSprite(CPhasedSprite* pSprite);		  
		void SetScript(int numCells, int iCurCell, chint32 lFrameRate, ChCell *pScript, bool boolCopy = false);
		void SetScript(ChAnimScript *pScript, bool boolCopy = false);

		inline ChCell* GetScriptCells() { return m_pScript; };
		inline string& GetScriptURL() { return m_strScriptURL; };
		inline ChAnimCastMember*  SetScriptURL(string& strURL)
				{ m_strScriptURL = strURL; return this; };
		inline string& GetName() { return m_strName; };									 
		inline CPhasedSprite* GetSprite( ) { return m_pSprite; }
		inline string& GetSpriteURL()  { return m_strSpriteURL; }
		inline ChAnimCastMember* SetSpriteURL(const string& strURL)
				{m_strSpriteURL = strURL; return this; }
		void InitFromMsg( ChCastMsg *pMsg );
		void OnAddition(ChAnimView *pView);
		void InitializeScript();
	 	inline ChAnimAnchor *GetAnchor() { return m_pAnchor; };
		inline void SetAnchor(ChAnimAnchor *pAnchor)
		{ 
			if(m_pAnchor && m_pAnchor != pAnchor)
			{
				pAnchor->m_pHotCast = 0;
				delete pAnchor;
			}
			m_pAnchor = pAnchor;
			pAnchor->m_pHotCast = this;
		};

	protected:
	    CPhasedSprite* m_pSprite;		// just one for now; array in future ?
									// or could change CPhasedSprite to handle
									// multiple dibs (but then it's 3d...maybe not
									// a good idea
		string		m_strSpriteURL;	// where to find sprite data
		string		m_strScriptURL;	// where to find sprite data
    	chint32 	m_iCurCell;
	    ChCell* 	m_pScript;
		chint32		m_numCells;
		chint32		m_lFrameRate;
		chint32		m_lTicksPerFrame; // hundredths of a millisec
		chint32		m_lLastTick;
		bool		m_boolFrozen;
		bool		m_boolVisible;
		bool		m_boolDraggable;
		int			m_version;   // for serializing
		chint32		m_iNumSpriteRows, m_iNumSpriteCols;	// stash while loading
		chuint32	m_id;
		ChAnimAnchor *m_pAnchor;
		ChAnimView *m_pView;
		string 		m_strName;
		void SetId(chuint32 luId) { m_id = luId; };
		inline void SetName(string& strName) {  m_strName = strName; };
};


inline void ChPtrSplayDestruct( ChAnimAnchor* pAnchor )
{
	delete pAnchor;
}


class ChAnimView : public ChGraphicView
{
	CH_FRIEND_MESSAGE_HANDLER( animatorLoadCompleteHandler );
	protected: 


	public:
	    ChAnimView( ChGraphicMainInfo *pInfo );
	    virtual ~ChAnimView();

	public:
		bool Create( const CRect& rtView, CWnd* pParent,
						DWORD dwStyle = WS_VISIBLE | WS_VSCROLL | WS_BORDER,
						UINT uiID = 0 );

		ChDibBmp* GetDIB() {return m_pDIB;}
		BOOL Create(ChDibBmp* pDIB);            // Create a new buffer.
		virtual void OnInitialUpdate(); // First time after construction.
 		virtual void Draw(CDC* pDC = NULL, 
              RECT* pClipRect = NULL);  // Draw off-screen buffer to screen.

		virtual void Render(CRect* pClipRect=0);

		bool LoadBackground( const string & strURL ); 
		bool LoadBackgroundJPEG( const string & strURL ); 
		bool LoadBackgroundGIF( const string & strURL );
		bool LoadBackground( chuint16 suResId );      

		ChDibBmp* GetBackground() {return m_pDibBkgnd;}
		inline CSpriteList* GetSpriteList() {return &m_spriteList;}
		bool LoadCharacter( ChArchive& ar );	// module should expose
		bool LoadAnchor( ChArchive& ar );	// module should expose
		bool LoadCharacterScript( chuint32 luId, ChArchive& ar );	// module should expose
		ChAnimView* DeleteCharacter( chuint32 luId );	// module should expose
		bool AddAnchor( ChAnimAnchor* pAnchor, bool boolPutInPending = true );	// module should expose
		bool DeleteAnchor( const chuint32 luId );	// module should expose
		bool DeleteAnchors( void );	// module should expose
		ChAnimView* AnimateCharacter( chuint32 luId, bool boolRun = true );	// module should expose
		ChAnimView* ShowCharacter( chuint32 luId, bool boolShow = true);	// module should expose
		virtual void Animate( bool boolRun );			// module should expose
		bool IsAnimating() const;
		void OnTick();							// called by system timer mgr (to be defined)
		void AddCharacter(ChAnimCastMember * pChar);	 // prob internal only for now
		ChAnimCastMember * FindChar(chuint32 luId);
		void ChAnimView::NewSprite(CSprite* pSprite);
    	inline BOOL Insert(CSprite* pSprite) { return m_spriteList.Insert( pSprite ); };
    	inline CSprite *Remove(CSprite* pSprite) { return m_spriteList.Remove( pSprite ); };
		inline void SetCmdHookMgr( ChHookManager *pHookMgr ) {m_pHookMgr = pHookMgr;};
		inline ChHookManager *GetCmdHookMgr( ) { return m_pHookMgr; };
	    void AddDirtyRegion(CRect* pRect);
	    void RenderAndDrawDirtyList();

											/* ClassWizard generated virtual
												function overrides */
		//{{AFX_VIRTUAL(ChMazeWnd)
		protected:
		virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
		//}}AFX_VIRTUAL
	public:

	protected: 
	    ChDibBmp* m_pDIB;           // The DIB buffer.

	    BITMAPINFO* m_pOneToOneClrTab;  // Pointer to 1-to-1 color table
	    BOOL m_bUseCreateDIBSection;    // Flag
	    CDSPROC* m_pCDSProc;            // Pointer to CreateDIBSection
	    HBITMAP m_hbmSection;           // Bitmap from section
	    CObList m_DirtyList;            // Dirty regions

		bool	m_boolBackgroundDirty;
	    void EmptyDirtyList();

		bool	m_boolCenterIt;
	    ChDibBmp *m_pDibBkgnd;
		bool NewBackground(ChDibBmp* pDIB);
		bool DeferredNewBackground();
		ChHookManager	*m_pHookMgr;

		ChPtrList<ChAnimCastMember> m_characters;


		// m_Anchors has to be fast on walks, but also ought to be a list
		// or tree (by id). Splay trees will work because walk is done
		// usually on OnSetCursor; last anchor hit is highly probable this
		// time.
		
		ChPtrSplay<ChAnimAnchor> m_Anchors;
		chuint32	m_anchorId;		// last anchor with hint displayed

		// Anchors waiting for characters
		ChPtrList<ChAnimAnchor>	*m_pCastAnchors;

		//class ChAnchorHitTest - tests for hits in rectangular anchors
		class ChAnchorHitTest : public ChPtrSplayVisitor2<ChAnimAnchor>
		{
			protected:
				CPoint 	m_pt;
				ChAnimAnchor *m_pHit;

			public:
				ChAnchorHitTest( const CPoint & pt ) :  m_pt(pt), m_pHit(0) { };
				ChAnchorHitTest( ) :  m_pt(0), m_pHit(0) { };

				bool Visit( chuint32 key, const  ChAnimAnchor* pAnchor )
						{
							if (pAnchor->HitTest(m_pt))
							{	
								m_pHit = (ChAnimAnchor*)pAnchor;
								return false;
							} 
							return true;
						}
				inline ChAnimAnchor * GetHit() { return m_pHit; }
				void Initialize( const CPoint & pt )
					{
						m_pt = pt;
						m_pHit = 0;
					}
		};

		ChAnchorHitTest m_HitFinder;
		ChAnimAnchor *FindAnchor( const CPoint & pt );

		CSpriteList m_spriteList;			  // currently active sprites
	    UINT m_uiTimer;                 // timer id
		#define MAX_CURSOR_COUNT	10
		HCURSOR m_cursors[MAX_CURSOR_COUNT];	   // temporary; make it work first !!!!
		chuint m_cursorId;

		inline HCURSOR GetCursor(chuint32 lCursor) { return m_cursors[lCursor]; };
		BOOL SetCursor( POINT& pointInClient );
	    void LoadAnchors(const string& strFilename);
		void UpdateAnchorList();

// Generated message map functions
protected:
    //{{AFX_MSG(ChAnimView)
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnDestroy();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	//}}AFX_MSG
    DECLARE_MESSAGE_MAP()

	#if 0
	// these are used for moving the background dib
	protected: 
	    BOOL m_bInPlace;
	public:
		BOOL IsInPlace() {return m_bInPlace;}
	    int m_iBkgndPos;
		int GetBkgndPos() {return m_iBkgndPos;}
		void SetBkgndPos(int iPos)
		    {m_iBkgndPos = iPos;}

	#endif
};

#endif  //( _CHANIM_H )

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?