Better Button Strokes in Degrafa

Better Button Strokes in Degrafa

View Sample | Source Code

Degrafa supports strokes but the output is a little disappointing. A quick solution is to apply age-old Photoshop skills. And that is to create a smaller shape enclosed inside another shape to mimic a stroke. The containing shape’s background color will serve as the artificial stroke. You also need to add 2 pixels to both the height and width if you’re going to use this approach since a real stroke is an extra 1 pixel (at least in this example) border around the button, easily take care of this inside the overriden updateDisplayList function.

The result looks smoother and more consistent than Degrafa’s built in stroke. However this approach will require more code and may consume more system resource.

The smoothness of the stroke is also affected by the chosen color. It seems that the darker the color of the stroke or if it’s a complement of the button’s color, the less smooth it appears. The size of the corner radius also affects the smoothness of the stroke. You just have to experiment to find the best combination. Thicker strokes on the other hand look alright, so I guess this example only applies to 1 pixel strokes.

Another thing I noticed with Degrafa is it sometimes renders inconsistent corner radii (see screenshot above). One corner may seem off or may not be curved at all. This can be fixed, albeit inelegantly, by using a RoundedRectangleComplex to allow setting of radii for individual corners.

1 Response to “Better Button Strokes in Degrafa”


  1. 1 ricoz November 24, 2009 at 7:35 am

    Here’s a more detailed explanation from one of the members of the Degrafa team:

    Hi, thanks for sharing this.
    I wanted to let you know that we are aware of this problem, but Degrafa is not to blame here. This is more the fault of the native drawing api in the flash player. Actually Degrafa has some minor tweaks to reduce the impact of this issue compared to other implementations (take a close look at the left edges of the RoundedRectangles in the two examples shown here http://twurl.nl/c6riur ). But the underlying problem remains the anti-aliasing of certain curved strokes in the flash player itself.

    The hack you mentioned is currently the most well known way to address this – and one that is used internally in flex itself for some things. Here’s another post on this:
    http://twurl.nl/neuzys

    cheers,
    Degrafa Team

    Greg Dove
    http://linearticulator.com
    http://greg-dove.com


Leave a Reply

You must login to post a comment.