This is StatusView.m in view mode; [Download] [Up]
// StatusView.m
// Part of Risk by Mike Ferris
#import "StatusView.h"
#import <appkit/TextFieldCell.h>
#import <appkit/Font.h>
#import <appkit/Text.h>
#import <dpsclient/psops.h>
#import "GameSetup.h"
#import "CardManager.h"
#import "DefaultManager.h"
#import "Mover.h"
@implementation StatusView
+ initialize
{
if (self == [StatusView class]) {
[self setVersion:1];
}
return self;
}
- initFrame:(NXRect *)r
{
self = [super initFrame:r];
[self setFlipped:YES];
myTextCell = [[TextFieldCell allocFromZone:[self zone]] init];
[myTextCell setBackgroundGray:NX_LTGRAY];
[myTextCell setBezeled:NO];
[myTextCell setBordered:NO];
[myTextCell setFont:[Font newFont:"Helvetica" size:10.0]];
[myTextCell setAlignment:NX_CENTERED];
[myTextCell setEditable:NO];
[myTextCell setSelectable:NO];
[myTextCell setTextGray:NX_BLACK];
return self;
}
- free
{
[myTextCell free];
return [super free];
}
#define INTERSPACE 5.0
#define TEXTWIDTH 10.0
#define TEXTHEIGHT 15.0
#define INSET 5.0
- drawSelf:(NXRect *)rects :(int)rectCount
{
int numPlayers = [theGameSetup numberOfPlayers];
int p = [theMover currentPlayer];
NXCoord boxHeight, boxWidth;
NXRect boxRect, textRect;
int i, offset;
PSsetgray(NX_LTGRAY);
PSrectfill(bounds.origin.x, bounds.origin.y,
bounds.size.width, bounds.size.height);
if ((numPlayers == 0) | (![theMover isGameInProgress])) {
return self;
}
boxHeight = (bounds.size.height-((numPlayers+1)*INTERSPACE)) / numPlayers;
boxWidth = (bounds.size.width-(3*INTERSPACE)) - TEXTWIDTH;
boxRect.origin.x = INTERSPACE;
boxRect.size.width = boxWidth;
boxRect.size.height = boxHeight;
textRect.origin.x = (INTERSPACE*2)+boxWidth;
textRect.size.width = TEXTWIDTH;
textRect.size.height = TEXTHEIGHT;
offset=0;
for (i=0;i<6;i++) {
if ([theGameSetup strategyOfPlayer:(i+p)%6]!=S_NOTPLAYING) {
// draw his entry
boxRect.origin.y = ((offset+1) * INTERSPACE) +
(offset * boxHeight);
NXDrawWhiteBezel(&boxRect, &bounds);
NXSetColor([theGameSetup colorOfPlayer:(i+p)%6]);
PSrectfill(boxRect.origin.x+INSET, boxRect.origin.y+INSET,
boxRect.size.width-(2*INSET),
boxRect.size.height-(2*INSET));
textRect.origin.y = ((offset+1) * INTERSPACE) +
(offset * boxHeight) +
((boxHeight-TEXTHEIGHT)/2);
if (([theDefaultManager statusShowSets]) &&
([theCardManager canPlayerPlay:(i+p)%6])) {
[myTextCell setTextGray:NX_WHITE];
} else {
[myTextCell setTextGray:NX_BLACK];
}
[myTextCell setIntValue:[theCardManager
numCardsForPlayer:(i+p)%6]];
[myTextCell drawSelf:&textRect inView:self];
offset++;
}
}
return self;
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.