A couple of changes to wxImage:
1. changed wxBMP_foo, wxCUR_foo to wxIMAGE_OPTION_{BMP,CUR}_foo (with backward compatiblity macros, of course) 2. applied Chris' patch to update hotspot when scaling an image 3. applied Chris' patch to write a filename in XPM and generalized it to pass wxIMAGE_OPTION_FILENAME to all saving handlers git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14247 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -145,8 +145,8 @@ initialized with \helpref{wxImage::AddHandler}{wximageaddhandler} or
|
|||||||
Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
|
Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
|
||||||
hotspot for loaded cursor file:
|
hotspot for loaded cursor file:
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
int hotspot_x = image.GetOptionInt(wxCUR_HOTSPOT_X);
|
int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
|
||||||
int hotspot_y = image.GetOptionInt(wxCUR_HOTSPOT_Y);
|
int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
|
||||||
|
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
@@ -581,8 +581,8 @@ Depending on how wxWindows has been configured, not all formats may be available
|
|||||||
Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
|
Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
|
||||||
hotspot for loaded cursor file:
|
hotspot for loaded cursor file:
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
int hotspot_x = image.GetOptionInt(wxCUR_HOTSPOT_X);
|
int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
|
||||||
int hotspot_y = image.GetOptionInt(wxCUR_HOTSPOT_Y);
|
int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
|
||||||
|
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
@@ -684,8 +684,8 @@ Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to set the
|
|||||||
hotspot before saving an image into a cursor file (default hotspot is in
|
hotspot before saving an image into a cursor file (default hotspot is in
|
||||||
the centre of the image):
|
the centre of the image):
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
image.SetOption(wxCUR_HOTSPOT_X, hotspotX);
|
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
|
||||||
image.SetOption(wxCUR_HOTSPOT_Y, hotspotY);
|
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
|
||||||
|
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
@@ -17,8 +17,19 @@
|
|||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
|
||||||
// defines for saving the BMP file in different formats, Bits Per Pixel
|
// defines for saving the BMP file in different formats, Bits Per Pixel
|
||||||
// USE: wximage.SetOption( wxBMP_FORMAT, wxBMP_xBPP );
|
// USE: wximage.SetOption( wxIMAGE_OPTION_BMP_FORMAT, wxBMP_xBPP );
|
||||||
#define wxBMP_FORMAT wxString(_T("wxBMP_FORMAT"))
|
#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
|
enum
|
||||||
{
|
{
|
||||||
@@ -100,11 +111,6 @@ private:
|
|||||||
// wxCURHandler
|
// 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
|
class WXDLLEXPORT wxCURHandler : public wxICOHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#if wxUSE_IMAGE
|
#if wxUSE_IMAGE
|
||||||
|
|
||||||
|
#define wxIMAGE_OPTION_FILENAME wxString(_T("FileName"))
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// classes
|
// classes
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@@ -151,7 +151,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
image.SetOption(wxBMP_FORMAT, bppvalues[bppselection]);
|
image.SetOption(wxIMAGE_OPTION_BMP_FORMAT, bppvalues[bppselection]);
|
||||||
|
|
||||||
wxString deffilename = bppchoices[bppselection];
|
wxString deffilename = bppchoices[bppselection];
|
||||||
deffilename.Replace(wxT(" "), wxT("_"));
|
deffilename.Replace(wxT(" "), wxT("_"));
|
||||||
@@ -173,7 +173,7 @@ public:
|
|||||||
if ( savefilename.empty() )
|
if ( savefilename.empty() )
|
||||||
return;
|
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];
|
unsigned char *cmap = new unsigned char [256];
|
||||||
for ( int i = 0; i < 256; i++ )
|
for ( int i = 0; i < 256; i++ )
|
||||||
@@ -204,8 +204,8 @@ public:
|
|||||||
else if (extension == "cur")
|
else if (extension == "cur")
|
||||||
{
|
{
|
||||||
image.Rescale(32,32);
|
image.Rescale(32,32);
|
||||||
image.SetOption(wxCUR_HOTSPOT_X, 0);
|
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 0);
|
||||||
image.SetOption(wxCUR_HOTSPOT_Y, 0);
|
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 0);
|
||||||
saved=image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
|
saved=image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -415,8 +415,8 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
my_horse_cur = new wxBitmap( image );
|
my_horse_cur = new wxBitmap( image );
|
||||||
xH = 30 + image.GetOptionInt(wxCUR_HOTSPOT_X) ;
|
xH = 30 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) ;
|
||||||
yH = 2420 + image.GetOptionInt(wxCUR_HOTSPOT_Y) ;
|
yH = 2420 + image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -89,8 +89,8 @@ bool wxBMPHandler::SaveDib(wxImage *image,
|
|||||||
|
|
||||||
// get the format of the BMP file to save, else use 24bpp
|
// get the format of the BMP file to save, else use 24bpp
|
||||||
unsigned format = wxBMP_24BPP;
|
unsigned format = wxBMP_24BPP;
|
||||||
if ( image->HasOption(wxBMP_FORMAT) )
|
if ( image->HasOption(wxIMAGE_OPTION_BMP_FORMAT) )
|
||||||
format = image->GetOptionInt(wxBMP_FORMAT);
|
format = image->GetOptionInt(wxIMAGE_OPTION_BMP_FORMAT);
|
||||||
|
|
||||||
wxUint16 bpp; // # of bits per pixel
|
wxUint16 bpp; // # of bits per pixel
|
||||||
int palette_size; // # of color map entries, ie. 2^bpp colors
|
int palette_size; // # of color map entries, ie. 2^bpp colors
|
||||||
@@ -1001,10 +1001,10 @@ bool wxICOHandler::SaveFile(wxImage *image,
|
|||||||
}
|
}
|
||||||
// Set the formats for image and mask
|
// Set the formats for image and mask
|
||||||
// (Windows never saves with more than 8 colors):
|
// (Windows never saves with more than 8 colors):
|
||||||
image->SetOption(wxBMP_FORMAT, wxBMP_8BPP);
|
image->SetOption(wxIMAGE_OPTION_BMP_FORMAT, wxBMP_8BPP);
|
||||||
|
|
||||||
// monochome bitmap:
|
// monochome bitmap:
|
||||||
mask.SetOption(wxBMP_FORMAT, wxBMP_1BPP_BW);
|
mask.SetOption(wxIMAGE_OPTION_BMP_FORMAT, wxBMP_1BPP_BW);
|
||||||
bool IsBmp = FALSE;
|
bool IsBmp = FALSE;
|
||||||
bool IsMask = FALSE;
|
bool IsMask = FALSE;
|
||||||
|
|
||||||
@@ -1049,11 +1049,11 @@ bool wxICOHandler::SaveFile(wxImage *image,
|
|||||||
icondirentry.wBitCount = wxUINT16_SWAP_ON_BE(wxBMP_8BPP);
|
icondirentry.wBitCount = wxUINT16_SWAP_ON_BE(wxBMP_8BPP);
|
||||||
if ( type == 2 /*CUR*/)
|
if ( type == 2 /*CUR*/)
|
||||||
{
|
{
|
||||||
int hx = image->HasOption(wxCUR_HOTSPOT_X) ?
|
int hx = image->HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) ?
|
||||||
image->GetOptionInt(wxCUR_HOTSPOT_X) :
|
image->GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X) :
|
||||||
image->GetWidth() / 2;
|
image->GetWidth() / 2;
|
||||||
int hy = image->HasOption(wxCUR_HOTSPOT_Y) ?
|
int hy = image->HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) ?
|
||||||
image->GetOptionInt(wxCUR_HOTSPOT_Y) :
|
image->GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y) :
|
||||||
image->GetHeight() / 2;
|
image->GetHeight() / 2;
|
||||||
|
|
||||||
// actually write the values of the hot spot here:
|
// actually write the values of the hot spot here:
|
||||||
@@ -1175,8 +1175,8 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream,
|
|||||||
if ( bResult && bIsCursorType && nType == 2 )
|
if ( bResult && bIsCursorType && nType == 2 )
|
||||||
{
|
{
|
||||||
// it is a cursor, so let's set the hotspot:
|
// it is a cursor, so let's set the hotspot:
|
||||||
image->SetOption(wxCUR_HOTSPOT_X, wxUINT16_SWAP_ON_BE(pCurrentEntry->wPlanes));
|
image->SetOption(wxIMAGE_OPTION_CUR_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_Y, wxUINT16_SWAP_ON_BE(pCurrentEntry->wBitCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] pIconDirEntry;
|
delete[] pIconDirEntry;
|
||||||
|
@@ -274,6 +274,13 @@ wxImage wxImage::Scale( int width, int height ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -933,6 +940,9 @@ bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype, int
|
|||||||
bool wxImage::SaveFile( const wxString& filename, int type ) const
|
bool wxImage::SaveFile( const wxString& filename, int type ) const
|
||||||
{
|
{
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
|
if ( !HasOption(wxIMAGE_OPTION_FILENAME) )
|
||||||
|
((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
|
||||||
|
|
||||||
wxFileOutputStream stream(filename);
|
wxFileOutputStream stream(filename);
|
||||||
|
|
||||||
if ( stream.LastError() == wxStream_NOERROR )
|
if ( stream.LastError() == wxStream_NOERROR )
|
||||||
@@ -948,6 +958,9 @@ bool wxImage::SaveFile( const wxString& filename, int type ) const
|
|||||||
bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) const
|
bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) const
|
||||||
{
|
{
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
|
if ( !HasOption(wxIMAGE_OPTION_FILENAME) )
|
||||||
|
((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
|
||||||
|
|
||||||
wxFileOutputStream stream(filename);
|
wxFileOutputStream stream(filename);
|
||||||
|
|
||||||
if ( stream.LastError() == wxStream_NOERROR )
|
if ( stream.LastError() == wxStream_NOERROR )
|
||||||
|
@@ -128,12 +128,25 @@ bool wxXPMHandler::SaveFile(wxImage * image,
|
|||||||
chars_per_pixel++;
|
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];
|
char tmpbuf[200];
|
||||||
// VS: 200b is safe upper bound for anything produced by sprintf below
|
// 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,
|
sprintf(tmpbuf,
|
||||||
"/* XPM */\n"
|
"[] = {\n"
|
||||||
"static char *xpm_data[] = {\n"
|
|
||||||
"/* columns rows colors chars-per-pixel */\n"
|
"/* columns rows colors chars-per-pixel */\n"
|
||||||
"\"%i %i %i %i\",\n",
|
"\"%i %i %i %i\",\n",
|
||||||
image->GetWidth(), image->GetHeight(), cols, chars_per_pixel);
|
image->GetWidth(), image->GetHeight(), cols, chars_per_pixel);
|
||||||
|
Reference in New Issue
Block a user