ftp.nice.ch/pub/next/graphics/filter/IconBuilderScaleFilter.bs.tar.gz#/IconBuilderScaleFilter/Scale/ProgressView.m

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

/* Copyright (c) 1992 The Geometry Center; University of Minnesota
   1300 South Second Street;  Minneapolis, MN  55454, USA;
 */

#import "ProgressView.h"

@implementation ProgressView

#define STANDARD_UPDATE \
	if (newPercent != percent && newPercent >= 0 && newPercent <= 100) { \
		percent = newPercent; \
		[self displayFromOpaqueAncestor:&bounds :1 :YES]; \
	} \
	NXPing ();

- initFrame:(const NXRect *)frameRect
{
	char path[MAXPATHLEN + 1];
		
	[super initFrame:frameRect];
	
	[self setOpaque:NO];
	[self setAutosizing:NX_NOTSIZABLE];
	
	if ([[NXBundle bundleForClass:[self class]]
		getPath:path forResource:"ProgressDials" ofType:"tiff"]) {
		dials = [[NXImage allocFromZone:[self zone]] initFromFile:path];
		drawMode = COMPOSITE_IMAGE;
	} else
		drawMode = RENDER_POSTSCRIPT;
		
	return self;
}

- free
{
	[dials free];
	return [super free];
}

- reset:sender
{
	int newPercent = 0;
	STANDARD_UPDATE
	return self;
}

- increment:sender
{
	int newPercent = percent + 1;
	STANDARD_UPDATE
    return self;
}

- decrement:sender
{
	int newPercent = percent - 1;
	STANDARD_UPDATE
    return self;
}

- takeDoubleValueFrom:sender
{
	int newPercent = (int)(100. * [sender doubleValue] + .5);
	STANDARD_UPDATE
    return self;
}

- takeFloatValueFrom:sender
{
	int newPercent = (int)(100. * [sender floatValue] + .5);
	STANDARD_UPDATE
    return self;
}

- takeIntValueFrom:sender
{
	int newPercent = [sender intValue];
	STANDARD_UPDATE
    return self;
}

- setRatio:(float)ratio
{
	int newPercent = (int)(100. * ratio + .5);
	STANDARD_UPDATE
	return self;
}

- setRatio:(int)numerator :(int)denominator
{
	int newPercent = -1;
	if (denominator != 0) newPercent = (numerator * 100) / denominator;
	STANDARD_UPDATE
	return self;
}

- setPercent:(int)newPercent
{
	STANDARD_UPDATE
	return self;
}

- drawSelf:(const NXRect *)rects :(int)rectCount
{
	int count, slot, unit, romid, x, y, width, height, depth;
	char string[1024];
	BOOL twoBitOnly = YES;

	PScountframebuffers (&count);
	while (count--) {
		PSframebuffer (count, 1024, string, &slot, &unit, &romid, &x, &y,
			&width, &height, &depth);
		if (depth != NX_TwoBitGrayDepth) {
			twoBitOnly = NO;
			break;
		}
	}
	
	if (twoBitOnly) drawMode = RENDER_POSTSCRIPT;
	
	switch (drawMode) {
	
		case COMPOSITE_IMAGE: {
		
			NXRect source = {0., 0., 48., 48.};
			
			source.origin.x = (NXCoord)(percent % 10) * 48.;
			source.origin.y = (NXCoord)(percent / 10) * 48.;
			[dials composite:NX_SOVER fromRect:&source toPoint:&bounds.origin];
			break;
		}
			
		default: {
		
			float p = (float)percent;
			float radius;
			NXPoint center;
	
			if (bounds.size.width < bounds.size.height)
				radius = bounds.size.width / 2. - 2.;
			else
				radius = bounds.size.height / 2. - 2.;
			center.x = floor (bounds.origin.x + bounds.size.width / 2.) + .5;
			center.y = floor (bounds.origin.y + bounds.size.height / 2.) + .5;
			
			PSsetlinewidth (0.);
			NXSetColor (NX_COLORDKGRAY);
			PSmoveto (center.x, center.y);
			PSarc (center.x, center.y, radius, 90. - 3.6 * p, 90.);
			PSlineto (center.x, center.y);
			PSfill ();
			NXSetColor (NX_COLORBLACK);
			PSmoveto (center.x, center.y);
			PSarc (center.x, center.y, radius, 90. - 3.6 * p, 90. + 360.);
			PSlineto (center.x, center.y);
			PSstroke ();
			break;
		}
	}
	
	return self;
}

@end

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