diff --git a/interface/wx/dc.h b/interface/wx/dc.h index c47efb0bed..7ce1987771 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -648,7 +648,8 @@ public: refers to the right or bottom corner instead. The current pen is used for the outline and the current brush - for filling the shape. + for filling the shape. Special case: If the current pen is + transparent, then the current brush is used for the entire rectangle. */ void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); diff --git a/tests/graphics/bitmap.cpp b/tests/graphics/bitmap.cpp index 5dd92cb530..7c6a4bef1f 100644 --- a/tests/graphics/bitmap.cpp +++ b/tests/graphics/bitmap.cpp @@ -140,7 +140,7 @@ TEST_CASE("BitmapTestCase::ToImage", "[bitmap][image][convertto]") wxBitmap bmp(16, 16, 24); { wxMemoryDC dc(bmp); - dc.SetPen(*wxYELLOW_PEN); + dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(*wxYELLOW_BRUSH); dc.DrawRectangle(0, 0, bmp.GetWidth(), bmp.GetHeight()); } @@ -153,19 +153,67 @@ TEST_CASE("BitmapTestCase::ToImage", "[bitmap][image][convertto]") REQUIRE(image.GetWidth() == bmp.GetWidth()); REQUIRE(image.GetHeight() == bmp.GetHeight()); - wxNativePixelData dataBmp(bmp); - wxNativePixelData::Iterator rowStartBmp(dataBmp); - - for ( int y = 0; y < bmp.GetHeight(); ++y ) { - wxNativePixelData::Iterator iBmp = rowStartBmp; - for ( int x = 0; x < bmp.GetWidth(); ++x, ++iBmp ) + wxNativePixelData dataBmp(bmp); + wxNativePixelData::Iterator rowStartBmp(dataBmp); + + for ( int y = 0; y < bmp.GetHeight(); ++y ) { - wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue()); - wxColour imgc(image.GetRed(x, y), image.GetGreen(x, y), image.GetBlue(x, y)); - CHECK_EQUAL_COLOUR_RGB(imgc, bmpc); + wxNativePixelData::Iterator iBmp = rowStartBmp; + for ( int x = 0; x < bmp.GetWidth(); ++x, ++iBmp ) + { + wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue()); + wxColour imgc(image.GetRed(x, y), image.GetGreen(x, y), image.GetBlue(x, y)); + CHECK_EQUAL_COLOUR_RGB(imgc, bmpc); + } + rowStartBmp.OffsetY(dataBmp, 1); + } + } + + for ( int size = 4 ; size != 0 ; --size ) + { + INFO("Red square size: " << size) + wxBitmap bmp2 = bmp; + // verify bmp starts yellow + { + wxNativePixelData dataBmp(bmp2); + wxNativePixelData::Iterator rowStartBmp(dataBmp); + for ( int y = 0; y < bmp2.GetHeight(); ++y ) + { + wxNativePixelData::Iterator iBmp = rowStartBmp; + for ( int x = 0; x < bmp2.GetWidth(); ++x, ++iBmp ) + { + wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue()); + CHECK_EQUAL_COLOUR_RGB(bmpc, (*wxYELLOW)); + } + rowStartBmp.OffsetY(dataBmp, 1); + } + } + + // change square to red + wxRect square(wxPoint(5, 5), wxSize(size, size)); + { + wxMemoryDC dc(bmp2); + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(*wxRED_BRUSH); + dc.DrawRectangle(square); + } + + // verify bitmap is still yellow, except square is red + { + wxNativePixelData dataBmp(bmp2); + wxNativePixelData::Iterator rowStartBmp(dataBmp); + for ( int y = 0; y < bmp2.GetHeight(); ++y ) + { + wxNativePixelData::Iterator iBmp = rowStartBmp; + for ( int x = 0; x < bmp2.GetWidth(); ++x, ++iBmp ) + { + wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue()); + CHECK_EQUAL_COLOUR_RGB(bmpc, (square.Contains(x, y) ? *wxRED : *wxYELLOW)); + } + rowStartBmp.OffsetY(dataBmp, 1); + } } - rowStartBmp.OffsetY(dataBmp, 1); } }