1 /* xscreensaver, Copyright (c) 2006 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 return [[NSAttributedString alloc] initWithString:[self stringValue]];
70 /* Implment all setter methods in terms of "setDoubleValue", above.
73 -(void) setFloatValue:(double)v
75 [self setDoubleValue:(double)v];
78 -(void) setIntValue:(int)v
80 [self setDoubleValue:(double)v];
83 -(void) setObjectValue:(id <NSCopying>)v
85 NSAssert2((v == nil) ||
86 [(NSObject *) v respondsToSelector:@selector(doubleValue)],
87 @"argument %@ to %s does not respond to doubleValue",
88 v, __PRETTY_FUNCTION__);
89 [self setDoubleValue:[((NSNumber *) v) doubleValue]];
92 -(void) setStringValue:(NSString *)v
94 [self setDoubleValue:[v doubleValue]];
97 -(void) setAttributedStringValue:(NSAttributedString *)v
99 [self setStringValue:[v string]];