Fixed: An exception in the Go game if you mouse down on the board but then drag to the captured-pieces area and release the mouse.
1 /* This code is based on Apple's "GeekGameBoard" sample code, version 1.0.
2 http://developer.apple.com/samplecode/GeekGameBoard/
3 Copyright © 2007 Apple Inc. Copyright © 2008 Jens Alfke. All Rights Reserved.
5 Redistribution and use in source and binary forms, with or without modification, are permitted
6 provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this list of
11 conditions and the following disclaimer in the documentation and/or other materials provided
12 with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
17 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
21 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #import "QuartzUtils.h"
31 - (id) copyWithZone: (NSZone*)zone
33 Bit *clone = [super copyWithZone: zone];
34 clone->_owner = _owner;
38 @synthesize owner=_owner;
40 - (BOOL) isFriendly {return _owner.friendly;}
41 - (BOOL) isUnfriendly {return _owner.unfriendly;}
46 NSNumber *scale = [self valueForKeyPath: @"transform.scale"];
47 return scale.floatValue;
50 - (void) setScale: (CGFloat)scale
52 [self setValue: [NSNumber numberWithFloat: scale]
53 forKeyPath: @"transform.scale"];
59 NSNumber *rot = [self valueForKeyPath: @"transform.rotation"];
60 return round( rot.doubleValue * 180.0 / M_PI );
63 - (void) setRotation: (int)rotation
65 [self setValue: [NSNumber numberWithDouble: rotation*M_PI/180.0]
66 forKeyPath: @"transform.rotation"];
72 return self.zPosition >= kPickedUpZ;
75 - (void) setPickedUp: (BOOL)up
77 if( up != self.pickedUp ) {
78 CGFloat shadow, offset, radius, opacity, z, scale;
86 _restingZ = self.zPosition;
88 shadow = offset = radius = 0.0;
96 self.shadowOpacity = shadow;
97 self.shadowOffset = CGSizeMake(offset,-offset);
98 self.shadowRadius = radius;
100 self.opacity = opacity;
106 - (BOOL)containsPoint:(CGPoint)p
108 // Make picked-up pieces invisible to hit-testing.
109 // Otherwise, while dragging a Bit, hit-testing the cursor position would always return
110 // that Bit, since it's directly under the cursor...
114 return [super containsPoint: p];
118 -(id<BitHolder>) holder
120 // Look for my nearest ancestor that's a BitHolder:
121 for( CALayer *layer=self.superlayer; layer; layer=layer.superlayer ) {
122 if( [layer conformsToProtocol: @protocol(BitHolder)] )
123 return (id<BitHolder>)layer;
124 else if( [layer isKindOfClass: [Bit class]] )
133 // "Pop" the Bit by expanding it 5x as it fades away:
136 // Removing the view from its superlayer right now would cancel the animations.
137 // Instead, defer the removal until sometime shortly after the animations finish:
138 [self performSelector: @selector(removeFromSuperlayer) withObject: nil afterDelay: 1.0];