From 2f6a98730f6af18a71b31c72468042f3b5b81915 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Wed, 18 Apr 2012 13:45:43 +0100 Subject: Add edge colours --- tikzit/src/common/EdgeStyle.h | 8 ++++++++ tikzit/src/common/EdgeStyle.m | 30 ++++++++++++++++++++++++++++++ tikzit/src/common/NodeStyle.h | 4 ++-- tikzit/src/common/Preambles.m | 11 +++++++++-- 4 files changed, 49 insertions(+), 4 deletions(-) (limited to 'tikzit/src/common') diff --git a/tikzit/src/common/EdgeStyle.h b/tikzit/src/common/EdgeStyle.h index 248d8f4..83c3ecd 100644 --- a/tikzit/src/common/EdgeStyle.h +++ b/tikzit/src/common/EdgeStyle.h @@ -23,6 +23,7 @@ #import #import "PropertyHolder.h" +#import "ColorRGB.h" typedef enum { AH_None = 0, @@ -40,10 +41,17 @@ typedef enum { ArrowHeadStyle headStyle, tailStyle; EdgeDectorationStyle decorationStyle; float thickness; + ColorRGB *colorRGB; NSString *name; NSString *category; } +/*! + @property colorRGB + @brief The color to render the line in + */ +@property (copy) ColorRGB *colorRGB; + @property (copy) NSString *name; @property (copy) NSString *category; @property (assign) ArrowHeadStyle headStyle; diff --git a/tikzit/src/common/EdgeStyle.m b/tikzit/src/common/EdgeStyle.m index da669e3..88b1f54 100644 --- a/tikzit/src/common/EdgeStyle.m +++ b/tikzit/src/common/EdgeStyle.m @@ -31,9 +31,16 @@ @"headStyle", @"decorationStyle", @"thickness", + @"colorRGB.red", + @"colorRGB.blue", + @"colorRGB.green", @"name", nil] triggerChangeNotificationsForDependentKey:@"tikz"]; + [self setKeys:[NSArray arrayWithObjects: + @"colorRGB.name", + nil] + triggerChangeNotificationsForDependentKey:@"colorIsKnown"]; } - (id)initWithName:(NSString*)nm { @@ -43,6 +50,7 @@ headStyle = AH_None; tailStyle = AH_None; decorationStyle = ED_None; + colorRGB = [[ColorRGB alloc] initWithRed:0 green:0 blue:0]; name = nm; category = nil; thickness = 1.0f; @@ -64,12 +72,14 @@ [style setTailStyle:[self tailStyle]]; [style setDecorationStyle:[self decorationStyle]]; [style setThickness:[self thickness]]; + [style setColorRGB:[self colorRGB]]; return style; } - (void)dealloc { [name release]; [category release]; + [colorRGB release]; [super dealloc]; } @@ -127,9 +137,26 @@ } } +- (ColorRGB*)colorRGB { + return colorRGB; +} + +- (void)setColorRGB:(ColorRGB*)c { + if (colorRGB != c) { + ColorRGB *oldValue = colorRGB; + colorRGB = [c copy]; + [self postPropertyChanged:@"colorRGB" oldValue:oldValue]; + [oldValue release]; + } +} + - (NSString*)tikz { NSMutableString *buf = [NSMutableString stringWithFormat:@"\\tikzstyle{%@}=[", name]; + NSString *colorName = [colorRGB name]; + if (colorName == nil) + colorName = [colorRGB hexName]; + if (tailStyle == AH_Plain) [buf appendString:@"<"]; else if (tailStyle == AH_Latex) @@ -142,6 +169,9 @@ else if (headStyle == AH_Latex) [buf appendString:@"latex"]; + [buf appendString:@",draw="]; + [buf appendString:colorName]; + if (decorationStyle != ED_None) { [buf appendString:@",postaction={decorate},decoration={markings,mark="]; if (decorationStyle == ED_Arrow) diff --git a/tikzit/src/common/NodeStyle.h b/tikzit/src/common/NodeStyle.h index a78abaa..68aafad 100644 --- a/tikzit/src/common/NodeStyle.h +++ b/tikzit/src/common/NodeStyle.h @@ -59,13 +59,13 @@ /*! @property strokeColorRGB - @brief Stroke color. + @brief The stroke color used to render the node */ @property (copy) ColorRGB *strokeColorRGB; /*! @property fillColorRGB - @brief Fill color. + @brief The fill color used to render the node */ @property (copy) ColorRGB *fillColorRGB; diff --git a/tikzit/src/common/Preambles.m b/tikzit/src/common/Preambles.m index d41f9b0..e107d5e 100644 --- a/tikzit/src/common/Preambles.m +++ b/tikzit/src/common/Preambles.m @@ -23,6 +23,7 @@ #import "Preambles.h" #import "NodeStyle.h" +#import "EdgeStyle.h" static NSString *PREAMBLE_HEAD = @"\\documentclass{article}\n" @@ -112,15 +113,21 @@ static NSString *POSTAMBLE = [fill hexName], [fill redFloat], [fill greenFloat], [fill blueFloat]]; } - if ([fill name] == nil && ![colors containsObject:fill]) { + if ([stroke name] == nil && ![colors containsObject:stroke]) { [colors addObject:stroke]; [colbuf appendFormat:@"\\definecolor{%@}{rgb}{%.3f,%.3f,%.3f}\n", - [fill hexName], [fill redFloat], [fill greenFloat], [fill blueFloat]]; + [stroke hexName], [stroke redFloat], [stroke greenFloat], [stroke blueFloat]]; } } [buf appendString:@"\n"]; for (EdgeStyle *st in [styleManager edgeStyles]) { [buf appendFormat:@"%@\n", [st tikz]]; + ColorRGB *color = [st colorRGB]; + if ([color name] == nil && ![colors containsObject:color]) { + [colors addObject:color]; + [colbuf appendFormat:@"\\definecolor{%@}{rgb}{%.3f,%.3f,%.3f}\n", + [color hexName], [color redFloat], [color greenFloat], [color blueFloat]]; + } } NSString *defs = [[NSString alloc] initWithFormat:@"%@\n%@", colbuf, buf]; -- cgit v1.2.3