]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/image/image.cpp
fix compilation for GTK1
[wxWidgets.git] / samples / image / image.cpp
index 1df4e86ac5bb870839913235606ec48445491714..ef9f1914177ddfe32aef842d9443117a1f6cf356 100644 (file)
 #include "wx/quantize.h"
 
 #include "smile.xbm"
 #include "wx/quantize.h"
 
 #include "smile.xbm"
-#include "smile.xpm"
+
+#if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
+    #include "smile.xpm"
+#endif
 
 
 // derived classes
 
 
 // derived classes
@@ -57,12 +60,14 @@ public:
     wxBitmap  *my_horse_ico16;
     wxBitmap  *my_horse_ico;
     wxBitmap  *my_horse_cur;
     wxBitmap  *my_horse_ico16;
     wxBitmap  *my_horse_ico;
     wxBitmap  *my_horse_cur;
+    wxBitmap  *my_horse_ani;
 
     wxBitmap  *my_smile_xbm;
     wxBitmap  *my_square;
     wxBitmap  *my_anti;
 
     int xH, yH ;
 
     wxBitmap  *my_smile_xbm;
     wxBitmap  *my_square;
     wxBitmap  *my_anti;
 
     int xH, yH ;
+    int m_ani_images ;
 
 protected:
     wxBitmap m_bmpSmileXpm;
 
 protected:
     wxBitmap m_bmpSmileXpm;
@@ -130,14 +135,18 @@ public:
         SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
     }
 
         SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
     }
 
+    void OnEraseBackground(wxEraseEvent& WXUNUSED(event))
+    {
+        // do nothing here to be able to see how transparent images are shown
+    }
+
     void OnPaint(wxPaintEvent& WXUNUSED(event))
     {
         wxPaintDC dc( this );
     void OnPaint(wxPaintEvent& WXUNUSED(event))
     {
         wxPaintDC dc( this );
-        //TRUE for masked images
-        dc.DrawBitmap( m_bitmap, 0, 0, TRUE );
+        dc.DrawBitmap( m_bitmap, 0, 0, TRUE /* use mask */ );
     }
 
     }
 
-    void OnSave(wxCommandEvent& WXUNUSED(event))
+    void OnSave(wxMouseEvent& WXUNUSED(event))
     {
         wxImage image = m_bitmap.ConvertToImage();
 
     {
         wxImage image = m_bitmap.ConvertToImage();
 
@@ -232,8 +241,9 @@ IMPLEMENT_APP(MyApp)
 IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
 
 BEGIN_EVENT_TABLE(MyImageFrame, wxFrame)
 IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
 
 BEGIN_EVENT_TABLE(MyImageFrame, wxFrame)
-  EVT_PAINT(MyImageFrame::OnPaint)
-  EVT_LEFT_DCLICK(MyImageFrame::OnSave)
+    EVT_ERASE_BACKGROUND(MyImageFrame::OnEraseBackground)
+    EVT_PAINT(MyImageFrame::OnPaint)
+    EVT_LEFT_DCLICK(MyImageFrame::OnSave)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
 END_EVENT_TABLE()
 
 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
@@ -261,11 +271,14 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
     my_horse_ico16 = (wxBitmap*) NULL;
     my_horse_ico = (wxBitmap*) NULL;
     my_horse_cur = (wxBitmap*) NULL;
     my_horse_ico16 = (wxBitmap*) NULL;
     my_horse_ico = (wxBitmap*) NULL;
     my_horse_cur = (wxBitmap*) NULL;
+    my_horse_ani = (wxBitmap*) NULL;
 
     my_smile_xbm = (wxBitmap*) NULL;
     my_square = (wxBitmap*) NULL;
     my_anti = (wxBitmap*) NULL;
 
 
     my_smile_xbm = (wxBitmap*) NULL;
     my_square = (wxBitmap*) NULL;
     my_anti = (wxBitmap*) NULL;
 
+    m_ani_images = 0 ;
+
     SetBackgroundColour(* wxWHITE);
 
     wxBitmap bitmap( 100, 100 );
     SetBackgroundColour(* wxWHITE);
 
     wxBitmap bitmap( 100, 100 );
@@ -282,9 +295,9 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
     // try to find the directory with our images
     wxString dir;
     if ( wxFile::Exists(wxT("./horse.png")) )
     // try to find the directory with our images
     wxString dir;
     if ( wxFile::Exists(wxT("./horse.png")) )
-        dir = "./";
+        dir = wxT("./");
     else if ( wxFile::Exists(wxT("../horse.png")) )
     else if ( wxFile::Exists(wxT("../horse.png")) )
-        dir = "../";
+        dir = wxT("../");
     else
         wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
 
     else
         wxLogWarning(wxT("Can't find image files in either '.' or '..'!"));
 
@@ -319,7 +332,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
 #if wxUSE_GIF
     image.Destroy();
 
 #if wxUSE_GIF
     image.Destroy();
 
-    if ( !image.LoadFile( dir + wxString("horse.gif")))
+    if ( !image.LoadFile( dir + _T("horse.gif" )) )
         wxLogError(wxT("Can't load GIF image"));
     else
         my_horse_gif = new wxBitmap( image );
         wxLogError(wxT("Can't load GIF image"));
     else
         my_horse_gif = new wxBitmap( image );
@@ -414,6 +427,27 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
         xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
         yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
     }
         xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
         yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
     }
