summaryrefslogtreecommitdiff
path: root/tikzit/src/common/ColorRGB.m
diff options
context:
space:
mode:
authorrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-14 16:30:17 +0000
committerrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-14 16:30:17 +0000
commita1f668bffbea12453ecc330ec243f9f656582c57 (patch)
tree8e733c708109dce593899ef985b418654aa3927e /tikzit/src/common/ColorRGB.m
parentbf911ac87c17599bc07bb25726f1fa332d233a64 (diff)
Use KVO for listening to style changes in the selectors
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@426 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'tikzit/src/common/ColorRGB.m')
-rw-r--r--tikzit/src/common/ColorRGB.m24
1 files changed, 14 insertions, 10 deletions
diff --git a/tikzit/src/common/ColorRGB.m b/tikzit/src/common/ColorRGB.m
index 673a88d..74d1c55 100644
--- a/tikzit/src/common/ColorRGB.m
+++ b/tikzit/src/common/ColorRGB.m
@@ -183,19 +183,22 @@ static NSMapTable *colorHash = nil;
@implementation ColorRGB
-- (unsigned short)red { return red; }
-- (void)setRed:(unsigned short)r { red = r; }
-- (unsigned short)green { return green; }
-- (void)setGreen:(unsigned short)g { green = g; }
-- (unsigned short)blue { return blue; }
-- (void)setBlue:(unsigned short)b { blue = b; }
++ (void)initialize {
+ [self setKeys:[NSArray arrayWithObject:@"red"] triggerChangeNotificationsForDependentKey:@"redFloat"];
+ [self setKeys:[NSArray arrayWithObject:@"green"] triggerChangeNotificationsForDependentKey:@"greenFloat"];
+ [self setKeys:[NSArray arrayWithObject:@"blue"] triggerChangeNotificationsForDependentKey:@"blueFloat"];
+ [self setKeys:[NSArray arrayWithObjects:@"red", @"green", @"blue", nil]
+ triggerChangeNotificationsForDependentKey:@"name"];
+}
+
+@synthesize red, green, blue;
- (float)redFloat { return ((float)red)/255.0f; }
-- (void)setRedFloat:(float)r { red = round(r*255.0f); }
+- (void)setRedFloat:(float)r { [self setRed:round(r*255.0f)]; }
- (float)greenFloat { return ((float)green)/255.0f; }
-- (void)setGreenFloat:(float)g { green = round(g*255.0f); }
+- (void)setGreenFloat:(float)g { [self setGreen:round(g*255.0f)]; }
- (float)blueFloat { return ((float)blue)/255.0f; }
-- (void)setBlueFloat:(float)b { blue = round(b*255.0f); }
+- (void)setBlueFloat:(float)b { [self setBlue:round(b*255.0f)]; }
- (int)hash {
return (red<<4) + (green<<2) + blue;
@@ -230,7 +233,8 @@ static NSMapTable *colorHash = nil;
}
- (NSString*)name {
- if (colorHash == nil) [ColorRGB makeColorHash];
+ if (colorHash == nil)
+ [ColorRGB makeColorHash];
return [colorHash objectForKey:self];
}