Re: Dragging a group of Objects
Re: Dragging a group of Objects
- Subject: Re: Dragging a group of Objects
- From: Lorenzo <email@hidden>
- Date: Thu, 15 May 2003 17:28:52 +0200
Thank you.
I tried what you say but the result is the same.
I write here my code, so may be you can tell me where I do wrong.
The problem is that, even if I move one only object, the mouse pointer
seems to be faster than the objects. I move the mouse pointer and I see it
in a different position, then, some ticks later the objects come there.
It seems that the objects are connected to the mouse pointer through an
elastic cable... and anyway the object doesn't move fluently.
I click on an object in the NSView "MYView"
Then I quick pass the job to its parent view class "MYView"
// ---------------------------------------------------------
- (void)mouseDown:(NSEvent *)theEvent
{
[(MYView*)superView DragObjects:theEvent];
}
This routine is inside the parent view "MYView" of the object
It first quickly builds the array of all the selectedObjects,
then it goes into the drag-loop
// ---------------------------------------------------------
- (void)DragObjects:(NSEvent *)theEvent
{
NSPoint lastPoint, curPoint;
unsigned i, totSelectedObjects;
id theObject;
[self GroupSelection]; // this builds the selectedObjects array below
totSelectedObjects = [selectedObjects count];
lastPoint = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
BOOL isOnDragging = YES;
while (isOnDragging) {
theEvent = [[self window]
nextEventMatchingMask:(NSLeftMouseDraggedMask | NSLeftMouseUpMask)];
curPoint = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
switch([theEvent type]){
case NSLeftMouseUp:
isOnDragging = NO;
break;
default:
for (i = 0; i < totSelectedObjects; i++) {
theObject = [selectedObjects objectAtIndex:i];
[self setNeedsDisplayInRect:[theObject frame]];
[theObject setFrame:NSOffsetRect([theObject frame],
curPoint.x - lastPoint.x, curPoint.y - lastPoint.y)];
[self setNeedsDisplayInRect:[theObject frame]];
}
lastPoint = curPoint;
break;
}
}
[self UngroupSelection];
}
I tried also to put away the overriding method
-(void)drawRect:(NSRect)rect
from both the classes of the object and the view, but I got the same slow
result.
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.