home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl_ani2.zip / person.cpp < prev    next >
Text File  |  1997-07-06  |  2KB  |  79 lines

  1. /* Stéphane Charette, stephane@venus.ubishops.ca
  2.  * IBM Open Class Library Animation Sample #2
  3.  * (using Visual Age C++ v3.0 with OS/2 v4.0)
  4.  * 1997July06
  5.  */
  6.  
  7. /* includes */
  8. #include "ocl_ani2.hpp"    // class definitions
  9.  
  10. // constructor for "people" objects
  11. Person::Person( int rcId, IWindowHandle handle ) :
  12.    IGBitmap( rcId ),
  13.    moveDestination( 0, 0 ),
  14.    canvasHandle( handle )
  15. {
  16.    // save the bitmap id...used when cloning
  17.    bitmapId = rcId;
  18.  
  19.    // variables used when moving the object...for now just reset them
  20.    moveX = 0.0;
  21.    moveY = 0.0;
  22.    moveDX = 0.0;
  23.    moveDY = 0.0;
  24.    moveCount = 0;
  25.    moveTimer = '\0';
  26.  
  27.    // set the transparent background colour
  28.       // Note: since I created the bitmaps (more like modified
  29.       //       existing bitmaps) that are displayed, I know
  30.       //       that the color I intended to make see-through
  31.       //       is pure blue...( 0, 0, 255 ).
  32.    setTransparentColor( IColor( 0, 0, 255 ) );
  33.  
  34.    return;
  35. }
  36.  
  37.  
  38. // destructor for "people" objects
  39. Person::~Person()
  40. {
  41.    // is there an active timer?
  42.    if( moveTimer )
  43.    {
  44.       moveTimer->stop();               // ...stop the timer...
  45.       delete( moveTimer );             // ...delete the timer...
  46.       moveTimer = '\0';                // ...set timer as non-existant
  47.    }
  48.    return;
  49. }
  50.  
  51.  
  52. void Person::animateMove()
  53. {
  54.    if( moveCount == 1 )
  55.    {
  56.       // this is the last call...delete the timer
  57.       moveTimer->stop();
  58.       delete( moveTimer );
  59.       moveTimer = '\0';
  60.    }
  61.  
  62.    // find the current position
  63.    IRectangle rect1 = IRectangle( position(), size() );
  64.  
  65.    moveCount --;                    // decrease count...
  66.    moveX += moveDX;                 // ...find new X...
  67.    moveY += moveDY;                 // ...finx new Y...
  68.    moveTo( IPoint( (int)moveX, (int)moveY ) ); // ...draw
  69.  
  70.    // find the new position
  71.    IRectangle rect2 = IRectangle( position(), size() );
  72.  
  73.    // invalidate rect to force the canvas to redraw
  74.    RECTL rectl = ( rect1 | rect2 ).asRECTL();
  75.    WinInvalidateRect( canvasHandle, &rectl, FALSE );
  76.  
  77.    return;
  78. }
  79.