// copy ctors and assignment operators
wxColour( const wxColour& col );
- wxColour( const wxColour* col );
+/* wxColour( const wxColour* col ); */
wxColour& operator = ( const wxColour& col );
// dtor
~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;
//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 );
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.
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)
}
}
+// 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
+}
+