• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Moderator] Drawing from lower left, why?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Moderator] Drawing from lower left, why?


  • Subject: Re: [Moderator] Drawing from lower left, why?
  • From: Shawn Erickson <email@hidden>
  • Date: Sun, 17 Jun 2007 08:04:56 -0700


On Jun 15, 2007, at 5:06 PM, Ken Tozier wrote:


On Jun 15, 2007, at 7:36 PM, cocoa-dev-admins wrote:

Please stay on topic.


Coordinate system "design" is not specific to Cocoa.

If you are having issues that are directly relevant to Cocoa application development, then please describe the problems and solicit solutions. Posting a rant is not constructive and makes it more difficult for others to identify your problem and offer solutions.

Per the List Guidelines:

When you ask a question, whenever possible please:

1. Describe what your high-level goal is

High level, I wrote a custom matrix class with dynamically resizable page thumbnail cells (similar to iPhoto's thumbnail view) The matrix has an optional title which classifies what types of pages a user is looking at (unstarted with ads, started, sent to prepress etc). The cells draw from the upper left and flow down the page wrapping to another line the same way text in a text view does.


2. Include any relevant code

Here are the cell origin calculation/drawing methods. I'm not entirely sure which part or parts are interacting to produce the vertical placement errors but I suspect one major part is in the "y" calculation of the "rectForCell" method.


- (BOOL) isFlipped
{
	return YES;
}

- (void) drawRect:(NSRect) rect
{
	NSGraphicsContext		*context		= [NSGraphicsContext currentContext];
	[context saveGraphicsState];

	[[NSColor greenColor] set];
	NSRectFillUsingOperation(rect, NSCompositeSourceOver);

	titleRect.size.width = rect.size.width;

	if (title != nil)
		[self drawTitle];

	[self drawCells];

	[context restoreGraphicsState];
}

The save and restore graphics state is unneeded in the above.

- (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.


// This method Calculates the rectangle for a given cell
- (NSRect) rectForCell:(id) inCell
{
float vOffset = titleRect.origin.y + titleRect.size.height + verticalSpacing; // <- adding this to y kicks it too far below the title bar

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,


// Next line is where I suspect the main problem is
// This places the cells in the right place but I think it's just a luck coincidence because
// it doesn't account for the depth of the title. I add 1 to "row" index because otherwise
// cellHeight * (row + 1) would be zero for the entire top row of cells. What I want is to rework
// this calculation so I don't need to do the (row + 1) and account for the title depth
y = cellHeight * (row + 1) + verticalSpacing;


	return NSMakeRect(x, y, cellWidth, cellHeight);
}

Are you working in a flipped view?

-Shawn
_______________________________________________

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


  • Follow-Ups:
    • Re: Drawing from lower left, why?
      • From: Ken Tozier <email@hidden>
References: 
 >Drawing from lower left, why? (From: Ken Tozier <email@hidden>)
 >[Moderator] Drawing from lower left, why? (From: cocoa-dev-admins <email@hidden>)
 >Re: [Moderator] Drawing from lower left, why? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Resolution-independent toolbar icons
  • Next by Date: Exporting tables or tabular data
  • Previous by thread: Re: [Moderator] Drawing from lower left, why?
  • Next by thread: Re: Drawing from lower left, why?
  • Index(es):
    • Date
    • Thread