This is Square.m in view mode; [Download] [Up]
#include <sys/types.h> #include <sys/time.h> #import <appkit/appkit.h> #import "Square.h" @implementation Square : Cell /* This class represents one square on a chess board. It has a color and may contain a piece. */ - free { if( icon ) free( icon ); [super free]; } - (int)type { return type; } - setIcon: (char const *)i { if( icon ) free( icon ); if( !i ){ icon = 0; return self; } icon = (char *)malloc( strlen(i) + 1 ); strcpy( icon, i ); } - (char const *)icon { return icon; } - setBackground: (float) b { background = b; } - drawSelf:(const NXRect *)f inView: v { PSsetgray( background ); PSrectfill( f->origin.x, f->origin.y, f->size.width, f->size.height ); [self drawInside: f inView: v]; } - drawBackground:(const NXRect *)f inView: v { PSsetgray( background ); PSrectfill( f->origin.x, f->origin.y, f->size.width, f->size.height ); } - highlight: (const NXRect *)f inView: v { struct timeval timeout; NXInsetRect( f, 1.0, 1.0 ); PSgsave(); PSsetlinewidth( 2.0 ); PSsetgray( NX_WHITE ); PSrectstroke ( f->origin.x, f->origin.y, f->size.width, f->size.height ); /*** PSmoveto( f->origin.x, f->origin.y ); PSrlineto( f->size.width, 0.0 ); PSrlineto( 0.0, f->size.height ); PSrlineto( -1.0 * f->size.width, 0.0 ); PSclosepath(); PSstroke(); ***/ // PSflushgraphics(); NXPing(); timeout.tv_sec = 0; timeout.tv_usec = 150000; select( 0, 0, 0, 0, &timeout ); PSsetgray( NX_BLACK ); PSrectstroke ( f->origin.x, f->origin.y, f->size.width, f->size.height ); /*** PSmoveto( f->origin.x, f->origin.y ); PSrlineto( f->size.width, 0.0 ); PSrlineto( 0.0, f->size.height ); PSrlineto( -1.0 * f->size.width, 0.0 ); PSclosepath(); PSstroke(); ***/ // PSflushgraphics(); NXPing(); timeout.tv_sec = 0; timeout.tv_usec = 150000; select( 0, 0, 0, 0, &timeout ); PSsetgray( NX_WHITE ); PSrectstroke ( f->origin.x, f->origin.y, f->size.width, f->size.height ); /*** PSmoveto( f->origin.x, f->origin.y ); PSrlineto( f->size.width, 0.0 ); PSrlineto( 0.0, f->size.height ); PSrlineto( -1.0 * f->size.width, 0.0 ); PSclosepath(); PSstroke(); ***/ // PSflushgraphics(); NXPing(); timeout.tv_sec = 0; timeout.tv_usec = 150000; select( 0, 0, 0, 0, &timeout ); PSsetgray( background ); PSrectstroke ( f->origin.x, f->origin.y, f->size.width, f->size.height ); /*** PSmoveto( f->origin.x, f->origin.y ); PSrlineto( f->size.width, 0.0 ); PSrlineto( 0.0, f->size.height ); PSrlineto( -1.0 * f->size.width, 0.0 ); PSclosepath(); PSstroke(); ***/ // PSflushgraphics(); NXPing(); PSgrestore(); } - drawInside:(const NXRect *)r inView:v /* Draw the chess piece. */ { NXPoint p; NXSize s; id bitmap; char temp[1024]; if( !icon ) return; /* Composite the piece icon in the center of the rect. */ bitmap = [NXImage findImageNamed: icon]; if (!bitmap){ [[NXBundle mainBundle] getPath: temp forResource: icon ofType: "tiff"]; bitmap = [[NXImage alloc] initFromFile: temp]; if (bitmap) [bitmap setName: icon]; } [bitmap getSize: &s]; p.x = floor(((r->size.width - s.width) / 2.0) + r->origin.x); p.y = floor(((r->size.height - s.height) / 2.0) + r->origin.y); [bitmap composite: NX_SOVER toPoint: &p]; return self; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.