home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / sprmgr20 / sprite / sprite.txt < prev    next >
Encoding:
Text File  |  1994-07-10  |  23.1 KB  |  701 lines

  1. The CSprite Class
  2.  
  3. Overview
  4.  
  5. The CSprite class provides an easy to use interface for animating sprites.
  6.  
  7. Supported features are:
  8.     Transparency:
  9.         This works with any given color as transparent color (not only black).
  10.     Animated sprites:
  11.         A Sprite can have more then one fixed image. You may assign as many images as
  12.         you wish (and memory can hold). This images are iterated every n-th moving action.
  13.     Ownerdraw sprites:
  14.         A sprites image is not a fixed one but can be changed with standard GDI 
  15.         functions during every redraw action of the sprite.
  16.     Mouse dragging:
  17.         The CSprite class owns some helper functions to make implementing mouse 
  18.         dragging a little bit easier.
  19.     Flicker-free animation:
  20.         Moving sprites and calculating transparency occures in an off-screen dc to prevent 
  21.         from flickering
  22.  
  23. The interface of the CSprite class
  24.  
  25. CSprite(int nID = -1, BOOL bVisible = TRUE, BOOL bDraggable = FALSE, 
  26.      BOOL bOwnerDraw = FALSE)
  27.  
  28. int nID            the id of this sprite; it's the users responsability to 
  29.             pass a unique id to this sprite if it's managed by a 
  30.             CSpriteMgr object else undefined behavior of the 
  31.             sprite would take place
  32. BOOL bVisible        the initial state of the sprite. This value is only used 
  33.             if the sprite is managed by a CSpriteMgr object.
  34. BOOL bDraggable            if this boolean is set TRUE the sprite could be dragged 
  35.             with the mouse. this value is only used if the sprite 
  36.             is managed by a CSpriteMgr object
  37. BOOL bOwnerDraw            this value specifies wheter the sprite has fixed number 
  38.             of images or is an ownerdraw sprite.
  39.  
  40. Constructor of the CSprite object. One of the InitSpriteInfo functions has to 
  41. be called after the constructor. Which of the two functions has to be called 
  42. depends on bOwnerDraw.
  43.  
  44.  
  45.  
  46. virtual void InitSpriteInfo(CDC* pDC, CBitmap& newBitmap, int nLoops, 
  47.                 BOOL bTransparent, COLORREF transparent, 
  48.                 CPoint& spritePos, BOOL bAutoSkip, 
  49.                 CSize* pStretchSize = NULL)
  50.  
  51. CDC* pDC             pointer to the windows client device context
  52. CBitmap& newBitmap         the first sprite image
  53. int nLoops            number of movements this image should be shown; 
  54.                 if there is only one image for this sprite it 
  55.                 should be set to 1
  56. BOOL bTransparent        boolean value determing wheter the image uses a 
  57.                 transparent color or not
  58. COLORREF transparent        the RGB value of the transparent color; if 
  59.                 bTransparent is FALSE this value is ignored
  60. CPoint& spritePos        the initial sprite position
  61. BOOL bAutoSkip            this value determins wheter the sprites frame 
  62.                 counter is incremented automatically on every 
  63.                 movement of the sprite; if there is only one 
  64.                 image for this sprite it should be set to FALSE
  65. CSize* pStretchSize        if the sprite should have an diferent size then 
  66.                 the bitmap, it could be passed as pointer to a 
  67.                 CSize object; if not, the pointer should be 
  68.                 NULL; the given bitmap and any additional 
  69.                 bitmaps are stretched to this size.
  70.  
  71. This function initializes a sprite with a given image at a specified position. 
  72. The sprite is not displayed due to this function call. This function should be 
  73. used for fixed-images sprites only, if called for an ownerdraw sprite the debug 
  74. version of the library asserts.
  75.  
  76.  
  77.  
  78. virtual void AddSpriteImage(CDC* pDC, CBitmap& newBitmap, int nLoops)
  79.  
  80. CDC* pDC        pointer to the windows client device context
  81. CBitmap& newBitmap    an additional sprite image
  82. int nLoops        number of movements this image should be shown
  83.  
  84. This function adds another image to the sprite. This function should be used 
  85. for fixed-images sprites only, if called for an ownerdraw sprite the debug 
  86. version of the library asserts.
  87.  
  88.  
  89. virtual void InitSpriteInfo(CDC* pDC, CRect& spriteRect)
  90.  
  91. CDC* pDC        pointer to the windows client device context
  92. CRect& spriteRect    the initial position of the sprite; the CRect object 
  93.             implicitly defines the size of the image buffer to be 
  94.             prepared.
  95.  
  96. This function initializes a owner draw sprite, if called for fixed-images 
  97. sprites the degub version of the library asserts. The sprite is not displayed 
  98. due to this function call but the first call to OnRenderSprite is done to 
  99. retrieve the first image to display.
  100.  
  101.  
  102.  
  103. virtual BOOL OnRenderSprite(CDC* pDC, CRect positionInfo, COLORREF& transparent,
  104.                 int nDrawingType)
  105.  
  106. CDC* pDC            pointer to memory device context used as buffer 
  107.                 for the image
  108. CRect positionInfo        CRect object containing the position of the 
  109.                 sprite
  110. COLORREF& transparent        the RGB value of the transparent color, should 
  111.                 be set by the function
  112. int nDrawingType        this is a hint for what drawing action resulted 
  113.                 in the call to this function. it is one of the 
  114.                 following constants:
  115.                 DT_SHOWSPRITE    call to CSpriteMgr::ShowSprite
  116.                 DT_MOVESPRITE    call to CSpriteMgr::MoveSprite 
  117.                         or CSprite::MoveSprite
  118.                 DT_INITSPRITE    call to CSprite::InitSpriteInfo
  119.                 DT_KEEPIMAGE    this is an internal constant 
  120.                         that prevents the function from 
  121.                         being called, so this value is 
  122.                         never passed to the function
  123.                 DT_ONPAINT    call to CSpriteMgr::OnPaint
  124.  
  125. To create an ownerdraw sprite this member function must be overwritten to 
  126. render the sprite's image. The default implementation asserts. Do not call 
  127. CSprite::OnRenderSprite out of your function. Ownerdraw sprites call this 
  128. function every time a drawing action occures. The function should return a 
  129. boolean specifying if the rendered image uses a transparent color. If the 
  130. function returns TRUE it should also change the transparent-variable to the 
  131. RGB value of the transparent color used.
  132.  
  133.  
  134.  
  135. virtual void DrawSprite(CDC* pDC, CSize offset = CSize(0, 0))
  136.  
  137. CDC* pDC    pointer to the windows client device context
  138. CSize offset    offset of the bitmap position within the given dc
  139.  
  140. This function renders the sprite to the given dc. If used on a buffer dc with 
  141. extensions other then the client dc it may be usefull to specify an offset to 
  142. the bitmap position. Usually you will call CSprite::StoreBkg first to save the 
  143. sprites background.
  144.  
  145.  
  146.  
  147. virtual void StoreBkg(CDC* pDC, CSize offset = CSize(0, 0))
  148.  
  149. CDC* pDC    pointer to the windows client device context
  150. CSize offset    offset of the bitmap position within the given dc
  151.  
  152. This function stores the background of the sprite. The background is copyed 
  153. from the sprites current position. If used on a buffer dc with extensions 
  154. other then the client dc it may be usefull to specify an offset to the bitmap 
  155. position.
  156.  
  157.  
  158.  
  159. virtual void RestoreBkg(CDC *pDC, CSize offset = CSize(0, 0))
  160.  
  161. CDC* pDC    pointer to the windows client device context
  162. CSize offset    offset of the bitmap position within the given dc
  163.  
  164. This function restores the stored background in the given dc. If used on a 
  165. buffer dc with extensions other then the client dc it may be usefull to specify 
  166. an offset to the bitmap position.
  167.  
  168.  
  169.  
  170. virtual BOOL IntersectSprite(CRect& rect)
  171.  
  172. CRect& rect    rectangle to check for
  173.  
  174. This function returns TRUE if the given rectangle intersects with the sprites 
  175. position else it returns FALSE.
  176.  
  177.  
  178.  
  179. virtual BOOL HitTest(CPoint& pos, BOOL bExact = FALSE, CDC* pDC = NULL)
  180.  
  181. CPoint& pos    point to check for
  182. BOOL bExact    boolean specifying wheter the sprites image transparency 
  183.         should be involved or not
  184. CDC* pDC    if bExact is TRUE this has to be a pointer to the windows 
  185.         client dc else it is ignored
  186.  
  187. This function checks if the given point hits the sprites image. If the given 
  188. point lies within the sprites rectangle the function returns TRUE else it will 
  189. return FALSE. If bExact is TRUE and the given point hits the sprite on a 
  190. transparent pixel the function will return FALSE.
  191.  
  192.  
  193.  
  194. virtual void MoveSprite(CDC* pDC, CPoint &pos)
  195.  
  196. CDC* pDC    pointer to the windows client dc
  197. CPoint &pos    new sprite position 
  198.  
  199. This function moves the sprite to the given position restoring the previous 
  200. positions background. Important: This function should only be used if there 
  201. is no other sprite intersecting with the privious or the new sprite position. 
  202. A second limitation is that this function only works correctly if the client 
  203. area is completely visible. To work around this limitations let the sprite be 
  204. managed by a CSpriteMgr object and use CSpriteMgr::MoveSprite instead.
  205.  
  206.  
  207.     
  208. virtual void AnimateSprite(CDC *pDC, CPoint& newPos, int nStepFactor)
  209.  
  210. CDC *pDC        pointer to the windows client dc
  211. CPoint& newPos    end position of the animation
  212. int nStepFactor        number of animation steps
  213.  
  214. This function animates the sprite from the current position to the given 
  215. position drawing nStepFactor frames. Important: This function should only be 
  216. used if there is no other sprite intersecting with one of the positions the 
  217. sprite is animated through. A second limitation is that this function only 
  218. works correctly if the client area is completely visible. To work around this 
  219. limitations let the sprite be managed by a CSpriteMgr object and use 
  220. CSpriteMgr::AnimateSprite instead.
  221.  
  222.  
  223.  
  224. virtual void BeginSpriteDragging(CWnd* pWnd , CPoint &pos)
  225.  
  226. CWnd* pWnd    pointer to the window containing the sprite
  227. CPoint &pos    current mouse position
  228.  
  229. This function starts a mouse dragging action by setting intern variables and 
  230. calling SetCapture to make sure the given window will receive all the mouse 
  231. messages until EndSpriteDragging is called.
  232. Important: This function does not check if the mouse position hits the sprite. 
  233. To check this out use CSprite::HitTest.
  234.  
  235. Usually you will implement mouse dragging like this:
  236.  
  237. void CMyWindow::OnLButtonDown(..., CPoint point)
  238. {
  239.     if (pSprite->HitTest(point, ....)
  240.     {
  241.         pSprite->BeginSpriteDragging(this, point);
  242.         m_bDragging = TRUE;
  243.     }
  244.     CWnd::OnLButtonDown(..., CPoint point);
  245. }
  246.  
  247. void CMyWindow::OnMouseMove(..., CPoint point)
  248. {
  249.     if(m_bDragging)
  250.     {
  251.         CClientDC dc(this);
  252.         pSprite->MoveSprite(&dc, point);
  253.     }
  254.     CWnd::OnMouseMove(..., CPoint point);
  255. }
  256.  
  257. void CMyWindow::OnLButtonUp(..., CPoint point)
  258. {
  259.     if(m_bDragging)
  260.     {
  261.         CClientDC dc(this);
  262.         pSprite->EndSpriteDragging(&dc, point);
  263.     }
  264.     CWnd::OnLButtonUp(..., CPoint point);
  265. }
  266.  
  267.  
  268. virtual void EndSpriteDragging(CDC* pDC, CPoint& newPos)
  269.  
  270. CDC* pDC        pointer to the windows client dc
  271. CPoint& newPos    current mouse position
  272.  
  273. This function positions the sprite and releases the mouse capturing.
  274.  
  275.  
  276.  
  277. virtual void SkipFrames(int nOffset = 1)
  278.  
  279. int nOffset    number of frames to skip
  280.  
  281. Call this function to increment or decrement the sprites frame counter. 
  282. The function does not redraw the sprite. The number of frames a sprites image 
  283. is displayd is given by the parameters of InitSpriteInfo and AddSpriteImage. 
  284. If bAutoSkip is TRUE calling CSprite::InitSpriteInfo the frame counter is 
  285. incremented automatically on every call to CSprite::MoveSprite, 
  286. CSpriteMgr::MoveSprite and between the animation steps from calls to 
  287. CSprite::AnimateSprite and CSpriteMgr::AnimateSprite.
  288.  
  289.  
  290.  
  291. virtual void FreeBitmaps(BOOL bDeleteObjectsOnly = FALSE)
  292.  
  293. BOOL bDeleteObjectsOnly        If TRUE, only CBitmap::DeleteObject() is called, 
  294.                 else the delete operator is used on the Cbitmaps 
  295.                 containing the sprites images
  296.  
  297. This function deletes the GDI bitmap objects and depending on 
  298. bDeleteObjectsOnly it removes the CBitmap objects from memory. This function 
  299. usually is not called from the user of the library but from the CSprite 
  300. destructor and CSprite::InitSpriteInfo function.
  301.  
  302.  
  303.  
  304. virtual void GetSpritePos(CRect& pos)
  305.  
  306. CRect& pos    CRect object to receive the coordinates
  307.  
  308. This function places the sprites current position in the given CRect object.
  309.  
  310.  
  311.  
  312. virtual void GetBoundingRect(CRect& rect)
  313.  
  314. CRect& rect    CRect object to receive the coordinates
  315.  
  316. This function places the sprites boundig rectangle in the given CRect object. 
  317. Called from outside the library this would return the same coordinates then 
  318. CSprite::GetSpritePos.
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332. The CSpriteMgr class
  333.  
  334. Overview
  335.  
  336. The CSpriteMgr class provides you an object that is capable of managing an 
  337. unlimited (limited by memory, of course) number of CSprite objects. Usually 
  338. you may not use tewo or more CSprite objects without having them managed by 
  339. a CSpriteMgr object.
  340.  
  341. Managing CSprite object means:
  342.     
  343.     preventing from painting errors if two or more sprites positions 
  344.     intersect
  345.     
  346.     preventing from painting errors if the sprites are partialy overlapped 
  347.     by other windows
  348.  
  349.     providing an easy way to access information about sprite position 
  350.     intersections
  351.     
  352.     implementing a Z-order on CSprite objects
  353.     
  354.     making standard operations like handling mouse dragging or OnPaint 
  355.     calls a lot easier
  356.  
  357.     providing the possibility to move several sprites with intersecting 
  358.     boundaries without flickering
  359.  
  360. The interface of the CSpriteMgr class
  361.  
  362. virtual BOOL AddSprite(CSprite* pSprite, int nPlaceInFrontOfID = TOPSPRITE)
  363.  
  364. CSprite* pSprite    pointer to sprite that should be added
  365. int nPlaceInFrontOfID    the new sprite should be placed in Z-order in front of 
  366.             the sprite identified by this id
  367.  
  368. Adds a sprite to the sprite manager.
  369. You may also pass one of the folowing constants as nPlaceInFrontOfID:
  370.     TOPSPRITE        positions the sprite in front of all other 
  371.                 sprites
  372.     BOTTOMSPRITE        positions the sprite beneath all other sprites
  373.  
  374.  
  375.  
  376. virtual void RemoveSprite(CDC* pDC, int nID, BOOL bFreeMem = TRUE)
  377.  
  378. CDC* pDC        pointer to the windows client dc
  379. int nID            id of sprite to remove
  380. BOOL bFreeMem        boolean that specifies wether the sprite should only 
  381.             be removed from the CSpriteMgr's sprite list (FALSE) 
  382.             or if it should be removed from memory (TRUE) too.
  383.  
  384. Removes a sprite from the sprite manager.
  385.  
  386.  
  387.  
  388. virtual void ShowSprite(CDC* pDC, int nID, BOOL bShow)
  389.  
  390. CDC* pDC    pointer to the windows client dc
  391. int nID        id of sprite to manipulate
  392. BOOL bShow    boolean specifying wheter the sprite should be shown (TRUE) 
  393.         or hidden (FALSE)
  394.  
  395. This function shows or hides a sprite. If the sprite has allready the desired 
  396. state nothing happens.
  397.  
  398.  
  399.  
  400. virtual BOOL IsSpriteVisible(int nID)
  401.  
  402. int nID        id of sprite
  403.  
  404. Returns TRUE if the sprite is visible else FALSE. "Visible" does not mean that 
  405. the sprite is not hidden by another window but if it has been made visible by 
  406. passing TRUE as bVisible in the sprites construtor or calling ShowSprite with 
  407. bShow = TRUE.
  408.  
  409.  
  410.  
  411. virtual BOOL IntersectSprites(CObArray* pObArray, CRect& rect)
  412.  
  413. CObArray* pObArray    pointer to a CObArray object holding the function 
  414.             results
  415. CRect& rect        rectangle to intersect with
  416.  
  417. Calculates for all sprites if there positions are intersecting with the given 
  418. rectangle. The intersecting sprites are returned in pObArray in Z-order 
  419. (top-most sprite at index 0 and so on). The function returns TRUE if there are 
  420. intersecting sprites. 
  421. Important: The CObArray object receiving the result has to be constructed by 
  422. the user before calling this function.
  423.  
  424.  
  425.  
  426. virtual BOOL IntersectSprites(CObArray* pBeneath, CObArray* pAbove, 
  427.                 CSprite* pSprite, 
  428.                 CRect additionalRect = CRect(0,0,0,0))
  429.  
  430. CObArray* pBeneath    pointer to a CObArray object holding the function 
  431.             results
  432. CObArray* pAbove    pointer to a CObArray object holding the function 
  433.             results
  434. CSprite* pSprite    pointer to the CSprite that should be manipulated
  435. CRect additionalRect    an additional rect to intersect with
  436.  
  437. Calculates for all sprites if there positions are intersecting with the given 
  438. rectangle or the bounding rectangle of pSprite. The intersecting sprites are 
  439. returned in pBeneath and pAbove in Z-order (top-most sprite at index 0 and so 
  440. on). pBeneath holds the sprites with lower Z-order then pSprite. pAbove holds 
  441. the sprites with higher Z-order then pSprite.
  442. Important: The CObArray objects receiving the result have to be constructed by 
  443. the user before calling this function.
  444.  
  445.  
  446.  
  447. virtual void MoveSprite(int nID, CDC* pDC, CPoint &pos)
  448.  
  449. int nID        id of sprite to manipulate
  450. CDC* pDC    pointer to the windows client dc
  451. CPoint &pos    new position
  452.  
  453. This function moves the given sprite to the given position.
  454.  
  455.  
  456.  
  457. virtual void MoveSprite(CSprite* pSprite, CDC* pDC, CPoint &pos)
  458.  
  459. CSprite* pSprite    pointer to the CSprite that should be manipulated
  460. CDC* pDC        pointer to the windows client dc
  461. CPoint &pos        new position
  462.  
  463. This function moves the given sprite to the given position.
  464.  
  465.  
  466.  
  467. virtual void AnimateSprite(int nID, CDC *pDC, CPoint& newPos, int nStepFactor)
  468.  
  469. int nID            id of sprite to manipulate
  470. CDC *pDC        pointer to the windows client dc
  471. CPoint& newPos    end position of the animation
  472. int nStepFactor        number of animation steps
  473.  
  474. This function animates the given sprite from the current position to the 
  475. given position drawing nStepFactor frames.
  476.  
  477.  
  478.  
  479. virtual void AnimateSprite(CSprite* pSprite, CDC *pDC, CPoint& newPos, 
  480.                 int nStepFactor)
  481.  
  482. CSprite* pSprite    pointer to the CSprite that should be manipulated
  483. CDC *pDC        pointer to the windows client dc
  484. CPoint& newPos        end position of the animation
  485. int nStepFactor        number of animation steps
  486.  
  487. This function animates the given sprite from the current position to the 
  488. given position drawing nStepFactor frames.
  489.  
  490.  
  491.  
  492. virtual void SkipFrames(int nID, BOOL bShow, int nOffset = 1, CDC *pDC = NULL)
  493.  
  494. int nID        id of sprite to manipulate
  495. BOOL bShow    boolean that specifies wether the new selected images should 
  496.         be displayd or not
  497. int nOffset    number of frames to skip
  498. CDC *pDC    pointer to the windows client dc
  499.  
  500. For an explanation of this function look at the description of 
  501. CSprite::SkipFrames. The differences to CSprite::SkipFrames are:
  502.     The new image could be displayed automatically using parameter bShow
  503.  
  504.     If you set bShow to TRUE you also have to pass a valid pointer to the 
  505.     device context in which the changing should be displayed in 
  506.     parameter pDC.
  507.  
  508.  
  509. virtual void OnPaint(CDC* pDC)
  510.  
  511. CDC* pDC    pointer to the windows client dc
  512.  
  513. This function calls StoreBkg and DrawSprite for alle sprites managed by the 
  514. CSpriteMgr object. This is usefull in the CWnd::OnPaint or the CView::OnDraw 
  515. method of the window containing the sprites. Calling this function all sprites 
  516. read there new background and draw themself on the given dc.
  517.  
  518. Example:
  519.  
  520. void CMyView::OnDraw(CDC* pDC)
  521. {
  522.     ...
  523.     // some drawing code of your window
  524.     ...
  525.     m_SpriteMgr.OnPaint(pDC);
  526. }
  527.  
  528.  
  529.  
  530. virtual BOOL HitTest(CObArray* pObArray, CPoint& point, BOOL bExact, CDC* pDC)
  531.  
  532. CObArray* pObArray    pointer to a CObArray object holding the function 
  533.             results
  534. CPoint& point        point to check for 
  535. BOOL bExact        boolean specifying wheter the sprites image 
  536.             transparency should be involved or not
  537. CDC* pDC        pointer to the windows client dc
  538.  
  539. This function checks if the given point hits one of the sprites. If the given 
  540. point lies within the sprites rectangle the function returns TRUE else it will 
  541. return FALSE. If bExact is TRUE and the given point hits the sprite on a 
  542. transparent pixel the function will return FALSE. The sprites that are hit by 
  543. the given point are returned in pObArray in there Z-order (top-most sprite at 
  544. id 0 and so on).
  545. Important: The CObArray object receiving the result has to be constructed by 
  546. the user before calling this function.
  547.  
  548.  
  549.  
  550. virtual int  StartDrag(CWnd* pWnd, CPoint& pos, BOOL bExact, CDC* pDC)
  551.  
  552. CWnd* pWnd    pointer to the window containing the sprite
  553. CPoint& pos    current mouse position
  554. BOOL bExact    boolean specifying wheter the sprites image transparency 
  555.         should be involved or not
  556. CDC* pDC    pointer to the windows client dc
  557.  
  558. This function starts a mouse dragging action by setting intern variables and 
  559. calling SetCapture to make sure the given window will receive all the mouse 
  560. messages until EndDrag is called.
  561. The function checks which sprite has been hit and returns the sprite id or 
  562. the constant SPRITE_ERROR_ID if no sprite has been hit.
  563.  
  564. Usually you will implement mouse dragging like this:
  565.  
  566. void CMyWindow::OnLButtonDown(..., CPoint point)
  567. {
  568.     CClientDC dc(this);
  569.     if(m_SpriteMgr.StartDrag(this, point, TRUE, &dc) == SPRITE_ERROR_ID)
  570.         ::MessageBeep(MB_OK);    // no sprite has been hit!
  571.  
  572.     CWnd::OnLButtonDown(..., CPoint point);
  573. }
  574.  
  575. void CMyWindow::OnMouseMove(..., CPoint point)
  576. {
  577.     if(m_SpriteMgr.IsDragging())
  578.     {
  579.         CClientDC dc(this);
  580.         m_SpriteMgr.OnDrag(&dc, point);
  581.     }
  582.     CWnd::OnMouseMove(..., CPoint point);
  583. }
  584.  
  585. void CMyWindow::OnLButtonUp(..., CPoint point)
  586. {
  587.     if(m_SpriteMgr.IsDragging())
  588.     {
  589.         CClientDC dc(this);
  590.         m_SpriteMgr.EndDrag(&dc, point);
  591.     }
  592.     CWnd::OnLButtonUp(..., CPoint point);
  593. }
  594.  
  595.  
  596. virtual void OnDrag(CDC* pDC, CPoint& pos)
  597.  
  598. CDC* pDC    pointer to the windows client dc
  599. CPoint& pos    current mouse position
  600.  
  601. Moves the dragging sprite to the new position
  602.  
  603.  
  604.  
  605. virtual void EndDrag(CDC* pDC, CPoint& pos)
  606.  
  607. CDC* pDC    pointer to the windows client dc
  608. CPoint& pos    current mouse position
  609.  
  610. Moves the dragging sprite to the new position and releases the mouse capturing.
  611.  
  612.  
  613.  
  614. virtual BOOL IsDragging()
  615.  
  616. This function returns TRUE if one of the sprite managers sprites is currently 
  617. dragged with the mouse.
  618.  
  619.  
  620.  
  621. virtual CSprite* GetSpriteFromID(int nID)
  622.  
  623. int nID    id of sprite to get pointer from
  624.  
  625. This function returns a pointer to the sprite with the given id or NULL if
  626. there is no such sprite.
  627.  
  628.  
  629.  
  630. CSprite* operator[](int nID)
  631.  
  632. int nID    id of sprite to get pointer from
  633.  
  634. This operator returns a pointer to the sprite with the given id or NULL if 
  635. there is no such sprite.
  636.  
  637.  
  638.  
  639. virtual void ChangeZOrder(CDC* pDC, int nID, int nPlaceInFrontOfID = TOPSPRITE)
  640.  
  641. CDC* pDC        pointer to the windows client dc
  642. int nID            id of sprite to manipulate
  643. int nPlaceInFrontOfID    the sprite should be placed in Z-order in front of the 
  644.             sprite identified by this id
  645.  
  646. Changing the given sprites Z-order by placing it in front of the sprite given 
  647. by nPlaceInFrontOfID.
  648. You may also pass one of the folowing constants as nPlaceInFrontOfID:
  649.     TOPSPRITE    positions the sprite in front of all other sprites
  650.     BOTTOMSPRITE    positions the sprite beneath all other sprites
  651.  
  652.  
  653.  
  654. virtual BOOL BeginDeferSpritePos()
  655.  
  656. This function starts a block of sprite movements which are combined so that 
  657. they could executed all at once. Doing so prevents from flickering if the 
  658. sprites moved have overlapping bounding rectangles.
  659. There can only be on DeferSpritePos- Block at a time. The function returns 
  660. TRUE if successfull.
  661.  
  662. virtual void DeferSpritePos(int nID, CPoint &pos)
  663.  
  664. int nID        id of sprite to manipulate
  665. CPoint &pos    new position
  666.  
  667. This function works like a call to MoveSprite but with the diffference that 
  668. the drawing itself will not occure until the next call to EndDeferSpritePos.
  669.  
  670.  
  671.  
  672. virtual void DeferSpritePos(CSprite* pSprite, CPoint &pos)
  673.  
  674. CSprite* pSprite    pointer to the CSprite that should be manipulated
  675. CPoint &pos        new position
  676.  
  677. This function works like a call to MoveSprite but with the diffference that 
  678. the drawing itself will not occure until the next call to EndDeferSpritePos.
  679.  
  680.  
  681.  
  682. virtual void EndDeferSpritePos(CDC* pDC)
  683.  
  684. CDC* pDC    pointer to the windows client dc
  685.  
  686. This function realizes all DeferSpritePos-calls to the given dc.
  687.  
  688. Example:
  689.  
  690. if(!m_SpriteMgr.BeginDeferSpritePos())    // begin the DeferSpritePos-block
  691.     return;
  692.  
  693. m_SpriteMgr.DeferSpritePos(5, CPoint(100, 100));    // no painting is done
  694. m_SpriteMgr.DeferSpritePos(3, CPoint(100, 200));    // no painting is done
  695. m_SpriteMgr.DeferSpritePos(4, CPoint(200, 100));    // no painting is done
  696.  
  697. CClientDC dc(this);
  698. m_SpriteMgr.EndDeferSpritePos(&dc);    // all movements are displayed at once
  699.  
  700.  
  701.