ftp.nice.ch/pub/next/developer/resources/classes/misckit/MiscKit.1.10.0.s.gnutar.gz#/MiscKit/Palettes/MiscProgressPalette/MiscProgressView.subproj/MiscProgressView.m

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

//
//	MiscProgressView.m -- a simple view class for displaying progress
//		Written originally by Don Yacktman Copyright (c) 1993 by James Heiser.
//				Modified from an example in the NeXT documentation.
//				This file is maintained by James Heiser, jheiser@adobe.com.
//				Version 1.0.  All rights reserved.
//
//		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 "MiscProgressView.h"

@implementation MiscProgressView

- initFrame:(const NXRect *)frameRect
{
	[super initFrame:frameRect];
	bg = NXConvertGrayToColor(NX_LTGRAY);
	fg = NXConvertGrayToColor(NX_DKGRAY);
	bd = NXConvertGrayToColor(NX_BLACK);
	total = MISC_PROGRESS_MAXSIZE;
	stepSize = MISC_PROGRESS_DEFAULTSTEPSIZE;
	count = 0;
	ratio = 0.0;
	return self;
}

- renderBackground
{
	NXSetColor(bg);
	NXRectFill(&bounds);
	return self;
}

- renderBar
{
	if ((ratio > 0) && (ratio <= 1.0)) {
		NXRect r = bounds;
		r.size.width = bounds.size.width * ratio;
		NXSetColor(fg);
		NXRectFill(&r);
	}
	return self;
}

- renderBorder
{
	NXSetColor(bd);
	NXFrameRect(&bounds);
	return self;
}


- drawSelf:(const NXRect *)rects :(int)rectCount
{ // Note from Don on why this -drawSelf: is split up --
// The three separate rendering methods make things a little less efficient,
// but make it a lot easier to subclass and retain parts of the original
// rendering.  I wish NeXT had done something like this with the various
// control classes so that subclasses could override parts of the steps
// in the rendering process...or insert things at certain points in time.
	[self renderBackground];
	[self renderBar];
	[self renderBorder];
	return self;
}

- setStepSize:(int)value
{
	stepSize = value;
	return self;
}

- (int)stepSize { return stepSize; }
- (NXColor)backgroundColor { return bg; }
- (NXColor)foregroundColor { return fg; }
- (NXColor)borderColor { return bd; }

- setBackgroundColor:(NXColor)color
{
	bg = color;
	return self;
}

- setForegroundColor:(NXColor)color
{
	fg = color;
	return self;
}

- setBorderColor:(NXColor)color
{
	bd = color;
	return self;
}

- setProgressForStream:(NXStream*)localStream
{
	[self setRatio:(float)(localStream->buf_ptr-localStream->buf_base) /
				   (float)localStream->buf_size];
	return self;
}

- setRatio:(float)newRatio
{
	if (newRatio > 1.0) newRatio = 1.0;
	if (ratio != newRatio) {
		ratio = newRatio;
		[self display];
	}
	return self;
}


- takeIntValueFrom:sender
{
	int temp = [sender intValue];
	if ((temp < 0) || (temp > total)) return nil;
	count = temp;
	[self setRatio:(float)count/(float)total];
	return self;
}

- increment:sender
{
	count += stepSize;
	[self setRatio:(float)count/(float)total];
	return self;
}

- takeFloatValueFrom:sender
{
	[self setRatio:[sender floatValue]];
	count = ceil(ratio * (float)total);
	return self;
}

- (const char *)getInspectorClassName
{
	return "MiscProgressViewInspector";
}

- clear:sender
{
	count = 0;
	[self setRatio: 0];
	return self;
}


- read:(NXTypedStream *)stream
{
	[super read:stream];
	NXReadTypes(stream, "ii", &total, &stepSize);
	bg = NXReadColor(stream);
	fg = NXReadColor(stream);
	bd = NXReadColor(stream);
	return self;
}

- write:(NXTypedStream *)stream
{
	[super write:stream];
	NXWriteTypes(stream, "ii", &total, &stepSize);
	NXWriteColor(stream, bg);
	NXWriteColor(stream, fg);
	NXWriteColor(stream, bd);
	return self;
}


@end

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