Re: Drag button within bounds of superview.
Re: Drag button within bounds of superview.
- Subject: Re: Drag button within bounds of superview.
- From: Ken Tozier <email@hidden>
- Date: Thu, 5 Jul 2007 14:36:38 -0400
Actually, the set frame origin line should be this instead as the
deltaX will be correctly signed
[self setFrameOrigin: NSMakePoint(selfFrame.origin.x + [inEvent
deltaX], selfFrame.origin.y)];
On Jul 5, 2007, at 2:22 PM, Ken Tozier wrote:
Hi Elroy
In your case, you might be able to do something simpler than resort
to the full blown dragging mechanism. In your button subclass, you
could do something like this
- (void) mouseDragged:(NSEvent *) inEvent
{
NSRect selfFrame = [self frame];
[self setFrameOrigin: NSMakePoint(selfFrame.origin.x - [inEvent
deltaX], selfFrame.origin.y)];
[self setNeedsDisplay: YES];
}
HTH
Ken
On Jul 5, 2007, at 12:21 PM, Eloy Duran wrote:
Hello,
First off all a heads up: I'm new to custom view and drag & drop
programming, so sorry for any duh kind of questions :)
Also I'm doing this in rubycocoa so there are bound to be some errors
in my translation back to objective-c, but this code works and is
only
meant as a context reference.
I have a custom view, which is a bar, with multiple buttons aligned
horizontally and I would like a user to be able to reorder them.
I was able to start a drag operation of a button by implementing this
in the button class:
- (void)mouseDown:(NSEvent *)theEvent
{
// other code...
draggingPasteBoard = [NSPasteboard pasteboardWithName:NSDragPboard];
[self lockFocus];
bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self
bounds]];
[self unlockFocus];
image = [[NSImage alloc] initWithSize:[self bounds].size];
[image addRepresentation:bitmap];
[self dragImage:image,
at:NSMakePoint(NSMinX([self frame]), NSMaxY([self
frame])),
offset:NSZeroSize,
event:theEvent,
pasteboard:draggingPasteBoard,
source: self,
slideBack:YES];
}
But here's the catch, I want the image to only move horizontally
within the bounds of the superview of the button.
Just like the bookmark buttons in the bookmark bar of Safari do.
Does anybody know of some code or opensource app that implements this
kind of behaviour?
Or could somebody explain me which class I need to subclass to add
this drawing behaviour to? Is it NSImage, or is there some sort of
drag & drop controller object?
Thanks in advance!
Cheers,
Eloy
_______________________________________________
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:
40comcast.net
This email sent to email@hidden
_______________________________________________
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:
40comcast.net
This email sent to email@hidden
_______________________________________________
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