/// <summary> /// 获取当前鼠标位于屏幕的位置 /// </summary> /// <returns></returns> public static Point GetMouseScreenLocation() { var p = new TempPoint(); if (GetCursorPos(out p)) { return(ConvertToPoint(p)); } return(new Point(0, 0)); }
protected override void MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (TempPoint != null) { TempPoint.MoveTo(Coordinates(e)); TempPoint.RecalculateAllDependents(); } Drawing.RaiseConstructionFeedback(new Drawing.ConstructionFeedbackEventArgs() { FigureTypeNeeded = ExpectedDependency, IsMouseButtonDown = IsMouseButtonDown }); }
private void MouseMove(Point pt) { Point logPt = ToLogical(pt); if (TempPoint != null) { TempPoint.MoveTo(logPt); TempPoint.RecalculateAllDependents(); } Drawing.RaiseConstructionFeedback(new Drawing.ConstructionFeedbackEventArgs() { FigureTypeNeeded = ExpectedDependency, IsMouseButtonDown = IsMouseButtonDown }); }
/// <summary> /// Assumes coordinates are logical already /// </summary> /// <param name="coordinates">Logical coordinates of the click point</param> protected virtual void Click(System.Windows.Point coordinates) { IFigure underMouse = null; Type expectedType = ExpectedDependency; if (TempPoint != null) { underMouse = Drawing.Figures.HitTest( coordinates, typeof(IPoint)); } else if (expectedType != null) { underMouse = Drawing.Figures.HitTest(coordinates, expectedType); } else { underMouse = Drawing.Figures.HitTest(coordinates); } if (underMouse != null && underMouse != TempPoint && ((FoundDependencies.Contains(underMouse) && !CanReuseDependency()) || underMouse == TempResult)) { return; } if (ExpectingAPoint()) { if (underMouse == null) { underMouse = CreatePointAtCurrentPosition(coordinates, true); } } RemoveIntermediateFigureIfNecessary(); if (TempPoint != null) { if (underMouse == TempPoint || underMouse == TempResult || underMouse == null) { underMouse = CreatePointAtCurrentPosition(coordinates, true); } TempPoint.SubstituteWith(underMouse); FoundDependencies.Remove(TempPoint); Drawing.Figures.Remove(TempPoint); TempPoint = null; } if (ExpectedDependency != null) { AddFoundDependency(underMouse); } if (ExpectedDependency != null) { if (ExpectingAPoint()) { TempPoint = CreateTempPoint(coordinates); AddFoundDependency(TempPoint); if (ExpectedDependency == null) { CreateAndAddFigure(); } } AddIntermediateFigureIfNecessary(); AdvertiseNextDependency(); } else { Finish(); } Drawing.Figures.CheckConsistency(); }
/// <summary> /// Assumes coordinates are logical already /// </summary> /// <param name="coordinates">Logical coordinates of the click point</param> protected virtual void Click(object sender, System.Windows.Input.MouseButtonEventArgs e) { System.Windows.Point coordinates = Coordinates(e); IFigure underMouse = null; Type expectedType = ExpectedDependency; if (TempPoint != null) { underMouse = Drawing.Figures.HitTest( coordinates, typeof(IPoint)); } else if (expectedType != null) { underMouse = Drawing.Figures.HitTest(coordinates, expectedType); } else { underMouse = Drawing.Figures.HitTest(coordinates); } if (underMouse != null && underMouse != TempPoint && ((FoundDependencies.Contains(underMouse) && !CanReuseDependency()) || underMouse == TempResult)) { return; } if (ExpectingAPoint()) { if (underMouse == null) { //underMouse = CreatePointAtCurrentPosition(coordinates, true); return; } else { // one branch only if (underMouse is Webb.Playbook.Geometry.Game.PBPlayer && underMouse.Dependents.Count > 0) { return; } // at most two branch if (underMouse is IPoint && underMouse.Dependents.Count > 1) { return; } } } RemoveIntermediateFigureIfNecessary(); if (TempPoint != null) { //if (underMouse == TempPoint || underMouse == TempResult || underMouse == null) //{ underMouse = CreatePointAtCurrentPosition(coordinates, true); //} TempPoint.SubstituteWith(underMouse); FoundDependencies.Remove(TempPoint); Drawing.Figures.Remove(TempPoint); TempPoint = null; } if (ExpectedDependency != null) { AddFoundDependency(underMouse); } if (ExpectedDependency != null) { if (ExpectingAPoint()) { TempPoint = CreateTempPoint(coordinates); AddFoundDependency(TempPoint); if (ExpectedDependency == null) { CreateAndAddFigure(); } } AddIntermediateFigureIfNecessary(); AdvertiseNextDependency(); } else { Finish(); //07-22-2009 scott if (IsMouseButtonDown) {// click mode IFigure endFigure = Drawing.Figures.HitTest(coordinates, typeof(Webb.Playbook.Geometry.Game.PBPlayer)); if (endFigure is Webb.Playbook.Geometry.Game.PBPlayer) { Drawing.ActionManager.Undo(); } else { MouseLeftButtonDown(sender, e as System.Windows.Input.MouseButtonEventArgs); } } else {// drag mode } } Drawing.Figures.CheckConsistency(); }
static Point ConvertToPoint(TempPoint tp) { return(new Point(tp.X, tp.Y)); }
private static extern bool GetCursorPos(out TempPoint lpPoint);
protected virtual void AddDependency(Point coordinates) { IFigure underMouse = null; if (GetExpectedDependencyType() != null) { // MouseDownUnconstrainedCoordinates used here to properly find the figure under the mouse. underMouse = LookForExpectedDependencyUnderCursor(ClickedUnconstrainedCoordinates); if (underMouse != null && FoundDependencies.Contains(underMouse) && !CanReuseDependency) { return; } if (underMouse == null && ExpectingAPoint()) { underMouse = CreatePointAtCurrentPosition(coordinates); } else if (ExpectingAPoint() && !usePointsUnderMouse) { var pointUnderMouse = underMouse as IPoint; var freePoint = CreatePointAtCurrentPosition(coordinates); if (pointUnderMouse != null) { freePoint.Coordinates = pointUnderMouse.Coordinates; } underMouse = freePoint; } } Drawing.RaiseConstructionStepStarted(); RemoveIntermediateFigureIfNecessary(); RemoveTempResultsIfNecessary(); if (TempPoint != null) { if (underMouse == null) { throw new NullReferenceException("How come underMouse is null at this point?"); } TempPoint.SubstituteWith(underMouse); RemoveTempPointIfNecessary(); } if (GetExpectedDependencyType() != null) { AddFoundDependency(underMouse); } if (GetExpectedDependencyType() != null) { if (ExpectingAPoint()) { CreateTempPoint(coordinates); if (CanCreateTempResults()) { CreateTempResults(); } else { AddIntermediateFigureIfNecessary(); } } AdvertiseNextDependency(); } else { AddFiguresAndRestart(); } Drawing.Figures.CheckConsistency(); }