X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1b806b98241ab649c169aaa1f134df85e80fb8b..11e3c6ef36393fb5863ea2f9601d8facd73acb12:/samples/image/canvas.cpp diff --git a/samples/image/canvas.cpp b/samples/image/canvas.cpp index 3bff81316f..31ea54f76e 100644 --- a/samples/image/canvas.cpp +++ b/samples/image/canvas.cpp @@ -35,6 +35,7 @@ #include "smile.xbm" #include "smile.xpm" +#include "cursor_png.c" #include "canvas.h" @@ -62,7 +63,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, wxMemoryDC dc; dc.SelectObject( bitmap ); - dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) ); + dc.SetBrush( wxBrush( wxS("orange") ) ); dc.SetPen( *wxBLACK_PEN ); dc.DrawRectangle( 0, 0, 100, 100 ); dc.SetBrush( *wxWHITE_BRUSH ); @@ -243,7 +244,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, #if wxUSE_LIBTIFF image.Destroy(); - if ( !image.LoadFile( dir + wxT("horse.tif"), wxBITMAP_TYPE_TIF ) ) + if ( !image.LoadFile( dir + wxT("horse.tif"), wxBITMAP_TYPE_TIFF ) ) { wxLogError(wxT("Can't load TIFF image")); } @@ -376,6 +377,19 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, free(data); } + + // This macro loads PNG from either resources on the platforms that support + // this (Windows and OS X) or from in-memory data (coming from cursor_png.c + // included above in our case). + my_png_from_res = wxBITMAP_PNG(cursor); + + // This one always loads PNG from memory but exists for consistency with + // the above one and also because it frees you from the need to specify the + // length explicitly, without it you'd have to do it and also spell the + // array name in full, like this: + // + // my_png_from_mem = wxBitmap::NewFromPNGData(cursor_png, WXSIZEOF(cursor_png)); + my_png_from_mem = wxBITMAP_PNG_FROM_DATA(cursor); } MyCanvas::~MyCanvas() @@ -393,7 +407,7 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawBitmap( my_square, 30, 30 ); dc.DrawText( wxT("Drawn directly"), 150, 10 ); - dc.SetBrush( wxBrush( wxT("orange"), wxSOLID ) ); + dc.SetBrush( wxBrush( wxS("orange") ) ); dc.SetPen( *wxBLACK_PEN ); dc.DrawRectangle( 150, 30, 100, 100 ); dc.SetBrush( *wxWHITE_BRUSH ); @@ -635,6 +649,13 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, true ); } } + + dc.DrawText("PNG from resources", 30, 2460); + if ( my_png_from_res.IsOk() ) + dc.DrawBitmap(my_png_from_res, 30, 2480, true); + dc.DrawText("PNG from memory", 230, 2460); + if ( my_png_from_mem.IsOk() ) + dc.DrawBitmap(my_png_from_mem, 230, 2480, true); } void MyCanvas::CreateAntiAliasedBitmap()