+
+    m_ani_images = wxImage::GetImageCount ( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI );
+    if (m_ani_images==0)
+        wxLogError(wxT("No ANI-format images found"));
+    else
+        my_horse_ani = new wxBitmap [m_ani_images];
+    int i ;
+    for (i=0; i < m_ani_images; i++)
+    {
+        image.Destroy();
+        if (!image.LoadFile( dir + _T("horse3.ani"), wxBITMAP_TYPE_ANI, i ))
+        {
+            wxString tmp = wxT("Can't load image number ");
+            tmp << i ;
+            wxLogError(tmp);
+        }
+        else    
+            my_horse_ani [i] = wxBitmap( image );
+    }
+    
+    
 #endif
 
     image.Destroy();
 #endif
 
     image.Destroy();
@@ -451,6 +485,7 @@ MyCanvas::~MyCanvas()
     delete my_horse_ico16;
     delete my_horse_ico;
     delete my_horse_cur;
     delete my_horse_ico16;
     delete my_horse_ico;
     delete my_horse_cur;
+    delete [] my_horse_ani;
     delete my_smile_xbm;
     delete my_square;
     delete my_anti;
     delete my_smile_xbm;
     delete my_square;
     delete my_anti;
@@ -608,6 +643,13 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
         dc.DrawLine (xH-10,yH,xH+10,yH);
         dc.DrawLine (xH,yH-10,xH,yH+10);
     }
         dc.DrawLine (xH-10,yH,xH+10,yH);
         dc.DrawLine (xH,yH-10,xH,yH+10);
     }
+    dc.DrawText( _T("ANI handler"), 230, 2390 );
+    int i ;
+    for (i=0; i < m_ani_images; i ++)
+        if (my_horse_ani[i].Ok())
+        {
+            dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, TRUE );
+        }
 }
 
 void MyCanvas::CreateAntiAliasedBitmap()
 }
 
 void MyCanvas::CreateAntiAliasedBitmap()
@@ -765,6 +807,7 @@ bool MyApp::OnInit()
 #if wxUSE_ICO_CUR
   wxImage::AddHandler( new wxICOHandler );
   wxImage::AddHandler( new wxCURHandler );
 #if wxUSE_ICO_CUR
   wxImage::AddHandler( new wxICOHandler );
   wxImage::AddHandler( new wxCURHandler );
+  wxImage::AddHandler( new wxANIHandler );
 #endif
 
   wxFrame *frame = new MyFrame();
 #endif
 
   wxFrame *frame = new MyFrame();