Re: View hierarchy, documentation, and origin location.
Re: View hierarchy, documentation, and origin location.
- Subject: Re: View hierarchy, documentation, and origin location.
- From: "Gary L. Wade" <email@hidden>
- Date: Tue, 24 Sep 2013 10:26:25 -0700
The object you created has an inset of 40, and since NSMatrix organizes its cells from the top left, that is what you are seeing, regardless of whether or not NSMatrix returns YES for -isFlipped. If this is a matter of personal discovery, override -isFlipped in your class and have it return NO to see if it changes anything for your own satisfaction. If you must override NSMatrix for some extra drawing, use the value of -isFlipped to know whether top left or bottom left is the origin.
--
Gary L. Wade (Sent from my iPhone)
http://www.garywade.com/
On Sep 24, 2013, at 9:47 AM, Peter Teeson <email@hidden> wrote:
> Let me try again to clarify my lack of understanding.
> (0) I created a new Document project.
> All I did in IB Inspector pane was to make the window size 500, 500
> and Center Horizontally and Vertically
>
> (1) I added a sub-class of NSButtonCell with a class name of Class (it will be used as the prototype cell)
> (I understand about the convention of 3 char Class prefix but for this project I don't need it)
> All I did was add
> [self setEnabled:YES];
> [self setState:NSOffState];
> to it's init method
>
> (2) I added a sub-class of NSMatrix with a class name of Matrix.
> I overrode - (void)drawRect:(NSRect)dirtyRect
> and for now just added to it the statement [super drawRect:dirtyRect];
>
> (3) In Document.h I added @property Matrix *theMatrix
> In Document.m I added this code in method
> - (void)windowControllerDidLoadNib:(NSWindowController *)aController {
> [super windowControllerDidLoadNib:aController];
> // Get the initial content view size so as to
> // (a)compute where to place the matrix and
> // (b)what size to make the matrix cells
>
> // Local vars for this method
> NSWindow *theWindow = [aController window];
> NSView *theContentView = theWindow.contentView;
> NSRect frame =[theContentView frame];
> NSRect bounds = [theContentView bounds];
>
> NSRect theContentFrame = theContentView.frame;
> NSRect theMatrixFrame = NSInsetRect(theContentFrame, 40.0, 40.);
> Cell * protoCell = [Cell new];
>
> // Instance vars
> _theMatrix = [[Matrix alloc]initWithFrame:theMatrixFrame
> mode:NSListModeMatrix prototype:protoCell
> numberOfRows:3 numberOfColumns:3];
>
> [theContentView addSubview:_theMatrix];
> }
>
> (4) Running the code produces a window centred horizontally and vertically on the screen, as desired,
> but with the matrix drawn at the top left of the content view but with the origin inset by 40.0, 40.0 from the top left.
>
> Based on my reading of the docs I anticipated that it would be drawn at the bottom left with the origin inset by 40.0, 40.0 from the bottom left.
> Here are quotes from the View Programming Guide 2013-08-08
> "By default, the graphics environment origin (0.0,0.0) is located in the lower left,…." page 11
> "The frame rectangle defines the view's location and size in the superview using the superview’s coordinate system.
> The bounds rectangle defines the interior coordinate system that is used when drawing the contents of the view, including the origin and scaling." page 12
> "The content view acts as the root of the visible view hierarchy in a window." Page 17
>
> (5) The values of the frame and bounds rects are as follows:
> Document windowControllerDidLoadNib
> Frame 0 ,0, 500, 500; Bounds 0, 0, 500, 500
>
> Matrix drawRect:(NSRect)dirtyRect
> Frame 40, 40, 420, 420; Bounds 0, 0, 40, 40
>
> (6) So I must be missing something in my understanding of the documentation.
> My thinking is that since the window's contentView is a View and it's graphics environment origin is 0.0, 0.0 located in the lower left
> the matrix should have been drawn with a lower left origin.
>
> Why am I wrong?
>
> (In pre-OS X days QuickDraw origin was top left based if I recall correctly).
>
>
> _______________________________________________
>
> 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
_______________________________________________
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
References: | |
| >View hierarchy, documentation, and origin location. (From: Peter Teeson <email@hidden>) |
| >Re: View hierarchy, documentation, and origin location. (From: Kyle Sluder <email@hidden>) |
| >Re: View hierarchy, documentation, and origin location. (From: Peter Teeson <email@hidden>) |
| >Re: View hierarchy, documentation, and origin location. (From: Kyle Sluder <email@hidden>) |
| >Re: View hierarchy, documentation, and origin location. (From: Peter Teeson <email@hidden>) |