#import <UIKit/UIKit.h>
@interface ShapeGlowView : UIView {
CGMutablePathRef multiSquare;
UIColor *greenColor;
UIColor *blackColor;
}
@end
@implementation ShapeGlowView
- (void) _commonInit {
greenColor = [[UIColor alloc] initWithRed:0.56f green:0.86f blue:0.30f alpha:1.0f];
blackColor = [[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];
multiSquare = CGPathCreateMutable();
CGPathMoveToPoint(multiSquare, NULL, 0.0f, 0.0f);
CGPathAddLineToPoint(multiSquare, NULL, 1.0f, 0.0f);
CGPathAddLineToPoint(multiSquare, NULL, 1.0f, 1.0f);
CGPathAddLineToPoint(multiSquare, NULL, 0.0f, 1.0f);
CGPathAddLineToPoint(multiSquare, NULL, 0.0f, 0.0f);
CGPathMoveToPoint(multiSquare, NULL, 0.5f, 0.0f);
CGPathAddLineToPoint(multiSquare, NULL, 1.0f, 0.5f);
CGPathAddLineToPoint(multiSquare, NULL, 0.5f, 1.0f);
CGPathAddLineToPoint(multiSquare, NULL, 0.0f, 0.5f);
CGPathAddLineToPoint(multiSquare, NULL, 0.5f, 0.0f);
CGPathMoveToPoint(multiSquare, NULL, 0.25f, 0.25f);
CGPathAddLineToPoint(multiSquare, NULL, 0.75f, 0.25f);
CGPathAddLineToPoint(multiSquare, NULL, 0.75f, 0.75f);
CGPathAddLineToPoint(multiSquare, NULL, 0.25f, 0.75f);
CGPathAddLineToPoint(multiSquare, NULL, 0.25f, 0.25f);
CGPathCloseSubpath(multiSquare);
}
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self _commonInit];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
[self _commonInit];
}
return self;
}
- (void) drawPathWithContext: (CGContextRef) c atPoint: (CGPoint) point andScale: (CGFloat) scale andRotation: (CGFloat) rotate {
CGContextSaveGState(c);
CGContextSetShadowWithColor(c, CGSizeZero, scale/2.0f, greenColor.CGColor);
CGContextTranslateCTM(c, point.x, point.y);
CGContextRotateCTM(c, rotate);
CGContextScaleCTM(c, scale, scale);
CGContextSetLineWidth(c, 2.0f/scale);
CGContextAddPath(c, multiSquare);
CGContextStrokePath(c);
CGContextRestoreGState(c);
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, greenColor.CGColor);
CGContextSetFillColorWithColor(context, blackColor.CGColor);
CGContextAddRect(context, self.bounds);
CGContextFillPath(context);
// draw some squares
[self drawPathWithContext:context
atPoint:CGPointMake(25.0f, 50.0f)
andScale: 25.0f
andRotation: 0.1f ];
[self drawPathWithContext:context
atPoint:CGPointMake(58.0f, 20.0f)
andScale: 50.0f
andRotation: 0.0f ];
[self drawPathWithContext:context
atPoint:CGPointMake(100.0f, 125.0f)
andScale: 30.0f
andRotation: 0.25f ];
}
- (void)dealloc {
CGPathRelease(multiSquare);
[greenColor release];
[blackColor release];
[super dealloc];
}
@end