Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A category for Sparrow 2.X that allows a SPQuad (or subclass) to get/set red, green, and blue color components.
//
// SPQuad+ColorComponents.h
// Sparrow 2.X
//
// Created by Shilo White on 7/9/13.
//
#import "SPQuad.h"
@interface SPQuad (ColorComponents)
- (id)initWithWidth:(float)width height:(float)height red:(uint)red green:(uint)green blue:(uint)blue premultipliedAlpha:(BOOL)pma;
- (id)initWithWidth:(float)width height:(float)height red:(uint)red green:(uint)green blue:(uint)blue;
+ (id)quadWithWidth:(float)width height:(float)height red:(uint)red green:(uint)green blue:(uint)blue;
- (void)setRed:(uint)red green:(uint)green blue:(uint)blue ofVertex:(int)vertexID;
- (void)setRedValue:(uint)red ofVertex:(int)vertexID;
- (void)setGreenValue:(uint)green ofVertex:(int)vertexID;
- (void)setBlueValue:(uint)blue ofVertex:(int)vertexID;
- (uint)redValueOfVertex:(int)vertexID;
- (uint)greenValueOfVertex:(int)vertexID;
- (uint)blueValueOfVertex:(int)vertexID;
@property (nonatomic, assign) uint redValue;
@property (nonatomic, assign) uint greenValue;
@property (nonatomic, assign) uint blueValue;
@end
//
// SPQuad+ColorComponents.m
// Sparrow 2.X
//
// Created by Shilo White on 7/9/13.
//
#import "SPQuad+ColorComponents.h"
@implementation SPQuad (ColorComponents)
- (id)initWithWidth:(float)width height:(float)height red:(uint)red green:(uint)green blue:(uint)blue premultipliedAlpha:(BOOL)pma
{
return [self initWithWidth:width height:height color:SP_COLOR(red, green, blue) premultipliedAlpha:pma];
}
- (id)initWithWidth:(float)width height:(float)height red:(uint)red green:(uint)green blue:(uint)blue
{
return [self initWithWidth:width height:height color:SP_COLOR(red, green, blue)];
}
+ (id)quadWithWidth:(float)width height:(float)height red:(uint)red green:(uint)green blue:(uint)blue
{
return [[self alloc] initWithWidth:width height:height red:red green:green blue:blue];
}
- (void)setRed:(uint)red green:(uint)green blue:(uint)blue ofVertex:(int)vertexID
{
[self setColor:SP_COLOR(red, green, blue) ofVertex:vertexID];
}
- (void)setRedValue:(uint)red ofVertex:(int)vertexID
{
uint color = [self colorOfVertex:vertexID];
[self setColor:SP_COLOR(red, SP_COLOR_PART_GREEN(color), SP_COLOR_PART_BLUE(color)) ofVertex:vertexID];
}
- (void)setGreenValue:(uint)green ofVertex:(int)vertexID
{
uint color = [self colorOfVertex:vertexID];
[self setColor:SP_COLOR(SP_COLOR_PART_RED(color), green, SP_COLOR_PART_BLUE(color)) ofVertex:vertexID];
}
- (void)setBlueValue:(uint)blue ofVertex:(int)vertexID
{
uint color = [self colorOfVertex:vertexID];
[self setColor:SP_COLOR(SP_COLOR_PART_RED(color), SP_COLOR_PART_GREEN(color), blue) ofVertex:vertexID];
}
- (uint)redValueOfVertex:(int)vertexID
{
return SP_COLOR_PART_RED([self colorOfVertex:vertexID]);
}
- (uint)greenValueOfVertex:(int)vertexID
{
return SP_COLOR_PART_GREEN([self colorOfVertex:vertexID]);
}
- (uint)blueValueOfVertex:(int)vertexID
{
return SP_COLOR_PART_BLUE([self colorOfVertex:vertexID]);
}
- (void)setRedValue:(uint)red
{
uint color = self.color;
[self setColor:SP_COLOR(red, SP_COLOR_PART_GREEN(color), SP_COLOR_PART_BLUE(color))];
}
- (void)setGreenValue:(uint)green
{
uint color = self.color;
[self setColor:SP_COLOR(SP_COLOR_PART_RED(color), green, SP_COLOR_PART_BLUE(color))];
}
- (void)setBlueValue:(uint)blue
{
uint color = self.color;
[self setColor:SP_COLOR(SP_COLOR_PART_RED(color), SP_COLOR_PART_GREEN(color), blue)];
}
- (uint)redValue
{
return [self redValueOfVertex:0];
}
- (uint)greenValue
{
return [self greenValueOfVertex:0];
}
- (uint)blueValue
{
return [self blueValueOfVertex:0];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.