Skip to content

Commit

Permalink
Anchor points can now be dragged
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Lidholt committed Aug 29, 2012
1 parent b7fd9c7 commit 77d2d6b
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions CocosBuilder/ccBuilder/CocosScene.m
Expand Up @@ -491,6 +491,8 @@ - (int) transformHandleUnderPt:(CGPoint)pt
{
for (CCNode* node in appDelegate.selectedNodes)
{
transformScalingNode = node;

CGPoint center = [node.parent convertToWorldSpace: node.position];
if (ccpDistance(pt, center) < kCCBAnchorPointRadius) return kCCBTransformHandleAnchorPoint;

Expand All @@ -501,7 +503,6 @@ - (int) transformHandleUnderPt:(CGPoint)pt
CGPoint t = ccpAdd(center, ccp(0, kCCBSinglePointSelectionRadius));
CGPoint b = ccpAdd(center, ccp(0, -kCCBSinglePointSelectionRadius));

transformScalingNode = node;
if (ccpDistance(pt, l) < kCCBTransformHandleRadius) return kCCBTransformHandleScale;
if (ccpDistance(pt, r) < kCCBTransformHandleRadius) return kCCBTransformHandleScale;
if (ccpDistance(pt, t) < kCCBTransformHandleRadius) return kCCBTransformHandleScale;
Expand Down Expand Up @@ -603,11 +604,18 @@ - (BOOL) ccMouseDown:(NSEvent *)event

// Transform handles
int th = [self transformHandleUnderPt:pos];
BOOL transformedNodeZeroSize = (transformScalingNode.contentSize.width == 0 || transformScalingNode.contentSize.height == 0);

if (th == kCCBTransformHandleAnchorPoint && !transformedNodeZeroSize)
if (th == kCCBTransformHandleAnchorPoint)
{
// Move anchor point
// Anchor points are fixed for singel point nodes
if (transformScalingNode.contentSize.width == 0 || transformScalingNode.contentSize.height == 0)
{
return YES;
}

// Transform anchor point
currentMouseTransform = kCCBTransformHandleAnchorPoint;
transformScalingNode.transformStartPosition = transformScalingNode.anchorPoint;
return YES;
}
if (th == kCCBTransformHandleScale && appDelegate.selectedNode != rootNode)
Expand Down Expand Up @@ -708,11 +716,6 @@ - (BOOL) ccMouseDragged:(NSEvent *)event
selectedNode.transformStartPosition = [selectedNode.parent convertToWorldSpace:pos];
}

for (CCNode* selectedNode in appDelegate.selectedNodes)
{
NSLog(@"transformStartPosition: (%f,%f)",selectedNode.transformStartPosition.x, selectedNode.transformStartPosition.y);
}

if (appDelegate.selectedNode != rootNode)
{
currentMouseTransform = kCCBTransformHandleMove;
Expand Down Expand Up @@ -805,8 +808,6 @@ - (BOOL) ccMouseDragged:(NSEvent *)event


CGPoint newLocalPos = [selectedNode.parent convertToNodeSpace:newPos];

NSLog(@"newLocalPos: (%f,%f)", newLocalPos.x, newLocalPos.y);

[appDelegate saveUndoStateWillChangeProperty:@"position"];

Expand Down Expand Up @@ -893,6 +894,16 @@ - (BOOL) ccMouseDragged:(NSEvent *)event
transformScalingNode.rotation = newRotation;
[appDelegate refreshProperty:@"rotation"];
}
else if (currentMouseTransform == kCCBTransformHandleAnchorPoint)
{
CGPoint localPos = [transformScalingNode convertToNodeSpace:pos];
CGPoint localDownPos = [transformScalingNode convertToNodeSpace:mouseDownPos];

CGPoint deltaLocal = ccpSub(localPos, localDownPos);
CGPoint deltaAnchorPoint = ccp(deltaLocal.x / transformScalingNode.contentSize.width, deltaLocal.y / transformScalingNode.contentSize.height);

transformScalingNode.anchorPoint = ccpAdd(transformScalingNode.transformStartPosition, deltaAnchorPoint);
}
else if (isPanning)
{
CGPoint delta = ccpSub(pos, mouseDownPos);
Expand Down

0 comments on commit 77d2d6b

Please sign in to comment.