summaryrefslogtreecommitdiff
path: root/tikzit/src/common
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
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')
-rw-r--r--tikzit/src/common/ColorRGB.h4
-rw-r--r--tikzit/src/common/ColorRGB.m24
-rw-r--r--tikzit/src/common/EdgeStyle.m11
-rw-r--r--tikzit/src/common/NodeStyle.m23
4 files changed, 50 insertions, 12 deletions
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 {