Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created January 7, 2012 13:05
Show Gist options
  • Save Dimillian/1574706 to your computer and use it in GitHub Desktop.
Save Dimillian/1574706 to your computer and use it in GitHub Desktop.
Drag and drop, first working attempt
-(void)moveToLocation:(NSPoint)location withInitialMousePosition:(NSPoint)position
{
isDragging = YES;
windowContentView = [[self window]contentView];
if (isDragging) {
//down
if (previousMousePosition.y > location.y) {
float current = position.y - location.y;
swapForce = round(current/drop_height);
if (swapForce != 0 && swapForce != previousSwapForce) {
[delegate swapDown:self];
}
}
//up
else{
float current = location.y - position.y;
swapForce = round(current/drop_height);
if (swapForce != 0 && swapForce != previousSwapForce) {
[delegate swapUp:self];
}
}
(location.x > 85) ? [self setHideAfterDragginOperation:YES] : [self setHideAfterDragginOperation:NO];
}
[self setFrameOrigin:NSMakePoint(location.x - mouse_in_icon, location.y-mouse_in_icon)];
[windowContentView addSubview:self];
previousSwapForce = swapForce;
previousMousePosition = location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment