Thursday, June 09, 2005

Lines with Endcaps in Windows CE (1 of 3)

I believe that two things are important in any craft: having good tools, and knowing how to use your tools. Having good tools means that you won't spend needless amounts of time doing things the hard way. And knowing your tools means that you know which tool is the right tool for which job. It also means that when none of the tools in your toolbox is the right one, it's time to improvise.

Microsoft Windows CE .NET: Windows CE does not support user-specified endcap styles, such as PS_ENDCAP_ROUND.

Messages like this are a pretty good indicator that it's time to go outside of the toolbox. (For some reason it's also a great motivator for me; nothing gets my creative juices going like someone telling me they don't think I can do it.)

So I set about coming up with alternative. We were looking for a way to show glue lines. They needed to look like glue lines, and they needed to draw very quickly. In a worst-case scenario, we were drawing 24 patterns x 20 events per pattern = 480 lines, several times per second.

We could've showed a glue pattern with a simple thick line Plain line, but a line with an endcap Line with round endcaps looks much closer to what a bead of glue actually looks like. It shouldn't be very hard, I thought. A round endcap is simply a half-circle at the end of each line. Breakdown of line with round endcaps Even simpler, since CE doesn't support drawing arcs, a round endcap was simply a full-circle at the end of each line.

I wrote up a DrawGlueLine() function for our main dialog class to include two circles at the each end of a filled rectangle as the dimensions for a line.

Unfortunately, drawing circles is computationally expensive, and the performance was nowhere close to being fast enough. I considered other algorithms. The Abrash/Hardenbergh integer-only circle algorithm draws circles much more quickly, but implementing an x86 assembly (which I'm not very good at) routine just to draw endcaps seemed like overkill.

So, it was back to the drawing board. At least we knew what didn't work. As Thomas Edison told a reporter in 1879, "I have not failed 5,000 times. I have successfully discovered 5,000 ways that do not work and I do not need to try them again."

We had found way #1 that did not work.

Next time: Simplyfing the problem and trying again


At 8/10/2006 1:48 PM, Anonymous Anonymous said...

Looking for information and found it at this great site...
» » »

At 3/15/2007 1:22 PM, Anonymous Anonymous said...

What a great site here


Post a Comment

<< Home