• 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
NSRectArray by reference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSRectArray by reference


  • Subject: NSRectArray by reference
  • From: Keith Duncan <email@hidden>
  • Date: Sun, 9 Sep 2007 18:45:45 +0100

I'm writing a function which given a content rect and the number of required rows will split it up and put the resultant rects into an NSRectArray provided by reference - once again my basic C lets me down.

I'm creating the array and calling the function -

NSRectArray rowRects = calloc(calendarInfo.totalRows, sizeof(NSRect));
CalendarRowRects(calendarRect, calendarInfo.totalRows, &rowRects);

The function in question -

NS_INLINE void CalendarRowRects(NSRect calendarRect, NSUInteger rows, NSRectArray *rowRects) {
CGFloat rowGapHeight = NSHeight(calendarRect)/50.0;
CGFloat rowHeight = (NSHeight(calendarRect) - ((rows - 1) * rowGapHeight)) / rows;
CGFloat delta = (rowHeight + rowGapHeight);

NSRect currentRowRect, remainder;
NSDivideRect(calendarRect, &currentRowRect, &remainder, rowHeight, NSMaxYEdge);

for (NSUInteger index = 0; index < rows; index++) {
(*rowRects[index]) = currentRowRect; // it crashes here (for reasons that are probably obvious to the reader), notably the most crucial line
currentRowRect.origin.y += delta;
}
}


Granted that letting the function assume there is a enough space in the provided array isn't a good design decision but this is a private internal function that is only going to be called in -drawRect and - mouseDown: so I can get away with it.

I could wrap the rects in NSValues and return an NSArray but I don't really want that overhead, I always try to avoid using Obj-C in my drawing code as possible.

- Keith
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: NSRectArray by reference
      • From: Brian Stern <email@hidden>
    • Re: NSRectArray by reference
      • From: Uli Kusterer <email@hidden>
    • Re: NSRectArray by reference
      • From: Uli Kusterer <email@hidden>
    • Re: NSRectArray by reference
      • From: Keith Duncan <email@hidden>
  • Prev by Date: Re: count of a to-many relationship in an NSPredicate
  • Next by Date: determine volume name for folder that does not exist
  • Previous by thread: Re: Cocoa with CodeWarrior?
  • Next by thread: Re: NSRectArray by reference
  • Index(es):
    • Date
    • Thread