Text, playing cards, and Klondike solitaire all work on iPhone now. (Regression: Klondike UI layout has changed, and is awkward on Mac now. Need to special case that.)
5 // Created by Jens Alfke on 3/10/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "GGBTextLayer.h"
10 #import "QuartzUtils.h"
13 @implementation GGBTextLayer
16 + (GGBTextLayer*) textLayerInSuperlayer: (CALayer*)superlayer
17 withText: (NSString*)text
18 fontSize: (float) fontSize
19 alignment: (enum CAAutoresizingMask) align
22 UIFont *font = [UIFont systemFontOfSize: fontSize];
24 NSFont *font = [NSFont systemFontOfSize: fontSize];
26 return [self textLayerInSuperlayer: superlayer
33 + (GGBTextLayer*) textLayerInSuperlayer: (CALayer*)superlayer
34 withText: (NSString*)text
36 alignment: (enum CAAutoresizingMask) align
38 GGBTextLayer *label = [[self alloc] init];
42 UIFont *font = inputFont;
43 [label setNeedsDisplay];
44 label.needsDisplayOnBoundsChange = YES;
46 NSFont *font = inputFont;
47 label.fontSize = font.pointSize;
51 label.foregroundColor = kBlackColor;
54 if( align & kCALayerWidthSizable )
56 else if( align & kCALayerMinXMargin )
60 align |= kCALayerWidthSizable;
61 label.alignmentMode = mode;
64 if( [superlayer respondsToSelector: @selector(borderWidth)] )
65 inset += ((GGBLayer*)superlayer).borderWidth;
66 CGRect bounds = CGRectInset(superlayer.bounds, inset, inset);
68 bounds = CGRectInset(bounds,-inset,0);
69 CGFloat height = font.ascender;
70 float descender = font.descender;
72 descender = -descender;
74 CGFloat y = bounds.origin.y;
75 if( align & kCALayerHeightSizable ) {
76 y += (bounds.size.height-height)/2.0;
80 } else if( align & kCALayerMinYMargin )
81 y += bounds.size.height - height;
82 align &= ~kCALayerHeightSizable;
83 label.bounds = CGRectMake(0, descender,
84 bounds.size.width, height - descender);
85 label.position = CGPointMake(bounds.origin.x,y+descender);
86 label.anchorPoint = CGPointMake(0,0);
89 label.autoresizingMask = align;
91 [superlayer addSublayer: label];
94 //label.borderWidth = 1;
95 //label.borderColor = kBlackColor;
102 @synthesize string=_string, font=_font,
103 foregroundColor=_foregroundColor, alignmentMode=_alignmentMode;
106 - (id) copyWithZone: (NSZone*)zone
108 GGBTextLayer *clone = [super copyWithZone: zone];
109 clone.string = _string;
111 clone.foregroundColor = _foregroundColor;
112 clone.alignmentMode = _alignmentMode;
117 - (void)drawInContext:(CGContextRef)ctx
119 [super drawInContext: ctx];
121 if( _string.length > 0 ) {
122 CGContextSaveGState(ctx);
123 UIGraphicsPushContext(ctx);
125 if( _foregroundColor )
126 CGContextSetFillColorWithColor(ctx, _foregroundColor);
128 UITextAlignment align;
129 if( [_alignmentMode isEqualToString: @"center"] )
130 align = UITextAlignmentCenter;
131 else if( [_alignmentMode isEqualToString: @"right"] )
132 align = UITextAlignmentRight;
134 align = UITextAlignmentLeft;
136 CGRect bounds = self.bounds;
137 bounds.origin.y += _font.ascender+_font.descender - _font.leading;
138 [_string drawInRect: bounds
140 lineBreakMode: UILineBreakModeClip
143 UIGraphicsPopContext();
144 CGContextRestoreGState(ctx);
156 .times lt mm: (TimesLTMM)
157 times new roman: (TimesNewRomanBoldItalic, TimesNewRomanItalic, TimesNewRoman, TimesNewRomanBold)
158 phonepadtwo: (PhonepadTwo)
159 hiragino kaku gothic pron w3: (HiraKakuProN-W3)
160 helvetica neue: (HelveticaNeueBold, HelveticaNeue)
161 trebuchet ms: (TrebuchetMSItalic, TrebuchetMSBoldItalic, TrebuchetMSBold, TrebuchetMS)
162 courier new: (CourierNewBoldItalic, CourierNewBold, CourierNewItalic, CourierNew)
163 arial unicode ms: (arialuni)
164 georgia: (Georgia, GeorgiaBold, GeorgiaBoldItalic, GeorgiaItalic)
166 arial rounded mt bold: (ArialRoundedMTBold)
167 db lcd temp: (DB_LCD_Temp-Black)
168 verdana: (Verdana, VerdanaItalic, VerdanaBoldItalic, VerdanaBold)
169 american typewriter: (AmericanTypewriterCondensedBold, AmericanTypewriter)
170 helvetica: (HelveticaBoldOblique, Helvetica, HelveticaOblique, HelveticaBold)
171 lock clock: (LockClock)
172 courier: (CourierBoldOblique, CourierOblique)
173 hiragino kaku gothic pron w6: (HiraKakuProN-W6)
174 arial: (ArialItalic, ArialBold, Arial, ArialBoldItalic)
175 .helvetica lt mm: (HelveticaLTMM)
176 stheiti: (STHeiti, STXihei)
177 applegothic: (AppleGothicRegular)
178 marker felt: (MarkerFeltThin)