PDA

View Full Version : Setting a window's origin to the current mouse coordinates




Spike099
Feb 12, 2008, 10:46 PM
I am programming in Cocoa. When the window opens, I would like the window's origin to move to where the mouse is.

This is basically the exact same implementation as connecting outlets in Interface Builder.

I already have a IBAction function that is called to open a window, I just need to find the cursor's coordinates.

- (IBAction)open:(id)sender {
[self makeKeyAndOrderFront:self];
if (!isOpen) {
if (windowSetsOriginToMouseOnOpen) {
[self setFrameOrigin:*];
}

if (windowFades)
[[self animator] setAlphaValue:1.0];
else
[self setAlphaValue:1.0];
isOpen = YES;
}
}

So, where the * is, I need to input the mouse coordinates.

Is this how I should tackle this problem?

Thanks for your help guys.



kainjow
Feb 12, 2008, 11:16 PM
You should be able to use

[NSEvent mouseLocation]

Although I haven't tested it.

Spike099
Feb 13, 2008, 10:30 AM
Worked like a charm, thank you kainjow.