]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxBitmap constructors and Create methods to allow creating a wxBitmap from an...
authorDavid Elliott <dfe@tgwbd.org>
Thu, 9 Aug 2007 19:05:51 +0000 (19:05 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 9 Aug 2007 19:05:51 +0000 (19:05 +0000)
Copyright 2007 Software 2000 Ltd.

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

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

index ca2b3b07759934b8bfb66c9f583af838c61ef175..e8693703e139d4d7b657dca8d7dfc57ab65d6340 100644 (file)
@@ -77,6 +77,10 @@ public:
     wxBitmap(const char* const* bits);
     // Load a file or resource
     wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
+    // Construct from Cocoa's NSImage
+    wxBitmap(NSImage* cocoaNSImage);
+    // Construct from Cocoa's NSBitmapImageRep
+    wxBitmap(NSBitmapImageRep* cocoaNSBitmapImageRep);
     // Constructor for generalised creation from data
     wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
     // If depth is omitted, will create a bitmap compatible with the display
@@ -98,6 +102,8 @@ public:
     bool CreateFromImage(const wxImage& image, int depth=-1);
 
     virtual bool Create(int width, int height, int depth = -1);
+    virtual bool Create(NSImage* cocoaNSImage);
+    virtual bool Create(NSBitmapImageRep* cocoaNSBitmapImageRep);
     virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
     virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
     virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
index d075f0a56d41d93dee9f227b4eca4a809c2e3995..cddc8c192f545a6c9c5e6903a1262b300e74c5ae 100644 (file)
@@ -125,6 +125,16 @@ wxBitmap::wxBitmap(int w, int h, int d)
     (void)Create(w, h, d);
 }
 
+wxBitmap::wxBitmap(NSImage* cocoaNSImage)
+{
+    (void) Create(cocoaNSImage);
+}
+
+wxBitmap::wxBitmap(NSBitmapImageRep* cocoaNSBitmapImageRep)
+{
+    (void) Create(cocoaNSBitmapImageRep);
+}
+
 wxBitmap::wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth)
 {
     (void) Create(data, type, width, height, depth);
@@ -348,6 +358,33 @@ bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
     return true;
 }
 
+bool wxBitmap::Create(NSImage* cocoaNSImage)
+{
+    wxAutoNSAutoreleasePool pool;
+    NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData:[cocoaNSImage TIFFRepresentation]];
+    return Create(bitmapImageRep);
+}
+
+bool wxBitmap::Create(NSBitmapImageRep *imageRep)
+{
+    UnRef();
+    m_refData = new wxBitmapRefData;
+    if(imageRep != nil)
+    {
+        M_BITMAPDATA->m_width = [imageRep pixelsWide];
+        M_BITMAPDATA->m_height = [imageRep pixelsHigh];
+        M_BITMAPDATA->m_depth = [imageRep bitsPerPixel];
+        M_BITMAPDATA->m_ok = true;
+        M_BITMAPDATA->m_numColors = 0;
+        M_BITMAPDATA->m_quality = 0;
+        M_BITMAPDATA->m_cocoaNSBitmapImageRep = [imageRep retain];
+        M_BITMAPDATA->m_bitmapMask = NULL;
+        return true;
+    }
+    else
+        return false;
+}
+
 bool wxBitmap::Create(const void* data, wxBitmapType type, int width, int height, int depth)
 {
     UnRef();