+ // Get the world position of the active layer
+ const Vector3 parentWorldPosition = mActiveLayer.GetCurrentWorldPosition();
+
+ // Get the size of the UI control.
+ Vector2 targetSize;
+ mController.GetTargetSize( targetSize );
+
+ // The grab handle position in world coords.
+ position.x = parentWorldPosition.x - 0.5f * targetSize.width + handle.position.x;
+ position.y = parentWorldPosition.y - 0.5f * targetSize.height + handle.position.y + handle.lineHeight;
+ }
+
+ void SetGrabHandlePosition()
+ {
+ // Reference to the grab handle.
+ HandleImpl& grabHandle = mHandle[GRAB_HANDLE];
+
+ // The grab handle position in world coords.
+ Vector2 grabHandleWorldPosition;
+ CalculateHandleWorldCoordinates( grabHandle, grabHandleWorldPosition );
+
+ // Check if the grab handle exceeds the boundaries of the decoration box.
+ // At the moment only the height is checked for the grab handle.
+ grabHandle.verticallyFlipped = ( grabHandleWorldPosition.y + grabHandle.size.height > mBoundingBox.w );
+
+ // The grab handle 'y' position in local coords.
+ // If the grab handle exceeds the bottom of the decoration box,
+ // set the 'y' position to the top of the line.
+ // The SetGrabHandleImage() method will change the orientation.
+ const float yLocalPosition = grabHandle.verticallyFlipped ? grabHandle.position.y : grabHandle.position.y + grabHandle.lineHeight;
+
+ grabHandle.actor.SetPosition( grabHandle.position.x - floor( 0.5f * mCursorWidth ),
+ yLocalPosition ); // TODO : Fix for multiline.
+ }
+
+ void SetSelectionHandlePosition( HandleType type )
+ {
+ const bool isPrimaryHandle = LEFT_SELECTION_HANDLE == type;
+
+ // Reference to the selection handle.
+ HandleImpl& handle = mHandle[type];
+
+ // Get the world coordinates of the handle position.
+ Vector2 handleWorldPosition;
+ CalculateHandleWorldCoordinates( handle, handleWorldPosition );
+
+ // Whether to flip the handle.
+ bool flipHandle = isPrimaryHandle ? mFlipLeftSelectionHandleDirection : mFlipRightSelectionHandleDirection;
+
+ // Whether to flip the handles if they are crossed.
+ bool crossFlip = false;
+ if( mFlipSelectionHandlesOnCross || !mHandlePanning )
+ {
+ crossFlip = mHandleCurrentCrossed;
+ }
+
+ // Does not flip if both conditions are true (double flip)
+ flipHandle = flipHandle != ( crossFlip || mHandlePreviousCrossed );
+
+ // Check if the selection handle exceeds the boundaries of the decoration box.
+ const bool exceedsLeftEdge = ( isPrimaryHandle ? !flipHandle : flipHandle ) && ( handleWorldPosition.x - handle.size.width < mBoundingBox.x );
+
+ const bool exceedsRightEdge = ( isPrimaryHandle ? flipHandle : !flipHandle ) && ( handleWorldPosition.x + handle.size.width > mBoundingBox.z );
+
+ // Does not flip if both conditions are true (double flip)
+ flipHandle = flipHandle != ( exceedsLeftEdge || exceedsRightEdge );
+
+ if( flipHandle )
+ {
+ if( !handle.horizontallyFlipped )
+ {
+ // Change the anchor point to flip the image.
+ handle.actor.SetAnchorPoint( isPrimaryHandle ? AnchorPoint::TOP_LEFT : AnchorPoint::TOP_RIGHT );
+
+ handle.horizontallyFlipped = true;
+ }
+ }
+ else