Page 1 of 1

Refresh problems when drawing to Window Device Contexts

Posted: Wed Sep 01, 2004 9:32 pm
by jweathers
I've been developing a project with wxWidgets on MS Windows for the last few months. My current code runs just fine on that platform. However, I have recently started testing things on my Linux box with wxGTK, and I am now experiencing some bizarre problems.

I have written a subclass of wxWindow that I use as a canvas for displaying a board game. I maintain a wxBitmap that acts as a buffer for blitting to the window client area. Also, I have a bitmap of the empty board, a bitmap of the available pieces, and a bitmap of the available pieces rotated 180 degrees (for representing enemy pieces).

When I draw the board for the first time or update it just before or just after dragging a piece, I create a wxMemoryDC, select the buffer bitmap into it, draw my empty board onto it, and then draw each current piece onto it. Then, I unselect the buffer bitmap from the memory device context and draw the updated buffer bitmap to my canvas window's device context.

The problem is that all of my normal pieces (those created from the first pieces bitmap) get displayed just fine, but the rotated pieces (those created from the second bitmap) do not get displayed.

Here's a further oddity. I have implemented things so that when I click on a piece I can drag it around using a wxDragImage. When I click on a square where I know that a rotated piece should be located and then start to drag my mouse cursor, the missing piece mysteriously appears, but it just as suddenly disappears when I finish dragging it.

Again, my code works just fine on MS Windows.

I should mention that I am developing with the following:
wxMSW 2.5.2
wxGTK 2.5.1
gcc 3.3.3
Linux kernel 2.4.26
KDE 3.2.3
xorg-X11 6.7.0-r1
gtk+ 2.4.4

Any ideas on what might be going on?

Thanks in advance!

Posted: Mon Sep 06, 2004 7:30 pm
by jweathers
In case anyone else was curious about this problem, I'll share my "solution" with the list.
I still have no clue what was going on when I tried to use Blit to directly draw a subregion of my bitmap to the device context. All of my tests seemed to suggest something bizarre was happening with the underlying wxMask information.

However, I accomplished what I was attempting to do by using the GetSubBitmap method of wxBitmap and using DrawBitmap instead of Blit.

John Weathers
[email protected]

Posted: Tue Sep 07, 2004 6:40 am
by Jorg
Hi there John,

Thanks for sharing. Now someone in a similar situation might be able to find his solution on the forum ;-)

If this is really weird or bizarre, maybe you should post the bug to SF. If this is just Linux's way of doing things, there is not much to do about it ;-)

- Jorgen