summaryrefslogtreecommitdiff
path: root/cocoa/PSMTabBarControl/NSBezierPath_AMShading.m
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-01-26 10:52:13 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-01-26 10:52:13 +0000
commit7b2694e9f6c35d9f50c3fb3cf38b0fc766478162 (patch)
treec4e3d07a6bb51de884f53312a96d05849f072db1 /cocoa/PSMTabBarControl/NSBezierPath_AMShading.m
parenta663cf8f84942e1147d1d2f3db292308639c7fa5 (diff)
downloadnetsurf-7b2694e9f6c35d9f50c3fb3cf38b0fc766478162.tar.gz
netsurf-7b2694e9f6c35d9f50c3fb3cf38b0fc766478162.tar.bz2
Updated PSMTabBarControl source code to version from https://github.com/dergraf83/PSMTabBarControl
svn path=/trunk/netsurf/; revision=11490
Diffstat (limited to 'cocoa/PSMTabBarControl/NSBezierPath_AMShading.m')
-rw-r--r--[-rwxr-xr-x]cocoa/PSMTabBarControl/NSBezierPath_AMShading.m86
1 files changed, 39 insertions, 47 deletions
diff --git a/cocoa/PSMTabBarControl/NSBezierPath_AMShading.m b/cocoa/PSMTabBarControl/NSBezierPath_AMShading.m
index 73213f3b5..30ee24096 100755..100644
--- a/cocoa/PSMTabBarControl/NSBezierPath_AMShading.m
+++ b/cocoa/PSMTabBarControl/NSBezierPath_AMShading.m
@@ -11,8 +11,7 @@
@implementation NSBezierPath (AMShading)
-static void linearShadedColor(void *info, const CGFloat *in, CGFloat *out)
-{
+static void linearShadedColor(void *info, const CGFloat *in, CGFloat *out){
CGFloat *colors = (CGFloat *)info;
*out++ = colors[0] + *in * colors[8];
*out++ = colors[1] + *in * colors[9];
@@ -20,12 +19,11 @@ static void linearShadedColor(void *info, const CGFloat *in, CGFloat *out)
*out++ = colors[3] + *in * colors[11];
}
-static void bilinearShadedColor(void *info, const CGFloat *in, CGFloat *out)
-{
+static void bilinearShadedColor(void *info, const CGFloat *in, CGFloat *out){
CGFloat *colors = (CGFloat *)info;
- CGFloat factor = (*in)*2.0;
- if (*in > 0.5) {
- factor = 2-factor;
+ CGFloat factor = (*in) * 2.0;
+ if(*in > 0.5) {
+ factor = 2 - factor;
}
*out++ = colors[0] + factor * colors[8];
*out++ = colors[1] + factor * colors[9];
@@ -33,95 +31,89 @@ static void bilinearShadedColor(void *info, const CGFloat *in, CGFloat *out)
*out++ = colors[3] + factor * colors[11];
}
-- (void)linearGradientFillWithStartColor:(NSColor *)startColor endColor:(NSColor *)endColor
-{
+- (void)linearGradientFillWithStartColor:(NSColor *)startColor endColor:(NSColor *)endColor {
static const CGFunctionCallbacks callbacks = {0, &linearShadedColor, NULL};
-
+
[self customHorizontalFillWithCallbacks:callbacks firstColor:startColor secondColor:endColor];
}
-- (void)linearVerticalGradientFillWithStartColor:(NSColor *)startColor endColor:(NSColor *)endColor
-{
+- (void)linearVerticalGradientFillWithStartColor:(NSColor *)startColor endColor:(NSColor *)endColor {
static const CGFunctionCallbacks callbacks = {0, &linearShadedColor, NULL};
-
+
[self customVerticalFillWithCallbacks:callbacks firstColor:startColor secondColor:endColor];
}
-- (void)bilinearGradientFillWithOuterColor:(NSColor *)outerColor innerColor:(NSColor *)innerColor
-{
+- (void)bilinearGradientFillWithOuterColor:(NSColor *)outerColor innerColor:(NSColor *)innerColor {
static const CGFunctionCallbacks callbacks = {0, &bilinearShadedColor, NULL};
[self customHorizontalFillWithCallbacks:callbacks firstColor:innerColor secondColor:outerColor];
}
-- (void)customFillWithCallbacks:(CGFunctionCallbacks)functionCallbacks firstColor:(NSColor *)firstColor secondColor:(NSColor *)secondColor startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint
-{
+- (void)customFillWithCallbacks:(CGFunctionCallbacks)functionCallbacks firstColor:(NSColor *)firstColor secondColor:(NSColor *)secondColor startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint {
CGColorSpaceRef colorspace;
CGShadingRef shading;
CGFunctionRef function;
- CGFloat colors[12]; // pointer to color values
-
+ CGFloat colors[12]; // pointer to color values
+
// get my context
CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-
+
NSColor *deviceDependentFirstColor = [firstColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
NSColor *deviceDependentSecondColor = [secondColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
-
+
// set up colors for gradient
colors[0] = [deviceDependentFirstColor redComponent];
colors[1] = [deviceDependentFirstColor greenComponent];
colors[2] = [deviceDependentFirstColor blueComponent];
colors[3] = [deviceDependentFirstColor alphaComponent];
-
+
colors[4] = [deviceDependentSecondColor redComponent];
colors[5] = [deviceDependentSecondColor greenComponent];
colors[6] = [deviceDependentSecondColor blueComponent];
colors[7] = [deviceDependentSecondColor alphaComponent];
-
+
// difference between start and end color for each color components
- colors[8] = (colors[4]-colors[0]);
- colors[9] = (colors[5]-colors[1]);
- colors[10] = (colors[6]-colors[2]);
- colors[11] = (colors[7]-colors[3]);
-
+ colors[8] = (colors[4] - colors[0]);
+ colors[9] = (colors[5] - colors[1]);
+ colors[10] = (colors[6] - colors[2]);
+ colors[11] = (colors[7] - colors[3]);
+
// draw gradient
colorspace = CGColorSpaceCreateDeviceRGB();
size_t components = 1 + CGColorSpaceGetNumberOfComponents(colorspace);
- static const CGFloat domain[2] = {0.0, 1.0};
- static const CGFloat range[10] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
+ static const CGFloat domain[2] = {0.0, 1.0};
+ static const CGFloat range[10] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
//static const CGFunctionCallbacks callbacks = {0, &bilinearShadedColor, NULL};
-
+
// Create a CGFunctionRef that describes a function taking 1 input and kChannelsPerColor outputs.
function = CGFunctionCreate(colors, 1, domain, components, range, &functionCallbacks);
shading = CGShadingCreateAxial(colorspace, startPoint, endPoint, function, NO, NO);
-
+
CGContextSaveGState(currentContext);
[self addClip];
CGContextDrawShading(currentContext, shading);
CGContextRestoreGState(currentContext);
-
+
CGShadingRelease(shading);
CGFunctionRelease(function);
CGColorSpaceRelease(colorspace);
}
-- (void)customHorizontalFillWithCallbacks:(CGFunctionCallbacks)functionCallbacks firstColor:(NSColor *)firstColor secondColor:(NSColor *)secondColor
-{
- [self customFillWithCallbacks:functionCallbacks
- firstColor:firstColor
- secondColor:secondColor
- startPoint:CGPointMake(0, NSMinY([self bounds]))
- endPoint:CGPointMake(0, NSMaxY([self bounds]))];
+- (void)customHorizontalFillWithCallbacks:(CGFunctionCallbacks)functionCallbacks firstColor:(NSColor *)firstColor secondColor:(NSColor *)secondColor {
+ [self customFillWithCallbacks:functionCallbacks
+ firstColor:firstColor
+ secondColor:secondColor
+ startPoint:CGPointMake(0, NSMinY([self bounds]))
+ endPoint:CGPointMake(0, NSMaxY([self bounds]))];
}
-- (void)customVerticalFillWithCallbacks:(CGFunctionCallbacks)functionCallbacks firstColor:(NSColor *)firstColor secondColor:(NSColor *)secondColor
-{
- [self customFillWithCallbacks:functionCallbacks
- firstColor:firstColor
- secondColor:secondColor
- startPoint:CGPointMake(NSMinX([self bounds]), 0)
- endPoint:CGPointMake(NSMaxX([self bounds]), 0)];
+- (void)customVerticalFillWithCallbacks:(CGFunctionCallbacks)functionCallbacks firstColor:(NSColor *)firstColor secondColor:(NSColor *)secondColor {
+ [self customFillWithCallbacks:functionCallbacks
+ firstColor:firstColor
+ secondColor:secondColor
+ startPoint:CGPointMake(NSMinX([self bounds]), 0)
+ endPoint:CGPointMake(NSMaxX([self bounds]), 0)];
}
@end