BathyScapheのアイコンセット生成&適用ツール
Revisão | ee4ad1d0cafd697c4081ca8a453974e5ad25a6a7 (tree) |
---|---|
Hora | 2012-05-28 23:25:12 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
[Mod] マウスオーバーで売れビューの幅が変わるようにした
@@ -10,6 +10,10 @@ | ||
10 | 10 | |
11 | 11 | @interface BSCSLastUpdatePreview : NSView |
12 | 12 | { |
13 | + NSRect _imageRect; | |
14 | + NSTimer *_nobinobiTimer; | |
15 | + NSInteger _nobinobiStatus; | |
16 | + | |
13 | 17 | NSImage *_leftImage; |
14 | 18 | NSImage *_middleImage; |
15 | 19 | NSImage *_rightImage; |
@@ -17,6 +21,8 @@ | ||
17 | 21 | NSImageCell *imageCell; |
18 | 22 | NSImageCell *defauleImageCell; |
19 | 23 | } |
24 | +@property NSRect imageRect; | |
25 | + | |
20 | 26 | @property (retain, nonatomic) NSImage *defaultImage; |
21 | 27 | |
22 | 28 | @property (retain, nonatomic) NSImage *singleImage; |
@@ -19,8 +19,18 @@ | ||
19 | 19 | if (self) { |
20 | 20 | imageCell = [[NSImageCell alloc] initImageCell:nil]; |
21 | 21 | [imageCell setImageAlignment:NSImageAlignLeft]; |
22 | + [imageCell setImageScaling:NSImageScaleNone]; | |
22 | 23 | defauleImageCell = [[NSImageCell alloc] initImageCell:nil]; |
23 | 24 | [defauleImageCell setImageAlignment:NSImageAlignLeft]; |
25 | + [defauleImageCell setImageScaling:NSImageScaleNone]; | |
26 | + | |
27 | + NSTrackingArea *ta = [[NSTrackingArea alloc] initWithRect:frame | |
28 | + options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow | |
29 | + owner:self | |
30 | + userInfo:nil]; | |
31 | + | |
32 | + [self addTrackingArea:ta]; | |
33 | + [self updateImageRect]; | |
24 | 34 | } |
25 | 35 | |
26 | 36 | return self; |
@@ -36,11 +46,65 @@ | ||
36 | 46 | [super dealloc]; |
37 | 47 | } |
38 | 48 | |
49 | +enum { | |
50 | + nobinobiGrow = 0, | |
51 | + nobinobiShrink = 1, | |
52 | +}; | |
53 | + | |
54 | +- (void)nobinobi:(id)timer | |
55 | +{ | |
56 | + CGFloat myWidth = [self bounds].size.width; | |
57 | + NSRect imageRect = self.imageRect; | |
58 | + CGFloat imageWidth = imageRect.size.width; | |
59 | + imageWidth += _nobinobiStatus == nobinobiGrow ? 20 : -20; | |
60 | + if(imageWidth > myWidth) { | |
61 | + imageWidth = myWidth; | |
62 | + _nobinobiStatus = nobinobiShrink; | |
63 | + } | |
64 | + if(imageWidth < 150) { | |
65 | + imageWidth = 150; | |
66 | + _nobinobiStatus = nobinobiGrow; | |
67 | + } | |
68 | + imageRect.size.width = imageWidth; | |
69 | + self.imageRect = imageRect; | |
70 | +} | |
71 | +- (void)mouseEntered:(NSEvent *)theEvent | |
72 | +{ | |
73 | + if(!_leftImage) return; | |
74 | + | |
75 | + _nobinobiTimer = [NSTimer timerWithTimeInterval:0.08 | |
76 | + target:self | |
77 | + selector:@selector(nobinobi:) | |
78 | + userInfo:nil | |
79 | + repeats:YES]; | |
80 | + [[NSRunLoop mainRunLoop] addTimer:_nobinobiTimer | |
81 | + forMode:NSDefaultRunLoopMode]; | |
82 | +} | |
83 | +- (void)mouseExited:(NSEvent *)theEvent | |
84 | +{ | |
85 | + [_nobinobiTimer invalidate]; | |
86 | + _nobinobiTimer = nil; | |
87 | +} | |
88 | + | |
89 | +- (void)updateImageRect | |
90 | +{ | |
91 | + NSImage *current = self.leftImage; | |
92 | + if(!current) current = self.singleImage; | |
93 | + if(!current) current = self.defaultImage; | |
94 | + if(!current) return; | |
95 | + | |
96 | + CGFloat frameHeight = [self frame].size.height; | |
97 | + NSRect currentRect = self.imageRect; | |
98 | + currentRect.size.height = [current size].height; | |
99 | + currentRect.origin.y = (frameHeight - _imageRect.size.height) / 2.0; | |
100 | + self.imageRect = currentRect; | |
101 | +} | |
102 | + | |
39 | 103 | - (void)drawRect:(NSRect)dirtyRect |
40 | 104 | { |
41 | 105 | // Drawing code here. |
42 | 106 | if(_leftImage) { |
43 | - NSDrawThreePartImage([self bounds], _leftImage, _middleImage, _rightImage, NO, NSCompositeSourceOver, 1.0, [self isFlipped]); | |
107 | + NSDrawThreePartImage([self imageRect], _leftImage, _middleImage, _rightImage, NO, NSCompositeSourceOver, 1.0, [self isFlipped]); | |
44 | 108 | return; |
45 | 109 | } |
46 | 110 | if(self.singleImage) { |
@@ -50,8 +114,22 @@ | ||
50 | 114 | if(self.defaultImage) { |
51 | 115 | [defauleImageCell drawInteriorWithFrame:[self bounds] inView:self]; |
52 | 116 | } |
53 | - | |
54 | 117 | } |
118 | + | |
119 | +- (NSRect)imageRect | |
120 | +{ | |
121 | + if(NSEqualRects(NSZeroRect, _imageRect)) { | |
122 | + _imageRect = [self bounds]; | |
123 | + _imageRect.size.height = 100; | |
124 | + } | |
125 | + return _imageRect; | |
126 | +} | |
127 | +- (void)setImageRect:(NSRect)imageRect | |
128 | +{ | |
129 | + _imageRect = imageRect; | |
130 | + [self setNeedsDisplay:YES]; | |
131 | +} | |
132 | + | |
55 | 133 | - (NSImage *)defaultImage |
56 | 134 | { |
57 | 135 | return [defauleImageCell image]; |
@@ -59,6 +137,7 @@ | ||
59 | 137 | - (void)setDefaultImage:(NSImage *)defaultImage |
60 | 138 | { |
61 | 139 | [defauleImageCell setImage:defaultImage]; |
140 | + [self updateImageRect]; | |
62 | 141 | [self setNeedsDisplay:YES]; |
63 | 142 | } |
64 | 143 | - (NSImage *)singleImage |
@@ -68,12 +147,14 @@ | ||
68 | 147 | - (void)setSingleImage:(NSImage *)singleImage |
69 | 148 | { |
70 | 149 | [imageCell setImage:singleImage]; |
150 | + [self updateImageRect]; | |
71 | 151 | [self setNeedsDisplay:YES]; |
72 | 152 | } |
73 | 153 | - (void)setLeftImage:(NSImage *)leftImage |
74 | 154 | { |
75 | 155 | [_leftImage autorelease]; |
76 | 156 | _leftImage = [leftImage retain]; |
157 | + [self updateImageRect]; | |
77 | 158 | [self setNeedsDisplay:YES]; |
78 | 159 | } |
79 | 160 | - (void)setMiddleImage:(NSImage *)middleImage |