Skip to content

Commit 31f85ff

Browse files
committed
Use ratio instead of hardcoded sizes
1 parent aceff2f commit 31f85ff

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/net/raphimc/noteblocktool/frames/visualizer/DropRenderer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public class DropRenderer {
5454
private static final float BLACK_KEY_HEIGHT_RATIO = 0.6F;
5555
private static final float PIANO_HEIGHT_DIVIDER = 7F;
5656
private static final int KEY_LINE_HEIGHT = 2;
57-
private static final int KEY_LINE_OFFSET = 25;
58-
private static final int KEY_PRESS_DEPTH = 20;
57+
private static final float KEY_LINE_OFFSET_RATIO = 11.6F;
58+
private static final float KEY_PRESS_DEPTH_RATIO = 14.5F;
5959
private static final long KEY_ANIMATION_DURATION = 250_000_000L;
6060

6161
private final SoundSystemSongPlayer songPlayer;
@@ -233,24 +233,25 @@ private void drawPiano(final Matrix4fStack positionMatrix) {
233233
Renderer2D.INSTANCE.beginGlobalBuffering();
234234
Renderer2D.INSTANCE.filledRect(positionMatrix, 0, 0, width, height, Color.BLACK);
235235

236+
final float keyLineOffset = height / KEY_LINE_OFFSET_RATIO;
236237
for (int nbsKey = 0; nbsKey < this.pianoKeyPositions.length; nbsKey++) {
237238
final float x = this.pianoKeyPositions[nbsKey];
238239
final float progress = this.pianoKeyLastColors[nbsKey] != null ? MathUtils.clamp((System.nanoTime() - this.pianoKeyLastPlayed[nbsKey]) / (float) KEY_ANIMATION_DURATION, 0F, 1F) : 1F;
239-
final float pressOffset = KEY_PRESS_DEPTH - KEY_PRESS_DEPTH * (progress < 0.5F ? 1F - progress : progress);
240+
final float pressOffset = height / KEY_PRESS_DEPTH_RATIO - height / KEY_PRESS_DEPTH_RATIO * (progress < 0.5F ? 1F - progress : progress);
240241
if (!this.isBlackKey(nbsKey)) {
241242
Renderer2D.INSTANCE.filledRect(positionMatrix, x + 1, pressOffset, x + whiteKeyWidth - 1, height, Color.WHITE);
242243
if (this.pianoKeyLastColors[nbsKey] != null) {
243244
Renderer2D.INSTANCE.filledRect(positionMatrix, x + 1, pressOffset, x + whiteKeyWidth - 1, height, this.pianoKeyLastColors[nbsKey].withAlpha(Math.round(200 * (1 - progress))));
244245
}
245-
Renderer2D.INSTANCE.filledRect(positionMatrix, x, height - KEY_LINE_OFFSET + pressOffset, x + whiteKeyWidth, height - KEY_LINE_OFFSET - KEY_LINE_HEIGHT + pressOffset, Color.GRAY);
246+
Renderer2D.INSTANCE.filledRect(positionMatrix, x, height - keyLineOffset + pressOffset, x + whiteKeyWidth, height - keyLineOffset - KEY_LINE_HEIGHT + pressOffset, Color.GRAY);
246247
} else {
247248
positionMatrix.pushMatrix();
248249
positionMatrix.translate(0, 0, 1);
249250
Renderer2D.INSTANCE.filledRect(positionMatrix, x, pressOffset, x + blackKeyWidth, height * BLACK_KEY_HEIGHT_RATIO, Color.BLACK);
250251
if (this.pianoKeyLastColors[nbsKey] != null) {
251252
Renderer2D.INSTANCE.filledRect(positionMatrix, x, pressOffset, x + blackKeyWidth, height * BLACK_KEY_HEIGHT_RATIO, this.pianoKeyLastColors[nbsKey].withAlpha(Math.round(200 * (1 - progress))));
252253
}
253-
Renderer2D.INSTANCE.filledRect(positionMatrix, x, height * BLACK_KEY_HEIGHT_RATIO - KEY_LINE_OFFSET + pressOffset, x + blackKeyWidth, height * BLACK_KEY_HEIGHT_RATIO - KEY_LINE_OFFSET - KEY_LINE_HEIGHT + pressOffset, Color.GRAY);
254+
Renderer2D.INSTANCE.filledRect(positionMatrix, x, height * BLACK_KEY_HEIGHT_RATIO - keyLineOffset + pressOffset, x + blackKeyWidth, height * BLACK_KEY_HEIGHT_RATIO - keyLineOffset - KEY_LINE_HEIGHT + pressOffset, Color.GRAY);
254255
positionMatrix.popMatrix();
255256
}
256257
}

0 commit comments

Comments
 (0)