/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. #import "ftk_iphone_quartz_view.h"
  2. @implementation FtkQuartzView
  3. -(id)initWithFrame:(CGRect)frame
  4. {
  5. self = [super initWithFrame:frame];
  6. ctx = nil;
  7. image = nil;
  8. return self;
  9. }
  10. -(void)layoutSubviews
  11. {
  12. [super layoutSubviews];
  13. }
  14. -(void)dealloc
  15. {
  16. CGContextRelease(ctx);
  17. [super dealloc];
  18. }
  19. -(void)drawView:(FtkBitmap*)bitmap rect:(FtkRect*)rect bits:(void*)bits xoffset:(int)xoffset yoffset:(int)yoffset width:(int)width height:(int)height
  20. {
  21. if(ctx == nil)
  22. {
  23. CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
  24. ctx = CGBitmapContextCreate(bits, width, height, 8, 4 * width, color_space, kCGImageAlphaPremultipliedLast);
  25. CGColorSpaceRelease(color_space);
  26. }
  27. //if (image)
  28. //{
  29. //[image release];
  30. image = nil;
  31. //}
  32. [self setNeedsDisplayInRect:CGRectMake(xoffset, yoffset, rect->width, rect->height)];
  33. }
  34. -(void)drawRect:(CGRect)rect
  35. {
  36. CGImageRef img_ref = CGBitmapContextCreateImage(ctx);
  37. if(!img_ref)
  38. {
  39. return;
  40. }
  41. CGImageRef redraw_img_ref = CGImageCreateWithImageInRect(img_ref, rect);
  42. if(!redraw_img_ref)
  43. {
  44. CGImageRelease(img_ref);
  45. return;
  46. }
  47. image = [UIImage imageWithCGImage:redraw_img_ref];
  48. if(!image)
  49. {
  50. CGImageRelease(redraw_img_ref);
  51. CGImageRelease(img_ref);
  52. return;
  53. }
  54. [image drawInRect:rect];
  55. CGImageRelease(redraw_img_ref);
  56. CGImageRelease(img_ref);
  57. }
  58. @end