[Pyobjc-dev] Bridging NSRectFillList()
Brought to you by:
ronaldoussoren
From: Bill B. <bb...@co...> - 2003-01-11 16:44:12
|
I added bridge code for NSRectFillList() in _AppKit.m. For example.... def drawRect_(self, aRect): if self.backingStore: self.backingStore.draw() else: self.eraseView_(aRect) for pointArray, rectCount, color in self.pointsCountsAndColors: color.set() NSRectFillList(pointArray, rectCount) self.pointsCountsAndColors = [] self.backingStore = NSBitmapImageRep.alloc().initWithFocusedViewRect_(self.bounds()) ... where pointArray was created as .... pointsArray = array.array('f', [0.0,0.0,1.0,1.0] * len(points)) rectCount = 0 for p in points: x = int(round(p[0])) y = int(round(p[1])) if (x >= 0) and (x < pixelsWide) and (y >= 0) and (y < pixelsHigh): pointsArray[ (rectCount * 4) ] = x pointsArray[ (rectCount * 4) + 1 ] = y rectCount += 1 self.pointsCountsAndColors.append((pointsArray, rectCount, aColor)) ... the rectCount argument is optional. In this case, I preallocate the array to the maximum number of points and then count only the points that fall within the bounds of the view. In any case, this pattern of bridging is very, very fast and the addition to _AppKit.m is quite straightforward. b.bum |