PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/backend/iphone/ftk_iphone_quartz_view.m

http://ftk.googlecode.com/
Objective C | 74 lines | 54 code | 16 blank | 4 comment | 5 complexity | c073f0661f0c4864f7922bf08897719a MD5 | raw file
 1
 2#import "ftk_iphone_quartz_view.h"
 3
 4@implementation FtkQuartzView
 5
 6-(id)initWithFrame:(CGRect)frame
 7{
 8	self = [super initWithFrame:frame];
 9
10	ctx = nil;
11	image = nil;
12
13	return self;
14}
15
16-(void)layoutSubviews
17{
18	[super layoutSubviews];
19}
20
21-(void)dealloc
22{
23	CGContextRelease(ctx);
24	[super dealloc];
25}
26
27-(void)drawView:(FtkBitmap*)bitmap rect:(FtkRect*)rect bits:(void*)bits xoffset:(int)xoffset yoffset:(int)yoffset width:(int)width height:(int)height
28{
29	if(ctx == nil)
30	{
31		CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
32		ctx = CGBitmapContextCreate(bits, width, height, 8, 4 * width, color_space, kCGImageAlphaPremultipliedLast);
33		CGColorSpaceRelease(color_space);
34	}
35
36	//if (image)
37	//{
38		//[image release];
39		image = nil;
40	//}
41
42	[self setNeedsDisplayInRect:CGRectMake(xoffset, yoffset, rect->width, rect->height)];
43}
44
45-(void)drawRect:(CGRect)rect
46{
47	CGImageRef img_ref = CGBitmapContextCreateImage(ctx);
48	if(!img_ref)
49	{
50		return;
51	}
52
53	CGImageRef redraw_img_ref = CGImageCreateWithImageInRect(img_ref, rect);
54	if(!redraw_img_ref)
55	{
56		CGImageRelease(img_ref);
57		return;
58	}
59
60	image = [UIImage imageWithCGImage:redraw_img_ref];
61	if(!image)
62	{
63		CGImageRelease(redraw_img_ref);
64		CGImageRelease(img_ref);
65		return;
66	}
67
68	[image drawInRect:rect];
69
70	CGImageRelease(redraw_img_ref);
71	CGImageRelease(img_ref);
72}
73
74@end