Skip to content

Commit

Permalink
Merge branch 'statementreply-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hozuki committed Oct 16, 2016
2 parents 050a810 + 90f3661 commit ec33b6c
Showing 1 changed file with 108 additions and 29 deletions.
137 changes: 108 additions & 29 deletions DereTore.Applications.ScoreEditor/Controls/RenderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ internal static class RenderHelper {
public static void DrawAvatars(RenderParams renderParams) {
var clientSize = renderParams.ClientSize;
var centerY = clientSize.Height * BaseLineYPosition;
foreach (var position in AvatarCenterXPositions) {
foreach (var position in AvatarCenterXEndPositions) {
var centerX = clientSize.Width * position;
renderParams.Graphics.FillEllipse(Brushes.Firebrick, centerX - AvatarCircleRadius, centerY - AvatarCircleRadius, AvatarCircleDiameter, AvatarCircleDiameter);
}
}

public static void DrawCeilingLine(RenderParams renderParams) {
var clientSize = renderParams.ClientSize;
float p1 = AvatarCenterXPositions[0], p5 = AvatarCenterXPositions[AvatarCenterXPositions.Length - 1];
float p1 = AvatarCenterXStartPositions[0], p5 = AvatarCenterXStartPositions[AvatarCenterXStartPositions.Length - 1];
float x1 = clientSize.Width * p1, x2 = clientSize.Width * p5;
var ceilingY = FutureNoteCeiling * clientSize.Height;
renderParams.Graphics.DrawLine(Pens.Red, x1, ceilingY, x2, ceilingY);
Expand Down Expand Up @@ -92,7 +92,8 @@ public static void DrawNotes(RenderParams renderParams, IList<Note> notes, int s

public static void DrawSelectedRect(RenderParams renderParams, Note note, Pen pen) {
float x = GetNoteXPosition(renderParams, note), y = GetNoteYPosition(renderParams, note);
renderParams.Graphics.DrawRectangle(pen, x - AvatarCircleRadius, y - AvatarCircleRadius, AvatarCircleDiameter, AvatarCircleDiameter);
float r = GetNoteRadius(renderParams, note);
renderParams.Graphics.DrawRectangle(pen, x - r, y - r, r * 2f, r * 2f);
}

public static void DrawSyncLine(RenderParams renderParams, Note note1, Note note2) {
Expand All @@ -103,12 +104,31 @@ public static void DrawSyncLine(RenderParams renderParams, Note note1, Note note
float x1 = GetNoteXPosition(renderParams, note1),
y = GetNoteYPosition(renderParams, note2),
x2 = GetNoteXPosition(renderParams, note2);
float r = GetNoteRadius(renderParams, note2);
float xLeft = Math.Min(x1, x2), xRight = Math.Max(x1, x2);
renderParams.Graphics.DrawLine(Pens.DodgerBlue, xLeft + AvatarCircleRadius, y, xRight - AvatarCircleRadius, y);
renderParams.Graphics.DrawLine(Pens.DodgerBlue, xLeft + r, y, xRight - r, y);
}

public static void DrawHoldLine(RenderParams renderParams, Note startNote, Note endNote) {
DrawSimpleLine(renderParams, startNote, endNote, Pens.Yellow);
var graphics = renderParams.Graphics;
var now = renderParams.Now;
OnStageStatus s1 = GetNoteOnStageStatus(startNote, now), s2 = GetNoteOnStageStatus(endNote, now);
if (s1 == s2 && s1 != OnStageStatus.OnStage) {
return;
}
float t1 = GetNoteTransformedTime(renderParams, startNote, true, true);
float t2 = GetNoteTransformedTime(renderParams, endNote, true, true);
float tmid = (t1 + t2) * 0.5f;
float x1 = GetNoteXPosition(renderParams, startNote.FinishPosition, startNote.StartPosition, t1);
float x2 = GetNoteXPosition(renderParams, endNote.FinishPosition, endNote.StartPosition, t2);
float xmid = GetNoteXPosition(renderParams, endNote.FinishPosition, endNote.StartPosition, tmid);
float y1 = GetNoteYPosition(renderParams, t1);
float y2 = GetNoteYPosition(renderParams, t2);
float ymid = GetNoteYPosition(renderParams, tmid);
float xcontrol1, xcontrol2, ycontrol1, ycontrol2;
GetBezierFromQuadratic(x1, xmid, x2, out xcontrol1, out xcontrol2);
GetBezierFromQuadratic(y1, ymid, y2, out ycontrol1, out ycontrol2);
graphics.DrawBezier(Pens.Yellow, x1, y1, xcontrol1, ycontrol1, xcontrol2, ycontrol2, x2, y2);
}

public static void DrawFlickLine(RenderParams renderParams, Note startNote, Note endNote) {
Expand All @@ -133,74 +153,132 @@ public static void DrawSimpleNote(RenderParams renderParams, Note note) {
}
var graphics = renderParams.Graphics;
float x = GetNoteXPosition(renderParams, note), y = GetNoteYPosition(renderParams, note);
graphics.FillEllipse(Brushes.DarkMagenta, x - AvatarCircleRadius, y - AvatarCircleRadius, AvatarCircleDiameter, AvatarCircleDiameter);
float r = GetNoteRadius(renderParams, note);
graphics.FillEllipse(Brushes.DarkMagenta, x - r, y - r, r * 2f, r * 2f);
if (note.IsFlick) {
switch (note.FlickType) {
case NoteStatus.FlickLeft:
graphics.FillPie(Brushes.DarkOrange, x - AvatarCircleRadius, y - AvatarCircleRadius, AvatarCircleDiameter, AvatarCircleDiameter, 135, 90);
graphics.FillPie(Brushes.DarkOrange, x - r, y - r, r * 2f, r * 2f, 135, 90);
break;
case NoteStatus.FlickRight:
graphics.FillPie(Brushes.DarkOrange, x - AvatarCircleRadius, y - AvatarCircleRadius, AvatarCircleDiameter, AvatarCircleDiameter, -45, 90);
graphics.FillPie(Brushes.DarkOrange, x - r, y - r, r * 2f, r * 2f, -45, 90);
break;
}
}
}

public static void GetBezierFromQuadratic(float x1, float xmid, float x4, out float x2, out float x3) {
float xcontrol = xmid * 2f - (x1 + x4) * 0.5f;
x2 = (x1 + xcontrol * 2f) / 3f;
x3 = (x4 + xcontrol * 2f) / 3f;
}

public static void GetNotePairPositions(RenderParams renderParams, Note note1, Note note2, out float x1, out float x2, out float y1, out float y2) {
var now = renderParams.Now;
var clientSize = renderParams.ClientSize;
if (IsNotePassed(note1, now)) {
x1 = GetXByNotePosition(clientSize, note1.FinishPosition);
x1 = GetEndXByNotePosition(clientSize, note1.FinishPosition);
y1 = GetAvatarYPosition(clientSize);
} else if (IsNoteComing(note1, now)) {
x1 = GetXByNotePosition(clientSize, renderParams.IsPreview ? note1.StartPosition : note1.FinishPosition);
x1 = GetStartXByNotePosition(clientSize, renderParams.IsPreview ? note1.StartPosition : note1.FinishPosition);
y1 = GetBirthYPosition(clientSize);
} else {
x1 = GetNoteXPosition(renderParams, note1);
y1 = GetNoteYPosition(renderParams, note1);
}
if (IsNotePassed(note2, now)) {
x2 = GetXByNotePosition(clientSize, note2.FinishPosition);
x2 = GetEndXByNotePosition(clientSize, note2.FinishPosition);
y2 = GetAvatarYPosition(clientSize);
} else if (IsNoteComing(note2, now)) {
x2 = GetXByNotePosition(clientSize, renderParams.IsPreview ? note2.StartPosition : note2.FinishPosition);
x2 = GetStartXByNotePosition(clientSize, renderParams.IsPreview ? note2.StartPosition : note2.FinishPosition);
y2 = GetBirthYPosition(clientSize);
} else {
x2 = GetNoteXPosition(renderParams, note2);
y2 = GetNoteYPosition(renderParams, note2);
}
}

public static float GetNoteXPosition(RenderParams renderParams, Note note) {
public static float NoteTimeTransform(float timeRemainingInWindow) {
return timeRemainingInWindow / (2f - timeRemainingInWindow);
}

public static float NoteXTransform(float timeTransformed) {
return timeTransformed;
}

public static float NoteYTransform(float timeTransformed) {
return timeTransformed + 2.05128205f * timeTransformed * (1f - timeTransformed);
}

public static float GetNoteTransformedTime(RenderParams renderParams, Note note, bool clampComing = false, bool clampPassed = false) {
var timeRemaining = note.HitTiming - renderParams.Now;
var clientSize = renderParams.ClientSize;
var endPos = AvatarCenterXPositions[(int)note.FinishPosition - 1] * clientSize.Width;
if (renderParams.IsPreview) {
var startPos = AvatarCenterXPositions[(int)note.StartPosition - 1] * clientSize.Width;
return endPos - (endPos - startPos) * (float)timeRemaining / FutureTimeWindow;
} else {
return endPos;
var timeRemainingInWindow = (float)timeRemaining / FutureTimeWindow;
if (clampComing && timeRemaining > FutureTimeWindow) {
timeRemainingInWindow = 1f;
}
if (clampPassed && timeRemaining < 0f) {
timeRemainingInWindow = 0f;
}
return NoteTimeTransform(timeRemainingInWindow);
}

public static float GetNoteYPosition(RenderParams renderParams, Note note) {
var timeRemaining = note.HitTiming - renderParams.Now;
public static float GetNoteXPosition(RenderParams renderParams, Note note, bool clampComing = false, bool clampPassed = false) {
var timeTransformed = GetNoteTransformedTime(renderParams, note, clampComing, clampPassed);
return GetNoteXPosition(renderParams, note.FinishPosition, note.StartPosition, timeTransformed);
}

public static float GetNoteXPosition(RenderParams renderParams, NotePosition finishPosition, NotePosition startPosition, float timeTransformed) {
var clientSize = renderParams.ClientSize;
var endPos = AvatarCenterXEndPositions[(int)finishPosition - 1] * clientSize.Width;
var displayStartPosition = renderParams.IsPreview ? startPosition : finishPosition;
var startPos = AvatarCenterXStartPositions[(int)displayStartPosition - 1] * clientSize.Width;
return endPos - (endPos - startPos) * NoteXTransform(timeTransformed);
}

public static float GetNoteYPosition(RenderParams renderParams, Note note, bool clampComing = false, bool clampPassed = false) {
var timeTransformed = GetNoteTransformedTime(renderParams, note, clampComing, clampPassed);
return GetNoteYPosition(renderParams, timeTransformed);
}

public static float GetNoteYPosition(RenderParams renderParams, float timeTransformed) {
var clientSize = renderParams.ClientSize;
float ceiling = FutureNoteCeiling * clientSize.Height,
baseLine = BaseLineYPosition * clientSize.Height;
return baseLine - (baseLine - ceiling) * (float)timeRemaining / FutureTimeWindow;
return baseLine - (baseLine - ceiling) * NoteYTransform(timeTransformed);
}

public static float GetNoteRadius(RenderParams renderParams, Note note) {
var timeRemaining = note.HitTiming - renderParams.Now;
var timeTransformed = NoteTimeTransform((float)timeRemaining / FutureTimeWindow);
if (timeTransformed < 0.75f) {
if (timeTransformed < 0f) {
return AvatarCircleRadius;
} else {
return AvatarCircleRadius * (1f - timeTransformed * 0.933333333f);
}
} else {
if (timeTransformed < 1f) {
return AvatarCircleRadius * ((1f - timeTransformed) * 1.2f);
} else {
return 0f;
}
}
}

public static float GetAvatarXPosition(Size clientSize, NotePosition position) {
return clientSize.Width * AvatarCenterXPositions[(int)position - 1];
return clientSize.Width * AvatarCenterXEndPositions[(int)position - 1];
}

public static float GetAvatarYPosition(Size clientSize) {
return clientSize.Height * BaseLineYPosition;
}

public static float GetXByNotePosition(Size clientSize, NotePosition position) {
return clientSize.Width * AvatarCenterXPositions[(int)position - 1];
public static float GetStartXByNotePosition(Size clientSize, NotePosition position) {
return clientSize.Width * AvatarCenterXStartPositions[(int)position - 1];
}

public static float GetEndXByNotePosition(Size clientSize, NotePosition position) {
return clientSize.Width * AvatarCenterXEndPositions[(int)position - 1];
}

public static float GetBirthYPosition(Size clientSize) {
Expand Down Expand Up @@ -239,10 +317,11 @@ public enum OnStageStatus {
public static readonly float PastTimeWindow = 0.2f;
public static readonly float AvatarCircleDiameter = 50;
public static readonly float AvatarCircleRadius = AvatarCircleDiameter / 2;
public static readonly float[] AvatarCenterXPositions = { 0.2f, 0.35f, 0.5f, 0.65f, 0.8f };
public static readonly float BaseLineYPosition = 5f / 6;
public static readonly float[] AvatarCenterXStartPositions = { 0.272363281f, 0.381347656f, 0.5f, 0.618652344f, 0.727636719f };
public static readonly float[] AvatarCenterXEndPositions = { 0.192382812f, 0.346191406f, 0.5f, 0.653808594f, 0.807617188f };
public static readonly float BaseLineYPosition = 0.828125f;
// Then we know the bottom is <BaseLineYPosition + (PastWindow / FutureWindow) * (BaseLineYPosition - Ceiling))>.
public static readonly float FutureNoteCeiling = 1 - BaseLineYPosition;
public static readonly float FutureNoteCeiling = 0.21875f;

}
}

0 comments on commit ec33b6c

Please sign in to comment.