From: David Elliott Date: Mon, 21 Jul 2003 00:29:04 +0000 (+0000) Subject: Added bitmap drawing support X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1fd17880910977bc7fcea3ce14bea0db0b2416e6?ds=inline Added bitmap drawing support git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22189 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index 4b6e74c6af..7f19fe7709 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -22,6 +22,7 @@ #import #import #import +#import 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(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)