public int ManageTimelineByInputAndGetClickedTurn(out int turnUnderMouse, Frame frame, GlInput input, int turnCount, List <int> currentGameTurns, double speedMultiplier) { turnUnderMouse = -1; Vector2d positionOfFirstTile = new Vector2d(((IFramePainterInfo)frame).cameraViewport.right - FrameworkSettings.Timeline.TileWidth, 0); Rect2d fullTimelineRect = GetTimelineRect(frame); // var TIMELINE_SPEED_DECREASE_PER_TICK = FrameworkSettings.Timeline.TileLength / 30; double scrollTime = FrameworkSettings.Timeline.ScrollAnimationTimeMs; double followTime = speedMultiplier * FrameworkSettings.Timeline.FollowAnimationTimeMs * speedMultiplier; double allowedRangeDown = (-turnCount * FrameworkSettings.Timeline.TileWidth + fullTimelineRect.size.Y * 0.7).ToRange(0, double.MinValue), allowedRangeUp = 0; if (GeomHelper.PointInSimpleRect(input.Mouse, fullTimelineRect)) { if (_lastAnimatorReason == AnimatorReasons.followLastViewed) { _animator = new Animator <double>(Animator.Linear, _firstTurnOffset, _firstTurnOffset, 1); _lastAnimatorReason = AnimatorReasons.none; } int d = input.Wheel * FrameworkSettings.Timeline.TurnScrollSpeedByMouseOrArrow; if (input.KeyTime(System.Windows.Input.Key.Up) == 1) { d = FrameworkSettings.Timeline.TurnScrollSpeedByMouseOrArrow; } if (input.KeyTime(System.Windows.Input.Key.Down) == 1) { d = -FrameworkSettings.Timeline.TurnScrollSpeedByMouseOrArrow; } if (input.KeyTime(System.Windows.Input.Key.PageUp) == 1) { d = FrameworkSettings.Timeline.TurnScrollSpeedByPageUpDown; } if (input.KeyTime(System.Windows.Input.Key.PageDown) == 1) { d = -FrameworkSettings.Timeline.TurnScrollSpeedByPageUpDown; } if (d != 0) { double go = d * FrameworkSettings.Timeline.TileLength; _animator = new Animator <double>(Animator.EaseOutQuad, _firstTurnOffset, ((_lastAnimatorReason == AnimatorReasons.wheel ? _animator.finish : _firstTurnOffset) + go).ToRange(allowedRangeDown, allowedRangeUp), scrollTime / FrameworkSettings.ForInnerUse.TimerInterval, _timelineTick - 1); _lastAnimatorReason = AnimatorReasons.wheel; _timelineSpeed = 0; _firstTurnOffset += input.Wheel * FrameworkSettings.Timeline.TileLength; } } else { if (_indexOfLastViewedTile >= 0) { _lastAnimatorReason = AnimatorReasons.followLastViewed; } if (_lastAnimatorReason == AnimatorReasons.followLastViewed) { if (currentGameTurns.Count != 0) { _animator = new Animator <double>(Animator.EaseOutQuad, _firstTurnOffset, (fullTimelineRect.size.Y * 0.4 - currentGameTurns.First() * FrameworkSettings.Timeline.TileLength).ToRange(allowedRangeDown, allowedRangeUp), followTime / FrameworkSettings.ForInnerUse.TimerInterval, _timelineTick - 1); _lastAnimatorReason = AnimatorReasons.followLastViewed; } } } //if (_indexOfLastViewedTile >= 0) //{ // var halfYPosition = fullTimelineRect.size.Y / 2; // var viewedTurnPosition = _firstTurnOffset + _indexOfLastViewedTile * FrameworkSettings.Timeline.TileLength; // if (_followLastTurn && viewedTurnPosition < halfYPosition) // { // _animator = new Animator<double>(Animator.EaseOutQuad, // _firstTurnOffset, halfYPosition - _indexOfLastViewedTile * FrameworkSettings.Timeline.TileLength, // _followDuration, currentFrameTick-1); // } //} _firstTurnOffset = _animator.Get(_timelineTick); //if (input.RightMouseTime >= 1 && GeomHelper.PointInSimpleRect(input.Mouse, fullTimelineRect)) //{ // _timelineSpeed = 0; // if (input.RightMouseTime > 1) // { // _firstTurnOffset += input.MouseDelta.Y; // } //} //else if (input.RightMouseUp) //{ // _timelineSpeed = input.MouseDelta.Y; //} //if (input.Wheel != 0 && GeomHelper.PointInSimpleRect(input.Mouse, fullTimelineRect)) //{ // _timelineSpeed = 0; // _firstTurnOffset += input.Wheel * FrameworkSettings.Timeline.TileLength; //} //_firstTurnOffset += _timelineSpeed; //if (_timelineSpeed > 0) //{ // _timelineSpeed = Math.Max(0, _timelineSpeed - TIMELINE_SPEED_DECREASE_PER_TICK); //} //else //{ // _timelineSpeed = Math.Min(0, _timelineSpeed + TIMELINE_SPEED_DECREASE_PER_TICK); //} //correction - must be <=0 and at least one tile should be visible // if (_thereWasADraw == false) // { // _firstTurnOffset = -10000000; // _thereWasADraw = true; // } // _firstTurnOffset = _firstTurnOffset.ToRange(-turnCount * FrameworkSettings.Timeline.TileWidth + FrameworkSettings.Timeline.TileWidth * 10, 0); //todo now only ten are visible _timelineTick++; var underMouse = input.AllButtonsUnderMouse().FirstOrDefault(x => x.StartsWith("__timeline")); if (underMouse != null) { int turnIndex = int.Parse(underMouse.Replace("__timeline", "")); turnUnderMouse = turnIndex; } var clickedTurn = input.AllClickedButtons().FirstOrDefault(x => x.StartsWith("__timeline")); if (clickedTurn != null) { int turnIndex = int.Parse(clickedTurn.Replace("__timeline", "")); return(turnIndex); } return(-1); }
public static bool IsCircleIntersectsRect(Vector2d center, double radius, Rect2d rect, int partCountPerFullCircle = 64) { var circle = Circle(center, radius, partCountPerFullCircle); return(circle.Any(x => GeomHelper.PointInSimpleRect(x, rect))); }