Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Spike099

macrumors regular
Original poster
Feb 18, 2007
143
0
Canada
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.

Code:
- (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

Moderator emeritus
Jun 15, 2000
7,958
7
You should be able to use

Code:
[NSEvent mouseLocation]

Although I haven't tested it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.