Revision: 15247
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=15247&view=rev
Author: hofman
Date: 2009-04-30 17:08:54 +0000 (Thu, 30 Apr 2009)
Log Message:
-----------
Animate alpha of arrow buttons, copied from Adam's tree
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.h
2009-04-30 14:34:10 UTC (rev 15246)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.h
2009-04-30 17:08:54 UTC (rev 15247)
@@ -58,6 +58,16 @@
@param anArrowDirection Whether the arrow points left or right.
@return An initialized cell. */
- (id)initWithArrowDirection:(FVArrowDirection)anArrowDirection;
+
+/** @brief Draw with alpha blending.
+
+ Draws the cell in a view with transparency; useful for animating.
+
+ @param frame Passed to drawWithFrame:inView:
+ @param controlView Passed to drawWithFrame:inView:
+ @param alpha 1.0 for opaque, 0.0 for transparent. */
+- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView
alpha:(CGFloat)alpha;
+
@end
/** @typedef NSUInteger FVArrowDirection
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.m
2009-04-30 14:34:10 UTC (rev 15246)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVArrowButtonCell.m
2009-04-30 17:08:54 UTC (rev 15247)
@@ -85,11 +85,20 @@
- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView;
{
+ [self drawWithFrame:frame inView:controlView alpha:1.0];
+}
+
+- (void)drawWithFrame:(NSRect)frame inView:(NSView *)controlView
alpha:(CGFloat)alpha;
+{
// NSCell's highlight drawing does not look correct against a dark
background, so override it completely
NSColor *bgColor = nil;
NSColor *arrowColor = nil;
NSColor *strokeColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.9];
- NSRect rect = NSInsetRect(frame, 1.0, 1.0);
+ NSRect diskFrame = NSInsetRect(frame, 2.5, 2.5);
+ NSRect circleFrame = NSInsetRect(frame, 2.0, 2.0);
+ NSShadow *buttonShadow = [[[NSShadow alloc] init] autorelease];
+ [buttonShadow setShadowBlurRadius:1.5];
+ [buttonShadow setShadowColor:[NSColor blackColor]];
if ([self isEnabled] == NO) {
bgColor = [NSColor colorWithCalibratedWhite:0.3 alpha:0.5];
@@ -102,20 +111,22 @@
arrowColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.9];
}
- [NSGraphicsContext saveGraphicsState];
-
+ CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicsPort];
+ CGContextSaveGState(ctxt);
+
+ CGContextSetAlpha(ctxt, alpha);
+ NSRectClip(frame);
[bgColor setFill];
[strokeColor setStroke];
- [[NSBezierPath bezierPathWithOvalInRect:rect] fill];
- [[NSBezierPath bezierPathWithOvalInRect:NSInsetRect(frame, 0.5, 0.5)]
stroke];
+ [[NSBezierPath bezierPathWithOvalInRect:diskFrame] fill];
+ [[NSBezierPath bezierPathWithOvalInRect:circleFrame] stroke];
- CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicsPort];
- CGContextTranslateCTM(ctxt, NSMinX(rect), NSMinY(rect));
+ CGContextTranslateCTM(ctxt, NSMinX(diskFrame), NSMinY(diskFrame));
[arrowColor setFill];
- [[self arrowBezierPathWithSize:rect.size] fill];
+ [[self arrowBezierPathWithSize:diskFrame.size] fill];
- [NSGraphicsContext restoreGraphicsState];
+ CGContextRestoreGState(ctxt);
}
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView
*)controlView untilMouseUp:(BOOL)untilMouseUp {
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h 2009-04-30
14:34:10 UTC (rev 15246)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h 2009-04-30
17:08:54 UTC (rev 15247)
@@ -105,6 +105,8 @@
unsigned int isRescaling: 1;
unsigned int scheduledLiveResize : 1;
unsigned int updatingFromSlider : 1;
+ unsigned int hasArrows : 1;
+ unsigned int isAnimatingArrowAlpha : 1;
} _fvFlags;
NSSize _padding;
NSSize _iconSize;
@@ -118,6 +120,7 @@
NSButtonCell *_rightArrow;
NSRect _leftArrowFrame;
NSRect _rightArrowFrame;
+ CGFloat _arrowAlpha;
FVSliderWindow *_sliderWindow;
NSTrackingRectTag _topSliderTag;
NSTrackingRectTag _bottomSliderTag;
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2009-04-30
14:34:10 UTC (rev 15246)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2009-04-30
17:08:54 UTC (rev 15247)
@@ -272,6 +272,9 @@
_leftArrowFrame = NSZeroRect;
_rightArrowFrame = NSZeroRect;
+ _arrowAlpha = 0.0;
+ _fvFlags.isAnimatingArrowAlpha = NO;
+ _fvFlags.hasArrows = NO;
_minScale = 0.5;
_maxScale = 16.0;
@@ -2222,11 +2225,11 @@
if (isDrawingToScreen) {
- if ([self _hasArrows]) {
+ if (_fvFlags.hasArrows || _fvFlags.isAnimatingArrowAlpha) {
if (NSIntersectsRect(rect, _leftArrowFrame))
- [_leftArrow drawWithFrame:_leftArrowFrame inView:self];
+ [(FVArrowButtonCell *)_leftArrow drawWithFrame:_leftArrowFrame
inView:self alpha:_arrowAlpha];
if (NSIntersectsRect(rect, _rightArrowFrame))
- [_rightArrow drawWithFrame:_rightArrowFrame inView:self];
+ [(FVArrowButtonCell *)_rightArrow
drawWithFrame:_rightArrowFrame inView:self alpha:_arrowAlpha];
}
// drop highlight and rubber band are mutually exclusive
@@ -2587,10 +2590,43 @@
[self _redisplayIconAfterPageChanged:anIcon];
}
-- (BOOL)_hasArrows {
- return [_leftArrow representedObject] != nil;
+// note that hasArrows has to have the desired state before this fires
+- (void)_updateArrowAlpha:(NSTimer *)timer
+{
+ NSAnimation *animation = [timer userInfo];
+ CGFloat value = [animation currentValue];
+ if (value > 0.99) {
+ [animation stopAnimation];
+ [timer invalidate];
+ _fvFlags.isAnimatingArrowAlpha = NO;
+ _arrowAlpha = _fvFlags.hasArrows ? 1.0 : 0.0;
+ }
+ else {
+ _arrowAlpha = _fvFlags.hasArrows ? value : (1 - value);
+ }
+ [self setNeedsDisplayInRect:NSUnionRect(_leftArrowFrame,
_rightArrowFrame)];
}
+- (void)_startArrowAlphaTimer
+{
+ _fvFlags.isAnimatingArrowAlpha = YES;
+ // animate ~30 fps for 0.3 seconds, using NSAnimation to get the alpha
curve
+ NSAnimation *animation = [[NSAnimation alloc] initWithDuration:0.3
animationCurve:NSAnimationEaseInOut];
+ // runloop mode is irrelevant for non-blocking threaded
+ [animation setAnimationBlockingMode:NSAnimationNonblockingThreaded];
+ // explicitly alloc/init so it can be added to all the common modes
instead of the default mode
+ NSTimer *timer = [[NSTimer alloc] initWithFireDate:[NSDate date]
+ interval:0.03
+ target:self
+
selector:@selector(_updateArrowAlpha:)
+ userInfo:animation
+ repeats:YES];
+ [[NSRunLoop currentRunLoop] addTimer:timer forMode:(NSString
*)kCFRunLoopCommonModes];
+ [timer release];
+ [animation startAnimation];
+ [animation release];
+}
+
- (void)_showArrowsForIconAtIndex:(NSUInteger)anIndex
{
NSUInteger r, c;
@@ -2617,21 +2653,30 @@
[_leftArrow setRepresentedObject:anIcon];
[_rightArrow setRepresentedObject:anIcon];
-
+ _fvFlags.hasArrows = YES;
+
// set enabled states
- [self _updateButtonsForIcon:anIcon];
-
- [self setNeedsDisplayInRect:NSUnionRect(_leftArrowFrame,
_rightArrowFrame)];
+ [self _updateButtonsForIcon:anIcon];
+
+ if (_fvFlags.isAnimatingArrowAlpha) {
+ // make sure we redraw whatever area previously had the arrows
+ [self setNeedsDisplay:YES];
+ }
+ else {
+ [self _startArrowAlphaTimer];
+ }
}
}
}
- (void)_hideArrows
{
- if ([self _hasArrows]) {
+ if (_fvFlags.hasArrows) {
+ _fvFlags.hasArrows = NO;
[_leftArrow setRepresentedObject:nil];
[_rightArrow setRepresentedObject:nil];
- [self setNeedsDisplayInRect:NSUnionRect(_leftArrowFrame,
_rightArrowFrame)];
+ if (NO == _fvFlags.isAnimatingArrowAlpha)
+ [self _startArrowAlphaTimer];
}
}
@@ -2752,10 +2797,10 @@
NSUInteger flags = [event modifierFlags];
NSUInteger r, c, i;
- if ([self _hasArrows] && NSMouseInRect(p, _leftArrowFrame, [self
isFlipped])) {
+ if (_fvFlags.hasArrows && NSMouseInRect(p, _leftArrowFrame, [self
isFlipped])) {
[_leftArrow trackMouse:event inRect:_leftArrowFrame ofView:self
untilMouseUp:YES];
}
- else if ([self _hasArrows] && NSMouseInRect(p, _rightArrowFrame, [self
isFlipped])) {
+ else if (_fvFlags.hasArrows && NSMouseInRect(p, _rightArrowFrame, [self
isFlipped])) {
[_rightArrow trackMouse:event inRect:_rightArrowFrame ofView:self
untilMouseUp:YES];
}
// mark this icon for highlight if necessary
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit