def makeCairoSurface( self ): if not self._surface: self._imageRep = sendMsg( AppKit.NSBitmapImageRep.alloc(), "initWithBitmapDataPlanes:", None, "pixelsWide:", self.__maxWidth, "pixelsHigh:", self.__maxHeight, "bitsPerSample:", 8, "samplesPerPixel:", 4, "hasAlpha:", True, "isPlanar:", False, "colorSpaceName:", AppKit.NSCalibratedRGBColorSpace, "bitmapFormat:", 0, "bytesPerRow:", 4 * self.__maxWidth, "bitsPerPixel:", 32 ) # This NSGraphicsContext retains the NSBitmapImageRep we # pass it, but for some reason it doesn't release it on # destruction... See this class' __del__() method for how # we deal with this. nsContext = sendMsg( AppKit.NSGraphicsContext, "graphicsContextWithBitmapImageRep:", self._imageRep ) self._surface = cairo_surface_from_NSGraphicsContext( nsContext, self.__maxWidth, self.__maxHeight ) return self._surface
def drawRect_( self, rect ): parent = self.__parent() if not parent: return surface = parent._surface if not surface: return # Taken from the OS X Cocoa Drawing Guide section on # "Creating a Flip Transform". frameRect = self.bounds() xform = AppKit.NSAffineTransform.transform() xform.translateXBy_yBy_(0.0, frameRect.size.height) xform.scaleXBy_yBy_(1.0, -1.0) xform.concat() context = AppKit.NSGraphicsContext.graphicsContextWithBitmapImageRep_(parent._imageRep) surface = cairo_surface_from_NSGraphicsContext(context, parent.getMaxWidth(), parent.getMaxHeight()) ctx=cairo.Context(surface) ctx.set_source_surface(parent._surface) ctx.paint() surface.finish() parent._imageRep.draw()
def drawRect_(self, rect): parent = self.__parent() if not parent: return surface = parent._surface if not surface: return # Taken from the OS X Cocoa Drawing Guide section on # "Creating a Flip Transform". frameRect = self.bounds() xform = AppKit.NSAffineTransform.transform() xform.translateXBy_yBy_(0.0, frameRect.size.height) xform.scaleXBy_yBy_(1.0, -1.0) xform.concat() context = AppKit.NSGraphicsContext.graphicsContextWithBitmapImageRep_( parent._imageRep) surface = cairo_surface_from_NSGraphicsContext(context, parent.getMaxWidth(), parent.getMaxHeight()) ctx = cairo.Context(surface) ctx.set_source_surface(parent._surface) ctx.paint() surface.finish() parent._imageRep.draw()