1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Source/BitHolder.h Fri Mar 07 11:43:02 2008 -0800
1.3 @@ -0,0 +1,73 @@
1.4 +/* This code is based on Apple's "GeekGameBoard" sample code, version 1.0.
1.5 + http://developer.apple.com/samplecode/GeekGameBoard/
1.6 + Copyright © 2007 Apple Inc. Copyright © 2008 Jens Alfke. All Rights Reserved.
1.7 +
1.8 + Redistribution and use in source and binary forms, with or without modification, are permitted
1.9 + provided that the following conditions are met:
1.10 +
1.11 + * Redistributions of source code must retain the above copyright notice, this list of conditions
1.12 + and the following disclaimer.
1.13 + * Redistributions in binary form must reproduce the above copyright notice, this list of
1.14 + conditions and the following disclaimer in the documentation and/or other materials provided
1.15 + with the distribution.
1.16 +
1.17 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
1.18 + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
1.19 + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
1.20 + BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1.21 + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1.22 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1.23 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
1.24 + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.25 +*/
1.26 +#import <Quartz/Quartz.h>
1.27 +@class Bit;
1.28 +
1.29 +
1.30 +/** Protocol for a layer that acts as a container for Bits. */
1.31 +@protocol BitHolder <NSObject>
1.32 +
1.33 +/** Current Bit, or nil if empty */
1.34 +@property (retain) Bit* bit;
1.35 +
1.36 +/** Conveniences for comparing self.bit with nil */
1.37 +@property (readonly, getter=isEmpty) BOOL empty;
1.38 +
1.39 +/** BitHolders will be highlighted while the target of a drag operation */
1.40 +@property BOOL highlighted;
1.41 +
1.42 +
1.43 +/** Tests whether the bit is allowed to be dragged out of me.
1.44 + Returns the input bit, or possibly a different Bit to drag instead, or nil if not allowed.
1.45 + Either -cancelDragBit: or -draggedBit:to: must be called next. */
1.46 +- (Bit*) canDragBit: (Bit*)bit;
1.47 +
1.48 +/** Cancels a pending drag (begun by -canDragBit:). */
1.49 +- (void) cancelDragBit: (Bit*)bit;
1.50 +
1.51 +/** Called after a drag finishes. */
1.52 +- (void) draggedBit: (Bit*)bit to: (id<BitHolder>)dst;
1.53 +
1.54 +
1.55 +/** Tests whether the bit is allowed to be dropped into me.
1.56 + Either -willNotDropBit: or -dropBit:atPoint: must be called next. */
1.57 +- (BOOL) canDropBit: (Bit*)bit atPoint: (CGPoint)point;
1.58 +
1.59 +/** Cancels a pending drop (after -canDropBit:atPoint: was already called.) */
1.60 +- (void) willNotDropBit: (Bit*)bit;
1.61 +
1.62 +/** Finishes a drop. */
1.63 +- (BOOL) dropBit: (Bit*)bit atPoint: (CGPoint)point;
1.64 +
1.65 +@end
1.66 +
1.67 +
1.68 +/** A basic implementation of the BitHolder protocol. */
1.69 +@interface BitHolder : CALayer <BitHolder>
1.70 +{
1.71 + @protected
1.72 + Bit *_bit;
1.73 + BOOL _highlighted;
1.74 +}
1.75 +
1.76 +@end