]> git.saurik.com Git - wxWidgets.git/commitdiff
A couple of changes to wxImage:
authorVáclav Slavík <vslavik@fastmail.fm>
Sat, 16 Feb 2002 01:45:30 +0000 (01:45 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sat, 16 Feb 2002 01:45:30 +0000 (01:45 +0000)
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

docs/latex/wx/image.tex
include/wx/imagbmp.h
include/wx/image.h
samples/image/image.cpp
src/common/imagbmp.cpp
src/common/image.cpp
src/common/imagxpm.cpp

index cb487fc78ed67ebca516e98127d00683a72dba47..aa5589fcaca57a9a745356c381036528e8cff95d 100644 (file)
@@ -145,8 +145,8 @@ initialized with \helpref{wxImage::AddHandler}{wximageaddhandler} or
 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}
 
@@ -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 
 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}
 
@@ -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 
 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}
 
index d687121f67dbc81f753d45631a884b3ab1580b05..0ba6c31e9f8491ed5d470352fd2036d883ed3193 100644 (file)
 #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
 {
@@ -100,11 +111,6 @@ private:
 // 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:
index 14530e58bcde8379899ca69d4131d93e418b1e0f..cf69aa743aa9e8c98132d895c08fc8762622cd5c 100644 (file)
@@ -27,6 +27,8 @@
 
 #if wxUSE_IMAGE
 
+#define wxIMAGE_OPTION_FILENAME wxString(_T("FileName"))
+
 //-----------------------------------------------------------------------------
 // classes
 //-----------------------------------------------------------------------------
index 57260e265d0d575e17a38cc62fa2c69cbeea0a9d..c0668f233152a694988abd0ea6ee85178b24232f 100644 (file)
@@ -151,7 +151,7 @@ public:
             return;
         }
 
-        image.SetOption(wxBMP_FORMAT, bppvalues[bppselection]);
+        image.SetOption(wxIMAGE_OPTION_BMP_FORMAT, bppvalues[bppselection]);
 
         wxString deffilename = bppchoices[bppselection];
         deffilename.Replace(wxT(" "), wxT("_"));
@@ -173,7 +173,7 @@ public:
         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++ )
@@ -204,8 +204,8 @@ public:
         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
@@ -415,8 +415,8 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
     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
index f50bdbc30e2fd5c4cdebe9c9fc422acd1bd0748f..3dcd8b12548e2610a1a44c06fec6bff69a242666 100644 (file)
@@ -89,8 +89,8 @@ bool wxBMPHandler::SaveDib(wxImage *image,
 
     // 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
@@ -1001,10 +1001,10 @@ bool wxICOHandler::SaveFile(wxImage *image,
         }
         // 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;
 
@@ -1049,11 +1049,11 @@ bool wxICOHandler::SaveFile(wxImage *image,
         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:
@@ -1175,8 +1175,8 @@ bool wxICOHandler::DoLoadFile(wxImage *image, wxInputStream& stream,
         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;
index 48b39581f5a6a69f1d13687d93e268061fb44db7..f533e0043221509e88b34a8f51c29edc35663804 100644 (file)
@@ -274,6 +274,13 @@ wxImage wxImage::Scale( int width, int height ) const
         }
     }
 #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;
 }
@@ -933,6 +940,9 @@ bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype, int
 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 )
@@ -948,6 +958,9 @@ bool wxImage::SaveFile( const wxString& filename, int type ) const
 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 )
index 7ebe0c9edf228f2d7e444e0c74a8e1b464f19a1e..c6ad6d6aa1408f643a44fc58b1eb52becb01d593 100644 (file)
@@ -127,13 +127,26 @@ bool wxXPMHandler::SaveFile(wxImage * image,
     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);