#define kBallSize 20
Rect gBall = { 100, 100, 100 + kBallSize, 100 + kBallSize };
short gHorizontal = 8;
short gVertical = 10;
WindowPtr gWindow;
void Step( void ) {
EraseOval(&gBall);
gBall.left += gHorizontal;
gBall.top += gVertical;
gBall.right += gHorizontal;
gBall.bottom += gVertical;
if ( gBall.left < 0 || gBall.right > gWindow->portRect.right ) gHorizontal *= -1;
if ( gBall.top < 0 || gBall.bottom > gWindow->portRect.bottom ) gVertical *= -1;
PaintOval(&gBall);
}
void MyDragHook( void ) {
GrafPtr oldPort;
GetPort( &oldPort );
SetPort( gWindow );
Step();
SetPort( oldPort );
}
void main() {
Rect WinBounds = { 50, 30, 200, 200 };
short quit = false;
InitGraf( &thePort );
InitFonts();
FlushEvents( everyEvent, 0 );
InitWindows();
InitMenus();
TEInit();
InitDialogs(0);
InitCursor();
gWindow = NewWindow( 0L, &WinBounds, "\pClose me to exit", true, documentProc, (WindowPtr)-1L, true, 0);
if ( !gWindow ) ExitToShell();
SetPort( gWindow );
EraseRect( &gWindow->portRect );
ForeColor(blackColor);
DragHook = (ProcPtr) MyDragHook;
while ( !quit ) {
EventRecord event;
WindowPtr EventWin;
short ThePart;
if ( WaitNextEvent( everyEvent, &event, 1L, nil ) ) {
ThePart = FindWindow( event.where, &EventWin );
switch ( event.what ) {
case mouseDown:
switch ( ThePart ) {
case inDrag:
DragWindow( EventWin, event.where, &screenBits.bounds );
break;
case inGoAway:
if (TrackGoAway(EventWin, event.where)) quit = true;
break;
}
break;
case updateEvt:
BeginUpdate( (WindowPtr)event.message );
// noop
EndUpdate( (WindowPtr)event.message );
break;
}
} else {
Step();
}
}
}