home *** CD-ROM | disk | FTP | other *** search
-
- /* Generated by Interface Builder */
-
- #import "BounceView.h"
- #import <appkit/Form.h>
- #import <dpsclient/wraps.h>
- #import "ball.h"
- #import <appkit/Application.h>
-
-
- @implementation BounceView
-
- void update (teNum, now, myself)
- DPSTimedEntry teNum;
- double now;
- id myself;
- {
- [myself doTimedEntry];
- }
-
- +newFrame:(const NXRect *)tF {
- self = [super newFrame:tF];
- ballRadius = 8.0;
- ballDiameter = ballRadius*2.0;
- x = bounds.size.width/2.0;
- y = bounds.size.height/2.0;
- speed = 3.0; /* default speed in pixels per 1/10 second */
- Xdirection = Ydirection = 1.0; /* +1 is right to left, bottom to top */
- return self;
- }
-
- - start:sender
- {
- clockTE = DPSAddTimedEntry(0.1, &update, self, NX_MODALRESPTHRESHOLD);
- return self;
- }
-
- - stop:sender
- {
- DPSRemoveTimedEntry (clockTE);
- return self;
- }
-
- - doTimedEntry
- {
- static float localCounter;
- x += speed*Xdirection;
- y += speed*Ydirection;
- if (x > bounds.size.width-ballRadius) Xdirection = -1.0;
- if (x < ballRadius) Xdirection = 1.0;
- if (y > bounds.size.height-ballRadius) Ydirection = -1.0;
- if (y < ballRadius) Ydirection = 1.0;
- [self display];
- return self;
- }
-
- // Good programming practice. Free what you create!
- - free
- {
- [self stop:self];
- return [super free];
- }
-
- - speed:sender
- {
- speed = [sender floatValue];
- [self display];
- return self;
- }
-
-
- - drawSelf:(NXRect*)r :(int)c
- {
- NXEraseRect(&bounds);
- // PSsetgray(NX_BLACK);
- doBall(x, y, ballRadius);
- return self;
- }
-
-
- @end
-