]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement wxBitmap::GetSubBitmap.
authorDavid Elliott <dfe@tgwbd.org>
Thu, 29 Nov 2007 07:28:17 +0000 (07:28 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 29 Nov 2007 07:28:17 +0000 (07:28 +0000)
Patch authored by Software 2000 Ltd.

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

src/cocoa/bitmap.mm

index cddc8c192f545a6c9c5e6903a1262b300e74c5ae..05553108c4e74ac6f088606683719e3be445c99f 100644 (file)
@@ -426,9 +426,26 @@ bool wxBitmap::CopyFromIcon(const wxIcon& icon)
     return true;
 }
 
-wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
+wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const
 {
-    return wxNullBitmap;
+    wxAutoNSAutoreleasePool pool;
+    if(!Ok())
+        return wxNullBitmap;
+    NSImage *nsimage = GetNSImage(false);
+
+    [nsimage lockFocus];
+    NSRect imageRect = {{0,0}, [nsimage size]};
+    imageRect.origin.x = imageRect.size.width * rect.x / GetWidth();
+    imageRect.origin.y = imageRect.size.height * rect.y / GetHeight();
+    imageRect.size.width *= wx_static_cast(CGFloat, rect.width) / GetWidth();
+    imageRect.size.height *= wx_static_cast(CGFloat, rect.height) / GetHeight();
+
+    NSBitmapImageRep *newBitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect];
+    [nsimage unlockFocus];
+
+    wxBitmap newBitmap(newBitmapRep);
+
+    return (newBitmap);
 }
 
 wxImage wxBitmap::ConvertToImage() const