void IDrawer.DrawTangent(Vector3 position, Vector3 tangent) { m_Drawer.DrawTangent(position, tangent); }
public EditablePathView(IDrawer drawer) { m_Drawer = drawer; m_PointControl = new GenericControl("Point") { count = GetPointCount, distance = (guiState, i) => { var position = GetPoint(i).position; return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f)); }, position = (i) => { return(GetPoint(i).position); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = DrawPoint }; m_EdgeControl = new GenericControl("Edge") { onEndLayout = (guiState) => { controller.AddClosestPath(m_EdgeControl.layoutData.distance); }, count = GetEdgeCount, distance = DistanceToEdge, position = (i) => { return(GetPoint(i).position); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = DrawEdge }; m_LeftTangentControl = new GenericControl("LeftTangent") { count = () => { if (GetShapeType() != ShapeType.Spline) { return(0); } return(GetPointCount()); }, distance = (guiState, i) => { if (!IsSelected(i) || IsOpenEnded() && i == 0) { return(float.MaxValue); } var position = GetLeftTangent(i); return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f)); }, position = (i) => { return(GetLeftTangent(i)); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = (guiState, control, i) => { if (!IsSelected(i) || IsOpenEnded() && i == 0) { return; } var position = GetPoint(i).position; var leftTangent = GetLeftTangent(i); m_Drawer.DrawTangent(position, leftTangent); } }; m_RightTangentControl = new GenericControl("RightTangent") { count = () => { if (GetShapeType() != ShapeType.Spline) { return(0); } return(GetPointCount()); }, distance = (guiState, i) => { if (!IsSelected(i) || IsOpenEnded() && i == GetPointCount() - 1) { return(float.MaxValue); } var position = GetRightTangent(i); return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f)); }, position = (i) => { return(GetRightTangent(i)); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = (guiState, control, i) => { if (!IsSelected(i) || IsOpenEnded() && i == GetPointCount() - 1) { return; } var position = GetPoint(i).position; var rightTangent = GetRightTangent(i); m_Drawer.DrawTangent(position, rightTangent); } }; m_CreatePointAction = new CreatePointAction(m_PointControl, m_EdgeControl) { enable = (guiState, action) => { return(!guiState.isShiftDown && controller.closestEditablePath == controller.editablePath); }, enableRepaint = EnableCreatePointRepaint, repaintOnMouseMove = (guiState, action) => { return(true); }, guiToWorld = GUIToWorld, onCreatePoint = (index, position) => { controller.RegisterUndo("Create Point"); controller.CreatePoint(index, position); }, onPreRepaint = (guiState, action) => { if (GetPointCount() > 0) { var position = ClosestPointInEdge(guiState, guiState.mousePosition, m_EdgeControl.layoutData.index); m_Drawer.DrawCreatePointPreview(position); } } }; Action <IGUIState> removePoints = (guiState) => { controller.RegisterUndo("Remove Point"); controller.RemoveSelectedPoints(); guiState.changed = true; }; m_RemovePointAction1 = new CommandAction(kDeleteCommandName) { enable = (guiState, action) => { return(GetSelectedPointCount() > 0); }, onCommand = removePoints }; m_RemovePointAction2 = new CommandAction(kSoftDeleteCommandName) { enable = (guiState, action) => { return(GetSelectedPointCount() > 0); }, onCommand = removePoints }; m_MovePointAction = new SliderAction(m_PointControl) { onClick = (guiState, control) => { var index = control.layoutData.index; if (!guiState.isActionKeyDown && !IsSelected(index)) { controller.ClearSelection(); } controller.SelectPoint(index, true); guiState.changed = true; }, onSliderBegin = (guiState, control, position) => { controller.RegisterUndo("Move Point"); }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var delta = SnapIfNeeded(position) - GetPoint(index).position; controller.MoveSelectedPoints(delta); } }; m_MoveEdgeAction = new SliderAction(m_EdgeControl) { enable = (guiState, action) => { return(guiState.isShiftDown); }, onSliderBegin = (guiState, control, position) => { controller.RegisterUndo("Move Edge"); }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var delta = position - GetPoint(index).position; controller.MoveEdge(index, delta); } }; var cachedRightTangent = Vector3.zero; var cachedLeftTangent = Vector3.zero; m_MoveLeftTangentAction = new SliderAction(m_LeftTangentControl) { onSliderBegin = (guiState, control, position) => { controller.RegisterUndo("Move Tangent"); cachedRightTangent = GetPoint(control.hotLayoutData.index).rightTangent; }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var setToLinear = guiState.nearestControl == m_PointControl.ID && m_PointControl.layoutData.index == index; controller.SetLeftTangent(index, position, setToLinear, guiState.isShiftDown, cachedRightTangent); }, onSliderEnd = (guiState, control, position) => { controller.editablePath.UpdateTangentMode(control.hotLayoutData.index); guiState.changed = true; } }; m_MoveRightTangentAction = new SliderAction(m_RightTangentControl) { onSliderBegin = (guiState, control, position) => { controller.RegisterUndo("Move Tangent"); cachedLeftTangent = GetPoint(control.hotLayoutData.index).leftTangent; }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var setToLinear = guiState.nearestControl == m_PointControl.ID && m_PointControl.layoutData.index == index; controller.SetRightTangent(index, position, setToLinear, guiState.isShiftDown, cachedLeftTangent); }, onSliderEnd = (guiState, control, position) => { controller.editablePath.UpdateTangentMode(control.hotLayoutData.index); guiState.changed = true; } }; }