Skip to content

Commit 04beb87

Browse files
committed
• Replaced fancy tag drawn for SSYVectorImageStyleTag with simple tag that looks like one in Finder's toolbar.
• SSYVectorImages now always returns a template image. • Increased line width for SSYVectorImageStyleCheck1 and SSYVectorImageStyleCheck2. • Whitespace.
1 parent a71baf6 commit 04beb87

File tree

2 files changed

+92
-64
lines changed

2 files changed

+92
-64
lines changed

SSYTokenField.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
@details In the [email protected] archives I've seen where
2828
others have wanted an NSTokenField in an NSScrollView, and have been
2929
stymied by the lack of access to the layout mechanism in
30-
NSTokenField.  So I worked around this by adding tags one at
31-
a time, emulating the layout that NSTokenField must be doing. 
30+
NSTokenField. So I worked around this by adding tags one at
31+
a time, emulating the layout that NSTokenField must be doing.
3232
It's tedious, but works and doesn't hack into any Apple private
3333
methods.
3434
3535
Sizing is based on an interrow spacing of 2.0 which was
3636
determined empirically since NSTokenField, unlike NSTableView, does
3737
not make its interrow spacing accessible, and also the fact that
38-
the interrow spacing seems to be independent of font size. 
38+
the interrow spacing seems to be independent of font size.
3939
This has been tested with the token field's font size set to
40-
-[NSFont systemFontOfSize:11.0] and -[NSFont systemFontOfSize:21.0]. 
41-
The code may need to be tweaked if Apple ever changes the layout
40+
-[NSFont systemFontOfSize:11.0] and -[NSFont systemFontOfSize:21.0].
41+
The code may need to be tweaked if Apple ever changes the layout
4242
algorithm of NSTokenField.
4343
*/
4444
- (void)sizeHeightToFit ;

SSYVectorImages.m

+87-59
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ + (NSImage*)imageWithGlyphName:(NSString*)glyphName
4040

