From: Guillermo Rodriguez Garcia <guille@iies.es>
Date: Tue, 28 Dec 1999 12:28:39 +0000 (+0000)
Subject: Added GetSubBitmap()
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3f399a69cceccea1f955dab85af0c21b361c78a0

Added GetSubBitmap()


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

diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h
index a7d5676755..82b5d30251 100644
--- a/include/wx/msw/bitmap.h
+++ b/include/wx/msw/bitmap.h
@@ -116,6 +116,9 @@ public:
 
     virtual ~wxBitmap();
 
+    // GRG, Dic/99
+    wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect ) const;
+ 
     // copies the contents and mask of the given (colour) icon to the bitmap
     bool CopyFromIcon(const wxIcon& icon);
 
diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp
index 8219aae622..e74cf073a4 100644
--- a/src/msw/bitmap.cpp
+++ b/src/msw/bitmap.cpp
@@ -249,6 +249,46 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
     SetHBITMAP((WXHBITMAP)hbmp);
 }
 
+// GRG, Dic/99
+wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
+{
+    wxCHECK_MSG( Ok() &&
+                 (rect.x >= 0) && (rect.y >= 0) && 
+                 (rect.x+rect.width <= GetWidth()) &&
+                 (rect.y+rect.height <= GetHeight()),
+                 wxNullBitmap, wxT("Invalid bitmap or bitmap region") );
+    
+    wxBitmap ret( rect.width, rect.height, GetDepth() );
+    wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
+    
+    // copy bitmap data
+    HDC dcSrc = ::CreateCompatibleDC(NULL);
+    HDC dcDst = ::CreateCompatibleDC(NULL);
+    SelectObject(dcSrc, (HBITMAP) GetHBITMAP());
+    SelectObject(dcDst, (HBITMAP) ret.GetHBITMAP());
+    BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY);
+
+    // copy mask if there is one
+    if (GetMask())
+    {
+        HBITMAP hbmpMask = ::CreateBitmap(rect.width, rect.height, 1, 1, 0);
+
+        SelectObject(dcSrc, (HBITMAP) GetMask()->GetMaskBitmap());
+        SelectObject(dcDst, (HBITMAP) hbmpMask);
+        BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY);
+
+        wxMask *mask = new wxMask((WXHBITMAP) hbmpMask);
+        ret.SetMask(mask);
+    }
+
+    SelectObject(dcDst, NULL);
+    SelectObject(dcSrc, NULL);
+    DeleteDC(dcDst);
+    DeleteDC(dcSrc);
+
+    return ret;
+}
+
 // Create from XPM data
 wxBitmap::wxBitmap(char **data, wxControl *WXUNUSED(anItem))
 {