Re: Graphics artifacts in NSMatrix
Re: Graphics artifacts in NSMatrix
- Subject: Re: Graphics artifacts in NSMatrix
- From: James DiPalma <email@hidden>
- Date: Mon, 12 Nov 2001 12:37:23 -0800
On Thursday, November 8, 2001, at 02:12 PM, Peter Ammon wrote:
I am trying to implement an NSMatrix of my custom cells. To highlight
the cells, I do something like this in the cell class:
This works very well, except when I select a new cell in the matrix, it
doesn't redraw the old selected cell, so that the old selected cell
continues to appear highlighted until I scroll it offscreen and back on.
I've seen highlighting artifacts while drawing cells when I was
programmatically selecting cells. NSMatrix seems to remember which cells
are selected/highlighted and use this information for which cells need
to be redrawn. If you are selecting your own cells, I suggest calling a
highlight method:
[self selectCell:cell];
[self getRow:&row column:&column ofCell:cell];
[self highlightCell:YES atRow:row column:column];
The reason I both select the cell and highlight the cell (besides that
it seems to work) is that NSMatrix during mouseDown: first calls
setState: on the cell and then calls through highlight:withFrame:inView:
(see stack traces below).
My only other suggestion is to make sure you are drawing as if the Cell
is opaque: white wash the cell before drawing. Apple's sample code for a
simple browser does this drawing; I use this code in drawInterior...:
if (YES) { // why is this cell not opaque? by default.
[[NSColor controlBackgroundColor] set];
NSRectFill(cellFrame);
}
if ([self isHighlighted]) {
[[self highlightColorWithFrame:cellFrame inView:controlView]
set];
NSRectFill(cellFrame);
}
On Thursday, November 8, 2001, at 02:12 PM, Peter Ammon wrote:
- (void)drawWithFrame:(NSRect)frame inView:(NSMatrix*)view {
BOOL isSelected=([[view selectedCells]
indexOfObjectIdenticalTo:self] != NSNotFound);
A selected cell has its state set to 1 (or maybe to YES), so isSelected
could be [self state], but also consider [self isHighlighted].
On Thursday, November 8, 2001, at 02:44 PM, Erik M. Buck wrote:
See http://www.stepwise.com/Articles/Technical/NSCell.html
Specifically you must implement
- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView
*)controlView
I'm not sure that implementing highlight:withFrame:inView: is going to
help. Erik's implementation on stepwise simply sets the highlight flag
and then calls drawInterior:
[self setCellAttribute:NSCellHighlighted to:flag];
[self drawInteriorWithFrame:cellFrame inView:controlView];
I checked what NSBrowserCell does to highlight a cell. It appears that
the appkit is calling drawWithFrame:inView: and not drawInterior. I
don't know why Erik's code (from 1998) isn't calling
drawWithFrame:inView. Here is the backtrace:
#0 -[FileBrowserCell drawInteriorWithFrame:inView:] ()
#1 0x70ccd460 in -[NSBrowserCell drawWithFrame:inView:] ()
#2 0x70ccd59c in -[NSBrowserCell highlight:withFrame:inView:] ()
#3 0x70d31e34 in -[NSMatrix _highlightCell:atRow:column:andDraw:] ()
#4 0x70d397a0 in -[NSMatrix highlightCell:atRow:column:] ()
#5 0x70d363a0 in -[NSMatrix _selectRange::::] ()
Also, how on earth does the NSMatrix keep track of the selected cells?
I've tried overriding selectCell: and selectCellAtRow: column:, but
neither get called when I click on a cell. Also, I can't see any ivars
in the NSMatrix that could store the selected cells (unless it's that
one opaque void*)
I have been trying to get NSMatrix to programmatically select multiple
cells and have been unable to figure out how (requests to this list for
information have not helped). From my notes:
Breaking on setState: when using an alt-click to select a second file
results in this backtrace:
#0 -[FileBrowserCell setState:]
#1 0x70d36384 in -[NSMatrix _selectRange::::] ()
#2 0x70d36594 in -[NSMatrix _selectRectRange::] ()
#3 0x70d3725c in -[NSMatrix _setSelectionRange::] ()
#4 0x70d34808 in -[NSMatrix _mouseLoop::::::] ()
#5 0x70d37410 in -[NSMatrix _shiftDown::::] ()
#6 0x70d332a4 in -[NSMatrix _mouseDownListmode:] ()
#7 0x70d3ae7c in -[NSMatrix mouseDown:] ()
None of these methods are public and there is no simple override to hook
into an NSMatrix mouse selection. I don't know how NSMatrix stores its
selection (nor how it stores which cells are highlighted).
-jim