This is RoachesView.h in view mode; [Download] [Up]
/* RoachesView is Copyright 1994 by Brian Hill <bhill@physics.ucla.edu>. */
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* RoachesView.h: RoachesView is a BackSpace module inspired by xroach.
*
* In particular, roaches should scurry under other
* application's windows when the light comes on
* (i.e. when the screensaver goes off). For this
* behavior to be observable, the module must be
* run as a background as well as a screensaver.
*
* General organization: Each Roach is responsible for its own animation and
* drawing (although the Roaches share an NXImage array). The Roach has the
* id of the RoachesView, and it finds out whether a new position is ok
* (inside the window bounds and not to close to any other Roaches) and
* whether it is exposed by messaging the RoachesView.
*
* So that the Roaches can hide under the windows of other applications,
* the RoachesView maintains a client side copy of NXRect's and window numbers
* for all of the windows in the window server's screenlist. Commands needed
* to test whether a Roach is exposed do not exist on the server side,
* and even if they did, if they were as slow as findwindow, their execution
* would bog down the animation. positionExposed:: does the client side test.
*
* If the RoachesView is resized and a Roach finds itself out of bounds,
* it is repositioned. Thus going to smaller windows corrals the Roaches.
*
* Conversely, going from a smaller window to a larger window, one will find
* the Roaches initially clustered around the lower left part of the larger
* window.
*
* 3/21/94 Alpha release. --Brian Hill <bhill@physics.ucla.edu>
* 3/22/94 Makefile.postamble only worked in NS 3.2. Inserted Jonathan
* Flynn's <jflynn@skippy.phys.soton.ac.uk> patch for NS 3.1 and 3.0.
* 4/5/94 Preserved user's background color preference any time
* the RoachesView is not on top of the screenList (i.e., not
* serving as a screensaver). Also, made roach color user-selectable
* Beta release.
* 4/6/94 Changed to unbuffered windows. Offscreen composition in NXImage to
* reduce flicker. Changed drawing commands to user paths. Coordinate
* transformations are now done on client side. Still too slow :(
* 4/7/94 Reduced number of possible Roach angles to RESOLUTION. Introduced
* sharedImages array.
* 4/8/94 Added PSsetexposurecolor() to work around window server's failure to
* promptly flush events that would trigger RoachesView drawSelf::.
* Thanks Scott Hess <scott@nic.gac.edu>!
* 4/11/94 Improved roach-roach avoidance. Introduced imageClean flags. Fixed
* compositing when user's background is textured.
* Release Version 1.0 multiple-architecture binary.
* 4/12/94 Added Copyright notices so I feel more comfortable about
* e-mailing source to requestors.
* 4/21/94 Overrode fillBoundsWithBlack to reduce flicker when first drawing in
* a full-screen window. See SpaceView.m comment reproduced below.
* 4/24/94 Finished Pacemaker and combined all update method
* PostScript code into a single wrap. Background color bug fixed.
* RoachesView now cleans up exposure color by implementing
* removeFromSuperview.
* 7/9/94 Hacked Pacemaker doze method to try to isolate oversleeping bug.
* 10/14/94 Announced tri-fat version.
*
* To do:
*
* Optimize client side code.
*
* Set exposure color back to black before leaving background window,
* or other modules get the user's background color as their exposure color.
*
* Improve "artwork."
*
* Makefile.postamble is still less than satisfactory. (My fault, not
* Jonathan's.) Renaming of object module to .BackO extension shouldn't
* wait until make install. It should occur after make with no explicitly
* listed target, and after make debug.
*
* Think about alternative times for checking things that shouldn't change too
* often. Currently all those checks are stuffed into drawSelf:: (which the
* window server is not always logical about calling).
*/
#import <appkit/appkit.h>
#import "Pacemaker.h"
#ifdef DEBUG
/* #define TIMING */
#endif
/* Number of possible angles Roach can point in. Defined here rather than
* in Roach.h for use in sharedImages below. */
#define RESOLUTION 64
/* RESOLUTION affects Roach behavior. See comment in Roach oneStep method. */
/* The following defines are only used in case the user doesn't have the
* relevant defaults. In any case, the nib's initial values (for the sliders
* and the colorWell are irrelevant. */
#define SPEED_STRING "10"
#define NUMBER_STRING "10"
#define ROACH_RED (80.0f/256.0f)
#define ROACH_GREEN (24.0f/256.0f)
#define ROACH_BLUE (24.0f/256.0f)
#define COLORROACHCOLOR NXConvertRGBToColor(ROACH_RED, ROACH_GREEN, ROACH_BLUE)
typedef struct _windowRectangle {
NXRect rectangle;
int number;
struct _windowRectangle *next;
} windowRectangle;
// The following protocol eliminates the need for the BackSpace's Thinker.h.
@protocol ThinkerProtocol
- (const char *)moduleDirectory:(const char *)name;
@end
@interface RoachesView:View
{
id inspector;
id roachList;
id speedSlider;
id numberSlider;
id speedField;
id numberField;
id colorWell;
id pacemaker;
int speed, scaledSpeed;
DPSContext ctxt;
BOOL imageClean[RESOLUTION];
NXImage *sharedImages[RESOLUTION];
NXPoint roachesViewOffset;
int currentWindowNumber;
int next; /* The index in the screenlist of the of the next window
rectangle to update. */
windowRectangle *windowRectangles, *lastWindowRectangle;
NXZone *roachZone;
BOOL sizeInvalid; /* RoachesView has been resized; reposition Roaches. */
NXColor backgroundColor, roachesColor;
#ifdef TIMING
NXStream *stderrStream;
id timer0, timer1, timer2, timer10, timer11, timer12, timer3;
#endif
}
- takeSpeedFrom:sender;
- takeNumberFrom:sender;
- takeColorFrom:sender;
- (NXColor)backgroundColor;
- (float)scaledSpeed;
- initFrame:(const NXRect *)frameRect;
- readBackgroundColor;
- readRoachesColor;
- readRoachesSpeed;
- (unsigned)readRoachesNumber;
- (BOOL *)imageClean;
- (NXImage **)sharedImages;
- clearSharedImages;
- (BOOL)useBufferedWindow;
- addRoach;
- deleteRoach:roachGettingDeleted;
- free;
- oneStep;
- (BOOL)okPosition:(const NXPoint *)position :(NXCoord)size;
- (int)positionExposed:(const NXPoint *)position :(NXCoord)size;
- drawSelf:(const NXRect *)rects :(int)rectCount;
- removeFromSuperview;
- sizeTo:(NXCoord)width :(NXCoord)height;
- inspector:sender;
- (const char *)windowTitle;
- fillBoundsWithBlack;
@end
/* Comment from SpaceView.m: */
//@implementation View(nonretainedFillMethod)
// I add this method as a category of View to be sure that all
// my views implement it. I really want to use nonretained windows
// but they are drawn via drawSelf at all kinds of goofy times. It
// seems like the kit kind of throws up its hands when it doesn't have
// a buffer to draw from, so you get a lot more drawSelfs than you need,
// and sometimes you don't get them when you really want them. I know
// when I need the background filled in black, so I factor that out of
// my drawSelf and then drawself only draws things that are already on
// screen so you don't see it happen. I will only call this method on
// a nonretained (and full screen) window.
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.