4141
+ (void)checkmarkOnPath:(NSBezierPath*)path
4242
x:(CGFloat)x {
43-
[path setLineWidth:7] ;
43+
[path setLineWidth:8] ;
4444
[path moveToPoint:NSMakePoint(x,42)] ;
4545
[path lineToPoint:NSMakePoint(x+17,21)] ;
4646
[path curveToPoint:NSMakePoint(x+49, 79)
@@ -354,68 +354,25 @@ + (void)drawStyle:(SSYVectorImageStyle)style
354354

355355
break ;
356356
case SSYVectorImageStyleTag:;
357-
#define LINE_WIDTH 3.0
358-
#define LEFT_MARGIN 9
359-
#define TAG_WIDTH 67
360-
#define TAG_HEIGHT 42
361-
#define HOLE_FOR_STRING_RADIUS 6
362-
#define HOLE_OFFSET 5
363-
#define STRING_INSET 2
364-
#define TAG_ROTATION 30
357+
#define LINE_WIDTH 7.0
358+
#define TAG_HEIGHT 54
359+
#define TAG_INSET 22
360+
#define TAG_HOLE_RADIUS 4
365361
CGFloat bottomMargin = (100.0-TAG_HEIGHT)/2 ;
366-
NSRect tagRect = NSMakeRect(LEFT_MARGIN, bottomMargin, TAG_WIDTH, TAG_HEIGHT) ;
367-
368-
path = [NSBezierPath bezierPathWithRect:tagRect] ;
369-
370-
[path setLineWidth:LINE_WIDTH] ;
371-
372-
/* Punch a round hole near the left side of the tag body
373-
This is done by with a separate bezier path which we first
374-
*reverse* and then *append* to the bookmark bezier path. */
375-
NSBezierPath* stringHolePath = [NSBezierPath bezierPath] ;
376-
NSRect stringHoleRect = NSMakeRect(
377-
(LEFT_MARGIN + HOLE_OFFSET),
378-
(50.0 - HOLE_FOR_STRING_RADIUS),
379-
2*HOLE_FOR_STRING_RADIUS,
380-
2*HOLE_FOR_STRING_RADIUS
381-
) ;
382-
[stringHolePath appendBezierPathWithOvalInRect:stringHoleRect] ;
383-
stringHolePath = [stringHolePath bezierPathByReversingPath] ;
384-
[path appendBezierPath:stringHolePath] ;
385-
386-
NSBezierPath* stringPath = [NSBezierPath bezierPath] ;
387-
NSPoint stringStart = NSMakePoint(LEFT_MARGIN + HOLE_OFFSET + STRING_INSET, (50.0)) ;
388-
[stringPath moveToPoint:stringStart] ;
389-
[stringPath relativeCurveToPoint:NSMakePoint(-30, -30)
390-
controlPoint1:NSMakePoint(-15, 5)
391-
controlPoint2:NSMakePoint(-25,-15)] ;
392-
[stringPath setLineWidth:LINE_WIDTH] ;
393-
[stringPath setLineCapStyle:NSRoundLineCapStyle] ;
394-
395-
// Now move the origin to the center of the eye and rotate it
396-
NSAffineTransform* centerRotateTransform = [NSAffineTransform transform] ;
397-
[centerRotateTransform translateXBy:(50.0)
398-
yBy:(50.0)];
399-
[centerRotateTransform rotateByDegrees:TAG_ROTATION];
400-
[centerRotateTransform translateXBy:-(50.0)
401-
yBy:-(50.0)];
402-
[centerRotateTransform translateXBy:7
403-
yBy:0];
404-
[centerRotateTransform concat];
405-
406-
[[NSColor whiteColor] set] ;
407-
[path fill] ;
408-
362+
[path setLineWidth:4.0] ;
363+
[path moveToPoint:NSMakePoint(0, 50)] ;
364+
[path lineToPoint:NSMakePoint(TAG_INSET, bottomMargin)] ;
365+
[path lineToPoint:NSMakePoint(100, bottomMargin)] ;
366+
[path lineToPoint:NSMakePoint(100, 100 - bottomMargin)] ;
367+
[path lineToPoint:NSMakePoint(TAG_INSET, 100 - bottomMargin)] ;
368+
[path closePath] ;
369+
[path appendBezierPathWithArcWithCenter:NSMakePoint(TAG_INSET, 50)
370+
radius:TAG_HOLE_RADIUS
371+
startAngle:0.0
372+
endAngle:360.0] ;
409373
[[NSColor blackColor] set] ;
410374
[path stroke] ;
411375

412-
[[NSColor blackColor] set] ;
413-
[stringPath stroke] ;
414-
415-
// Clean up the coordinate system - although not technically necessary because we're all done
416-
[centerRotateTransform invert] ;
417-
[centerRotateTransform concat] ;
418-
419376
break ;
420377
case SSYVectorImageStyleCheck1:;
421378
[self checkmarkOnPath:path
@@ -562,9 +519,80 @@ + (NSImage*)imageStyle:(SSYVectorImageStyle)style
562519
[image release] ;
563520
}
564521

522+
[rotatedImage setTemplate:YES] ;
523+
565524
return rotatedImage ;
566525
}
567526

568527

569528
@end
570529

530+
#if 0
531+
/* The following code, which shows how to draw a fancy tag that is filled except
532+
for an unfilled hole, and rotated 30 degrees, is no longer used, but I'm
533+
keeping it as sample code in case the fashion designers at Apple someday
534+
decide that flat is out and fancy is in.
535+
*/
536+
#define LINE_WIDTH 3.0
537+
#define LEFT_MARGIN 9
538+
#define TAG_WIDTH 67
539+
#define TAG_HEIGHT 42
540+
#define HOLE_FOR_STRING_RADIUS 6
541+
#define HOLE_OFFSET 5
542+
#define STRING_INSET 2
543+
#define TAG_ROTATION 30
544+
CGFloat bottomMargin = (100.0-TAG_HEIGHT)/2 ;
545+
NSRect tagRect = NSMakeRect(LEFT_MARGIN, bottomMargin, TAG_WIDTH, TAG_HEIGHT) ;
546+
547+
path = [NSBezierPath bezierPathWithRect:tagRect] ;
548+
549+
[path setLineWidth:LINE_WIDTH] ;
550+
551+
/* Punch a round hole near the left side of the tag body
552+
This is done by with a separate bezier path which we first
553+
*reverse* and then *append* to the bookmark bezier path. */
554+
NSBezierPath* stringHolePath = [NSBezierPath bezierPath] ;
555+
NSRect stringHoleRect = NSMakeRect(
556+
(LEFT_MARGIN + HOLE_OFFSET),
557+
(50.0 - HOLE_FOR_STRING_RADIUS),
558+
2*HOLE_FOR_STRING_RADIUS,
559+
2*HOLE_FOR_STRING_RADIUS
560+
) ;
561+
[stringHolePath appendBezierPathWithOvalInRect:stringHoleRect] ;
562+
stringHolePath = [stringHolePath bezierPathByReversingPath] ;
563+
[path appendBezierPath:stringHolePath] ;
564+
565+
NSBezierPath* stringPath = [NSBezierPath bezierPath] ;
566+
NSPoint stringStart = NSMakePoint(LEFT_MARGIN + HOLE_OFFSET + STRING_INSET, (50.0)) ;
567+
[stringPath moveToPoint:stringStart] ;
568+
[stringPath relativeCurveToPoint:NSMakePoint(-30, -30)
569+
controlPoint1:NSMakePoint(-15, 5)
570+
controlPoint2:NSMakePoint(-25,-15)] ;
571+
[stringPath setLineWidth:LINE_WIDTH] ;
572+
[stringPath setLineCapStyle:NSRoundLineCapStyle] ;
573+
574+
// Now move the origin to the center of the eye and rotate it
575+
NSAffineTransform* centerRotateTransform = [NSAffineTransform transform] ;
576+
[centerRotateTransform translateXBy:(50.0)
577+
yBy:(50.0)];
578+
[centerRotateTransform rotateByDegrees:TAG_ROTATION];
579+
[centerRotateTransform translateXBy:-(50.0)
580+
yBy:-(50.0)];
581+
[centerRotateTransform translateXBy:7
582+
yBy:0];
583+
[centerRotateTransform concat];
584+
585+
[[NSColor whiteColor] set] ;
586+
[path fill] ;
587+
588+
[[NSColor blackColor] set] ;
589+
[path stroke] ;
590+
591+
[[NSColor blackColor] set] ;
592+
[stringPath stroke] ;
593+
594+
// Clean up the coordinate system - although not technically necessary because we're all done
595+
[centerRotateTransform invert] ;
596+
[centerRotateTransform concat] ;
597+
598+
#endif

0 commit comments

Comments
 (0)