next up previous contents
Next: Examples of calculations with Up: RECView.m program listing Previous: browser delegate methods

View methods

There are several methods which the programmer must supply to create or modify the content of a View. Which ones are needed and their complexity depends on the intricacy of the planned view. The most essential methods are:

Beyond these essentials there are other possibilities, such as assigning a delegate.

/* = = = = = = = = = = = = = =   R E C V I E W   = = = = = = = = = = = = = */

- initFrame:(const NXRect *)frameRect
/*
 * Initializes the new RECView object.  First, an initFrame: message is sent 
 * to super to initialize RECView as a View.  Next, the RECView sets its own 
 * state -- that it is opaque and that the origin of its coordinate system 
 * lies in the center of its area.  
 */
{	
	[super initFrame:frameRect];
	[self setOpaque:YES];
	[self translate:floor(frame.size.width/2) :floor(frame.size.height/2)];
	return self;
}

- drawSelf:(const NXRect *)rects :(int)rectCount
/*
 * Draws the RECView's background and axes.  If there are any points,
 * these are drawn too.
 */
{	
	if (rects == NULL) return self;

//	PSsetgray(NX_WHITE);
	PSsetgray(NX_LTGRAY);
	if (drawBack) NXRectFill(&rects[0]);
	PSsetgray(NX_DKGRAY);
//	PSsetgray(NX_BLACK);

		    plev=0;
		    isErrm=FALSE;
		    [RECValue setStringValue: "*"];
		    if (rec(cstr)) [RECValue setStringValue: "T"];
		              else [RECValue setStringValue: "F"];
		    if (isErrm) {[comment setStringValue: errm]; isErrm=FALSE;}
		    PSstroke();

	return self;
}

- sizeTo:(NXCoord)width :(NXCoord)height
/*
 * Ensures that whenever the RECView is resized, the origin of its 
 * coordinate system is repositioned to the center of its area.
 */
{
	[super sizeTo:width :height];
	[self setDrawOrigin:-floor(width/2) : -floor(height/2)]; 

	return self;
}

@end



Microcomputadoras
2001-02-12