On Monday, November 12, 2012 3:22:47 PM UTC+1, markww wrote:
>
> Hi,
>
> I need to do some drawing on a <canvas> element, is there any better way 
> of creating fill styles on the fly? Currently I have to do this:
>
>     public void drawFoo(Context2d context, int r, int g, int b, int a) {
>         CssColor clr = CssColor.make("rgba(" + r + "," + g + "," + b + "," 
> a + ")");
>         context.setFillStyle(clr);
>         context.fillRect(10, 10, 10, 10);
>     }
>
> so every time my drawFoo() method is called, I need to create a new 
> CssColor instance to handle the red,green,blue,alpha components passed in. 
> I don't know how efficient it is for CssColor.make() to parse the string, 
> also ignoring that a string object needs to be constructed in the first 
> place each time too.
>
> Is there any better way of creating different colors on the fly like this?
>

CssColor does not parse the string, it only wraps it. FYI, CssColor.make(r, 
g, b) simply calls  CssColor.make("rgb(" + r + ", " + g + ", " + b + ")").
The wrapping is a no-op once compiled to JS, leaving only the String 
concatenation.
If you were doing the same in pure JS, you'd still have to build that 
string to assign it to the context's fillStyle: 
http://dev.w3.org/html5/2dcontext/#fill-and-stroke-styles

So no, there's no better way of doing it, because there's no *other* way.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/U7_JohJ6bakJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to