• 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 12:19:06 -0500


On Apr 26, 2006, at 11:56 AM, James Bucanek wrote:

With the generous help of Ricky Sharp and others, I now have a spiffy semi-transparent floating child window that hovers over my NSTableView. The implementation went pretty smoothly, save for one mystery that I'm hoping someone here can explain to me -- or explain what I'm doing wrong.

I need my child window (which exists in screen coordinates) to be placed exactly over the frame of the table view. To accomplish this transformation, I wrote the following:

+ (NSRect)screenRectEquivelentOfView:(NSView*)view
{
    NSWindow*   viewWindow = [view window];
    NSView*     contentView = [viewWindow contentView];

NSRect frame = [view frame];
frame.origin.y += frame.size.height; // why is this needed?
frame.origin = [[view superview] convertPoint:frame.origin toView:contentView];
frame.origin = [viewWindow convertBaseToScreen:frame.origin];
return (frame);
}


The problem is that the frame returned by [view frame] has an origin of {0.0,0.0}. I assume this is because the NSScrollView its imbedded in uses flipped coordinates.

While I have a feeble grasp of flipped coordinate systems, what I can't figure out is this: Shouldn't convertPoint:toView: take flipped coordinate systems into account and convert the flipped coordinates of [view superview] and correctly translate it into the non-flipped coordinates of [viewWindow contentView]?

Ignoring the "flippedness" of coordinate systems seems like a gross bug in convertPoint:toView:. Which, naturally, leads me to believe that I've written this wrong but I can't for the life of me figure out what I've missed.


You've got a hodge podge of different views and coordinates (and make assumptions about what things are flipped and what aren't - especially since the windows content view isn't guaranteed to be the same thing as the window "base").

I'd also make it an instance method of the view itself (entirely typed in mail, so bound to have at least one problem):

- (NSRect) screenRectEquivalent
{
NSRect bounds = [view bounds]; // start with our bounds in our coordinate system
bounds = [self convertRect: bounds toView: nil]; // bounds is now in the windows base coordinate system
bounds.origin = [[self window] convertBaseToScreen: bounds.origin]; // now convert the origin to screen coordinates
return bounds; // done
}






Glenn Andreas                      email@hidden
 <http://www.gandreas.com/> wicked fun!
Dominogy | Just place all the dominos on the board...

_______________________________________________
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: 
 >Flipping over coordinate conversion (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: FYI: Cocoa's framework scaling works great!
  • Next by Date: Re: NSError: why returned directly?
  • Previous by thread: Flipping over coordinate conversion
  • Next by thread: Re: Flipping over coordinate conversion
  • Index(es):
    • Date
    • Thread