Permalink
Browse files

Import into GitHub

  • Loading branch information...
rickfillion committed Jan 2, 2011
0 parents commit c53637a06faa21bd9335d117679f4f258261bb9c
@@ -0,0 +1,23 @@
+//
+// AppController.h
+// RFAnimatedSlider
+//
+// Created by Rick Fillion on 23/07/09.
+// All code is provided under the New BSD license.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface AppController : NSObject {
+ NSNumber *value;
+}
+
+@property (nonatomic, retain) NSNumber *value;
+
+- (IBAction)setToMax:(id)sender;
+- (IBAction)setToMin:(id)sender;
+
+@end
+
+
@@ -0,0 +1,35 @@
+//
+// AppController.m
+// RFAnimatedSlider
+//
+// Created by Rick Fillion on 23/07/09.
+// All code is provided under the New BSD license.
+//
+
+#import "AppController.h"
+
+
+@implementation AppController
+
+@synthesize value;
+
+- (id)init
+{
+ if (self = [super init])
+ {
+ self.value = [NSNumber numberWithInt:0];
+ }
+ return self;
+}
+
+- (IBAction)setToMax:(id)sender
+{
+ self.value = [NSNumber numberWithInt:10];
+}
+
+- (IBAction)setToMin:(id)sender
+{
+ self.value = [NSNumber numberWithInt:0];
+}
+
+@end
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>ca.centrix.${PRODUCT_NAME:identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
@@ -0,0 +1,17 @@
+{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460
+{\fonttbl\f0\fnil\fcharset0 Verdana;}
+{\colortbl;\red255\green255\blue255;\red14\green14\blue14;}
+{\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid1}}
+{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}}
+\vieww9000\viewh8400\viewkind0
+\deftab720
+\pard\pardeftab720\sl400\sa280\ql\qnatural
+
+\f0\fs24 \cf2 Copyright (c) 2009, Centrix.ca\uc0\u8232 All rights reserved.\
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\
+\pard\tx220\tx720\pardeftab720\li720\fi-720\sl400\sa20\ql\qnatural
+\ls1\ilvl0\cf2 {\listtext \'95 }Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\
+{\listtext \'95 }Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\
+{\listtext \'95 }Neither the name of Centrix.ca nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\
+\pard\pardeftab720\sl400\sa280\ql\qnatural
+\cf2 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.}
0 README
No changes.
@@ -0,0 +1,21 @@
+//
+// RFAnimatedSlider.h
+// RFAnimatedSlider
+//
+// Created by Rick Fillion on 19/03/09.
+// All code is provided under the New BSD license.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface RFAnimatedSlider : NSSlider {
+ CALayer *knobLayer;
+ BOOL settingValue;
+ NSRect lastKnobRect;
+}
+
+- (void)refreshKnobImage;
+- (void)drawKnob:(NSRect)knobRect;
+
+@end
@@ -0,0 +1,256 @@
+//
+// RFAnimatedSlider.m
+// RFAnimatedSlider
+//
+// Created by Rick Fillion on 19/03/09.
+// All code is provided under the New BSD license.
+//
+
+#import "RFAnimatedSlider.h"
+#import <QuartzCore/QuartzCore.h>
+
+@interface RFAnimatedSliderCell : NSSliderCell
+{
+ BOOL drawKnob;
+ BOOL isTracking;
+}
+-(void)setDrawKnob:(BOOL)value;
+
+@end
+
+
+@implementation RFAnimatedSliderCell
+
+- (void)drawKnob:(NSRect)knobRect
+{
+ if (!drawKnob)
+ [(RFAnimatedSlider *)[self controlView] drawKnob: knobRect];
+ else
+ [super drawKnob:knobRect];
+}
+
+- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
+{
+ BOOL value = [super startTrackingAt:startPoint inView:controlView];
+ if (!isTracking)
+ {
+ [(RFAnimatedSlider *)[self controlView] refreshKnobImage];
+ isTracking = YES;
+ }
+ return value;
+}
+
+- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
+{
+ isTracking = NO;
+ if (![self isContinuous])
+ [(NSControl *)controlView sendAction:[self action] to:[self target]];
+
+ [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
+ [(RFAnimatedSlider *)[self controlView] refreshKnobImage];
+}
+
+- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
+{
+ BOOL value =[super continueTracking:lastPoint at:currentPoint inView:controlView];
+ if ([self isContinuous])
+ [(NSControl *)controlView sendAction:[self action] to:[self target]];
+ return value;
+}
+
+-(void)setDrawKnob:(BOOL)value
+{
+ drawKnob = value;
+}
+
+@end
+
+@interface RFAnimatedSlider (Private)
+
+- (void)swapCells;
+- (Class) cellClass;
+- (void)createKnobLayer:(NSRect)knobRect;
+
+@end
+
+@implementation RFAnimatedSlider (Private)
+
+- (Class) cellClass
+{
+ return [RFAnimatedSliderCell class];
+}
+
+- (void)swapCells
+{
+ RFAnimatedSliderCell *newCell = [[[[self cellClass] alloc] initImageCell: nil] autorelease];
+ NSSliderCell *oldCell = [self cell];
+
+ [newCell setAltIncrementValue: [oldCell altIncrementValue]];
+ [newCell setKnobThickness: [oldCell knobThickness]];
+ [newCell setTitle: [oldCell title]];
+ [newCell setMinValue: [oldCell minValue]];
+ [newCell setMaxValue: [oldCell maxValue]];
+ [newCell setAllowsTickMarkValuesOnly: [oldCell allowsTickMarkValuesOnly]];
+ [newCell setNumberOfTickMarks: [oldCell numberOfTickMarks]];
+ [newCell setTickMarkPosition: [oldCell tickMarkPosition]];
+
+ [self setCell: newCell];
+}
+
+- (void)createKnobLayer:(NSRect)knobRect
+{
+ knobLayer = [[CALayer layer] retain];
+ knobLayer.anchorPoint = CGPointMake(0,0);
+
+ [self refreshKnobImage];
+}
+
+
+
+@end
+
+@implementation RFAnimatedSlider
+
+
+
+-(id)initWithFrame:(NSRect) rect
+{
+ if (self = [super initWithFrame: rect]){
+ [self swapCells];
+ [self setWantsLayer: YES];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillBecomeKey:) name:NSWindowDidBecomeKeyNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillResignKey:) name:NSWindowDidResignKeyNotification object:nil];
+ }
+ return self;
+}
+
+-(id)initWithCoder:(NSCoder *)coder
+{
+ if (self = [super initWithCoder: coder]){
+ [self swapCells];
+ [self setWantsLayer: YES];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillBecomeKey:) name:NSWindowDidBecomeKeyNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillResignKey:) name:NSWindowDidResignKeyNotification object:nil];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [knobLayer release];
+ [super dealloc];
+}
+
+- (void)drawKnob:(NSRect)knobRect
+{
+ lastKnobRect = knobRect;
+ if (knobLayer == nil)
+ [self createKnobLayer: knobRect];
+
+
+ CGRect frame = NSRectToCGRect(lastKnobRect);
+ frame.origin.y = NSHeight([self frame]) - NSMaxY(lastKnobRect);
+ if (!settingValue)
+ {
+ [NSAnimationContext beginGrouping];
+ [[NSAnimationContext currentContext] setDuration: 0];
+ knobLayer.frame = frame;
+ [NSAnimationContext endGrouping];
+ }
+ else
+ {
+ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
+ animation.duration = 0.2;
+ animation.fromValue=[NSValue valueWithPoint: NSMakePoint(knobLayer.position.x, knobLayer.position.y)];
+ animation.toValue=[NSValue valueWithPoint: NSMakePoint(frame.origin.x, frame.origin.y)];
+ [knobLayer addAnimation:animation forKey:@"movePosition"];
+ knobLayer.frame = frame;
+ settingValue = NO;
+ }
+}
+
+
+#pragma mark Methods that can trigger an explicit slider animation
+
+- (void)setDoubleValue:(double)value
+{
+ settingValue = YES;
+ [super setDoubleValue:value];
+}
+
+- (void)setFloatValue:(float)value
+{
+ settingValue = YES;
+ [super setFloatValue:value];
+}
+
+- (void)setIntValue:(int)value
+{
+ settingValue = YES;
+ [super setIntValue:value];
+}
+
+- (void)setIntegerValue:(NSInteger)value
+{
+ settingValue = YES;
+ [super setIntegerValue:value];
+}
+
+#pragma mark Methods that can change the look of the knob
+- (void)setNumberOfTickMarks:(NSInteger)numberOfTickMarks
+{
+ [super setNumberOfTickMarks:numberOfTickMarks];
+ [self refreshKnobImage];
+}
+
+- (void)windowWillBecomeKey:(id)sender
+{
+ [self refreshKnobImage];
+}
+
+- (void)windowWillResignKey:(id)sender
+{
+ [self refreshKnobImage];
+}
+
+- (void)refreshKnobImage
+{
+ NSImage *bigImage = [[[NSImage alloc] initWithSize: [self frame].size] autorelease];
+ [bigImage lockFocus];
+ [(RFAnimatedSliderCell*)[self cell] setDrawKnob:YES];
+ [[self cell] drawKnob: lastKnobRect];
+ [(RFAnimatedSliderCell*)[self cell] setDrawKnob:NO];
+ [bigImage unlockFocus];
+
+ NSImage *knobImage = [[[NSImage alloc] initWithSize:lastKnobRect.size] autorelease];
+ NSRect rectAtOrigin = lastKnobRect;
+ rectAtOrigin.origin.x = 0.0;
+ rectAtOrigin.origin.y = 0.0;
+
+ if ([knobImage respondsToSelector:@selector(lockFocusFlipped:)])
+ {
+ // 10.6 needs this.
+ [knobImage lockFocusFlipped: YES];
+ }
+ else {
+ [knobImage lockFocus];
+ }
+ [bigImage drawInRect:rectAtOrigin fromRect:lastKnobRect operation:NSCompositeSourceOver fraction: 1.0];
+ [knobImage unlockFocus];
+
+ NSData* cocoaData = [knobImage TIFFRepresentation];
+ CFDataRef carbonData = (CFDataRef)cocoaData;
+ CGImageSourceRef imageSourceRef = CGImageSourceCreateWithData(carbonData, NULL);
+ CGImageRef knobImageRef = CGImageSourceCreateImageAtIndex(imageSourceRef, 0, NULL);
+ knobLayer.contents = (id)knobImageRef;
+ CFRelease(imageSourceRef);
+ CFRelease(knobImageRef);
+ [[self layer] addSublayer: knobLayer];
+ CGRect frame = NSRectToCGRect(lastKnobRect);
+ frame.origin.y = NSHeight([self frame]) - NSMaxY(lastKnobRect);
+ [knobLayer setFrame: frame];
+}
+
+
+@end
Binary file not shown.
Oops, something went wrong.

0 comments on commit c53637a

Please sign in to comment.