Error in "CGContextDrawRadialGradient" with solution (problem sits in "to_string")

已查看 72 次
跳至第一个未读帖子

Michael Bach

未读,
2015年8月30日 15:10:222015/8/30
收件人 Cappuccino & Objective-J
Dear Cappuccinorites:

"CGContextDrawRadialGradient" does not work, after a prolonged bug safari I found the error in "CGContextCanvas.j", specifically in the function "to_string(aColor)".
I know I should do a pull request, but I don't know how to do this well, so I would ask you to do this, please.

The error in "to_string(aColor)" is the use of the properties "aColor.components[0…".
It should be "aColor._components[0…".
So the underscore is missing 4 times.

Fully correct function like so:

function to_string(aColor) {
    return "rgba("
        + ROUND(aColor._components[0] * 255) + ", "
        + ROUND(aColor._components[1] * 255) + ", "
        + ROUND(aColor._components[2] * 255) + ", "
        + aColor._components[3] + ")";
}


When I include this "to_string" in my code, the gradients work fine.


Thanks for your work on wonderful Cappuccino!


Best, Michael

Aparajita Fishman

未读,
2015年8月30日 16:30:142015/8/30
收件人 objec...@googlegroups.com
Thanks Michael for tracking that down. Nuage guys, can you take care of this? I'm busy with the compiler.
Regards,

Aparajita

Dogild

未读,
2015年8月31日 08:47:042015/8/31
收件人 Cappuccino & Objective-J
Nuage guys are currently in vacation :p 

t00f can you take a look ?

daboe01

未读,
2015年9月2日 17:03:062015/9/2
收件人 Cappuccino & Objective-J

Dogild

未读,
2015年9月22日 16:01:532015/9/22
收件人 Cappuccino & Objective-J
Hi Michael, 

How do you create your gradient color ?

Not sure that your solution is the best actually. It would work when you use some CPColors, however you should use the method CGGradientCreateWithColorComponents() to create gradient color (which is going to create some CGColor). You can take a look in one of the manual test (CPGradientTest) and to works pretty well !

Thanks,

Michael Bach

未读,
2015年9月22日 16:52:402015/9/22
收件人 objec...@googlegroups.com
Cher Alexandre:

> How do you create your gradient color ?
>
> Not sure that your solution is the best actually. It would work when you use some CPColors, however you should use the method CGGradientCreateWithColorComponents() to create gradient color (which is going to create some CGColor). You can take a look in one of the manual test (CPGradientTest) and to works pretty well !

CGContextDrawRadialGradient needs as second parameter a gradient which indeed I created with “CGGradientCreateWithColors”, and that, in turn, uses “to_string(aColor)” which is (was) buggy.
I don’t really understand why it works in the test then.
If you look at the original source of to_string it’s quite obvious that the variables were missing the underline.

Thank you for thinking along!

Best, Michael
--
Prof. Michael Bach PhD, Eye Center, University of Freiburg, Killianstr. 5, 79106 Freiburg, Germany.
Michae...@uni-freiburg.de <http://michaelbach.de>

Dogild

未读,
2015年9月22日 17:52:402015/9/22
收件人 Cappuccino & Objective-J


On Tuesday, September 22, 2015 at 1:52:40 PM UTC-7, Michael Bach wrote:
Cher Alexandre:

> How do you create your gradient color ?
>
> Not sure that your solution is the best actually. It would work when you use some CPColors, however you should use the method CGGradientCreateWithColorComponents() to create gradient color (which is going to create some CGColor). You can take a look in one of the manual test (CPGradientTest) and to works pretty well !

CGContextDrawRadialGradient needs as second parameter a gradient which indeed I created with “CGGradientCreateWithColors”, and that, in turn, uses “to_string(aColor)” which is (was) buggy.

How do you create the colors you give to CGGradientCreateWithColors or CGGradientCreateWithColorComponents ? You should create some CGColor and not some CPColor which is something different.

CGColor has an attribute components (the one used in to_string, this is why the example works). But CPColor has an attribute _components, this is why it crashes when using that with the gradient features.

Michael Bach

未读,
2015年11月1日 12:59:012015/11/1
收件人 Cappuccino & Objective-J
Dear dogild & all:
 
… You should create some CGColor and not some CPColor which is something different. …

It's a while ago, but to put a lid on it:
Yes, if I create CGColors (they were CPColors before), then CGGradientCreateWithColors works as should with the current builds.
Thank you!


Best, Michael 
-- 
Prof. Michael Bach PhD, Eye Center, University of Freiburg, Killianstr. 5, 79106 Freiburg, Germany. 
回复全部
回复作者
转发
0 个新帖子