ftp.nice.ch/pub/next/developer/objc/threads/Multi.s.tar.gz#/Multi/CircleView.m

This is CircleView.m in view mode; [Download] [Up]

/*-------------------------------------------------------------------------------
   A simple View subclass that draws a series of circles.  The list of
	 circles to be drawn is kept in a Storage object; we just run down
	 the list, drawing them.
	 
	 HISTORY:
	 	
			10Oct93	DM	New
-------------------------------------------------------------------------------*/

#import "CircleView.h"

@implementation CircleView

- initFrame															// Designated initializer for View
	:(const NXRect*)frameRect;
{
  /*-------------------------------------------------------------------
	   The designated initializer for Views.  We take this opportunity
		 to initialize our Storage object.
	-------------------------------------------------------------------*/
	
	self = [super initFrame:frameRect];
	
	circleList = [[Storage alloc] initCount:0
																elementSize:(sizeof(NXPoint) + sizeof(double)) 
																description:"{dd}d"];
	return self;
}
	
- addCircleAt														// Add a circle to the display list
	:(NXPoint)pPoint											// INPUT: the center of the circle
		withRadius:(double)pRadius;					// INPUT: the radius of the circle
{
  /*-------------------------------------------------------------------
	   We get passed in one circle, and it gets added to a display list.
		 This lets us redraw and get all the old circles if we want.
		 
		 CircleList should probably be called something else.  It's a 
		 Storage object, not a List.  We should probably also lock-focus
		 and draw the new circle directly; this would prevent having to
		 draw all the circles in the list just to add one new one.
	-------------------------------------------------------------------*/
	circle	aCircle;
	
	aCircle.center = pPoint;
	aCircle.radius = pRadius;
	
	[circleList addElement:&aCircle];
	
	return self;
}

- emptyCircles;													// Remove all the circles from the display list
{
  [circleList empty];
	return self;
}

- drawSelf
		:(const NXRect *)rects 
		:(int)rectCount;
{
  /*-------------------------------------------------------------------
	   The quintessential View method.  Draws all the circles in the 
		 display list.
		 
		 This is not particularly rapid.  A pswrap would speed things
		 up appreciably.  Being smarter about how this is drawn would
		 help a lot too.  In fact, this is a pretty bad example of a
		 drawSelf: method.
	-------------------------------------------------------------------*/
	int			i;
	circle	*thisCircle;
	
		// lay down the background
		
	PSsetgray(NX_LTGRAY);								// Wipe out the current contents by filling the view w/ lt. grey
	NXRectFill(&rects[0]);	
	
	PSsetgray(NX_BLACK);								// Draw a rectangle to frame the view
	NXFrameRect(&rects[0]);
		
		// Loop through the list of Circles, drawing them one-by-one.
		// This would be significantly sped up with a pswrap.
		
	for(i = 0; i < [circleList count]; i++)
		{
			thisCircle = [circleList elementAt:i];
			
			PSnewpath();
			PSarc(thisCircle->center.x, thisCircle->center.y, thisCircle->radius, 0, 360);
			PSstroke();
		}
	
	return self;
}
	

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.