• 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
Point Conversion Between Coordinate Spaces. Working with NSControl and NSCell. Quick Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Point Conversion Between Coordinate Spaces. Working with NSControl and NSCell. Quick Question


  • Subject: Point Conversion Between Coordinate Spaces. Working with NSControl and NSCell. Quick Question
  • From: aaron smith <email@hidden>
  • Date: Tue, 11 May 2010 21:51:03 -0700

Heyo, quick question.

I've got an NSControl and NSCell, and am doing some logic with testing
if the mouse is down, and making sure the event location is within the
bounds of the cell's control view.

I've tried quite a bit of different ways of getting the event point
converted to the control view. Would you mid telling me if there's
something painfully obvious with this code?

Here's a snippet of code extracted from the cell:

- (void) drawBezelWithFrame:(NSRect) frame inView:(NSView *) controlView {
	NSEvent * currentEvent = [NSApp currentEvent];

	BOOL isMouseUp = true;
	BOOL isLeftMouseDown = ([currentEvent type] == NSLeftMouseDown);

	if(isLeftMouseDown) {
		isMouseUp = false;
		NSPoint localPoint;
		BOOL coordsAreScreen = ([currentEvent window]==nil);
		NSPoint windowPoint = [currentEvent locationInWindow];
		if(coordsAreScreen) {
			NSLog(@"coords are screen");
			windowPoint = [[[self controlView] window] convertScreenToBase:windowPoint];
		}
		if(windowPoint.x < 0 || windowPoint.y < 0) {
			isLeftMouseDown = false;
			isMouseUp = true;
		} else {
                        //this block is where I can't get "localPoint"
to correctly convert.

                        NSLog(@"windowPoint:
%@",GDPrintGetPrintedNSPoint(windowPoint));

			localPoint = [[self controlView] convertPoint:windowPoint toView:nil];
			NSLog(@"localPoint: %@",GDPrintGetPrintedNSPoint(localPoint));

			localPoint = [[[[self controlView] window] contentView]
convertPoint:windowPoint fromView:[self controlView]];
			NSLog(@"localPoint2: %@",GDPrintGetPrintedNSPoint(localPoint));

			localPoint = [[self controlView] convertPoint:windowPoint
fromView:[self controlView]];
			NSLog(@"localPoint3: %@",GDPrintGetPrintedNSPoint(localPoint));

			NSLog(@"is in rect: %i",NSPointInRect(localPoint,frame));
			NSLog(@"frame: %@",GDPrintGetPrintedNSRect(frame));
			if(!NSPointInRect(localPoint,frame)) isLeftMouseDown = false;
		}
	}
}

I also threw this up on pastebin if you want some color:
http://pastebin.com/ZyTju8UY

To me the first "localPoint = ..." should be the correct way to
convert the windowPoint to the control views' coordinate space. But
it's never right.

Any ideas?
Thanks!
_______________________________________________

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: Point Conversion Between Coordinate Spaces. Working with NSControl and NSCell. Quick Question
      • From: Graham Cox <email@hidden>
  • Prev by Date: Core Data NSExpression Error
  • Next by Date: Re: Point Conversion Between Coordinate Spaces. Working with NSControl and NSCell. Quick Question
  • Previous by thread: Re: Core Data NSExpression Error
  • Next by thread: Re: Point Conversion Between Coordinate Spaces. Working with NSControl and NSCell. Quick Question
  • Index(es):
    • Date
    • Thread