From 2ac50443ddbf69b7594808ba4e6de49eecbc0b84 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 22 Aug 2011 19:52:08 -0400 Subject: Added borders to level selection images The image for each level selection now has a tutorial bubble-esque border around it, which was achieved using image masking. The border is included in the graying-out effect when the image is being tapped, and it is also included in the grayscaling when the level is not yet unlocked. Also rewrote most of the selection drawing code. The titles are now drawn above the image, with Quartz instead of Cocos2D. The highscore label is also drawn with Quartz, though it is still below the image. The unlock condition label no longer appears, and instead, locked levels are now tappable and tapping them shows an alert view containing the unlock condition. Will probably be changed to be more elegant later. Really, the biggest thing left before the selection screen is done is the ability to scroll through levels. The background also needs changing, but that will come later once I recruit a graphics designer. :P Refs #207 --- Classes/UIImage+ColorMasking.m | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Classes/UIImage+ColorMasking.m (limited to 'Classes/UIImage+ColorMasking.m') diff --git a/Classes/UIImage+ColorMasking.m b/Classes/UIImage+ColorMasking.m new file mode 100644 index 0000000..e4da8c8 --- /dev/null +++ b/Classes/UIImage+ColorMasking.m @@ -0,0 +1,77 @@ +// +// UIImage+ColorMasking.m +// Cartographic +// +// Created by Starla Insigna on 8/22/11. +// Copyright 2011 Four Island. All rights reserved. +// + +#import "UIImage+ColorMasking.h" + +@implementation UIImage (ColorMasking) + +typedef enum { + ALPHA = 0, + BLUE = 1, + GREEN = 2, + RED = 3 +} PIXELS; + +- (UIImage *)opaqueMaskFromWhiteImage +{ + CGSize size = [self size]; + int width = size.width; + int height = size.height; + + // the pixels will be painted to this array + uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t)); + + // clear the pixels so any transparency is preserved + memset(pixels, 0, width * height * sizeof(uint32_t)); + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + // create a context with RGBA pixels + CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, + kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast); + + // paint the bitmap to our context which will fill in the pixels array + CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]); + + for(int y = 0; y < height; y++) { + for(int x = 0; x < width; x++) { + uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x]; + + if ((rgbaPixel[RED] == 255) && (rgbaPixel[GREEN] == 255) && (rgbaPixel[BLUE] == 255) && (rgbaPixel[ALPHA] == 255)) + { + rgbaPixel[RED] = 255; + rgbaPixel[GREEN] = 255; + rgbaPixel[BLUE] = 255; + rgbaPixel[ALPHA] = 255; + } else { + rgbaPixel[RED] = 0; + rgbaPixel[GREEN] = 0; + rgbaPixel[BLUE] = 0; + rgbaPixel[ALPHA] = 0; + } + } + } + + // create a new CGImageRef from our context with the modified pixels + CGImageRef image = CGBitmapContextCreateImage(context); + + // we're done with the context, color space, and pixels + CGContextRelease(context); + CGColorSpaceRelease(colorSpace); + free(pixels); + + // make a new UIImage to return + UIImage *resultUIImage = [UIImage imageWithCGImage:image]; + + // we're done with image now too + CGImageRelease(image); + + return resultUIImage; +} + +@end -- cgit 1.4.1