• 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: Flipping over coordinate conversion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Flipping over coordinate conversion


  • Subject: Re: Flipping over coordinate conversion
  • From: glenn andreas <email@hidden>
  • Date: Wed, 26 Apr 2006 13:18:01 -0500


On Apr 26, 2006, at 1:01 PM, James Bucanek wrote:


- (NSRect) screenRectEquivalent { NSRect bounds = [view bounds]; // start with our bounds in our coordinate system

I need to get the frame of the view, not its bounds. When a view is in a scroll view its bounds is often larger than its frame (the portion we're going to see in the scroll view). So my code gets the frame of the view and translates it using the coordinate system of its superview.




Then what you want isn't the frame (i.e., it's coordinates in the superclass view space) so much as the visibleRect of the view.

It basically boils down to if you are thinking "what is the screen coordinates of the visible part of me" vs "what is the screen coordinates of where my parent has me located". Note that the only case where you'll probably see a clear difference is if your view is hidden (in which case, the visibleRect is NSZeroRect, even though you still have a location within your parent).

(I'm always forgetting which is which on "frame" vs "bounds", since those words are used almost interchangeably in various frameworks).


And now that I've had time to step away from the problem and think about it again, I realize that it's entirely my mistake. The problem was in using the origin of the view's frame, rather than the entire frame rectangle. The origin will always be {0,0} whether it's the bottom/left corner and the rectangle extends up, or it's the top/left corner and the rectangle extends down. By trying to translate just the origin of the view's rectangle instead of the rectangle itself, I threw away the direction of the rectangle. (I think I was thrown by the fact that there is no rectangle flavor of -[NSWindow convertBaseToScreen:] so I focused on converting the origin point throughout. So I'm guessing that there is no such thing as a "flipped" base coordinate system.)


Exactly - an NSWindow has "base coordinates", and NSScreen has "global screen" coordinates, and neither can be flipped - only NSView, so once you convert away from NSView's coordinate space you no longer deal with "flipped".



Glenn Andreas                      email@hidden
 <http://www.gandreas.com/> wicked fun!
quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Flipping over coordinate conversion
      • From: James Bucanek <email@hidden>
References: 
 >Re: Flipping over coordinate conversion (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: how do I put ints in for NSUserDefaults for keys?
  • Next by Date: Re: NSError: why returned directly?
  • Previous by thread: Re: Flipping over coordinate conversion
  • Next by thread: Re: Flipping over coordinate conversion
  • Index(es):
    • Date
    • Thread