[wxMac] [CVS HEAD] wxPaintEvent + wxFULL_REPAINT_ON_RESIZE = nothing happen?

Ryan Wilcox rwilcox at wilcoxd.com
Thu Sep 21 21:33:33 PDT 2006


Howdy all,

I'm trying to draw (via a paint event and wxPaintDC) an icon onto my wxFrame based class. I'm using wxMac 2.7 (updated maybe beginning of the week?) The idea is to draw an icon horizontally centered in the window.

The question is: how do I properly do this on the Mac?

When I try the following paint event handler, with my frame style set to include wxFULL_REPAINT_ON_RESIZE) I don't see my icon move horizontally in the window (although the event happens, as the wxLogDebug() proves):

_______________________________

<code language="C++">

wxPaintDC dc(this);
	
wxSize windSize = GetClientSize();
    
//figure out the middle of the window (adjusted by 32 (64 / 2))
wxIcon alertIcon;
alertIcon.LoadFile( wxT("wxICON_INFORMATION"),
     wxBITMAP_TYPE_ICON_RESOURCE );
   
wxCoord startX = ( windSize.GetWidth() / 2 ) - 32;

//dc.DrawRectangle( wxRect( 0, 0, windSize.GetWidth(), 200) );	
dc.DrawIcon( alertIcon, startX, 20);
wxLogDebug("Paint event happened width = %d", startX);

</code>

_______________________________


Now, I can do something do something very similar, but slightly less kosher (or so the wxBook leads me to believe) with the following (which has its own set of problems):


_______________________________

<code language="C++">

wxPaintDC junk(this);
wxClientDC dc(this);

wxSize windSize = GetClientSize();

PrepareDC(dc);

//figure out the middle of the window (adjusted by 32 (64 / 2))
wxIcon alertIcon;

alertIcon.LoadFile( wxT("wxICON_INFORMATION"),     
    wxBITMAP_TYPE_ICON_RESOURCE );

wxCoord startX = ( windSize.GetWidth() / 2 ) - 32;
dc.SetBrush( MacGetBackgroundBrush()  );
dc.DrawRectangle( wxRect( 0, 0, windSize.GetWidth(), 200) );

Refresh();
dc.DrawIcon( alertIcon, startX, 20);

wxLogDebug("Paint event happened width = %d", startX);


</code>

_______________________________

This approach technically works, but does not properly refresh (leaving little copies of the icon everywhere it goes). (In addition, it sometimes doesn't respond properly when the resize event is done, refusing to draw the icon at the "at rest" window size).

In both cases I can replace the dc.DrawIcon() call with dc.DrawBitmap() (after constructing a bitmap via bitmap.CopyFromIcon()), with identical behavior.

For those interested in running the actual program, download a modified minimal.cpp from <http://www.wilcoxd.com/drop/minimal.cpp>.

Ideas? Suggestions?

Thanks in advance,
_Ryan Wilcox

-- 
Wilcox Development Solutions:          <http://www.wilcoxd.com>
Toolsmiths for the Internet Age            PGP: 0x2F4E9C31




More information about the wx-users mailing list