public void Draw(Graphics g, LaneBook laneBook, Point originLocation) { if (StartPosition == null || EndPosition == null) { return; } ScoreLane futureLane = laneBook.Find( x => x.StartTick <= TopLeftPosition.Tick && TopLeftPosition.Tick <= x.EndTick); ScoreLane pastLane = laneBook.Find( x => x.StartTick <= BottomRightPosition.Tick && BottomRightPosition.Tick <= x.EndTick); int passingLanes = futureLane != null ? futureLane.Index - pastLane.Index : laneBook.Count - pastLane.Index - 1; PointF topLeft = new PointF( pastLane.LaneRect.Left + TopLeftPosition.Lane * ScoreInfo.UnitLaneWidth - originLocation.X, pastLane.LaneRect.Bottom - (TopLeftPosition.Tick - pastLane.StartTick) * ScoreInfo.UnitBeatHeight - originLocation.Y - minHeight / 2); PointF topRight = new PointF( pastLane.LaneRect.Left + (BottomRightPosition.Lane + 1) * ScoreInfo.UnitLaneWidth - originLocation.X, pastLane.LaneRect.Bottom - (TopLeftPosition.Tick - pastLane.StartTick) * ScoreInfo.UnitBeatHeight - originLocation.Y - minHeight / 2); PointF bottomLeft = new PointF( pastLane.LaneRect.Left + TopLeftPosition.Lane * ScoreInfo.UnitLaneWidth - originLocation.X, pastLane.LaneRect.Bottom - (BottomRightPosition.Tick - pastLane.StartTick) * ScoreInfo.UnitBeatHeight - originLocation.Y + minHeight / 2); PointF bottomRight = new PointF( pastLane.LaneRect.Left + (BottomRightPosition.Lane + 1) * ScoreInfo.UnitLaneWidth - originLocation.X, pastLane.LaneRect.Bottom - (BottomRightPosition.Tick - pastLane.StartTick) * ScoreInfo.UnitBeatHeight - originLocation.Y + minHeight / 2); using (GraphicsPath graphicsPath = new GraphicsPath()) { var smoothingMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.Default; var itrLane = pastLane; for (int i = 0; i <= passingLanes; ++i, itrLane = laneBook.Next(itrLane)) { graphicsPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); graphicsPath.CloseFigure(); if (itrLane.StartTick <= Status.DrawTickLast && itrLane.EndTick >= Status.DrawTickFirst) { using (Pen pen = new Pen(Color.White, 1)) { pen.DashPattern = new float[] { 4f, 4f }; RectangleF clipRect = new RectangleF( itrLane.LaneRect.X - originLocation.X, itrLane.LaneRect.Y - originLocation.Y, //HACK: 選択領域矩形が少し大きいので見切れないようにする itrLane.LaneRect.Width + 1, itrLane.LaneRect.Height + 5); g.Clip = new Region(clipRect); g.DrawPath(pen, graphicsPath); } } topLeft = topLeft.Add(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, itrLane.LaneRect.Height); topRight = topRight.Add(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, itrLane.LaneRect.Height); bottomLeft = bottomLeft.Add(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, itrLane.LaneRect.Height); bottomRight = bottomRight.Add(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, itrLane.LaneRect.Height); graphicsPath.ClearMarkers(); } g.SmoothingMode = smoothingMode; } g.ResetClip(); }
public void UpdateLocation(LaneBook laneBook) { ScoreLane lane = laneBook.Find(x => x.StartTick <= Position.Tick && Position.Tick <= x.EndTick); if (lane == null) { return; } PointF location = new PointF( lane.LaneRect.Left + Position.Lane * ScoreInfo.UnitLaneWidth, //HACK: Y座標が微妙にずれるので-1して調節する lane.HitRect.Bottom - (Position.Tick - lane.StartTick) * ScoreInfo.UnitBeatHeight - 1); RelocateOnly(location, lane.Index); }
private static void DrawHoldLine(Graphics g, Note past, Note future, Point drawLocation, LaneBook laneBook) { float distance = (future.Position.Tick - past.Position.Tick) * ScoreInfo.UnitBeatHeight; //グラデーション矩形 //x座標と幅は適当だけど動いてるはず。重要なのはy座標と高さ RectangleF gradientRect = new RectangleF(0, past.Location.Y - distance + drawOffset.Y - drawLocation.Y, 10, distance <= 0 ? 1 : distance); //相対位置 PointF pastRerativeLocation = new PointF(past.Location.X - drawLocation.X, past.Location.Y - drawLocation.Y); int passingLanes = future.LaneIndex - past.LaneIndex; float positionDistance = (future.Position.Tick - past.Position.Tick) * ScoreInfo.UnitBeatHeight; float diffX = (future.Position.Lane - past.Position.Lane) * ScoreInfo.UnitLaneWidth; //ノーツfutureの位置はノーツpastの位置に2ノーツの距離を引いて表す。またTopRightの水平位置はfutureのWidthを使うことに注意 PointF topLeft = pastRerativeLocation.Add(diffX, -positionDistance).Add(drawOffset); PointF topRight = pastRerativeLocation.Add(diffX, -positionDistance).Add(-drawOffset.X, drawOffset.Y).AddX(future.Width); //以下の2つはレーンをまたがないときと同じ PointF bottomLeft = pastRerativeLocation.Add(drawOffset); PointF bottomRight = pastRerativeLocation.Add(-drawOffset.X, drawOffset.Y).AddX(past.Width); using (GraphicsPath graphicsPath = new GraphicsPath()) { graphicsPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); ScoreLane scoreLane = laneBook.Find(x => x.Contains(past)); for (int i = 0; i <= passingLanes && scoreLane != null; ++i) { if (Status.DrawTickFirst < scoreLane.EndTick && scoreLane.StartTick < Status.DrawTickLast) { RectangleF clipRect = new RectangleF( scoreLane.LaneRect.X - drawLocation.X, scoreLane.LaneRect.Y - drawLocation.Y, scoreLane.LaneRect.Width, scoreLane.LaneRect.Height); g.Clip = new Region(clipRect); using (LinearGradientBrush myBrush = new LinearGradientBrush(gradientRect, baseColor, baseColor, LinearGradientMode.Vertical)) { myBrush.InterpolationColors = colorBlend; g.FillPath(myBrush, graphicsPath); } } // インクリメント if (i != passingLanes) { graphicsPath.Translate(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, scoreLane.HitRect.Height); gradientRect.Y += scoreLane.HitRect.Height; scoreLane = laneBook.Next(scoreLane); } } } }
/// <summary> /// SlideCurveの当たり判定 /// </summary> private bool ContainsInCurve(Note past, Note curve, Note future, LaneBook laneBook, PointF locationVirtual) { int passingLanes = future.LaneIndex - past.LaneIndex; using (GraphicsPath graphicsPath = MyUtil.CreateSlideCurvePath(past, curve, future, drawOffset)) { ScoreLane lane = laneBook.Find(x => x.Contains(past)); for (int i = 0; i <= passingLanes && lane != null; ++i) { if (graphicsPath.IsVisible(locationVirtual)) { return(true); } else { graphicsPath.Translate( ScoreLane.scoreWidth + ScoreLane.Margin.Left + ScorePanel.Margin.Right + ScorePanel.Margin.Left + ScoreLane.Margin.Right, lane.HitRect.Height); lane = laneBook.Next(lane); } } } return(false); }
/// <summary> /// ノーツ間を繋ぐ帯の描画(ベジェ) /// </summary> private static void DrawSlideCurve(Graphics g, Note past, Note curve, Note future, Point drawLocation, LaneBook laneBook, ref RectangleF gradientRect) { if (gradientRect.Width <= 0) { gradientRect.Width = 1; } if (gradientRect.Height <= 0) { gradientRect.Height = 1; } //相対位置 PointF pastRerativeLocation = new PointF(past.Location.X - drawLocation.X, past.Location.Y - drawLocation.Y); int passingLanes = future.LaneIndex - past.LaneIndex; float positionDistanceFuture = (future.Position.Tick - past.Position.Tick) * ScoreInfo.UnitBeatHeight; float positionDistanceCurve = (curve.Position.Tick - past.Position.Tick) * ScoreInfo.UnitBeatHeight; float diffXFuture = (future.Position.Lane - past.Position.Lane) * ScoreInfo.UnitLaneWidth; float diffXCurve = (curve.Position.Lane - past.Position.Lane) * ScoreInfo.UnitLaneWidth; //ノーツfutureの位置はノーツpastの位置に2ノーツの距離を引いて表す。またTopRightの水平位置はfutureのWidthを使うことに注意 PointF topLeft = pastRerativeLocation.Add(diffXFuture, -positionDistanceFuture).Add(drawOffset); PointF topRight = pastRerativeLocation.Add(diffXFuture, -positionDistanceFuture).Add(-drawOffset.X, drawOffset.Y).AddX(future.Width); //以下の2つはレーンをまたがないときと同じ PointF bottomLeft = pastRerativeLocation.Add(drawOffset).AddY(deltaHeight); PointF bottomRight = pastRerativeLocation.Add(-drawOffset.X, drawOffset.Y).AddX(past.Width).AddY(deltaHeight); //3つのそれぞれのノーツの中心の座標 PointF topCenter = topLeft.AddX(future.Width / 2f - drawOffset.X); PointF bottomCenter = bottomLeft.AddX(past.Width / 2f - drawOffset.X); PointF curveCenter = pastRerativeLocation.Add(diffXCurve, -positionDistanceCurve).AddX(curve.Width / 2f); // //下からアンカーまでの比率 float ratio = (curveCenter.Y - bottomCenter.Y) / (topCenter.Y - bottomCenter.Y); //カーブノーツのY座標で水平にスライドを切ったときのスライド幅 float widthAnchor = (topRight.X - topLeft.X) * ratio + (bottomRight.X - bottomLeft.X) * (1 - ratio); using (GraphicsPath graphicsPath = new GraphicsPath()) { graphicsPath.AddBezier(bottomLeft, curveCenter.AddX(-widthAnchor / 2f), topLeft); graphicsPath.AddLine(topLeft, topRight); graphicsPath.AddBezier(topRight, curveCenter.AddX(widthAnchor / 2f), bottomRight); graphicsPath.AddLine(bottomLeft, bottomRight); ScoreLane scoreLane = laneBook.Find(x => x.Contains(past)); RectangleF clipRect; for (int i = 0; i <= passingLanes && scoreLane != null; ++i) { if (Status.DrawTickFirst < scoreLane.EndTick && scoreLane.StartTick < Status.DrawTickLast) { clipRect = new RectangleF( scoreLane.LaneRect.X - drawLocation.X, scoreLane.LaneRect.Y - drawLocation.Y, scoreLane.LaneRect.Width, scoreLane.LaneRect.Height); g.Clip = new Region(clipRect); using (LinearGradientBrush myBrush = new LinearGradientBrush(gradientRect, baseColor, baseColor, LinearGradientMode.Vertical)) { myBrush.InterpolationColors = colorBlend; g.FillPath(myBrush, graphicsPath); } using (Pen myPen = new Pen(lineColor, 2)) { g.DrawBezier(myPen, bottomCenter, curveCenter, topCenter); } } // インクリメント bottomCenter = bottomCenter.Add(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, scoreLane.HitRect.Height); curveCenter = curveCenter.Add(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, scoreLane.HitRect.Height); topCenter = topCenter.Add(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, scoreLane.HitRect.Height); if (i != passingLanes) { graphicsPath.Translate(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, scoreLane.HitRect.Height); gradientRect.Y += scoreLane.HitRect.Height; scoreLane = laneBook.Next(scoreLane); } } } }
/// <summary> /// ノーツ間を繋ぐ帯の描画(直線) /// </summary> private static void DrawSlideLine(Graphics g, Note past, Note future, Point drawLocation, LaneBook laneBook, ref RectangleF gradientRect) { if (gradientRect.Width <= 0) { gradientRect.Width = 1; } if (gradientRect.Height <= 0) { gradientRect.Height = 1; } //相対位置 PointF pastRerativeLocation = new PointF(past.Location.X - drawLocation.X, past.Location.Y - drawLocation.Y); int passingLanes = future.LaneIndex - past.LaneIndex; float positionDistance = (future.Position.Tick - past.Position.Tick) * ScoreInfo.UnitBeatHeight; float diffX = (future.Position.Lane - past.Position.Lane) * ScoreInfo.UnitLaneWidth; //ノーツfutureの位置はノーツpastの位置に2ノーツの距離を引いて表す。またTopRightの水平位置はfutureのWidthを使うことに注意 PointF topLeft = pastRerativeLocation.Add(diffX, -positionDistance).Add(drawOffset); PointF topRight = pastRerativeLocation.Add(diffX, -positionDistance).Add(-drawOffset.X, drawOffset.Y).AddX(future.Width); //以下の2つはレーンをまたがないときと同じ PointF bottomLeft = pastRerativeLocation.Add(drawOffset).AddY(deltaHeight); PointF bottomRight = pastRerativeLocation.Add(-drawOffset.X, drawOffset.Y).AddX(past.Width).AddY(deltaHeight); using (GraphicsPath graphicsPath = new GraphicsPath()) { graphicsPath.AddPolygon(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); ScoreLane scoreLane = laneBook.Find(x => x.Contains(past)); RectangleF clipRect; for (int i = 0; i <= passingLanes && scoreLane != null; ++i) { if (Status.DrawTickFirst < scoreLane.EndTick && scoreLane.StartTick < Status.DrawTickLast) { clipRect = new RectangleF( scoreLane.LaneRect.X - drawLocation.X, scoreLane.LaneRect.Y - drawLocation.Y, scoreLane.LaneRect.Width, scoreLane.LaneRect.Height); g.Clip = new Region(clipRect); using (LinearGradientBrush myBrush = new LinearGradientBrush(gradientRect, baseColor, baseColor, LinearGradientMode.Vertical)) { myBrush.InterpolationColors = colorBlend; g.FillPath(myBrush, graphicsPath); } using (Pen myPen = new Pen(lineColor, 2)) { g.DrawLine( myPen, (graphicsPath.PathPoints[1].X + graphicsPath.PathPoints[2].X) / 2, graphicsPath.PathPoints[1].Y, (graphicsPath.PathPoints[0].X + graphicsPath.PathPoints[3].X) / 2, graphicsPath.PathPoints[0].Y); } } // インクリメント if (i != passingLanes) { graphicsPath.Translate(ScoreLane.Width + ScorePanel.Margin.Left + ScorePanel.Margin.Right, scoreLane.HitRect.Height); gradientRect.Y += scoreLane.HitRect.Height; scoreLane = laneBook.Next(scoreLane); } } } }
/// <summary> /// 与えられた座標がスライド帯の上に乗っているか判定します /// </summary> public bool Contains(PointF locationVirtual, LaneBook laneBook) { var list = this.OrderBy(x => x.Position.Tick).ToList(); foreach (Note note in list) { if (list.IndexOf(note) >= list.Count - 1) { break; } Note next = list.ElementAt(list.IndexOf(note) + 1); if (note is SlideCurve) { continue; } else if (next is SlideCurve) { var ret = ContainsInCurve(note, next, list.ElementAt(list.IndexOf(next) + 1), laneBook, locationVirtual); if (ret) { return(true); } } // int passingLanes = next.LaneIndex - note.LaneIndex; if (passingLanes == 0) { PointF topLeft = next.Location.Add(drawOffset); PointF topRight = next.Location.Add(-drawOffset.X, drawOffset.Y).AddX(next.Width); PointF bottomLeft = note.Location.Add(drawOffset); PointF bottomRight = note.Location.Add(-drawOffset.X, drawOffset.Y).AddX(note.Width); using (GraphicsPath hitPath = new GraphicsPath()) { hitPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); if (hitPath.IsVisible(locationVirtual)) { return(true); } } } else if (passingLanes >= 1) { float positionDistance = (next.Position.Tick - note.Position.Tick) * ScoreInfo.UnitBeatHeight; float diffX = (next.Position.Lane - note.Position.Lane) * ScoreInfo.UnitLaneWidth; #region 最初のレーンでの判定処理 PointF topLeft = note.Location.Add(drawOffset).Add(diffX, -positionDistance); PointF topRight = note.Location.Add(-drawOffset.X, drawOffset.Y).AddX(next.Width).Add(diffX, -positionDistance); PointF bottomLeft = note.Location.Add(drawOffset); PointF bottomRight = note.Location.Add(-drawOffset.X, drawOffset.Y).AddX(note.Width); using (GraphicsPath hitPath = new GraphicsPath()) { hitPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); if (hitPath.IsVisible(locationVirtual)) { return(true); } } #endregion #region 以降最後までの判定処理 ScoreLane prevLane, curLane; for (prevLane = laneBook.Find(x => x.Contains(note)), curLane = laneBook.Next(prevLane); curLane != null && laneBook.IndexOf(curLane) <= next.LaneIndex; prevLane = curLane, curLane = laneBook.Next(curLane)) { topLeft.X = curLane.LaneRect.X + next.Position.Lane * ScoreInfo.UnitLaneWidth + drawOffset.X; topLeft.Y += prevLane.LaneRect.Height; topRight.X = topLeft.X + next.Width - 2 * drawOffset.X; topRight.Y += prevLane.LaneRect.Height; bottomLeft.X = curLane.LaneRect.X + note.Position.Lane * ScoreInfo.UnitLaneWidth + drawOffset.X; bottomLeft.Y += prevLane.LaneRect.Height; bottomRight.X = bottomLeft.X + note.Width - 2 * drawOffset.X; bottomRight.Y += prevLane.LaneRect.Height; using (GraphicsPath hitPath = new GraphicsPath()) { hitPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); if (hitPath.IsVisible(locationVirtual)) { return(true); } } } #endregion } } return(false); }
private static void DrawAirHoldLine(Graphics g, Note past, Note future, Point drawLocation, LaneBook laneBook) { float distance = (future.Position.Tick - past.Position.Tick) * ScoreInfo.UnitBeatHeight; PointF drawOffset = new PointF(past.Width / 2f - lineWidth / 2f, LongNote.drawOffset.Y); //相対位置 PointF pastRerativeLocation = new PointF(past.Location.X - drawLocation.X, past.Location.Y - drawLocation.Y); PointF futureRerativeLocation = new PointF(future.Location.X - drawLocation.X, future.Location.Y - drawLocation.Y); int passingLanes = future.LaneIndex - past.LaneIndex; //スライドのノーツとノーツがレーンをまたがないとき if (passingLanes == 0) { PointF topLeft = futureRerativeLocation.Add(drawOffset); PointF topRight = futureRerativeLocation.Add(-drawOffset.X, drawOffset.Y).AddX(future.Width); PointF bottomLeft = pastRerativeLocation.Add(drawOffset); PointF bottomRight = pastRerativeLocation.Add(-drawOffset.X, drawOffset.Y).AddX(past.Width); using (GraphicsPath graphicsPath = new GraphicsPath()) { graphicsPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); using (SolidBrush myBrush = new SolidBrush(lineColor)) { g.FillPath(myBrush, graphicsPath); } } } //スライドのノーツとノーツがレーンをまたぐとき else if (passingLanes >= 1) { float positionDistance = (future.Position.Tick - past.Position.Tick) * ScoreInfo.UnitBeatHeight; float diffX = (future.Position.Lane - past.Position.Lane) * ScoreInfo.UnitLaneWidth; #region 最初のレーンでの描画 //ノーツfutureの位置はノーツpastの位置に2ノーツの距離を引いて表す。またTopRightの水平位置はfutureのWidthを使うことに注意 PointF topLeft = pastRerativeLocation.Add(diffX, -positionDistance).Add(drawOffset); PointF topRight = pastRerativeLocation.Add(diffX, -positionDistance).Add(-drawOffset.X, drawOffset.Y).AddX(future.Width); //以下の2つはレーンをまたがないときと同じ PointF bottomLeft = pastRerativeLocation.Add(drawOffset); PointF bottomRight = pastRerativeLocation.Add(-drawOffset.X, drawOffset.Y).AddX(past.Width); using (GraphicsPath graphicsPath = new GraphicsPath()) { graphicsPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); ScoreLane scoreLane = laneBook.Find(x => x.Contains(past)); if (scoreLane != null) { RectangleF clipRect = new RectangleF( scoreLane.LaneRect.X - drawLocation.X, scoreLane.LaneRect.Y - drawLocation.Y, scoreLane.LaneRect.Width, scoreLane.LaneRect.Height); g.Clip = new Region(clipRect); } using (SolidBrush myBrush = new SolidBrush(lineColor)) { g.FillPath(myBrush, graphicsPath); } } #endregion #region 以降最後までのレーンでの描画 { ScoreLane prevLane, curLane; for (prevLane = laneBook.Find(x => x.Contains(past)), curLane = laneBook.Next(prevLane); curLane != null && laneBook.IndexOf(curLane) <= future.LaneIndex; prevLane = curLane, curLane = laneBook.Next(curLane)) { topLeft.X = curLane.LaneRect.X + future.Position.Lane * ScoreInfo.UnitLaneWidth - drawLocation.X + drawOffset.X; topLeft.Y += prevLane.LaneRect.Height; topRight.X = topLeft.X + future.Width - 2 * drawOffset.X; topRight.Y += prevLane.LaneRect.Height; bottomLeft.X = curLane.LaneRect.X + past.Position.Lane * ScoreInfo.UnitLaneWidth - drawLocation.X + drawOffset.X; bottomLeft.Y += prevLane.LaneRect.Height; bottomRight.X = bottomLeft.X + past.Width - 2 * drawOffset.X; bottomRight.Y += prevLane.LaneRect.Height; using (GraphicsPath graphicsPath = new GraphicsPath()) { graphicsPath.AddLines(new PointF[] { topLeft, bottomLeft, bottomRight, topRight }); RectangleF clipRect = new RectangleF(curLane.LaneRect.Location.Sub(drawLocation), curLane.LaneRect.Size); g.Clip = new Region(clipRect); using (SolidBrush myBrush = new SolidBrush(lineColor)) { g.FillPath(myBrush, graphicsPath); } } } } #endregion } }