Sampling Breakthrough #

First thing I did today was to add 48x48 (huge) icon support. It wasn't that hard, just a menial task of looking for places where I had previously ignored the user's clicks and hooking up the code. Of course first I had to add the properly GWorlds/PixMaps to the base icns class, but that was a matter of looking for the proper 4 letter resource codes. This is all rather useless of course, since the Finder doesn't support 48x48 icons yet, but I found some Rhapsody screenshots with 48x48 icons, and they look really cool, so it's worth it...

The rest of the day I dedicated to tackling the mouse sampling problem. My initial drawing loop looked something like this:
while the button was down
- get mouse position
- set pixel at the position
- refresh
However this didn't work very well since I was missing points because the drawing took too long and the mouse moved a lot, especially if it was at above average speeds. Obviously this didn't happen in all the other editors I have tried. I tried to optimize my pixel setting and drawing functions, but it didn't work very well. Then I tried to restrict the refreshing to once ever 10 ticks, but that didn't help either.

As a test I decided to completely take out the pixel setting and refreshing, and have a simple loop which got the mouse position, and stored it in an array if it wasn't different from the last one. It turned out that even when I did this the sampling wasn't done often enough for the sampled points to be next to each other. So I arrived at the conclusion that instead of setting pixels one by one I should be drawing lines to connect from the last sampled point to the current one. This did it, and it's not noticeable at all. Theoretically it should be when drawing curved lines very quickly, but that's very hard and I don't see any reason why people would do that when drawing an icon.

In the end I might write my own DrawLine function, but until then the system one works very well, and I don't have to worry about writing a function for each bith depth (it was bad enough for setting pixels, for lines it'd be even worse).

Post a Comment