File:  [NeXTSTEP 3.3 examples] / Examples / AppKit / Draw / Rectangle.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:36 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

#import "draw.h"

@implementation Rectangle : Graphic
/*
 * This is the canonical Graphic.
 * It doesn't get much simpler than this.
 *
 * This line is just a stub to get genstrings to generate
 * a .strings file entry for the name of this type of Graphic.
 * The name is used in the Undo New <Whatever> menu item.
 *
 * NXLocalString("Rectangle", NULL, "Name of the tool that draws rectangles, i.e., the %s of the New %s operation.")
 */

+ initialize
/*
 * This bumps the class version so that we can compatibly read
 * old Graphic objects out of an archive.
 */
{
    [Rectangle setVersion:1];
    return self;
}

/* Methods overridden from superclass */

- (float)naturalAspectRatio
/*
 * The natural aspect ratio of a rectangle is 1.0 (a square).
 */
{
    return 1.0;
}

- (Graphic *)colorAcceptorAt:(const NXPoint *)point
{
    if ([self hit:point]) return self;
    return nil;
}

- draw
{
    if (bounds.size.width < 1.0 || bounds.size.height < 1.0) return self;

    if ([self fill]) {
	[self setFillColor];
	NXRectFill(&bounds);
    }
    if (!gFlags.nooutline) {
	[self setLineColor];
	PSrectstroke(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
    }

    return self;
}

@end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.