From d6f0a4b367c6d68d9fea84817f5a982163665f37 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 17 Feb 2000 20:36:52 +0000 Subject: [PATCH] Removed redundant wxColour constructor (how come this didn't cause problems before...) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6125 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/colour.h | 2 +- include/wx/msw/dcmemory.h | 1 + samples/drawing/drawing.cpp | 28 +++++++++++++++++----- src/msw/dcmemory.cpp | 47 +++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/include/wx/msw/colour.h b/include/wx/msw/colour.h index 7546b611c3..3f0c568c4a 100644 --- a/include/wx/msw/colour.h +++ b/include/wx/msw/colour.h @@ -35,7 +35,7 @@ public: // copy ctors and assignment operators wxColour( const wxColour& col ); - wxColour( const wxColour* col ); +/* wxColour( const wxColour* col ); */ wxColour& operator = ( const wxColour& col ); // dtor diff --git a/include/wx/msw/dcmemory.h b/include/wx/msw/dcmemory.h index da908bf3a4..85d83bd981 100644 --- a/include/wx/msw/dcmemory.h +++ b/include/wx/msw/dcmemory.h @@ -26,6 +26,7 @@ public: ~wxMemoryDC(); + virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); virtual void SelectObject(const wxBitmap& bitmap); virtual void DoGetSize(int* width, int* height) const; diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 06f587a9a3..aa985078e8 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -598,7 +598,9 @@ void MyCanvas::DrawDefault(wxDC& dc) //dc.SetBrush( *wxTRANSPARENT_BRUSH ); #include "../image/smile.xpm" wxBitmap bmp(smile_xpm); - dc.DrawBitmap(bmp, x + rectSize - 20, rectSize - 10, TRUE); + + if (bmp.Ok()) + dc.DrawBitmap(bmp, x + rectSize - 20, rectSize - 10, TRUE); dc.SetBrush( *wxBLACK_BRUSH ); dc.DrawRectangle( 0, 160, 1000, 300 ); @@ -717,12 +719,11 @@ void MyCanvas::DrawDefault(wxDC& dc) wxMemoryDC memdc2; memdc2.SelectObject(bitmap2); - memdc2.SetBackground(*wxWHITE_BRUSH); + wxBrush yellowBrush(wxColour(255, 255, 0), wxSOLID); + memdc2.SetBackground(yellowBrush); + memdc2.Clear(); - // Draw a yellow rectangle filling the bitmap - memdc2.SetPen(wxPen(wxColour(255, 255, 0), 1, wxSOLID)); - memdc2.SetBrush(wxBrush(wxColour(255, 255, 0), wxSOLID)); - memdc2.DrawRectangle(0, 0, totalWidth+2, totalHeight+2); // Just to make sure! + wxPen yellowPen(wxColour(255, 255, 0), 1, wxSOLID); // Now draw a white rectangle with red outline. It should // entirely eclipse the yellow background. @@ -736,6 +737,21 @@ void MyCanvas::DrawDefault(wxDC& dc) memdc2.SelectObject(wxNullBitmap); dc.DrawBitmap(bitmap2, 500, 270); + + // Repeat, but draw directly on dc + // Draw a yellow rectangle filling the bitmap + + x = 600; int y = 270; + dc.SetPen(yellowPen); + dc.SetBrush(yellowBrush); + dc.DrawRectangle(x, y, totalWidth, totalHeight); + + // Now draw a white rectangle with red outline. It should + // entirely eclipse the yellow background. + dc.SetPen(*wxRED_PEN); + dc.SetBrush(*wxWHITE_BRUSH); + + dc.DrawRectangle(x, y, totalWidth, totalHeight); } void MyCanvas::DrawText(wxDC& dc) diff --git a/src/msw/dcmemory.cpp b/src/msw/dcmemory.cpp index 1a59e06627..64ff3c778f 100644 --- a/src/msw/dcmemory.cpp +++ b/src/msw/dcmemory.cpp @@ -139,3 +139,50 @@ void wxMemoryDC::DoGetSize(int *width, int *height) const } } +// For some reason, drawing a rectangle on a memory DC has problems. +// Use this substitute if we can. +static void wxDrawRectangle(wxDC& dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height) +{ + wxBrush brush(dc.GetBrush()); + wxPen pen(dc.GetPen()); + if (brush.Ok() && brush.GetStyle() != wxTRANSPARENT) + { + HBRUSH hBrush = (HBRUSH) brush.GetResourceHandle() ; + if (hBrush) + { + RECT rect; + rect.left = x; rect.top = y; + rect.right = x + width - 1; + rect.bottom = y + height - 1; + ::FillRect((HDC) dc.GetHDC(), &rect, hBrush); + } + } + width --; height --; + if (pen.Ok() && pen.GetStyle() != wxTRANSPARENT) + { + dc.DrawLine(x, y, x + width, y); + dc.DrawLine(x, y, x, y + height); + dc.DrawLine(x, y+height, x+width, y + height); + dc.DrawLine(x+width, y+height, x+width, y); + } +} + +void wxMemoryDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) +{ +// Set this to 0 to demonstrate strange rectangle behaviour in the Drawing sample. +#if 0 + if (m_brush.Ok() && m_pen.Ok() && + (m_brush.GetStyle() == wxSOLID || m_brush.GetStyle() == wxTRANSPARENT) && + (m_pen.GetStyle() == wxSOLID || m_pen.GetStyle() == wxTRANSPARENT)) + { + wxDrawRectangle(* this, x, y, width, height); + } + else + { + wxDC::DoDrawRectangle(x, y, width, height); + } +#else + wxDC::DoDrawRectangle(x, y, width, height); +#endif +} + -- 2.47.2