ftp.nice.ch/pub/next/games/card/NeXTmille.2.0.s.tar.gz#/NeXTmille-2.0a/HandTileView.m

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

/* Generated by Interface Builder */

#import "HandTileView.h"
#import	<assert.h>


@implementation HandTileView

+ newFrame:( const NXRect * )frameRect
{

	int		i;
	

	self = [ super newFrame:frameRect ];
	for( i = 0; i < ( sizeof( myHand ) / sizeof( CardView * )); ++i )
		myHand[ i ] = nil;
	
	return self;
}


- addCard:( CardView * )aCard :sender
{


	assert( !myHand[ 0 ] );
	myHand[ 0 ] = aCard;
	[ self addSubview:[ aCard setEventsEnabled:reactiveCardsFlag ]];
	
	return [ self _adjustCards ];
}


- removeCard:( CardView * )aCard :sender
{

	int		i;
	

	assert([ aCard isDescendantOf:self ]);
	[ aCard removeFromSuperview ];
	for( i = 0; i < ( sizeof( myHand ) / sizeof( CardView * )); ++i )
		if( myHand[ i ] == aCard )
			myHand[ i ] = nil;

	return [ self _adjustCards ];
}


- _adjustCards
{

	
	if( myHand[ 0 ] ) {
		int			i,
					placementAdjust = 0;
		BOOL		placeMoved = NO;
		NXRect		cardBounds;
		NXCoord		x_offset;
		
												// Try to move the card from the leftmost position
												//	to another position in the hand.
		for( i = 1; !placeMoved && ( i < ( sizeof( myHand ) / sizeof( CardView * ))); ++i )
			if( !myHand[ i ] ) {
				myHand[ i ] = myHand[ 0 ];
				myHand[ 0 ] = nil;
				placementAdjust = i;
				placeMoved = YES;
			}

												// Wherever the card was moved to then calculate and
												//	adjust its position.
		[ myHand[ placementAdjust ] getBounds:&cardBounds ];
		x_offset = ( NX_WIDTH( &bounds ) / HAND_SIZE ) - NX_WIDTH( &cardBounds );
		[ myHand[ placementAdjust ] moveTo:(( x_offset / 2 ) + (( x_offset + NX_WIDTH( &cardBounds )) * placementAdjust )) :(( NX_HEIGHT( &bounds ) - NX_HEIGHT( &cardBounds )) / 2 )];
	}
	
	return self;
}


- sendCard:( CardView * )aCard to:anObject
{

	assert([ aCard isDescendantOf:self ]);
	[ self removeCard:aCard		:self ];
	[ anObject addCard:aCard	:self ];
	
	return self;
}

	 
- sendAllCardsTo:anObject
{

	int		i;
	
	
	for( i = 0; i < ( sizeof( myHand ) / sizeof( CardView * )); ++i )
		if( myHand[ i ])
			[ self sendCard:myHand[ i ] to:anObject ];
		
	return self;
}



@end

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