ftp.nice.ch/Attic/openStep/developer/resources/MiscKit.2.0.5.s.gnutar.gz#/MiscKit2/Temp/MiscProgressPalette2/MiscProgressView.subproj/MiscProgressPie.m

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

//
//	MiscProgressPie.m -- a simple view class for displaying a pie
//		Written and Copyright (c) 1993 by James Heiser.  (jheiser@adobe.com)
//				Rendering code massaged by Don Yacktman.
//				Version 1.0.  All rights reserved.
//
//		OPENSTEP conversion and mods:  Todd Anthony Nathan <todd@thoughtful.com>
//
//		This notice may not be removed from this source code.
//
//	This object is included in the MiscKit by permission from the author
//	and its use is governed by the MiscKit license, found in the file
//	"LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
//	for a list of all applicable permissions and restrictions.
//	

#import "MiscProgressPie.h"

@implementation MiscProgressPie

- initWithFrame:(NSRect)frameRect
{
	[super initWithFrame:frameRect];

	pb = [[self backgroundColor] retain];  // pie color
	[self setHidden:NO];

	return ( self );
}


- (void) dealloc
{
	[pb release];
	[super dealloc];

	return;
}


- (void) renderBackground
{
	if ( [self isHidden] ) {
		return;
	}

	[super renderBackground];

	// Fill in the circle portion (pie background) first ...
	PSmoveto (NSWidth([self bounds]) / 2.0,
			NSHeight([self bounds]) / 2.0);
	PSarc (NSWidth([self bounds]) / 2.0,
			NSHeight([self bounds]) / 2.0,
			NSHeight([self bounds]) / 2.0,
			0, 360);
	PSclosepath ();
	[pb set];
	PSfill();

	return;
}


- (void) renderBar
{
	float angle;

	if ([self isHidden] || (ratio <= 0.0)) {
		return;
	}

	angle = 90.0;

	if (ratio >= 1.0)  {
		angle = -270.0;
	}
	if (ratio < 1.0 && ratio > 0.0) {
		angle = 90.0 - 360.0 * ratio;
	}

	PSmoveto (NSWidth([self bounds]) / 2.0,
			NSHeight([self bounds]) / 2.0);
	PSarcn (NSWidth([self bounds]) / 2.0,
			NSHeight([self bounds]) / 2.0,
			NSHeight([self bounds]) / 2.0,
			90.0,
			angle);
	PSclosepath ();
	[fg set];
	PSfill();

	return;
}

- (void) renderBorder
{
	float angle;

	if ([self isHidden]) return;

	angle = 90.0;
	[bd set];
	PSarc (([self bounds].size.width / 2), ([self bounds].size.height / 2),
			([self bounds].size.height / 2), 0.0, 360.0);
	PSstroke();
	if (ratio >= 1.0) {
		angle = -270.0;
	}
	if ((ratio < 1.0) && (ratio > 0.0)) {
		angle = 90.0 - 360.0 * ratio;
	}

	PSmoveto (NSWidth([self bounds]) / 2.0, NSHeight([self bounds]) / 2.0);
	PSarcn (NSWidth([self bounds]) / 2.0, NSHeight([self bounds]) / 2.0,
			NSHeight([self bounds]) / 2.0, 90.0, angle);

	PSclosepath();
	PSstroke();

	return;
}


- (void) setPieBackgroundColor:(NSColor *)newPieBackgroundColor
{
	if ( pb != newPieBackgroundColor ) {
		id	tmp;
		tmp = newPieBackgroundColor;
		pb = [newPieBackgroundColor retain];
		[tmp release];
	}

	return;
}


- (NSColor *)pieBackgroundColor
{
	return ( pb );
}


- (void) setHidden:(BOOL)aBool
{
	isHidden = aBool;
	return;
}


- (BOOL) isHidden
{
	return ( isHidden );
}


- (id) initWithCoder:(NSCoder *)aDecoder
{
	[super initWithCoder:aDecoder];
	[aDecoder decodeValuesOfObjCTypes:"c", &isHidden];
	pb = [[aDecoder decodeObject] retain];  // Brings in the Pie Background Color

	return ( self );
}


- (void) encodeWithCoder:(NSCoder *)aCoder
{
	[super encodeWithCoder:aCoder];
	[aCoder encodeValuesOfObjCTypes:"c", &isHidden];
	[aCoder encodeObject:pb];  // Save out the Pie Background Color

	return;
}


- (NSString *) inspectorClassName
{
     return @"MiscProgressPieInspector";
}


@end

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