• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BathyScapheのアイコンセット生成&適用ツール


Commit MetaInfo

Revisãoee4ad1d0cafd697c4081ca8a453974e5ad25a6a7 (tree)
Hora2012-05-28 23:25:12
Autormasakih <masakih@user...>
Commitermasakih

Mensagem de Log

[Mod] マウスオーバーで売れビューの幅が変わるようにした

Mudança Sumário

Diff

--- a/BSCSLastUpdatePreview.h
+++ b/BSCSLastUpdatePreview.h
@@ -10,6 +10,10 @@
1010
1111 @interface BSCSLastUpdatePreview : NSView
1212 {
13+ NSRect _imageRect;
14+ NSTimer *_nobinobiTimer;
15+ NSInteger _nobinobiStatus;
16+
1317 NSImage *_leftImage;
1418 NSImage *_middleImage;
1519 NSImage *_rightImage;
@@ -17,6 +21,8 @@
1721 NSImageCell *imageCell;
1822 NSImageCell *defauleImageCell;
1923 }
24+@property NSRect imageRect;
25+
2026 @property (retain, nonatomic) NSImage *defaultImage;
2127
2228 @property (retain, nonatomic) NSImage *singleImage;
--- a/BSCSLastUpdatePreview.m
+++ b/BSCSLastUpdatePreview.m
@@ -19,8 +19,18 @@
1919 if (self) {
2020 imageCell = [[NSImageCell alloc] initImageCell:nil];
2121 [imageCell setImageAlignment:NSImageAlignLeft];
22+ [imageCell setImageScaling:NSImageScaleNone];
2223 defauleImageCell = [[NSImageCell alloc] initImageCell:nil];
2324 [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];
2434 }
2535
2636 return self;
@@ -36,11 +46,65 @@
3646 [super dealloc];
3747 }
3848
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+
39103 - (void)drawRect:(NSRect)dirtyRect
40104 {
41105 // Drawing code here.
42106 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]);
44108 return;
45109 }
46110 if(self.singleImage) {
@@ -50,8 +114,22 @@
50114 if(self.defaultImage) {
51115 [defauleImageCell drawInteriorWithFrame:[self bounds] inView:self];
52116 }
53-
54117 }
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+
55133 - (NSImage *)defaultImage
56134 {
57135 return [defauleImageCell image];
@@ -59,6 +137,7 @@
59137 - (void)setDefaultImage:(NSImage *)defaultImage
60138 {
61139 [defauleImageCell setImage:defaultImage];
140+ [self updateImageRect];
62141 [self setNeedsDisplay:YES];
63142 }
64143 - (NSImage *)singleImage
@@ -68,12 +147,14 @@
68147 - (void)setSingleImage:(NSImage *)singleImage
69148 {
70149 [imageCell setImage:singleImage];
150+ [self updateImageRect];
71151 [self setNeedsDisplay:YES];
72152 }
73153 - (void)setLeftImage:(NSImage *)leftImage
74154 {
75155 [_leftImage autorelease];
76156 _leftImage = [leftImage retain];
157+ [self updateImageRect];
77158 [self setNeedsDisplay:YES];
78159 }
79160 - (void)setMiddleImage:(NSImage *)middleImage