Re: Drawing from lower left, why?
Re: Drawing from lower left, why?
- Subject: Re: Drawing from lower left, why?
- From: Ken Tozier <email@hidden>
- Date: Sun, 17 Jun 2007 15:05:22 -0400
On Jun 17, 2007, at 11:04 AM, Shawn Erickson wrote:
On Jun 15, 2007, at 5:06 PM, Ken Tozier wrote:
The save and restore graphics state is unneeded in the above.
The drawCells method uses transforms to scale page icons and I just
wanted to make sure that, upon exit, drawRect restored everything.
- (void) drawTitle
{
if (title != nil)
{
attrSize = [title size];
if (attrSize.width >= titleRect.size.width)
{
attrSize.width = titleRect.size.width - 20;
attrSize.height += psize.height;
}
attrSize.height = (attrSize.height > titleRect.size.height) ?
titleRect.size.height : attrSize.height ;
titleTextRect.origin.x = (titleRect.size.width -
attrSize.width) / 2;
titleTextRect.origin.y = titleRect.origin.y + attrSize.height / 9;
titleTextRect.size.width = attrSize.width;
titleTextRect.size.height = attrSize.height;
// draw text into context
[[NSColor redColor] set]; // <- for testing
NSRectFillUsingOperation(titleRect, NSCompositeSourceOver); //
<- for testing
[title drawInRect: titleTextRect];
}
}
The math in the avoid seems a little weird to me... like if one
width is large then the other then subtracting a fix value of 20, etc.
The math IS pretty squirrely but it's a "first pass" method and still
contains the "how do I make this work" code. I plan on cleaning it up.
Are you working in a flipped view?
Yes.
After spending the entire day yesterday tweaking variables, I
finally got it working. Still have an issue on scrollbar hide/show
where the entire document view shifts right/left by the width of the
vertical scrollbar. Although I'd like to fix this, its not a deal
breaker. Here's the corrected "rectForCell" method
#define TITLE_OFFSET 8
- (NSRect) rectForCell:(id) inCell
{
// NOTE: Move "vOffset" to the "updateGeometry" method. No need to
recalculate it for every cell
float vOffset = margin + titleRect.size.height + cellSize.height +
TITLE_OFFSET - cellLabelHeight;
int cellIndex = [cells indexOfObject: inCell],
row = cellIndex / cellsPerRow,
column = cellIndex - row * cellsPerRow, // NOTE: this doesn't
always equal zero because it's mod division
x = margin + column * cellWidth + horizontalSpacing * column,
y = vOffset + row * (cellHeight + verticalSpacing);
return NSMakeRect(x, y, cellWidth, cellHeight);
}
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden