mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-09 10:20:59 +00:00
Merged pull request #1241 from gorenje/remove_two_color_assumption.
remove an assumption of two colors in the gradient creation stuff
This commit is contained in:
commit
7d1b873beb
2 files changed
+42
-3
No files matched your search
@@ -29,10 +29,15 @@ kCGGradientDrawsAfterEndLocation = 1 << 1;
|
||||
|
||||
function CGGradientCreateWithColorComponents(aColorSpace, components, locations, count)
|
||||
{
|
||||
if (locations === NULL)
|
||||
var locations = [0.0, 1.0];
|
||||
if ( locations === undefined || locations === NULL )
|
||||
{
|
||||
var num_of_colors = components.length / 4,
|
||||
locations = [];
|
||||
for ( var idx = 0; idx < num_of_colors; idx++ )
|
||||
locations.push( idx / (num_of_colors - 1) );
|
||||
}
|
||||
|
||||
if (count === NULL)
|
||||
if ( count === undefined || count === NULL)
|
||||
var count = locations.length;
|
||||
|
||||
var colors = [];
|
||||
|
||||
@@ -7,6 +7,22 @@
|
||||
*/
|
||||
- (void)testCreateWithColorComponentsDefault
|
||||
{
|
||||
|
||||
// Test one color and no location
|
||||
var components = [ 0.2,0.2,0.4,0.4 ];
|
||||
|
||||
var tmp = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),
|
||||
components);
|
||||
[self assert:1 equals:tmp.colors.length];
|
||||
[self assert:1 equals:tmp.locations.length];
|
||||
|
||||
// TODO: This should not be supported since there is no gradient if only one color
|
||||
// TODO: NaN not really helpful...
|
||||
[self assert:NaN equals:tmp.locations[0]];
|
||||
|
||||
[self assert:components.slice(0,4) equals:tmp.colors[0].components];
|
||||
|
||||
// Test two colors and no location
|
||||
var components = [ 0.2,0.2,0.4,0.4,
|
||||
0.6,0.6,0.8,0.8 ];
|
||||
|
||||
@@ -20,6 +36,24 @@
|
||||
|
||||
[self assert:components.slice(4,8) equals:tmp.colors[1].components];
|
||||
[self assert:components.slice(0,4) equals:tmp.colors[0].components];
|
||||
|
||||
// Test three colors and no location
|
||||
var components = [ 0.2,0.2,0.4,0.4,
|
||||
0.6,0.6,0.8,0.8,
|
||||
0.6,0.6,0.8,0.8 ];
|
||||
|
||||
var tmp = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),
|
||||
components);
|
||||
[self assert:3 equals:tmp.colors.length];
|
||||
[self assert:3 equals:tmp.locations.length];
|
||||
|
||||
[self assert:0 equals:tmp.locations[0]];
|
||||
[self assert:0.5 equals:tmp.locations[1]];
|
||||
[self assert:1.0 equals:tmp.locations[2]];
|
||||
|
||||
[self assert:components.slice(8,12) equals:tmp.colors[2].components];
|
||||
[self assert:components.slice(4,8) equals:tmp.colors[1].components];
|
||||
[self assert:components.slice(0,4) equals:tmp.colors[0].components];
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in new issue
Block a user