NSRectArray by reference
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, ¤tRowRect, &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