Permalink
Browse files

Abstracting out gradient scale

  • Loading branch information...
1 parent 40dca9a commit e36c194777e715cb821aa82c159f148f8c848bd7 @soffes soffes committed Nov 2, 2011
Showing with 16 additions and 0 deletions.
  1. +2 −0 SSToolkit/SSDrawingUtilities.h
  2. +14 −0 SSToolkit/SSDrawingUtilities.m
@@ -75,7 +75,9 @@ extern void SSDrawRoundedRect(CGContextRef context, CGRect rect, CGFloat cornerR
///-------------------------
extern CGGradientRef SSCreateGradientWithColors(NSArray *colors);
+extern CGGradientRef SSCreateGradientWithColorsAndScale(NSArray *colors, CGFloat scale);
extern CGGradientRef SSCreateGradientWithColorsAndLocations(NSArray *colors, NSArray *locations);
+extern NSArray *SSGradientLocationsWithScale(CGFloat scale);
///------------------------
@@ -95,6 +95,11 @@ CGGradientRef SSCreateGradientWithColors(NSArray *colors) {
}
+CGGradientRef SSCreateGradientWithColorsAndScale(NSArray *colors, CGFloat scale) {
+ return SSCreateGradientWithColorsAndLocations(colors, SSGradientLocationsWithScale(scale));
+}
+
+
CGGradientRef SSCreateGradientWithColorsAndLocations(NSArray *colors, NSArray *locations) {
NSUInteger colorsCount = [colors count];
if (colorsCount < 2) {
@@ -128,6 +133,15 @@ CGGradientRef SSCreateGradientWithColorsAndLocations(NSArray *colors, NSArray *l
}
+NSArray *SSGradientLocationsWithScale(CGFloat scale) {
+ CGFloat top = fmaxf((1.0f - scale) / 2.0f, 0.0f);
+ CGFloat bottom = top + (scale > 1.0f ? scale - 1.0f : scale);
+ NSArray *locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:top], [NSNumber numberWithFloat:bottom], nil];
+ NSLog(@"Locations: %@", locations);
+ return locations;
+}
+
+
void SSDrawGradientInRect(CGContextRef context, CGGradientRef gradient, CGRect rect) {
CGContextSaveGState(context);
CGContextClipToRect(context, rect);

0 comments on commit e36c194

Please sign in to comment.