Re: wxEuphoria image scaling
- Posted by ghaberek (admin) Nov 21, 2014
- 2051 views
It's good to see that things are working out for you. Here are a few more tips based on your current code...
- It looks like you're repeating a lot of code when loading and rescaling your bitmaps during each paint event.
- Load your bitmaps once at the start of your code, before you declare your controls. You already did this with the wxColor objects, which is a good start. Otherwise you'll waste system resource loading the same bitmap over and over again in a paint event.
- Move the code to rescale a bitmap into a separate function as I did above. Then use this to scale your static bitmaps once, outside the paint event. Follow the Don't repeat yourself (DRY) principle.
- Keep your paint events as slim as possible. Your applications can become slow or unresponsive if the paint event takes too long. You can create a wxBitmap in memory as a buffer and draw everything to that, and then copy it to the window with draw_bitmap() during the paint event.
- Load your bitmaps once at the start of your code, before you declare your controls. You already did this with the wxColor objects, which is a good start. Otherwise you'll waste system resource loading the same bitmap over and over again in a paint event.
- You do not have to double-up on forward slashes (/) in strings. You only have to "escape" backslashes (\) because the backslash servers as the "escape" character for other values, like tab (\t) or new line (\n).
-Greg