开发者

Resizing a double buffered widget?

Right now, my text widget is double buffered ( it draws the text to a bitmap when an event occurs) . This works great except when I resize the widget. When I resize, I al_destroy_bitmap and create a new one with the new dimensions This is very slow. How do most double buffered guis such as Windows and Mac OSX avoi开发者_如何学运维d this issue?

Thanks


Most widgets that are backed by bitmaps (or used to render by OGL or DX) have locked borders and don't allow resizing.

Those that do very often suffer from speed issues caused by that.

You could watch for resizing to begin and end and only update your bitmap when it's done, or if only receiving a resize-happened event, watch for a few back to back and disable your bitmap resizing until they stop coming (after, say, the first 5 in a second, wait until no resize events arrive for 250ms).


I recently did double-buffering for the purpose of collision detection in Flash. It had a similar problem, creating bitmap data structures was relatively slow (this in itself is sad since allocating raw memory should be fast, for Flash and in your case).

What I did was to simply cache the backing bitmaps and reuse them when possible. So if somebody would resize to 250x250 I could reused a bitmap that was 280x260. Whenever a widget was done with the bitmap it'd free it back up to be used again, or if they shrunk and could use a smaller one. I had a cap on the total memory that could be used and would prune the unused bitmaps if exceeded.

But you don't have to be so extreme. For a simple first step ensure you resize in large increments. For example, even if the user has only resized by 2 pixels, you can resize the internal bitmap by 50. That way you can keep reusing the bitmap until the user hits the new size limit.

If the user decreases the size you don't have to do anything, since your existing bitmap is big enough to do the drawing. When you copy it to the screen just copy the upper-left corner of it (the part you actually use).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