home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-10 | 4.2 KB | 182 lines |
- import java.awt.*;
- import java.applet.*;
- import com.ms.com.*;
- import com.ms.com.*;
- import com.ms.awt.*;
- import com.ms.awt.peer.*;
- import com.ms.directX.*;
-
- class FlickStretch implements Runnable, ddConstants
- {
- private Thread t;
- private boolean running = true;
-
- private long lastTickCount = 0;
- private int currentFrame = 0;
- private long UpdateDelay = 13;
-
- private dDraw dd; // DirectDraw object
- private ddSurface ddsPrimary; // DirectDraw primary surface
- private ddSurface ddsOne; // Offscreen surface 1
- private Rect toScreen;
- private String szBitmap;
- private Rect rc;
- private Rectangle r;
-
- private ComponentPeerX peer;
-
- //////////////////////////////////////////////////////////////////////////
-
- public FlickStretch(dDraw dx, ddSurface ddsP, ddSurface ddsO, String sz,
- ComponentPeerX p)
- {
- t = new Thread(this);
- t.setPriority(Thread.NORM_PRIORITY);
-
- dd = dx;
- ddsPrimary = ddsP;
- ddsOne = ddsO;
- szBitmap = sz;
- peer = p;
- toScreen = new Rect();
- rc = new Rect();
- r = new Rectangle();
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- public void run()
- {
- while(running)
- updateFrame();
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- public void stop()
- {
- running = false;
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- public void start()
- {
- t.start();
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- //
- // load a bitmap from a file or resource into a DirectDraw surface.
- // normaly used to re-load a surface after a restore.
- //
- boolean ReloadBitmap (ddSurface pdds, String szBitmap)
- {
- dBitmap bm;
-
- bm = new dBitmap();
- bm.filename (szBitmap);
-
- if( bm.loaded() != 0 )
- {
- pdds.CopyBitmap(bm, 0, 0, 0, 0);
- return true;
- }
- else
- return false;
- }
-
- //////////////////////////////////////////////////////////////////////////
- //
- // basically the updateFrame from stretch
- //
- // Decide what needs to be blitted next, wait for flip to complete, then
- // flip the buffers.
- //
-
- void updateFrame()
- {
- long thisTickCount;
- int ddrval;
- Point pt;
- int rcleft;
- int rctop;
- int rcright;
- int rcbottom;
- int done;
-
- thisTickCount = dd.TickCount();
- if((thisTickCount - lastTickCount) > UpdateDelay)
- {
- //
- // Move to next frame;
- //
- lastTickCount = thisTickCount;
- currentFrame++;
- if(currentFrame > 59)
- currentFrame = 0;
-
- // find out where we are on the screen
- peer.GetPlaceOnScreen(r);
- toScreen.Left = r.x;
- toScreen.Top = r.y;
- toScreen.Right = r.x + r.width;
- toScreen.Bottom = r.y + r.height;
-
- //
- // Blit the stuff for the next frame
- //
- rc.Left = currentFrame%10*64;
- rc.Top = currentFrame/10*64;
- rc.Right = currentFrame%10*64+64;
- rc.Bottom = currentFrame/10*64+64;
-
- done = 0;
- do
- {
- //
- // put offset to hwnd in Blt so we dont need ClientToScreen here.
- //
- int retval ;
-
- retval = ddsPrimary.Blt( toScreen, ddsOne, rc, 0);
-
- if( retval == DD_OK)
- done = 1;
-
- else if (retval == DDERR_SURFACELOST)
- {
- if( !restoreAll() )
- {
- //
- // cant restore the surfaces, nothing we can do, quit
- //
- done = 1;
- }
- }
-
- else if( retval != DDERR_WASSTILLDRAWING)
- //
- // undetermined error, quit the loop.
- //
- done = 1;
-
- } while( done == 0);
- }
- }
-
- //////////////////////////////////////////////////////////////////////////
- //
- // restoreAll : restore all lost objects
- //
- boolean restoreAll()
- {
- return ddsPrimary.Restore() == DD_OK &&
- ddsOne.Restore() == DD_OK &&
- ReloadBitmap(ddsOne, szBitmap);
- }
-
- //////////////////////////////////////////////////////////////////////////
- }
-