// Created: 1998
// RCS-ID: $Id$
// Copyright: (c) 1998-2005 Robert Roebling
-// License: wxWindows licence
+// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "smile.xbm"
#include "smile.xpm"
+#include "cursor_png.c"
#include "canvas.h"
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 );
#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"));
}
smile_height, 1 );
// demonstrates XPM automatically using the mask when saving
- if ( m_bmpSmileXpm.Ok() )
+ if ( m_bmpSmileXpm.IsOk() )
m_bmpSmileXpm.SaveFile(wxT("saved.xpm"), wxBITMAP_TYPE_XPM);
#if wxUSE_ICO_CUR
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()
PrepareDC( dc );
dc.DrawText( wxT("Loaded image"), 30, 10 );
- if (my_square.Ok())
+ if (my_square.IsOk())
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 );
dc.DrawRectangle( 170, 50, 60, 60 );
- if (my_anti.Ok())
+ if (my_anti.IsOk())
dc.DrawBitmap( my_anti, 280, 30 );
dc.DrawText( wxT("PNG handler"), 30, 135 );
- if (my_horse_png.Ok())
+ if (my_horse_png.IsOk())
{
dc.DrawBitmap( my_horse_png, 30, 150 );
wxRect rect(0,0,100,100);
}
dc.DrawText( wxT("JPEG handler"), 30, 365 );
- if (my_horse_jpeg.Ok())
+ if (my_horse_jpeg.IsOk())
dc.DrawBitmap( my_horse_jpeg, 30, 380 );
dc.DrawText( wxT("Green rotated to red"), 280, 365 );
- if (colorized_horse_jpeg.Ok())
+ if (colorized_horse_jpeg.IsOk())
dc.DrawBitmap( colorized_horse_jpeg, 280, 380 );
dc.DrawText( wxT("CMYK JPEG image"), 530, 365 );
- if (my_cmyk_jpeg.Ok())
+ if (my_cmyk_jpeg.IsOk())
dc.DrawBitmap( my_cmyk_jpeg, 530, 380 );
dc.DrawText( wxT("GIF handler"), 30, 595 );
- if (my_horse_gif.Ok())
+ if (my_horse_gif.IsOk())
dc.DrawBitmap( my_horse_gif, 30, 610 );
dc.DrawText( wxT("PCX handler"), 30, 825 );
- if (my_horse_pcx.Ok())
+ if (my_horse_pcx.IsOk())
dc.DrawBitmap( my_horse_pcx, 30, 840 );
dc.DrawText( wxT("BMP handler"), 30, 1055 );
- if (my_horse_bmp.Ok())
+ if (my_horse_bmp.IsOk())
dc.DrawBitmap( my_horse_bmp, 30, 1070 );
dc.DrawText( wxT("BMP read from memory"), 280, 1055 );
- if (my_horse_bmp2.Ok())
+ if (my_horse_bmp2.IsOk())
dc.DrawBitmap( my_horse_bmp2, 280, 1070 );
dc.DrawText( wxT("PNM handler"), 30, 1285 );
- if (my_horse_pnm.Ok())
+ if (my_horse_pnm.IsOk())
dc.DrawBitmap( my_horse_pnm, 30, 1300 );
dc.DrawText( wxT("PNM handler (ascii grey)"), 280, 1285 );
- if (my_horse_asciigrey_pnm.Ok())
+ if (my_horse_asciigrey_pnm.IsOk())
dc.DrawBitmap( my_horse_asciigrey_pnm, 280, 1300 );
dc.DrawText( wxT("PNM handler (raw grey)"), 530, 1285 );
- if (my_horse_rawgrey_pnm.Ok())
+ if (my_horse_rawgrey_pnm.IsOk())
dc.DrawBitmap( my_horse_rawgrey_pnm, 530, 1300 );
dc.DrawText( wxT("TIFF handler"), 30, 1515 );
- if (my_horse_tiff.Ok())
+ if (my_horse_tiff.IsOk())
dc.DrawBitmap( my_horse_tiff, 30, 1530 );
dc.DrawText( wxT("TGA handler"), 30, 1745 );
- if (my_horse_tga.Ok())
+ if (my_horse_tga.IsOk())
dc.DrawBitmap( my_horse_tga, 30, 1760 );
dc.DrawText( wxT("XPM handler"), 30, 1975 );
- if (my_horse_xpm.Ok())
+ if (my_horse_xpm.IsOk())
dc.DrawBitmap( my_horse_xpm, 30, 2000 );
// toucans
dc.DrawBitmap(my_toucan_blur, x, y+15, true);
}
- if (my_smile_xbm.Ok())
+ if (my_smile_xbm.IsOk())
{
int x = 300, y = 1800;
memdc.DrawLine( 5, 42, 50, 42 );
memdc.SelectObject( wxNullBitmap );
- if (mono.Ok())
+ if (mono.IsOk())
{
int x = 300, y = 1900;
dc.DrawRectangle( 20, 2220, 560, 68 );
dc.DrawText(wxT("XPM bitmap"), 30, 2230 );
- if ( m_bmpSmileXpm.Ok() )
+ if ( m_bmpSmileXpm.IsOk() )
dc.DrawBitmap(m_bmpSmileXpm, 30, 2250, true);
dc.DrawText(wxT("XPM icon"), 110, 2230 );
- if ( m_iconSmileXpm.Ok() )
+ if ( m_iconSmileXpm.IsOk() )
dc.DrawIcon(m_iconSmileXpm, 110, 2250);
// testing icon -> bitmap conversion
wxBitmap to_blit( m_iconSmileXpm );
- if (to_blit.Ok())
+ if (to_blit.IsOk())
{
dc.DrawText( wxT("SubBitmap"), 170, 2230 );
wxBitmap sub = to_blit.GetSubBitmap( wxRect(0,0,15,15) );
- if (sub.Ok())
+ if (sub.IsOk())
dc.DrawBitmap( sub, 170, 2250, true );
dc.DrawText( wxT("Enlarged"), 250, 2230 );
}
dc.DrawText( wxT("ICO handler (1st image)"), 30, 2290 );
- if (my_horse_ico32.Ok())
+ if (my_horse_ico32.IsOk())
dc.DrawBitmap( my_horse_ico32, 30, 2330, true );
dc.DrawText( wxT("ICO handler (2nd image)"), 230, 2290 );
- if (my_horse_ico16.Ok())
+ if (my_horse_ico16.IsOk())
dc.DrawBitmap( my_horse_ico16, 230, 2330, true );
dc.DrawText( wxT("ICO handler (best image)"), 430, 2290 );
- if (my_horse_ico.Ok())
+ if (my_horse_ico.IsOk())
dc.DrawBitmap( my_horse_ico, 430, 2330, true );
dc.DrawText( wxT("CUR handler"), 30, 2390 );
- if (my_horse_cur.Ok())
+ if (my_horse_cur.IsOk())
{
dc.DrawBitmap( my_horse_cur, 30, 2420, true );
dc.SetPen (*wxRED_PEN);
dc.DrawText( wxT("ANI handler"), 230, 2390 );
for ( int i=0; i < m_ani_images; i++ )
{
- if (my_horse_ani[i].Ok())
+ if (my_horse_ani[i].IsOk())
{
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()
{
wxBitmap bitmap( 300, 300 );
- wxMemoryDC dc;
-
- dc.SelectObject( bitmap );
+ {
+ wxMemoryDC dc(bitmap);
- dc.Clear();
+ dc.Clear();
- dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
- dc.SetTextForeground( wxT("RED") );
- dc.DrawText( wxT("This is anti-aliased Text."), 20, 5 );
- dc.DrawText( wxT("And a Rectangle."), 20, 45 );
+ dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
+ dc.SetTextForeground( wxT("RED") );
+ dc.DrawText( wxT("This is anti-aliased Text."), 20, 5 );
+ dc.DrawText( wxT("And a Rectangle."), 20, 45 );
- dc.SetBrush( *wxRED_BRUSH );
- dc.SetPen( *wxTRANSPARENT_PEN );
- dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );
+ dc.SetBrush( *wxRED_BRUSH );
+ dc.SetPen( *wxTRANSPARENT_PEN );
+ dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );
+ }
- wxImage original= bitmap.ConvertToImage();
+ wxImage original = bitmap.ConvertToImage();
wxImage anti( 150, 150 );
/* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */