home *** CD-ROM | disk | FTP | other *** search
- #include "scroller.h"
-
- ImageScroller::ImageScroller()
- {
- AtNorthMost=AtSouthMost=AtEastMost=AtWestMost=FALSE;
- ImageWidth=ImageHeight=x=y=WorldWidth=WorldHeight=ScreenWidth=ScreenHeight=0;
- PixelIncrement=4;
- image=0;
- NumImages=0;
- }
-
- void ImageScroller::Setup( Director* director )
- {
- set_director( director );
- }
-
- boolean ImageScroller::AtMost( Direction dir )
- {
- boolean RetVal=NO;
-
- switch( dir )
- {
- case NORTHWEST:
- RetVal=( x<PixelIncrement && y<PixelIncrement ) ? YES:NO;
- break;
- case NORTH:
- RetVal=(y<PixelIncrement) ? YES:NO;
- break;
- case NORTHEAST:
- RetVal=(y<PixelIncrement && x==WorldWidth-ScreenWidth) ? YES:NO;
- break;
- case WEST:
- RetVal=(x<PixelIncrement) ? YES:NO;
- break;
- case EAST:
- RetVal=(x==WorldWidth-ScreenWidth) ? YES:NO;
- break;
- case SOUTHWEST:
- RetVal=(x<PixelIncrement && y==WorldHeight-ScreenHeight) ? YES:NO;
- break;
- case SOUTH:
- RetVal=(y==WorldHeight-ScreenHeight) ? YES:NO;
- break;
- case SOUTHEAST:
- RetVal=(y==WorldHeight-ScreenHeight && x==WorldWidth-ScreenWidth) ? YES:NO;
- break;
- }
- return RetVal;
- }
-
- void ImageScroller::draw(void)
- {
- // figure the index to the image
- int xIndex=x/ImageWidth;
- int yIndex=y/ImageHeight;
- // figure the remainder of pixels
- int xRemainder=x%ImageWidth;
- int yRemainder=y%ImageHeight;
- // figure number of images to draw
- int hImages=(ScreenWidth+xRemainder)/ImageWidth;
- hImages+=((ScreenWidth+xRemainder)%ImageWidth)!=0 ? 1:0;
- int vImages=(ScreenHeight+yRemainder)/ImageHeight;
- vImages+=((ScreenHeight+yRemainder)%ImageHeight)!=0 ? 1:0;
- // draw them
- int TotalHImages=WorldWidth/ImageWidth;
- int dy=0-yRemainder;
- for( int i=0; i<vImages; i++ )
- {
- int dx=0-xRemainder;
- for( int j=0; j<hImages; j++ )
- {
- show_clipped_image( dx, dy, image[((yIndex+i)*TotalHImages)+xIndex+j] );
- dx+=ImageWidth;
- }
- dy+=ImageHeight;
- }
- }