| 1 |
/* $Id$ */ |
|---|
| 2 |
|
|---|
| 3 |
/* |
|---|
| 4 |
* Copyright (c) 2007 Axel Andersson |
|---|
| 5 |
* All rights reserved. |
|---|
| 6 |
* |
|---|
| 7 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 8 |
* modification, are permitted provided that the following conditions |
|---|
| 9 |
* are met: |
|---|
| 10 |
* 1. Redistributions of source code must retain the above copyright |
|---|
| 11 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 13 |
* notice, this list of conditions and the following disclaimer in the |
|---|
| 14 |
* documentation and/or other materials provided with the distribution. |
|---|
| 15 |
* |
|---|
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 19 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|---|
| 20 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|---|
| 21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|---|
| 22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|---|
| 24 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|---|
| 25 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|---|
| 26 |
* POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 |
*/ |
|---|
| 28 |
|
|---|
| 29 |
#import "SPDrillCell.h" |
|---|
| 30 |
|
|---|
| 31 |
@implementation SPDrillCell |
|---|
| 32 |
|
|---|
| 33 |
- (id)copyWithZone:(NSZone *)zone { |
|---|
| 34 |
SPDrillCell *cell; |
|---|
| 35 |
|
|---|
| 36 |
cell = [super copyWithZone:zone]; |
|---|
| 37 |
cell->_image = [_image retain]; |
|---|
| 38 |
|
|---|
| 39 |
return cell; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
- (void)dealloc { |
|---|
| 45 |
[_image release]; |
|---|
| 46 |
|
|---|
| 47 |
[super dealloc]; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
#pragma mark - |
|---|
| 53 |
|
|---|
| 54 |
- (void)setImage:(NSImage *)image { |
|---|
| 55 |
[image retain]; |
|---|
| 56 |
[_image release]; |
|---|
| 57 |
|
|---|
| 58 |
_image = image; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
- (NSImage *)image { |
|---|
| 64 |
return _image; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
- (NSSize)imageSize { |
|---|
| 70 |
return NSMakeSize(128.0, 128.0); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
#pragma mark - |
|---|
| 76 |
|
|---|
| 77 |
- (NSSize)cellSize { |
|---|
| 78 |
NSSize size; |
|---|
| 79 |
|
|---|
| 80 |
size = [super cellSize]; |
|---|
| 81 |
size.height = 160.0; |
|---|
| 82 |
|
|---|
| 83 |
return size; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
- (void)drawWithFrame:(NSRect)frame inView:(NSView *)view { |
|---|
| 89 |
NSSize imageSize; |
|---|
| 90 |
NSRect imageFrame; |
|---|
| 91 |
|
|---|
| 92 |
if(_image) { |
|---|
| 93 |
imageSize = [self imageSize]; |
|---|
| 94 |
[_image setSize:imageSize]; |
|---|
| 95 |
|
|---|
| 96 |
NSDivideRect(frame, &imageFrame, &frame, 32.0 + imageSize.width, NSMinXEdge); |
|---|
| 97 |
|
|---|
| 98 |
imageFrame.size = imageSize; |
|---|
| 99 |
|
|---|
| 100 |
if ([view isFlipped]) |
|---|
| 101 |
imageFrame.origin.y += ceil((frame.size.height + imageFrame.size.height) / 2.0); |
|---|
| 102 |
else |
|---|
| 103 |
imageFrame.origin.y += ceil((frame.size.height - imageFrame.size.height) / 2.0); |
|---|
| 104 |
|
|---|
| 105 |
[_image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver]; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
frame.origin.y -= 32.0; |
|---|
| 109 |
|
|---|
| 110 |
[super drawWithFrame:frame inView:view]; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
@end |
|---|