MutIcon.h
gehe zur Dokumentation dieser Datei
00001 // -*- C++ -*-
00047 #ifndef MUTICON_H
00048 #define MUTICON_H
00049 
00050 #if defined(__WXMAC__)
00051 #include "Defs.h"
00052 #include <limits>
00053 
00055 
00063 class MutIcon:public wxIcon
00064 {
00065 protected:
00066         int width;
00067         int height;
00068 public:
00069 
00071         MutIcon():wxIcon(),width(-1),height(-1) {}
00072 
00074 
00078         MutIcon(const wxIcon & icon):wxIcon(icon) {
00079                 if (IsOk()) {
00080                         width = wxIcon::GetWidth();
00081                         height = wxIcon::GetHeight();
00082                 }
00083         }
00084 
00086 
00088         virtual int GetHeight() const
00089         {
00090                 return height;
00091         }
00092 
00094 
00096         virtual int GetWidth() const
00097         {
00098                 return width;
00099         }
00100 
00102 
00107         bool LoadFile(const wxString& name, wxBitmapType type)
00108         {
00109                 bool ret = wxIcon::LoadFile(name,type);
00110                 if (!ret) return false;
00111                 if (!IsOk ()) return false;
00112 
00113                 width = wxIcon::GetWidth();
00114                 height = wxIcon::GetHeight();
00115                 int m = std::max(width,height);
00116                 int newsize;
00117 
00118                 DEBUGLOG(other, _T("max: %d"),m);
00119                 if ((m == 16) || (m == 32) || (m == 48) || (m >= 128)) {
00120                         // if >128  I don't know, what to do
00121                         newsize = m;
00122                         //return ret;
00123                 }
00124                 if (m > 32) {
00125                         if (m > 48) newsize = 128;
00126                         else newsize = 48;
00127                 } else {
00128                         if (m > 16)
00129                                 newsize = 32;
00130                         else newsize = 16;
00131                 }
00132                 DEBUGLOG(other, _T("newsize: %d"), newsize);
00133 
00134                 wxBitmap bitmap;
00135                 wxImage image;
00136                 image.LoadFile(name,type);
00137                 image.ConvertAlphaToMask();
00138                 DEBUGLOG(other, _T("Mask: %d; Alpha: %d"),
00139                          (int)image.HasMask(),
00140                          (int)image.HasAlpha());
00141                 image.Resize(wxSize(newsize,newsize),wxPoint(0,0));
00142                 bitmap = image;
00143                 CopyFromBitmap(bitmap);
00144                 DEBUGLOG(other, _T("Real size: %dx%d"),wxIcon::GetWidth(),wxIcon::GetHeight());
00145 
00146                 SetWidth(width);
00147                 SetHeight(height);
00148                 DEBUGLOG(other, _T("Set size: %dx%d (%d,%d)"),GetWidth(),GetHeight(),width,height);
00149 
00150                 return true;
00151         }
00152   
00153 
00155 
00159   MutIcon & operator = (wxIcon & icon) 
00160   {
00161     *(static_cast<wxIcon *>(this)) = icon;
00162     if (IsOk()) {
00163       width = wxIcon::GetWidth();
00164       height = wxIcon::GetHeight();
00165     }
00166     return *this;
00167   }    
00168 };
00169 #define MutICON MutIcon
00170 #else
00171 #define MutIcon wxIcon
00172 #define MutICON(x) x
00173 #endif /* __WXMAC__ */
00174 
00175 #ifdef __WXMAC__
00176 extern MutIcon MutNullIcon; 
00177 #else
00178 #define MutNullIcon wxNullIcon;
00179 #endif
00180 
00181 #endif /* MUTROUTESHAPES_H */
00182 

Erzeugt am Sun Aug 21 2011 10:51:54 für Mutabor von doxygen 1.7.4