From fe75ce769014d6c60924b023aa93bacdcd527998 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Fri, 31 Jan 2014 22:17:54 +0100 Subject: [PATCH 1/4] Cache & disable shadows Actually we may cache NSShadow in the class variable. --- Classes/Views/PBGitRevisionCell.m | 72 ++++++++++++++----------------- html/views/history/history.css | 2 +- 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Classes/Views/PBGitRevisionCell.m b/Classes/Views/PBGitRevisionCell.m index 94c7a7f9d..b9e2d7d9b 100644 --- a/Classes/Views/PBGitRevisionCell.m +++ b/Classes/Views/PBGitRevisionCell.m @@ -17,7 +17,7 @@ #import "NSColor+RGB.h" const int COLUMN_WIDTH = 10; -const BOOL ENABLE_SHADOW = YES; +const BOOL ENABLE_SHADOW = NO; const BOOL SHUFFLE_COLORS = NO; @implementation PBGitRevisionCell @@ -55,23 +55,35 @@ + (NSArray *)laneColors return laneColors; } -+ (NSColor *)shadowColor ++ (NSShadow *)shadow { - static NSColor *shadowColor = nil; - if (!shadowColor) { - uint8_t l = 64; - shadowColor = [NSColor colorWithR:l G:l B:l]; + static NSShadow *shadow = nil; + if (!shadow) { + shadow = [NSShadow new]; + [shadow setShadowOffset:NSMakeSize(.5, -.5)]; + [shadow setShadowBlurRadius:2]; + [shadow setShadowColor:[NSColor colorWithWhite:0 alpha:.7]]; } - return shadowColor; + return shadow; } -+ (NSColor *)lineShadowColor ++ (NSShadow *)textInsetShadow { - static NSColor *shadowColor = nil; - if (!shadowColor) { - uint8_t l = 200; - shadowColor = [NSColor colorWithR:l G:l B:l]; + static NSShadow *shadow = nil; + if (!shadow) { + shadow = [NSShadow new]; + [shadow setShadowOffset:NSMakeSize(0, -.5)]; + [shadow setShadowBlurRadius:0]; + [shadow setShadowColor:[NSColor colorWithWhite:1 alpha:.5]]; } - return shadowColor; + return shadow; +} ++ (NSShadow *)lineShadow +{ + static NSShadow *shadow = nil; + if (!shadow) { + shadow = [NSShadow new]; + } + return shadow; } - (void) drawLineFromColumn: (int) from toColumn: (int) to inRect: (NSRect) r offset: (int) offset color: (int) c @@ -81,14 +93,9 @@ - (void) drawLineFromColumn: (int) from toColumn: (int) to inRect: (NSRect) r of NSPoint source = NSMakePoint(origin.x + COLUMN_WIDTH * from, origin.y + offset); NSPoint center = NSMakePoint( origin.x + COLUMN_WIDTH * to, origin.y + r.size.height * 0.5 + 0.5); - if (ENABLE_SHADOW) - { + if (ENABLE_SHADOW) { [NSGraphicsContext saveGraphicsState]; - - NSShadow *shadow = [NSShadow new]; - [shadow setShadowColor:[[self class] lineShadowColor]]; - [shadow setShadowOffset:NSMakeSize(0.5f, -0.5f)]; - [shadow set]; + [[[self class] lineShadow] set]; } NSArray* colors = [PBGitRevisionCell laneColors]; [(NSColor*)[colors objectAtIndex: (c % [colors count])] set]; @@ -126,11 +133,8 @@ - (void) drawCircleInRect: (NSRect) r NSBezierPath * path = [NSBezierPath bezierPathWithOvalInRect:oval]; if (ENABLE_SHADOW && false) { [NSGraphicsContext saveGraphicsState]; - NSShadow *shadow = [NSShadow new]; - [shadow setShadowColor:[[self class] shadowColor]]; - [shadow setShadowOffset:NSMakeSize(0.5f, -0.5f)]; - [shadow setShadowBlurRadius:2.0f]; - [shadow set]; + [[[self class] shadow] set]; + [[NSColor blackColor] set]; } [[NSColor blackColor] set]; [path fill]; @@ -192,19 +196,12 @@ - (NSMutableDictionary*) attributesForRefLabelSelected: (BOOL) selected [attributes setObject:style forKey:NSParagraphStyleAttributeName]; [attributes setObject:[NSFont fontWithName:@"LucidaGrande" size:10] forKey:NSFontAttributeName]; - NSShadow *shadow = nil; - if (selected && false) { // white text is a bit too hard to read (even with shadow) on refs [attributes setObject:[NSColor alternateSelectedControlTextColor] forKey:NSForegroundColorAttributeName]; - if (ENABLE_SHADOW) { - shadow = [NSShadow new]; - [shadow setShadowColor:[NSColor blackColor]]; - [shadow setShadowBlurRadius:2.0f]; - } } - if (shadow) { - attributes[NSShadowAttributeName] = shadow; + if (ENABLE_SHADOW) { + attributes[NSShadowAttributeName] = [[self class] textInsetShadow]; } return attributes; @@ -272,12 +269,7 @@ - (void) drawLabelAtIndex:(int)index inRect:(NSRect)rect if (ENABLE_SHADOW) { [NSGraphicsContext saveGraphicsState]; - - NSShadow *shadow = [NSShadow new]; - [shadow setShadowColor:[NSColor grayColor]];//[[self class] shadowColor]]; - [shadow setShadowOffset:NSMakeSize(0.5f, -0.5f)]; - [shadow setShadowBlurRadius:2.0f]; - [shadow set]; + [[[self class] shadow] set]; } [border fill]; if (ENABLE_SHADOW) { diff --git a/html/views/history/history.css b/html/views/history/history.css index 098da6afe..40afb91a7 100644 --- a/html/views/history/history.css +++ b/html/views/history/history.css @@ -162,7 +162,7 @@ a.showdiff { margin-right: 2px; padding: 1px 3px 1px 3px; -webkit-border-radius: 3px; - -webkit-box-shadow: 1px 1px 2px #444; + /*-webkit-box-shadow: 1px 1px 2px #444;*/ } .refs.head { From 24c64a1e481f6558f84c1d9270eb9e264e161184 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Fri, 31 Jan 2014 22:34:47 +0100 Subject: [PATCH 2/4] Don't shift .5 refs on list and make font bold Also use OSX UI bold font with little transparency, so text get's labels tint. --- Classes/Views/PBGitRevisionCell.m | 11 ++++------- html/views/history/history.css | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Classes/Views/PBGitRevisionCell.m b/Classes/Views/PBGitRevisionCell.m index b9e2d7d9b..f1c935133 100644 --- a/Classes/Views/PBGitRevisionCell.m +++ b/Classes/Views/PBGitRevisionCell.m @@ -194,11 +194,8 @@ - (NSMutableDictionary*) attributesForRefLabelSelected: (BOOL) selected [style setAlignment:NSCenterTextAlignment]; [attributes setObject:style forKey:NSParagraphStyleAttributeName]; - [attributes setObject:[NSFont fontWithName:@"LucidaGrande" size:10] forKey:NSFontAttributeName]; - - if (selected && false) { // white text is a bit too hard to read (even with shadow) on refs - [attributes setObject:[NSColor alternateSelectedControlTextColor] forKey:NSForegroundColorAttributeName]; - } + [attributes setObject:[NSFont boldSystemFontOfSize:9] forKey:NSFontAttributeName]; + [attributes setObject:[NSColor colorWithWhite:0 alpha:.6] forKey:NSForegroundColorAttributeName]; if (ENABLE_SHADOW) { attributes[NSShadowAttributeName] = [[self class] textInsetShadow]; @@ -244,8 +241,8 @@ -(NSArray *)rectsForRefsinRect:(NSRect) rect; NSRect newRect = lastRect; newRect.size.width = textSize.width + ref_padding; - newRect.size.height = textSize.height; - newRect.origin.y = rect.origin.y + (rect.size.height - newRect.size.height) / 2; + newRect.size.height = textSize.height + 1; + newRect.origin.y = ceil(rect.origin.y + (rect.size.height - newRect.size.height) / 2); if (NSContainsRect(rect, newRect)) { [array addObject:[NSValue valueWithRect:newRect]]; diff --git a/html/views/history/history.css b/html/views/history/history.css index 40afb91a7..a7df5d148 100644 --- a/html/views/history/history.css +++ b/html/views/history/history.css @@ -158,9 +158,11 @@ a.showdiff { .refs { font-size: 9px; - font-family: Helvetica; + font-family: ".Lucida Grande UI", "Lucida Grande", sans-serif; + font-weight: bold; + color: rgba(0,0,0,.7);; margin-right: 2px; - padding: 1px 3px 1px 3px; + padding: 2px 3px; -webkit-border-radius: 3px; /*-webkit-box-shadow: 1px 1px 2px #444;*/ } From 376f981e2bfdcc8e1665cc19be8320047a3052b4 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Mon, 9 Jun 2014 19:48:54 +0200 Subject: [PATCH 3/4] Use lane color for 'dots' in history lanes --- Classes/Views/PBGitRevisionCell.m | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Classes/Views/PBGitRevisionCell.m b/Classes/Views/PBGitRevisionCell.m index f1c935133..95e284ee5 100644 --- a/Classes/Views/PBGitRevisionCell.m +++ b/Classes/Views/PBGitRevisionCell.m @@ -122,11 +122,11 @@ - (BOOL) isCurrentCommit return [currentSha isEqual:thisSha]; } -- (void) drawCircleInRect: (NSRect) r +- (void) drawCircleInRect: (NSRect) r color: (int) c { - int c = cellInfo.position; + int p = cellInfo.position; NSPoint origin = r.origin; - NSPoint columnOrigin = { origin.x + COLUMN_WIDTH * c, origin.y}; + NSPoint columnOrigin = { origin.x + COLUMN_WIDTH * p, origin.y}; NSRect oval = { columnOrigin.x - 5, columnOrigin.y + r.size.height * 0.5 - 5, 10, 10}; @@ -134,9 +134,9 @@ - (void) drawCircleInRect: (NSRect) r if (ENABLE_SHADOW && false) { [NSGraphicsContext saveGraphicsState]; [[[self class] shadow] set]; - [[NSColor blackColor] set]; } - [[NSColor blackColor] set]; + NSArray* colors = [PBGitRevisionCell laneColors]; + [(NSColor*)[colors objectAtIndex: (c % [colors count])] set]; [path fill]; if (ENABLE_SHADOW && false) { [NSGraphicsContext restoreGraphicsState]; @@ -155,17 +155,17 @@ - (void) drawCircleInRect: (NSRect) r } -- (void) drawTriangleInRect: (NSRect) r sign: (char) sign +- (void) drawTriangleInRect: (NSRect) r sign: (char) sign color: (int) c { - int c = cellInfo.position; + int p = cellInfo.position; int columnHeight = 10; int columnWidth = 8; NSPoint top; if (sign == '<') - top.x = round(r.origin.x) + 10 * c + 4; + top.x = round(r.origin.x) + 10 * p + 4; else { - top.x = round(r.origin.x) + 10 * c - 4; + top.x = round(r.origin.x) + 10 * p - 4; columnWidth *= -1; } top.y = r.origin.y + (r.size.height - columnHeight) / 2; @@ -182,7 +182,8 @@ - (void) drawTriangleInRect: (NSRect) r sign: (char) sign [[NSColor whiteColor] set]; [path fill]; - [[NSColor blackColor] set]; + NSArray* colors = [PBGitRevisionCell laneColors]; + [(NSColor*)[colors objectAtIndex: (c % [colors count])] set]; [path setLineWidth: 2]; [path stroke]; } @@ -310,19 +311,22 @@ - (void) drawWithFrame: (NSRect) rect inView:(NSView *)view NSRect ownRect; NSDivideRect(rect, &ownRect, &rect, pathWidth, NSMinXEdge); - int i; + int i, cellColorIndex = 0; struct PBGitGraphLine *lines = cellInfo.lines; for (i = 0; i < cellInfo.nLines; i++) { + int colorIndex = lines[i].colorIndex; + if (lines[i].from == cellInfo.position && lines[i].to == cellInfo.position) + cellColorIndex = colorIndex; if (lines[i].upper == 0) - [self drawLineFromColumn: lines[i].from toColumn: lines[i].to inRect:ownRect offset: ownRect.size.height color: lines[i].colorIndex]; + [self drawLineFromColumn: lines[i].from toColumn: lines[i].to inRect:ownRect offset: ownRect.size.height color: colorIndex]; else - [self drawLineFromColumn: lines[i].from toColumn: lines[i].to inRect:ownRect offset: 0 color:lines[i].colorIndex]; + [self drawLineFromColumn: lines[i].from toColumn: lines[i].to inRect:ownRect offset: 0 color: colorIndex]; } if (cellInfo.sign == '<' || cellInfo.sign == '>') - [self drawTriangleInRect: ownRect sign: cellInfo.sign]; + [self drawTriangleInRect: ownRect sign: cellInfo.sign color: cellColorIndex]; else - [self drawCircleInRect: ownRect]; + [self drawCircleInRect: ownRect color: cellColorIndex]; } From 17cc14a69af1d7d486f8c67ef97e24172b328140 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Mon, 9 Jun 2014 21:43:22 +0200 Subject: [PATCH 4/4] Use static palette for colors This improves readability of colors on different lanes. --- Classes/Views/PBGitRevisionCell.m | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Classes/Views/PBGitRevisionCell.m b/Classes/Views/PBGitRevisionCell.m index 95e284ee5..826ed1386 100644 --- a/Classes/Views/PBGitRevisionCell.m +++ b/Classes/Views/PBGitRevisionCell.m @@ -29,15 +29,31 @@ - (id) initWithCoder: (id) coder return self; } +#define HEX_COLOR(hex) \ +{ \ + (CGFloat)((((hex) >> 16) & 0xFF) / 255.0f), \ + (CGFloat)((((hex) >> 8) & 0xFF) / 255.0f), \ + (CGFloat)((((hex) >> 0) & 0xFF) / 255.0f) \ +} + + (NSArray *)laneColors { - static const size_t colorCount = 8; + static const CGFloat colorPalette[][3] = { + HEX_COLOR(0xF00000), // red + HEX_COLOR(0xFF8000), // tangerine (orange) + HEX_COLOR(0xE0D030), // yellow + HEX_COLOR(0x008000), // clover (green) + HEX_COLOR(0x00D0D0), // cyan + HEX_COLOR(0x0000FF), // blueberry (navy) + HEX_COLOR(0x0080FF), // aqua (sky blue) + HEX_COLOR(0x8000FF), // grape (violet) + HEX_COLOR(0xFF00FF), // magenta + }; static NSArray *laneColors = nil; if (!laneColors) { - float segment = 1.0f / colorCount; NSMutableArray *colors = [NSMutableArray new]; - for (size_t i = 0; i < colorCount; ++i) { - NSColor *newColor = [NSColor colorWithCalibratedHue:(segment * i) saturation:0.9f brightness:0.9f alpha:1.0f]; + for (size_t i = 0; i < sizeof(colorPalette)/sizeof(*colorPalette); ++i) { + NSColor *newColor = [NSColor colorWithCalibratedRed:colorPalette[i][0] green:colorPalette[i][1] blue:colorPalette[i][2] alpha:1.0f]; [colors addObject:newColor]; } if (SHUFFLE_COLORS) {