Friday, August 13, 2004

Friday 13th

A semi-productive session before work saw the Line tool virtually finished. I'd not been looking forward to implementing this, mainly because of the checks required to see if the user is drawing a line, holding the mouse, releasing the mouse, etc.

I examined the code from an example paint program and surmised that they were doing their drawing routines using simple buffer swaps, which seemed promising - after a little tinkering, and more than a little rational thought, the conundrum was solved and the code written in just a few minutes (it's all flooding back, just a little too slowly!).

After I got the controls working, however, I hit a stumbling block: when the user is holding the mouse, a "virtual" line is plotted to the screen (so you can see where the line will be); when the mouse is released the "actual" line is plotted to the map array. A problem arose with the maths behind the routine - the virtual line is drawn with floating point numbers, while the plotted line isn't. This makes the virtual line ultra-smooth and not at all representative of the finished line.

After 20 minutes of trying various commands such as Mod and Floor (which discard remainders and round down numbers respectively), I had to leave for work and thus left the unsolved problem swimming around in my head. Grrr.