diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2017-01-11 16:33:00 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2017-01-11 16:33:00 +0100 |
commit | 1802977b95d29198f27535b1b731d1180c083667 (patch) | |
tree | 032c4beb7411d88d76794a25f0e3b00a3437da3e /tikzit/src/osx/CALayer+DrawLabel.m | |
parent | ff79a9c213dfd75ea00ed5112d3a6e314601e064 (diff) |
made new subdir
Diffstat (limited to 'tikzit/src/osx/CALayer+DrawLabel.m')
-rw-r--r-- | tikzit/src/osx/CALayer+DrawLabel.m | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/tikzit/src/osx/CALayer+DrawLabel.m b/tikzit/src/osx/CALayer+DrawLabel.m deleted file mode 100644 index 4860a3c..0000000 --- a/tikzit/src/osx/CALayer+DrawLabel.m +++ /dev/null @@ -1,84 +0,0 @@ -// -// CALayer+DrawLabel.m -// TikZiT -// -// Created by Aleks Kissinger on 09/05/2011. -// Copyright 2011 Aleks Kissinger. All rights reserved. -// - -#import "CALayer+DrawLabel.h" -#import "Transformer.h" - -@implementation CALayer(DrawLabel) - -- (void)drawLabel:(NSString*)label - atPoint:(NSPoint)pt - inContext:(CGContextRef)context - usingTrans:(Transformer*)t { - - CGContextSaveGState(context); - - if ([label length] > 15) { - label = [[label substringToIndex:12] stringByAppendingString:@"..."]; - } - - float fontSize = [t scaleToScreen:0.18f]; // size 9 @ 100% - if (fontSize > 18.0f) fontSize = 18.0f; - - // Prepare font - CTFontRef font = CTFontCreateWithName(CFSTR("Monaco"), fontSize, NULL); - - // Create an attributed string - CFStringRef keys[] = { kCTFontAttributeName }; - CFTypeRef values[] = { font }; - CFDictionaryRef attr = CFDictionaryCreate(NULL, - (const void **)&keys, - (const void **)&values, - sizeof(keys) / sizeof(keys[0]), - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - CFAttributedStringRef attrString = - CFAttributedStringCreate(NULL, (CFStringRef)label, attr); - CFRelease(attr); - - // Draw the string - CTLineRef line = CTLineCreateWithAttributedString(attrString); - CGContextSetTextMatrix(context, CGAffineTransformIdentity); - CGContextSetTextPosition(context, 0, 0); - - CGRect labelBounds = CGRectIntegral(CTLineGetImageBounds(line, context)); - //int shiftx = round(labelBounds.size.width / 2); - - CGContextSetTextPosition(context, - round(pt.x - (labelBounds.size.width/2)), - round(pt.y - (0.9*labelBounds.size.height/2))); - - labelBounds = CGRectIntegral(CTLineGetImageBounds(line, context)); - labelBounds.origin.x -= 2; - labelBounds.origin.y -= 2; - labelBounds.size.width += 4; - labelBounds.size.height += 4; - - CGContextSetShouldAntialias(context, NO); - - CGContextSetRGBFillColor(context, 1.0f, 1.0f, 0.5f, 0.7f); - CGContextSetRGBStrokeColor(context, 0.5f, 0.0f, 0.0f, 0.7f); - - CGContextFillRect(context, labelBounds); - CGContextStrokeRect(context, labelBounds); - - CGContextSetShouldAntialias(context, YES); - - CGContextSetRGBFillColor(context, 0.3f, 0.3f, 0.3f, 0.7f); - - CTLineDraw(line, context); - - // Clean up - CFRelease(line); - CFRelease(attrString); - CFRelease(font); - - CGContextRestoreGState(context); -} - -@end |