Where was the mouse clicked????
Where was the mouse clicked????
- Subject: Where was the mouse clicked????
- From: "Brian O'Brien" <email@hidden>
- Date: Mon, 25 Apr 2005 10:32:18 -0600
I've read this document but cannot figure out what I need to know and cant' find any other document or
posting that explains this simple concept.
http://developer.apple.com/documentation/Cocoa/Conceptual/BasicEventHandling/index.html
I get a mouseDown event in my NSImageView subclass, but the coordinates that it is giving me
seem to have nothing to do with the location I clicked on within the image...
The image being displayed is 256x256 pixels.
I've tried...
- (void)mouseDown:(NSEvent *)theEvent
{
NSRect theRect = [self frame];
float scalex = theRect.size.width / width;
float scaley = theRect.size.height / height;
NSLog(@"scalex = %f scaley = %f", scalex, scaley);
NSRect b = [self bounds];
NSLog(@"theEvent %@", theEvent);
NSLog(@"theRect %f %f %f %f", theRect.origin.x, theRect.origin.y, theRect.size.width, theRect.size.height);
NSLog(@"bounds are x=%f y=%f w=%f h=%f", b.origin.x, b.origin.y, b.size.width, b.size.height);
NSPoint p = [theEvent locationInWindow];
NSLog(@"The event was at %f, %f", p.x, p.y);
NSPoint p1 = [self convertPoint:p toView:Nil];
NSLog(@"xlat to %f, %f", p1.x, p1.y);
}
I click around the center of the image (which is 256x256) and get:
The log..
2005-04-25 10:27:20.435 knnGui[2694] scalex = 1.000000 scaley = 1.000000
2005-04-25 10:27:20.436 knnGui[2694] theEvent NSEvent: type=LMouseDown loc=(316,182) time=517017.8 flags=0 win=0 winNum=10088 ctxt=0x3202b evNum=5387 click=1 buttonNumber=0 pressure=1
2005-04-25 10:27:20.436 knnGui[2694] theRect 0.000000 0.000000 256.000000 256.000000
2005-04-25 10:27:20.436 knnGui[2694] bounds are x=0.000000 y=0.000000 w=256.000000 h=256.000000
2005-04-25 10:27:20.436 knnGui[2694] The event was at 316.000000, 182.000000
2005-04-25 10:27:20.436 knnGui[2694] xlat to 504.000000, 248.000000
What I'm looking for is the location the mouse was clicked relative to the frame or bounds...
Is there some scaling of the mouse location to the dpi of the image I'm displaying on the screen?
Should I be dividing by 72dpi or something like that?
I'm also thinking that the origin may be the top left or bottom left... I don't know yet.
_______________________________________________
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