mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-23 23:13:12 +08:00
Improve code showing wxOverlay use in the drawing sample
Make the code work on all platforms by adding SetOpacity(-1) call needed under wxMSW to enable overlay transparency and using wxGCDC to take into account the brush transparency.
This commit is contained in:
@@ -2310,18 +2310,21 @@ void MyCanvas::OnMouseMove(wxMouseEvent &event)
|
||||
m_currentpoint = wxPoint( xx , yy ) ;
|
||||
wxRect newrect ( m_anchorpoint , m_currentpoint ) ;
|
||||
|
||||
// This is required with wxMSW to allow per-pixel transparency.
|
||||
m_overlay.SetOpacity(-1);
|
||||
|
||||
wxOverlayDC dc(m_overlay, this);
|
||||
PrepareDC(dc);
|
||||
|
||||
// Note: this must be called on the overlay DC, not wxGCDC.
|
||||
dc.Clear();
|
||||
#ifdef __WXMAC__
|
||||
dc.SetPen( *wxGREY_PEN );
|
||||
dc.SetBrush( wxColour( 192,192,192,64 ) );
|
||||
#else
|
||||
dc.SetPen( wxPen( *wxLIGHT_GREY, 2 ) );
|
||||
dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
||||
#endif
|
||||
dc.DrawRectangle( newrect );
|
||||
|
||||
// Use wxGCDC to ensure that brush transparency is taken into account
|
||||
// even under wxMSW where plain wxDC doesn't support it.
|
||||
wxGCDC gdc(dc);
|
||||
gdc.SetPen( *wxGREY_PEN );
|
||||
gdc.SetBrush( wxColour( 192,192,192,64 ) );
|
||||
gdc.DrawRectangle( newrect );
|
||||
}
|
||||
#else
|
||||
wxUnusedVar(event);
|
||||
|
||||
Reference in New Issue
Block a user