From c4218a74033e3091a3566c9c6619809a00b53744 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Jun 2001 13:14:20 +0000 Subject: [PATCH] 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 --- samples/drawing/drawing.cpp | 63 +++++++++++++++++++++---------------- samples/drawing/smile.xpm | 42 +++++++++++++++++++++++++ src/msw/dc.cpp | 10 ++++-- 3 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 samples/drawing/smile.xpm diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index ac67006879..84d05d3412 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -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.DrawRectangle( 10,50,310,310 ); + + dc.SetClippingRegion( 20,60,100,270 ); + dc.SetBrush( *wxRED_BRUSH ); - dc.DrawRectangle( 10,10,310,310 ); + 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)); diff --git a/samples/drawing/smile.xpm b/samples/drawing/smile.xpm new file mode 100644 index 0000000000..c43402cecb --- /dev/null +++ b/samples/drawing/smile.xpm @@ -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 */ +" ........ ", +" ...@@@@@@@@... ", +" ..@@@@@@@@@@@@@@.. ", +" ..@@@@@@@@@@@@@@@@.. ", +" .@@@@@@@@@@@@@@@@@@@@. ", +" .@@@@@@@@@@@@@@@@@@@@@@. ", +" .@@@@@@@@@@@@@@@@@@@@@@@@. ", +" ..@@@@@@@@@@@@@@@@@@@@@@@@.. ", +" .@@@@@@@@..@@@@@@..@@@@@@@@. ", +" .@@@@@@@@....@@@@....@@@@@@@@. ", +" .@@@@@@@@....@@@@....@@@@@@@@. ", +" .@@@@@@@@....@@@@....@@@@@@@@. ", +".@@@@@@@@@....@@@@....@@@@@@@@@.", +".@@@@@@@@@....@@@@....@@@@@@@@@.", +".@@@@@@@@@@..@@@@@@..@@@@@@@@@@.", +".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.", +".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.", +".@@@@@@.@@@@@@@@@@@@@@@@.@@@@@@.", +".@@@....@@@@@@@@@@@@@@@@....@@@.", +".@@@@@@@.@@@@@@@@@@@@@@.@@@@@@@.", +" .@@@@@@@.@@@@@@@@@@@@.@@@@@@@. ", +" .@@@@@@@..@@@@@@@@@@..@@@@@@@. ", +" .@@@@@@@@...@@@@@@...@@@@@@@@. ", +" .@@@@@@@@.+......+.@@@@@@@@. ", +" ..@@@@@@@@.++++++.@@@@@@@@.. ", +" .@@@@@@@@@.++++.@@@@@@@@@. ", +" .@@@@@@@@@....@@@@@@@@@. ", +" .@@@@@@@@@@@@@@@@@@@@. ", +" ..@@@@@@@@@@@@@@@@.. ", +" ..@@@@@@@@@@@@@@.. ", +" ...@@@@@@@@... ", +" ........ "}; diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 2600103b1e..faa71428b5 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -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")); -- 2.45.2