From a1f668bffbea12453ecc330ec243f9f656582c57 Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Wed, 14 Mar 2012 16:30:17 +0000 Subject: 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 --- tikzit/src/common/ColorRGB.h | 4 ++-- tikzit/src/common/ColorRGB.m | 24 ++++++++++++++---------- tikzit/src/common/EdgeStyle.m | 11 +++++++++++ tikzit/src/common/NodeStyle.m | 23 +++++++++++++++++++++++ 4 files changed, 50 insertions(+), 12 deletions(-) (limited to 'tikzit/src/common') diff --git a/tikzit/src/common/ColorRGB.h b/tikzit/src/common/ColorRGB.h index 412a1f6..607ba64 100644 --- a/tikzit/src/common/ColorRGB.h +++ b/tikzit/src/common/ColorRGB.h @@ -36,6 +36,8 @@ @property (assign) float greenFloat; @property (assign) float blueFloat; +@property (readonly) NSString *name; + - (RColor)rColor; - (RColor)rColorWithAlpha:(CGFloat)alpha; @@ -48,8 +50,6 @@ - (id)initWithFloatRed:(float)r green:(float)g blue:(float)b; - (id)initWithRColor:(RColor)color; -- (NSString*)name; - - (void)setToClosestHashed; + (ColorRGB*)colorWithRed:(unsigned short)r green:(unsigned short)g blue:(unsigned short)b; 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]; } diff --git a/tikzit/src/common/EdgeStyle.m b/tikzit/src/common/EdgeStyle.m index a9dbc9f..da669e3 100644 --- a/tikzit/src/common/EdgeStyle.m +++ b/tikzit/src/common/EdgeStyle.m @@ -25,6 +25,17 @@ @implementation EdgeStyle ++ (void)initialize { + [self setKeys:[NSArray arrayWithObjects: + @"tailStyle", + @"headStyle", + @"decorationStyle", + @"thickness", + @"name", + nil] + triggerChangeNotificationsForDependentKey:@"tikz"]; +} + - (id)initWithName:(NSString*)nm { self = [super initWithNotificationName:@"EdgeStylePropertyChanged"]; diff --git a/tikzit/src/common/NodeStyle.m b/tikzit/src/common/NodeStyle.m index 8d8b83f..0794b6a 100644 --- a/tikzit/src/common/NodeStyle.m +++ b/tikzit/src/common/NodeStyle.m @@ -26,6 +26,29 @@ @implementation NodeStyle ++ (void)initialize { + [self setKeys:[NSArray arrayWithObjects: + @"fillColorRGB.red", + @"fillColorRGB.blue", + @"fillColorRGB.green", + @"strokeColorRGB.red", + @"strokeColorRGB.blue", + @"strokeColorRGB.green", + @"strokeThickness", + @"shapeName", + @"name", + nil] + triggerChangeNotificationsForDependentKey:@"tikz"]; + [self setKeys:[NSArray arrayWithObjects: + @"fillColorRGB.name", + nil] + triggerChangeNotificationsForDependentKey:@"fillColorIsKnown"]; + [self setKeys:[NSArray arrayWithObjects: + @"strokeColorRGB.name", + nil] + triggerChangeNotificationsForDependentKey:@"strokeColorIsKnown"]; +} + + (int) defaultStrokeThickness { return 1; } - (id)initWithName:(NSString*)nm { -- cgit v1.2.3