Finally fixed the slow animation performance of board games; all it took was changing the board's z index from 1 to 0, somehow. Games working well now.
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;
63 // Get the bounds of the interior of the superlayer:
65 if( [superlayer respondsToSelector: @selector(borderWidth)] )
66 yinset += ((GGBLayer*)superlayer).borderWidth;
71 xinset = yinset + round(font.pointSize/3.0);
72 CGRect bounds = CGRectInset(superlayer.bounds, xinset,yinset);
74 // Compute y position of bottom of layer's frame. (Remember, descender is negative!)
75 CGFloat y = bounds.origin.y;
76 CGFloat descender=font.descender, height=font.ascender-descender;
77 if( align & kCALayerHeightSizable ) {
78 // Vertical centering:
79 y += (bounds.size.height-height)/2.0;
80 #if ! TARGET_OS_IPHONE
83 align &= ~kCALayerHeightSizable;
84 } else if( align & kCALayerMinYMargin ) {
85 // Top alignment (Mac) or bottom (iPhone):
86 y += bounds.size.height - height;
89 // Compute label's geometry:
90 label.bounds = CGRectMake(0, descender,
91 bounds.size.width, height);
92 label.anchorPoint = CGPointMake(0,0);
93 label.position = CGPointMake(bounds.origin.x,y);
95 #if ! TARGET_OS_IPHONE
96 label.autoresizingMask = align;
98 [superlayer addSublayer: label];
101 #if 0 // for debugging layout, border the view
102 label.borderWidth = 1;
103 label.borderColor = kBlackColor;
111 @synthesize string=_string, font=_font,
112 foregroundColor=_foregroundColor, alignmentMode=_alignmentMode;
115 - (id) copyWithZone: (NSZone*)zone
117 GGBTextLayer *clone = [super copyWithZone: zone];
118 clone.string = _string;
120 clone.foregroundColor = _foregroundColor;
121 clone.alignmentMode = _alignmentMode;
126 - (void)drawInContext:(CGContextRef)ctx
128 [super drawInContext: ctx];
130 if( _string.length > 0 ) {
131 CGContextSaveGState(ctx);
132 UIGraphicsPushContext(ctx);
134 if( _foregroundColor )
135 CGContextSetFillColorWithColor(ctx, _foregroundColor);
137 UITextAlignment align;
138 if( [_alignmentMode isEqualToString: @"center"] )
139 align = UITextAlignmentCenter;
140 else if( [_alignmentMode isEqualToString: @"right"] )
141 align = UITextAlignmentRight;
143 align = UITextAlignmentLeft;
145 CGRect bounds = self.bounds;
146 //float ascender=_font.ascender, descender=_font.descender, leading=_font.leading;
147 //bounds.size.height -= ascender-descender - leading;
149 [_string drawInRect: bounds
151 lineBreakMode: UILineBreakModeClip
154 UIGraphicsPopContext();
155 CGContextRestoreGState(ctx);
167 .times lt mm: (TimesLTMM)
168 times new roman: (TimesNewRomanBoldItalic, TimesNewRomanItalic, TimesNewRoman, TimesNewRomanBold)
169 phonepadtwo: (PhonepadTwo)
170 hiragino kaku gothic pron w3: (HiraKakuProN-W3)
171 helvetica neue: (HelveticaNeueBold, HelveticaNeue)
172 trebuchet ms: (TrebuchetMSItalic, TrebuchetMSBoldItalic, TrebuchetMSBold, TrebuchetMS)
173 courier new: (CourierNewBoldItalic, CourierNewBold, CourierNewItalic, CourierNew)
174 arial unicode ms: (arialuni)
175 georgia: (Georgia, GeorgiaBold, GeorgiaBoldItalic, GeorgiaItalic)
177 arial rounded mt bold: (ArialRoundedMTBold)
178 db lcd temp: (DB_LCD_Temp-Black)
179 verdana: (Verdana, VerdanaItalic, VerdanaBoldItalic, VerdanaBold)
180 american typewriter: (AmericanTypewriterCondensedBold, AmericanTypewriter)
181 helvetica: (HelveticaBoldOblique, Helvetica, HelveticaOblique, HelveticaBold)
182 lock clock: (LockClock)
183 courier: (CourierBoldOblique, CourierOblique)
184 hiragino kaku gothic pron w6: (HiraKakuProN-W6)
185 arial: (ArialItalic, ArialBold, Arial, ArialBoldItalic)
186 .helvetica lt mm: (HelveticaLTMM)
187 stheiti: (STHeiti, STXihei)
188 applegothic: (AppleGothicRegular)
189 marker felt: (MarkerFeltThin)