]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/image/image.cpp
tooltip bug (which I introduced recently) corrected
[wxWidgets.git] / samples / image / image.cpp
index 74cb31a6c75b6bf444cb98c96104cb0c005163ba..5f215657ad42391a238214237a3019548a20bfc7 100644 (file)
@@ -84,6 +84,10 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
                     const wxPoint &pos, const wxSize &size )
         : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
 {
+  my_horse = (wxBitmap*) NULL;
+  my_square = (wxBitmap*) NULL;
+  my_anti = (wxBitmap*) NULL;
+
   SetBackgroundColour(* wxWHITE);
 
   wxBitmap bitmap( 100, 100 );
@@ -109,7 +113,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
   
   image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG );
   my_square = new wxBitmap( image.ConvertToBitmap() );
-  
+
   CreateAntiAliasedBitmap();
 }
 
@@ -124,28 +128,28 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
 {
   wxPaintDC dc( this );
   PrepareDC( dc );
-  
+
   dc.DrawText( "Loaded image", 30, 10 );
-  if (my_square->Ok()) dc.DrawBitmap( *my_square, 30, 30 );
+  if (my_square && my_square->Ok()) dc.DrawBitmap( *my_square, 30, 30 );
 
   dc.DrawText( "Drawn directly", 150, 10 );
   dc.SetBrush( wxBrush( "orange", wxSOLID ) );
   dc.SetPen( *wxWHITE_PEN );
   dc.DrawRectangle( 150, 30, 100, 100 );
 
-  if (my_anti->Ok()) dc.DrawBitmap( *my_anti, 250, 140 );
+  if (my_anti && my_anti->Ok()) dc.DrawBitmap( *my_anti, 250, 140 );
   
-  if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 140 );
+  if (my_horse && my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 140 );
 }
 
 void MyCanvas::CreateAntiAliasedBitmap()
 {
   wxBitmap bitmap( 300, 300 );
+
   wxMemoryDC dc;
+
   dc.SelectObject( bitmap );
-  
-  dc.SetPen( *wxTRANSPARENT_PEN );
-  
+
   dc.Clear();
   
   dc.SetFont( wxFont( 24, wxDECORATIVE, wxDEFAULT, wxDEFAULT ) );
@@ -158,7 +162,7 @@ void MyCanvas::CreateAntiAliasedBitmap()
   
   wxImage original( bitmap );
   wxImage anti( 150, 150 );
-  
+
   /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
   
   for (int y = 1; y < 149; y++)
@@ -237,7 +241,13 @@ void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
 
 bool MyApp::OnInit()
 {
+#if wxUSE_LIBPNG
   wxImage::AddHandler( new wxPNGHandler );
+#endif
+
+#if wxUSE_LIBJPEG
+  wxImage::AddHandler( new wxJPEGHandler );
+#endif
 
   wxFrame *frame = new MyFrame();
   frame->Show( TRUE );