http://ftp.nluug.nl/pub/os/Linux/distr/pardusrepo/sources/xscreensaver-5.02.tar.gz
[xscreensaver] / OSX / InvertedSlider.m
1 /* xscreensaver, Copyright (c) 2006 Jamie Zawinski <jwz@jwz.org>
2 *
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 
9 * implied warranty.
10 *
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.
13 */
14
15 #import "InvertedSlider.h"
16
17 @implementation InvertedSlider
18
19 -(double) transformValue:(double) value
20 {
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);
27   return trans;
28 }
29
30 -(double) doubleValue;
31 {
32   return [self transformValue:[super doubleValue]];
33 }
34
35 -(void) setDoubleValue:(double)v
36 {
37   return [super setDoubleValue:[self transformValue:v]];
38 }
39
40
41 /* Implement all accessor methods in terms of "doubleValue" above.
42  */
43
44 -(float) floatValue;
45 {
46   return (float) [self doubleValue];
47 }
48
49 -(int) intValue;
50 {
51   return (int) [self doubleValue];
52 }
53
54 -(id) objectValue;
55 {
56   return [NSNumber numberWithDouble:[self doubleValue]];
57 }
58
59 -(NSString *) stringValue;
60 {
61   return [NSString stringWithFormat:@"%f", [self floatValue]];
62 }
63
64 - (NSAttributedString *)attributedStringValue;
65 {
66   return [[NSAttributedString alloc] initWithString:[self stringValue]];
67 }
68
69
70 /* Implment all setter methods in terms of "setDoubleValue", above.
71  */
72
73 -(void) setFloatValue:(double)v
74 {
75   [self setDoubleValue:(double)v];
76 }
77
78 -(void) setIntValue:(int)v
79 {
80   [self setDoubleValue:(double)v];
81 }
82
83 -(void) setObjectValue:(id <NSCopying>)v
84 {
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]];
90 }
91
92 -(void) setStringValue:(NSString *)v
93 {
94   [self setDoubleValue:[v doubleValue]];
95 }
96
97 -(void) setAttributedStringValue:(NSAttributedString *)v
98 {
99   [self setStringValue:[v string]];
100 }
101
102 @end