]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxBitmap::GetNSImage() which creates an autoreleased NSImage either
authorDavid Elliott <dfe@tgwbd.org>
Mon, 15 Dec 2003 19:30:54 +0000 (19:30 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Mon, 15 Dec 2003 19:30:54 +0000 (19:30 +0000)
with or without the bitmap mask applied.

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

include/wx/cocoa/bitmap.h
src/cocoa/bitmap.mm

index 622aab943e37dc0a56e3f1a9af0464dcb3f2dcaa..053e85f29c81c28cd200d8b75c002e68678d4beb 100644 (file)
@@ -148,6 +148,7 @@ public:
     // wxCocoa
     WX_NSBitmapImageRep GetNSBitmapImageRep();
     void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep);
+    WX_NSImage GetNSImage(bool useMask) const;
 
     static void InitStandardHandlers() { }
     static void CleanUpHandlers() { }
index de552f54358851b20e71351840845a6bdcdbb157..6e5702044de04602de73f8d8202174d2ea6abcc1 100644 (file)
@@ -27,6 +27,7 @@
 
 #import <AppKit/NSBitmapImageRep.h>
 #import <AppKit/NSGraphics.h>
+#import <AppKit/NSImage.h>
 
 // ========================================================================
 // wxBitmapRefData
@@ -145,6 +146,27 @@ WX_NSBitmapImageRep wxBitmap::GetNSBitmapImageRep()
     return M_BITMAPDATA->m_cocoaNSBitmapImageRep;
 }
 
+WX_NSImage wxBitmap::GetNSImage(bool useMask) const
+{
+    if(!Ok())
+        return nil;
+    NSImage *nsimage = [[[NSImage alloc]
+            initWithSize:NSMakeSize(GetWidth(), GetHeight())] autorelease];
+    if(!nsimage)
+        return nil;
+    [nsimage addRepresentation: M_BITMAPDATA->m_cocoaNSBitmapImageRep];
+    if(useMask && GetMask())
+    {
+        NSImage *maskImage = [[NSImage alloc]
+                initWithSize:NSMakeSize(GetWidth(), GetHeight())];
+        [maskImage addRepresentation: GetMask()->GetNSBitmapImageRep()];
+        [nsimage lockFocus];
+        [maskImage compositeToPoint:NSZeroPoint operation:NSCompositeDestinationIn];
+        [nsimage unlockFocus];
+    }
+    return nsimage;
+}
+
 void wxBitmap::SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep)
 {
     if(!M_BITMAPDATA)