1 /* xscreensaver, Copyright (c) 2006-2010 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
11 * This is a subclass of NSSlider that is flipped horizontally:
12 * the high value is on the left and the low value is on the right.
15 #import "InvertedSlider.h"
17 @implementation InvertedSlider
19 -(double) transformValue:(double) value
21 double low = [self minValue];
22 double high = [self maxValue];
23 double range = high - low;
24 double off = value - low;
25 double trans = low + (range - off);
26 // NSLog (@" ... %.1f -> %.1f [%.1f - %.1f]", value, trans, low, high);
30 -(double) doubleValue;
32 return [self transformValue:[super doubleValue]];
35 -(void) setDoubleValue:(double)v
37 return [super setDoubleValue:[self transformValue:v]];
41 /* Implement all accessor methods in terms of "doubleValue" above.
46 return (float) [self doubleValue];
51 return (int) [self doubleValue];
56 return [NSNumber numberWithDouble:[self doubleValue]];
59 -(NSString *) stringValue;
61 return [NSString stringWithFormat:@"%f", [self floatValue]];
64 - (NSAttributedString *)attributedStringValue;
66 // #### "Build and Analyze" says this leaks. Unsure whether this is true.
67 return [[NSAttributedString alloc] initWithString:[self stringValue]];
71 /* Implment all setter methods in terms of "setDoubleValue", above.
74 -(void) setFloatValue:(float)v
76 [self setDoubleValue:(double)v];
79 -(void) setIntValue:(int)v
81 [self setDoubleValue:(double)v];
84 -(void) setObjectValue:(id <NSCopying>)v
86 NSAssert2((v == nil) ||
87 [(NSObject *) v respondsToSelector:@selector(doubleValue)],
88 @"argument %@ to %s does not respond to doubleValue",
89 v, __PRETTY_FUNCTION__);
90 [self setDoubleValue:[((NSNumber *) v) doubleValue]];
93 -(void) setStringValue:(NSString *)v
95 [self setDoubleValue:[v doubleValue]];
98 -(void) setAttributedStringValue:(NSAttributedString *)v
100 [self setStringValue:[v string]];