ftp.nice.ch/pub/next/games/board/Ergo.NIHS.bs.tar.gz#/Ergo/Proper_Ending/AbstractSquare.m

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

#import "AbstractSquare.h"

@implementation AbstractSquare

- (short) column {
    return column;
}

- (short) distanceTo: otherSquare {
    return MAX(ABS([self  row ]  - [otherSquare  row ]),
	       ABS([self column] - [otherSquare column]));
}

- drawSelf: (const NXRect *) rects : (int) rectCount {
    [super drawSelf: rects : rectCount];
    NXDrawGrayBezel(&bounds, rects);
    if ([self isHighlighted])
	[self highlight: rects];
    return self;
}

- (BOOL) isHighlighted {
    return isHighlighted;
}

- mouseExited: (NXEvent *) theEvent {
    if ([self isHighlighted])
	[self setIsHighlighted: NO];
    return self;
}

- (short) row {
    return row;
}

- setIsHighlighted: (BOOL) state {
    if (isHighlighted = state)
	[NXApp setHighlightedSquare: self];
    return [self display];
}

/* Private methods: */

- appDidInit {
    return [self appDidInitInside: NO];
}

- appDidInitInside: (BOOL) state {
    return [self setTrackingRect: &frame inside: state];
}

- become: newSquareClass {
    BOOL  wasHighlighted = [self isHighlighted];
    id    theSuperView = [self superview];
    id    newSquare = [[newSquareClass alloc] initFrame: &frame];

    [[[self freeTrackingRect] removeFromSuperview] free];
    [theSuperView addSubview: newSquare];
    return [newSquare appDidInitInside: wasHighlighted];
}

- free {
    if ([self isHighlighted])
	[NXApp setHighlightedSquare: nil];
    return [super free];
}

- freeTrackingRect {
    if (trackingRectNumber > 0)
	[[self window] discardTrackingRect: trackingRectNumber];
    return self;
}

#define INSET  2
#define WIDTH  7

- highlight: (const NXRect *) aRect {
    NXRect  theRect = *aRect;

    NXInsetRect(&theRect, INSET, INSET);
    PSsetgray(NX_DKGRAY);
    NXFrameRectWithWidth(&theRect, WIDTH);
    return self;
}

- initFrame: (const NXRect *) frameRect {
    [super initFrame: frameRect];	/* the below only works with small */
    row    = frameRect->origin.y / frameRect->size.height; 	/* borders */
    column = frameRect->origin.x / frameRect->size.width;
    return self;
}

- setTrackingRect: (const NXRect *) aRect inside: (BOOL) state {
    static int  rectNumber = 1;
    NXRect      winRect = *aRect;

    trackingRectNumber = rectNumber;
    [[self superview] convertRect: &winRect toView: nil];
    [[self window] setTrackingRect: &winRect
		   inside: state	/* cursor is inside/outside rect */
		   owner: self tag: rectNumber++ left: NO right: NO];
    return self;
}

@end

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