fixed clip rect when logical coords != device ones

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10604 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2001-06-17 13:14:20 +00:00
parent 78c1f5f1b8
commit c4218a7403
3 changed files with 86 additions and 31 deletions

View File

@ -344,9 +344,11 @@ BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_MOTION (MyCanvas::OnMouseMove)
END_EVENT_TABLE()
#include "../image/smile.xpm"
#include "smile.xpm"
MyCanvas::MyCanvas( MyFrame *parent ) : wxScrolledWindow( parent )
MyCanvas::MyCanvas(MyFrame *parent)
: wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE)
{
m_owner = parent;
m_show = Show_Default;
@ -361,8 +363,8 @@ MyCanvas::MyCanvas( MyFrame *parent ) : wxScrolledWindow( parent )
// the colors of the monochrome bitmap pixels to the fillpattern
//
// I abused the the menu items for setting so called back and fore ground color
// just to show how the those colors do influence the fillpatterns just play
// with those, and with the code variations are endless using other logical
// just to show how the those colors do influence the fillpatterns just play
// with those, and with the code variations are endless using other logical
// functions.
void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent )
@ -411,15 +413,15 @@ void MyCanvas::DrawTestPoly( int x, int y,wxDC &dc,int transparent )
dc.SetTextForeground(*wxCYAN);
dc.SetTextBackground(m_owner->m_colourBackground);
dc.DrawRectangle( x+10, y+10, 200, 200 );
dc.SetPen( wxPen( "green", 4, wxSOLID) );
dc.SetBrush( *brush4_mono );
dc.SetTextForeground(*wxCYAN);
dc.SetTextBackground(m_owner->m_colourBackground);
dc.DrawRectangle( x+50, y+50, 200, 200 );
dc.DrawCircle( x+400, y+50, 130 );
dc.SetBrush(wxNullBrush);
dc.SetPen(wxNullPen);
break;
@ -983,32 +985,38 @@ void MyCanvas::DrawCircles(wxDC& dc)
void MyCanvas::DrawRegions(wxDC& dc)
{
dc.DrawText("You should see a red rect partly covered by a cyan one "
"on the left", 10, 5);
dc.DrawText("and 5 smileys from which 4 are partially clipped on the "
"right", 10, 5 + dc.GetCharHeight());
dc.SetBrush( *wxWHITE_BRUSH );
dc.SetPen( *wxTRANSPARENT_PEN );
dc.DrawRectangle( 10,10,310,310 );
dc.SetClippingRegion( 20,20,100,270 );
dc.SetBrush( *wxRED_BRUSH );
dc.DrawRectangle( 10,10,310,310 );
dc.DrawRectangle( 10,50,310,310 );
dc.SetClippingRegion( 20,60,100,270 );
dc.SetBrush( *wxRED_BRUSH );
dc.DrawRectangle( 10,50,310,310 );
dc.SetClippingRegion( 20,60,100,100 );
dc.SetClippingRegion( 20,20,100,100 );
dc.SetBrush( *wxCYAN_BRUSH );
dc.DrawRectangle( 10,10,310,310 );
dc.DrawRectangle( 10,50,310,310 );
dc.DestroyClippingRegion();
dc.SetClippingRegion( 120,30,100,270 );
dc.SetClippingRegion( 120,70,100,270 );
dc.SetBrush( *wxGREY_BRUSH );
dc.DrawRectangle( 10,10,310,310 );
dc.DrawRectangle( 10,50,310,310 );
if (m_smile_bmp.Ok())
{
dc.DrawBitmap( m_smile_bmp, 140, 20, TRUE );
dc.DrawBitmap( m_smile_bmp, 140, 290, TRUE );
dc.DrawBitmap( m_smile_bmp, 110, 80, TRUE );
dc.DrawBitmap( m_smile_bmp, 210, 80, TRUE );
dc.DrawBitmap( m_smile_bmp, 160, 200, TRUE );
dc.DrawBitmap( m_smile_bmp, 140, 60, TRUE );
dc.DrawBitmap( m_smile_bmp, 140, 330, TRUE );
dc.DrawBitmap( m_smile_bmp, 110, 120, TRUE );
dc.DrawBitmap( m_smile_bmp, 210, 120, TRUE );
}
}
@ -1016,7 +1024,7 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
{
wxPaintDC dc(this);
PrepareDC(dc);
m_owner->PrepareDC(dc);
dc.SetBackgroundMode( m_owner->m_backgroundMode );
@ -1082,13 +1090,13 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
case Show_Ops:
DrawWithLogicalOps(dc);
break;
default:
{
dc.SetPen( *wxBLACK_PEN );
dc.DrawLine( 0,0,100,100 );
}
}
}
@ -1124,7 +1132,8 @@ END_EVENT_TABLE()
// frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size,
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
{
// set the frame icon
SetIcon(wxICON(mondrian));

42
samples/drawing/smile.xpm Normal file
View File

@ -0,0 +1,42 @@
/* XPM */
static char * smile_xpm[] = {
/* width height ncolors chars_per_pixel */
"32 32 4 1",
/* colors */
" s None c None",
". c #000000",
"+ c #ff0000",
"@ c #ffff00",
/* pixels */
" ........ ",
" ...@@@@@@@@... ",
" ..@@@@@@@@@@@@@@.. ",
" ..@@@@@@@@@@@@@@@@.. ",
" .@@@@@@@@@@@@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@@@@@@@. ",
" ..@@@@@@@@@@@@@@@@@@@@@@@@.. ",
" .@@@@@@@@..@@@@@@..@@@@@@@@. ",
" .@@@@@@@@....@@@@....@@@@@@@@. ",
" .@@@@@@@@....@@@@....@@@@@@@@. ",
" .@@@@@@@@....@@@@....@@@@@@@@. ",
".@@@@@@@@@....@@@@....@@@@@@@@@.",
".@@@@@@@@@....@@@@....@@@@@@@@@.",
".@@@@@@@@@@..@@@@@@..@@@@@@@@@@.",
".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.",
".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.",
".@@@@@@.@@@@@@@@@@@@@@@@.@@@@@@.",
".@@@....@@@@@@@@@@@@@@@@....@@@.",
".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.",
" .@@@@@@@.@@@@@@@@@@@@.@@@@@@@. ",
" .@@@@@@@..@@@@@@@@@@..@@@@@@@. ",
" .@@@@@@@@...@@@@@@...@@@@@@@@. ",
" .@@@@@@@@.+......+.@@@@@@@@. ",
" ..@@@@@@@@.++++++.@@@@@@@@.. ",
" .@@@@@@@@@.++++.@@@@@@@@@. ",
" .@@@@@@@@@....@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@@@. ",
" ..@@@@@@@@@@@@@@@@.. ",
" ..@@@@@@@@@@@@@@.. ",
" ...@@@@@@@@... ",
" ........ "};

View File

@ -276,12 +276,16 @@ void wxDC::SelectOldObjects(WXHDC dc)
m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \
}
void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
{
m_clipping = TRUE;
HRGN hrgn = ::CreateRectRgn(XLOG2DEV(cx), YLOG2DEV(cy),
XLOG2DEV(cx + cw), YLOG2DEV(cy + ch));
// the region coords are always the device ones, so do the translation
// manually
HRGN hrgn = ::CreateRectRgn(LogicalToDeviceX(x),
LogicalToDeviceY(y),
LogicalToDeviceX(x + w),
LogicalToDeviceY(y + h));
if ( !hrgn )
{
wxLogLastError(_T("CreateRectRgn"));