I have MSVC++ 15 and wxwidgets-3.1.0. I am following the book Cross-Platform GUI Programming with wxWidgets (2005). I am stuck on this code from Chapter 5 "Drawing and Printing":
#include <wx/effects.h>
void MyWindow::OnErase(wxEraseEvent& event){
wxClientDC* clientDC = NULL;
if (!event.GetDC())
clientDC = new wxClientDC(this);
wxDC* dc = clientDC ? clientDC : event.GetDC() ;
wxSize sz = GetClientSize();
wxEffects effects;
effects.TileBitmap(wxRect(0, 0, sz.x, sz.y), *dc, m_bitmap);
if (clientDC)
delete clientDC;
}
When I compile the code above I get the error: Identifier "wxEffects" is undefined
.
It seems wxEffects
has been removed from a default build of wxWidgets, but without any replacement being added for the TileBitmap
function.
If you build wxWidgets yourself then you could enable this by doing a 2.8 compatibility build (edit include/wx/msw/setup.h
before building).
However if you are just using wxWidgets headers and precompiled libraries then an option could be to put in your own version of this function. The source code is here so you can just copy the entire bool wxEffectsImpl::TileBitmap
out of that and into your program, remove the wxEffectsImpl::
and make sure you've got the right headers included.
One of the sample apps has the following simplified version that might work for you:
bool TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap)
{
int w = bitmap.GetWidth();
int h = bitmap.GetHeight();
int i, j;
for (i = rect.x; i < rect.x + rect.width; i += w)
{
for (j = rect.y; j < rect.y + rect.height; j+= h)
dc.DrawBitmap(bitmap, i, j);
}
return true;
}
The sample actually made this a member of MyApp
but you don't have to do that, you can just copy it into the .cpp
file where you need it and call it directly.