1. Problem with re-creating pixmaps when resizing
- Posted by Alexander Toresson <toressonodakra at swipnet.se> Jun 28, 2004
- 421 views
I'm coding on a program which will resize the view to the size of the window and at the same time keep the aspect ratio of the view. I'm double-buffering with a pixmap. The problem is that after I've destroyed and created the pixmap again, the background of the window will be filled with garbage! Anyone know why? Here's a little piece of code to demonstrate:
include win32lib.ew atom width, height integer need_repaint integer xratio, yratio integer main, pixmap xratio = 4 yratio = 3 width = 100 height = 100 need_repaint = 1 main = create(Window, "Resize and see the \"effect\"", 0, Default, Default, 640, 480, 0) pixmap = create(Pixmap, "", 0, 0, 0, width, height, 0) procedure main_onpaint(integer self, integer event, sequence params) integer x, y if need_repaint then setPenColor(pixmap, Black) drawRectangle(pixmap, True, 0, 0, width, height) setPenColor(pixmap, BrightBlue) drawRectangle(pixmap, True, floor(0.25 * width), floor(0.25 * height), floor(0.75 * width), floor(0.75 * height)) need_repaint = 0 end if copyBlt(main, 0, 0, pixmap) end procedure setHandler(main, w32HPaint, routine_id("main_onpaint")) procedure main_onresize(integer self, integer event, sequence params) destroy(pixmap) width = params[2] -- window width is limiting? height = floor((yratio / xratio) * width+.5) if height > params[3] then -- window height is limiting! height = params[3] width = floor((xratio / yratio) * height+.5) else -- window width is limiting! end if pixmap = create(Pixmap, "", 0, 0, 0, params[2], params[3], 0) need_repaint = 1 repaintWindow(main) end procedure setHandler(main, w32HResize, routine_id("main_onresize")) WinMain(main, Normal)
Shhh! Be vewy quiet! I'm hunting wuntime ewwows!