home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / sprmgr20 / sprite / demo32 / sprite.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  3.3 KB  |  90 lines

  1. // sprite.h : interface of the CSprite class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4.  
  5. #define DT_SHOWSPRITE    1
  6. #define DT_MOVESPRITE    2
  7. #define DT_INITSPRITE    3
  8. #define    DT_KEEPIMAGE    4
  9. #define DT_ONPAINT        5
  10.  
  11. class CSpriteMgr;
  12.  
  13. class CSprite : public CObject
  14. {
  15.     friend CSpriteMgr;
  16.  
  17.     DECLARE_SERIAL(CSprite)
  18. public:    
  19.     CSprite(int nID = -1, BOOL bVisible = TRUE, BOOL bDraggable = FALSE, BOOL bOwnerDraw = FALSE);
  20.     
  21. // Attributes
  22. public:
  23.     int            m_nID;
  24.     BOOL        m_bVisible;
  25.     BOOL        m_nZOrder;
  26.     BOOL        m_bDraggable;
  27.  
  28. protected:
  29.        CPoint        m_PrevPos;             // Previous location
  30.        CRect        m_BitmapRect;        // Bitmap origin, Bitmap width, Bitmap height
  31.     CRect        m_LastStoredRect;    // Size and position of last stored rect
  32.     CSize        m_DeltaLeftTop;        // offset of the last stored rectangle in m_BkgBitmap
  33.     CObArray    m_ImageBitmaps;        // Sprite's images                                    
  34.     CUIntArray    m_LoopsPerImage;    // how much loops should the bitmaps be displayed
  35.        CBitmap        m_BkgBitmap;        // What's behind our sprite
  36.     COLORREF    m_TransparentColor;    // Transparent color of sprite bitmap
  37.     int            m_nBitmaps;            // number of attached image bitmaps objects
  38.     int            m_nBitmapIdx;        // next image bitmap to show
  39.     int         m_nLoopIdx;            // how often was the actual bitmap diplayed
  40.     BOOL         m_bAutoSkip;        // should the bitmap index skip automatically in every MoveSprite call
  41.     BOOL        m_bOwnerDraw;        // use the given bitmaps or let the user override OnRenderSprite
  42.     BOOL         m_bTransparent;        // have the given images a transparent color
  43.     
  44. // Operations
  45. public:                // "normal" functions
  46.     virtual void InitSpriteInfo(CDC* pDC, CBitmap& newBitmap, int nLoops, BOOL bTransparent, COLORREF transparent, CPoint& spritePos, BOOL bAutoSkip, CSize* pStretchSize = NULL);    
  47.     virtual void AddSpriteImage(CDC* pDC, CBitmap& newBitmap, int nLoops);
  48.     
  49.                     // "owner draw" functions
  50.     virtual void InitSpriteInfo(CDC* pDC, CRect& spriteRect);
  51.     virtual BOOL OnRenderSprite(CDC* /*pDC*/, CRect /*positionInfo*/, COLORREF& /*transparent*/, int /*nDrawingType*/)
  52.         {ASSERT(FALSE); return FALSE;};    // has to be overwritten in an owner draw sprite    
  53.     
  54.     virtual void DrawSprite(CDC* pDC, int nDrawingType, CSize offset = CSize(0, 0));
  55.     virtual void StoreBkg(CDC* pDC, CSize offset = CSize(0, 0));
  56.     virtual void RestoreBkg(CDC *pDC, CSize offset = CSize(0, 0));
  57.  
  58.     virtual BOOL IntersectSprite(CRect& rect);
  59.     virtual BOOL HitTest(CPoint& pos, BOOL bExact = FALSE, CDC* pDC = NULL);
  60.     
  61.     virtual void MoveSprite(CDC* pDC, CPoint &pos);
  62.     
  63.     virtual void AnimateSprite(CDC *pDC, CPoint& newPos, int nStepFactor);    
  64.     
  65.     virtual void BeginSpriteDragging(CWnd* pWnd, CPoint &pos);
  66.     virtual void EndSpriteDragging(CDC* pDC, CPoint& newPos);
  67.  
  68.     virtual    void SkipFrames(int nOffset = 1);
  69.  
  70.     virtual void FreeBitmaps(BOOL bDeleteObjectsOnly = FALSE);
  71.  
  72.     virtual void GetSpritePos(CRect& pos);
  73.     virtual void GetBoundingRect(CRect& rect);
  74.  
  75. protected:
  76.     virtual void UpdateOwnerDrawBitmap(CDC* pDC, int nDrawingType);
  77.  
  78. // Implementation
  79. public:
  80.     virtual ~CSprite();
  81.     virtual void Serialize(CArchive& ar);    // overridden for document i/o
  82. #ifdef _DEBUG
  83.     virtual    void AssertValid() const;
  84.     virtual    void Dump(CDumpContext& dc) const;
  85. #endif
  86.  
  87. };
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90.