Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
hotspot for loaded cursor file:
\begin{verbatim}
- int hotspot_x = image.GetOptionInt(wxCUR_HOTSPOT_X);
- int hotspot_y = image.GetOptionInt(wxCUR_HOTSPOT_Y);
+ int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
+ int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
\end{verbatim}
Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
hotspot for loaded cursor file:
\begin{verbatim}
- int hotspot_x = image.GetOptionInt(wxCUR_HOTSPOT_X);
- int hotspot_y = image.GetOptionInt(wxCUR_HOTSPOT_Y);
+ int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
+ int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
\end{verbatim}
hotspot before saving an image into a cursor file (default hotspot is in
the centre of the image):
\begin{verbatim}
- image.SetOption(wxCUR_HOTSPOT_X, hotspotX);
- image.SetOption(wxCUR_HOTSPOT_Y, hotspotY);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
\end{verbatim}
#include "wx/image.h"
// defines for saving the BMP file in different formats, Bits Per Pixel
-// USE: wximage.SetOption( wxBMP_FORMAT, wxBMP_xBPP );
-#define wxBMP_FORMAT wxString(_T("wxBMP_FORMAT"))
+// USE: wximage.SetOption( wxIMAGE_OPTION_BMP_FORMAT, wxBMP_xBPP );
+#define wxIMAGE_OPTION_BMP_FORMAT wxString(_T("wxBMP_FORMAT"))
+
+// These two options are filled in upon reading CUR file and can (should) be
+// specified when saving a CUR file - they define the hotspot of the cursor:
+#define wxIMAGE_OPTION_CUR_HOTSPOT_X wxT("HotSpotX")
+#define wxIMAGE_OPTION_CUR_HOTSPOT_Y wxT("HotSpotY")
+
+// Do not use these macros, they are deprecated!! :
+#define wxBMP_FORMAT wxIMAGE_OPTION_BMP_FORMAT
+#define wxCUR_HOTSPOT_X wxIMAGE_OPTION_CUR_HOTSPOT_X
+#define wxCUR_HOTSPOT_Y wxIMAGE_OPTION_CUR_HOTSPOT_Y
+
enum
{
// wxCURHandler
// ----------------------------------------------------------------------------
-// These two options are filled in upon reading CUR file and can (should) be
-// specified when saving a CUR file - they define the hotspot of the cursor:
-#define wxCUR_HOTSPOT_X wxT("HotSpotX")
-#define wxCUR_HOTSPOT_Y wxT("HotSpotY")
-
class WXDLLEXPORT wxCURHandler : public wxICOHandler
{
public:
#if wxUSE_IMAGE
+#define wxIMAGE_OPTION_FILENAME wxString(_T("FileName"))
+
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
return;
}
- image.SetOption(wxBMP_FORMAT, bppvalues[bppselection]);
+ image.SetOption(wxIMAGE_OPTION_BMP_FORMAT, bppvalues[bppselection]);
wxString deffilename = bppchoices[bppselection];
deffilename.Replace(wxT(" "), wxT("_"));
if ( savefilename.empty() )
return;
- if ( image.GetOptionInt(wxBMP_FORMAT) == wxBMP_8BPP_PALETTE )
+ if ( image.GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT) == wxBMP_8BPP_PALETTE )
{
unsigned char *cmap = new unsigned char [256];
for ( int i = 0; i < 256; i++ )
else if (extension == "cur")
{
image.Rescale(32,32);
- image.SetOption(wxCUR_HOTSPOT_X, 0);
- image.SetOption(wxCUR_HOTSPOT_Y, 0);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 0);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 0);
saved=image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
}
else
else
{
my_horse_cur = new wxBitmap( image );
- xH = 30 + image.GetOptionInt(wxCUR_HOTSPOT_X) ;
- yH = 2420 + image.GetOptionInt(wxCUR_HOTSPOT_Y) ;
+ xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
+ yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
}
#endif
// get the format of the BMP file to save, else use 24bpp
unsigned format = wxBMP_24BPP;
- if ( image->HasOption(wxBMP_FORMAT) )
- format = image->GetOptionInt(wxBMP_FORMAT);
+ if ( image->HasOption(wxIMAGE_OPTION_BMP_FORMAT) )
+ format = image->GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT);
wxUint16 bpp; // # of bits per pixel
int palette_size; // # of color map entries, ie. 2^bpp colors
}
// Set the formats for image and mask
// (Windows never saves with more than 8 colors):
- image->SetOption(wxBMP_FORMAT, wxBMP_8BPP);
+ image->SetOption(wxIMAGE_OPTION_BMP_FORMAT, wxBMP_8BPP);
// monochome bitmap:
- mask.SetOption(wxBMP_FORMAT, wxBMP_1BPP_BW);
+ mask.SetOption(wxIMAGE_OPTION_BMP_FORMAT, wxBMP_1BPP_BW);
bool IsBmp = FALSE;
bool IsMask = FALSE;
icondirentry.wBitCount = wxUINT16_SWAP_ON_BE(wxBMP_8BPP);
if ( type == 2 /*CUR*/)
{
- int hx = image->HasOption(wxCUR_HOTSPOT_X) ?
- image->GetOptionInt(wxCUR_HOTSPOT_X) :
+ int hx = image->HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) ?
+ image->GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) :
image->GetWidth() / 2;
- int hy = image->HasOption(wxCUR_HOTSPOT_Y) ?
- image->GetOptionInt(wxCUR_HOTSPOT_Y) :
+ int hy = image->HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ?
+ image->GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) :
image->GetHeight() / 2;
// actually write the values of the hot spot here:
if ( bResult && bIsCursorType && nType == 2 )
{
// it is a cursor, so let's set the hotspot:
- image->SetOption(wxCUR_HOTSPOT_X, wxUINT16_SWAP_ON_BE(pCurrentEntry->wPlanes));
- image->SetOption(wxCUR_HOTSPOT_Y, wxUINT16_SWAP_ON_BE(pCurrentEntry->wBitCount));
+ image->SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, wxUINT16_SWAP_ON_BE(pCurrentEntry->wPlanes));
+ image->SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, wxUINT16_SWAP_ON_BE(pCurrentEntry->wBitCount));
}
}
delete[] pIconDirEntry;
}
}
#endif
+ // In case this is a cursor, make sure the hotspot is scalled accordingly:
+ if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,
+ (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X)*width)/old_width);
+ if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) )
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,
+ (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y)*height)/old_height);
return image;
}
bool wxImage::SaveFile( const wxString& filename, int type ) const
{
#if wxUSE_STREAMS
+ if ( !HasOption(wxIMAGE_OPTION_FILENAME) )
+ ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
+
wxFileOutputStream stream(filename);
if ( stream.LastError() == wxStream_NOERROR )
bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) const
{
#if wxUSE_STREAMS
+ if ( !HasOption(wxIMAGE_OPTION_FILENAME) )
+ ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
+
wxFileOutputStream stream(filename);
if ( stream.LastError() == wxStream_NOERROR )
for ( k = MaxCixels; cols > k; k *= MaxCixels)
chars_per_pixel++;
- // 2. write the header:
+ // 2. write the header:
+ wxString sName;
+ if ( image->HasOption(wxIMAGE_OPTION_FILENAME) )
+ {
+ wxSplitPath(image->GetOption(wxIMAGE_OPTION_FILENAME),
+ NULL, &sName, NULL);
+ sName << wxT("_xpm");
+ }
+
+ if ( !sName.IsEmpty() )
+ sName = wxString(wxT("/* XPM */\nstatic char *")) + sName;
+ else
+ sName = wxT("/* XPM */\nstatic char *xpm_data");
+ stream.Write(sName.c_str(), sName.Len());
+
char tmpbuf[200];
// VS: 200b is safe upper bound for anything produced by sprintf below
- // (101 bytes the string, neither %i can expand into more than 10 chars)
+ // (<101 bytes the string, neither %i can expand into more than 10 chars)
sprintf(tmpbuf,
- "/* XPM */\n"
- "static char *xpm_data[] = {\n"
+ "[] = {\n"
"/* columns rows colors chars-per-pixel */\n"
"\"%i %i %i %i\",\n",
image->GetWidth(), image->GetHeight(), cols, chars_per_pixel);