Added bitmap drawing support
authorDavid Elliott <dfe@tgwbd.org>
Mon, 21 Jul 2003 00:29:04 +0000 (00:29 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Mon, 21 Jul 2003 00:29:04 +0000 (00:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22189 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/cocoa/dc.mm

index 4b6e74c6af453fdad50db96a1ca7e9d9e6fc1822..7f19fe770932b1b218957f4f3be1e215488d92f7 100644 (file)
@@ -22,6 +22,7 @@
 #import <AppKit/NSAffineTransform.h>
 #import <AppKit/NSColor.h>
 #import <AppKit/NSTypeSetter.h>
+#import <AppKit/NSImage.h>
 
 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
 wxDC *wxDC::sm_focusedDC = NULL;
@@ -257,7 +258,7 @@ wxCoord wxDC::GetCharWidth() const
 
 bool wxDC::CanDrawBitmap() const
 {
-    return false;
+    return true;
 }
 
 bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
@@ -308,6 +309,48 @@ void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
 
 void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
 {
+    if(!bmp.Ok())
+        return;
+
+#if 0
+    // Draw a rect so we can see where it's supposed to be
+    wxLogDebug("image at (%d,%d) size %dx%d",x,y,bmp.GetWidth(),bmp.GetHeight());
+    NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,bmp.GetWidth(),bmp.GetHeight())];
+    [[NSColor blackColor] set];
+    [bezpath stroke];
+    [[NSColor blueColor] set];
+    [bezpath fill];
+#endif // 0
+
+    NSAffineTransform *transform = [NSAffineTransform transform];
+    [transform translateXBy:x yBy:y];
+
+    NSAffineTransform *flipTransform = [NSAffineTransform transform];
+    /*  x' = 1x + 0y + 0
+        y' = 0x + -1y + window's height
+    */
+    NSAffineTransformStruct matrix = {
+        1,  0
+    ,   0, -1
+    ,   0, bmp.GetHeight()
+    };
+    [flipTransform setTransformStruct: matrix];
+
+    NSGraphicsContext *context = [NSGraphicsContext currentContext];
+    [context saveGraphicsState];
+    [transform concat];
+    [flipTransform concat];
+
+    NSImage *nsimage = [[NSImage alloc]
+            initWithSize:NSMakeSize(bmp.GetWidth(), bmp.GetHeight())];
+    [nsimage addRepresentation: const_cast<wxBitmap&>(bmp).GetNSBitmapImageRep()];
+    [nsimage drawAtPoint: NSMakePoint(0,0)
+        fromRect: NSMakeRect(0.0,0.0,bmp.GetWidth(),bmp.GetHeight())
+        operation: NSCompositeCopy
+        fraction: 1.0];
+        
+    [nsimage release];
+    [context restoreGraphicsState];
 }
 
 bool wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)