Changeset 277

Show
Ignore:
Timestamp:
10/28/08 17:30:09 (2 months ago)
Author:
tal
Message:
Several improvements:
- Cells are only drawn if they are visible.
- Added a preloadGlyphCellImages methods.
- Fixed a click bug on the first cell in the view.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • packages/defconAppKit/trunk/Lib/defconAppKit/views/glyphCellView.py

    r268 r277  
    114114        self._glyphDetailOnMouseMoved = False 
    115115 
     116        self._windowIsClosed = False 
     117 
    116118        return self 
    117119 
     
    122124    def setAllowsDrag_(self, value): 
    123125        self._allowDrag = value 
     126 
     127    def preloadGlyphCellImages(self): 
     128        representationName = self._cellRepresentationName 
     129        representationArguments = self._cellRepresentationArguments 
     130        cellWidth = self._cellWidth 
     131        cellHeight = self._cellHeight 
     132        for glyph in self._glyphs: 
     133            glyph.getRepresentation(representationName, width=cellWidth, height=cellHeight, **representationArguments) 
    124134 
    125135    def setGlyphs_(self, glyphs): 
     
    221231 
    222232    def windowCloseNotification_(self, notification): 
     233        self._windowIsClosed = True 
    223234        if self._glyphDetailWindow is not None: 
    224235            if self._glyphDetailWindow.getNSWindow() is not None: 
     
    272283        self._indexToClickRects = {} 
    273284 
     285        visibleRect = self.visibleRect() 
     286 
    274287        NSColor.whiteColor().set() 
    275288        for index, glyph in enumerate(self._glyphs): 
     
    282295            self._indexToClickRects[index] = rect 
    283296 
    284             image = glyph.getRepresentation(representationName, width=cellWidth, height=cellHeight, **representationArguments) 
    285             image.drawAtPoint_fromRect_operation_fraction_( 
    286                 (left, t), ((0, 0), (cellWidth, cellHeight)), NSCompositeSourceOver, 1.0 
    287                 ) 
    288  
    289             if index in self._selection: 
    290                 selectionColor.set() 
    291                 r = ((left+1, t+1), (cellWidth-3, cellHeight-3)) 
    292                 NSRectFillUsingOperation(r, NSCompositePlusDarker) 
    293                 NSColor.whiteColor().set() 
     297            if NSIntersectsRect(visibleRect, rect): 
     298                image = glyph.getRepresentation(representationName, width=cellWidth, height=cellHeight, **representationArguments) 
     299                image.drawAtPoint_fromRect_operation_fraction_( 
     300                    (left, t), ((0, 0), (cellWidth, cellHeight)), NSCompositeSourceOver, 1.0 
     301                    ) 
     302 
     303                if index in self._selection: 
     304                    selectionColor.set() 
     305                    r = ((left+1, t+1), (cellWidth-3, cellHeight-3)) 
     306                    NSRectFillUsingOperation(r, NSCompositePlusDarker) 
     307                    NSColor.whiteColor().set() 
    294308 
    295309            left += cellWidth 
     
    299313 
    300314        path = NSBezierPath.bezierPath() 
    301         for i in xrange(1, self._rowCount): 
     315        for i in xrange(1, self._rowCount+1): 
    302316            top = (i * cellHeight) - .5 
    303317            path.moveToPoint_((0, top)) 
    304318            path.lineToPoint_((width, top)) 
    305         for i in xrange(1, self._columnCount): 
     319        for i in xrange(1, self._columnCount+1): 
    306320            left = (i * cellWidth) - .5 
    307321            path.moveToPoint_((left, 0)) 
     
    383397    def _handleDetailWindow(self, event, found, mouseDown=False, mouseMoved=False, mouseDragged=False, mouseUp=False, inDragAndDrop=False): 
    384398        # no window 
     399        if self._windowIsClosed: 
     400            return 
    385401        if self._glyphDetailWindow is None: 
    386402            return