]> git.saurik.com Git - wxWidgets.git/commitdiff
Handle hot spots in wxImage::Rotate90().
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 14 Nov 2010 01:02:27 +0000 (01:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 14 Nov 2010 01:02:27 +0000 (01:02 +0000)
Set hot spot coordinates for the rotated image if the original one had them.

Also handle the case when the source image has both alpha and mask correctly.

Closes #3680.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66145 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/image.cpp

index 4a070120399248e236e5c61f3cca4cc028a1251a..e82fa02082d78a84026d5a5a92ecd6f7a3b797ea 100644 (file)
@@ -1068,26 +1068,36 @@ wxImage wxImage::Rotate90( bool clockwise ) const
     unsigned char *source_data = M_IMGDATA->m_data;
     unsigned char *target_data;
     unsigned char *alpha_data = 0 ;
-    unsigned char *source_alpha = ;
+    unsigned char *source_alpha = M_IMGDATA->m_alpha;
     unsigned char *target_alpha = 0 ;
 
-    if (M_IMGDATA->m_hasMask)
+    if ( source_alpha )
     {
-        image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
-    }
-    else
-    {
-        source_alpha = M_IMGDATA->m_alpha ;
-        if ( source_alpha )
-        {
-            image.SetAlpha() ;
-            alpha_data = image.GetAlpha() ;
-        }
+        image.SetAlpha();
+        alpha_data = image.GetAlpha();
+        wxCHECK_MSG( alpha_data, image, wxS("unable to create alpha channel") );
     }
 
+    if ( M_IMGDATA->m_hasMask )
+        image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
+
     long height = M_IMGDATA->m_height;
     long width  = M_IMGDATA->m_width;
 
+    if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
+    {
+        int hot_x = GetOptionInt( wxIMAGE_OPTION_CUR_HOTSPOT_X );
+        image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,
+                        clockwise ? hot_x : width - 1 - hot_x);
+    }
+
+    if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) )
+    {
+        int hot_y = GetOptionInt( wxIMAGE_OPTION_CUR_HOTSPOT_Y );
+        image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,
+                        clockwise ? height - 1 - hot_y : hot_y);
+    }
+
     for (long j = 0; j < height; j++)
     {
         for (long i = 0; i < width; i++)