Skip to content

Commit 6daade3

Browse files
committed
Improved piano visuals
1 parent ac7879b commit 6daade3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public class DropRenderer {
5555
private static final float BLACK_KEY_HEIGHT_RATIO = 0.6F;
5656
private static final float PIANO_HEIGHT_DIVIDER = 7F;
5757
private static final int KEY_LINE_HEIGHT = 2;
58-
private static final float KEY_LINE_OFFSET_RATIO = 11.6F;
58+
private static final float WHITE_KEY_LINE_OFFSET_RATIO = 18F;
59+
private static final float BLACK_KEY_LINE_OFFSET_RATIO = 12F;
5960
private static final float KEY_PRESS_DEPTH_RATIO = 14.5F;
6061
private static final int PRESSED_KEY_COLOR_ALPHA = 175;
6162
private static final long KEY_ANIMATION_DURATION = 250_000_000L;
@@ -232,7 +233,8 @@ private void drawPiano(final Matrix4fStack positionMatrix) {
232233

233234
Renderer2D.INSTANCE.beginGlobalBuffering();
234235

235-
final float keyLineOffset = height / KEY_LINE_OFFSET_RATIO;
236+
final float whiteKeyLineOffset = height / WHITE_KEY_LINE_OFFSET_RATIO;
237+
final float blackKeyLineOffset = height / BLACK_KEY_LINE_OFFSET_RATIO;
236238
for (int nbsKey = 0; nbsKey < this.pianoKeyPositions.length; nbsKey++) {
237239
final float x = this.pianoKeyPositions[nbsKey];
238240
final float progress = this.pianoKeyLastColors[nbsKey] != null ? MathUtils.clamp((System.nanoTime() - this.pianoKeyLastPlayed[nbsKey]) / (float) KEY_ANIMATION_DURATION, 0F, 1F) : 1F;
@@ -246,11 +248,11 @@ private void drawPiano(final Matrix4fStack positionMatrix) {
246248
if (this.pianoKeyLastColors[nbsKey] != null) {
247249
Renderer2D.INSTANCE.filledRect(positionMatrix, x + 1, pressOffset, x + whiteKeyWidth - 1, height, this.pianoKeyLastColors[nbsKey].withAlpha(Math.round(PRESSED_KEY_COLOR_ALPHA * (1 - colorProgress))));
248250
}
249-
Renderer2D.INSTANCE.filledRect(positionMatrix, x, height - keyLineOffset + pressOffset, x + whiteKeyWidth, height - keyLineOffset - KEY_LINE_HEIGHT + pressOffset, Color.GRAY);
251+
Renderer2D.INSTANCE.filledRect(positionMatrix, x, height - whiteKeyLineOffset + pressOffset, x + whiteKeyWidth, height - whiteKeyLineOffset - KEY_LINE_HEIGHT + pressOffset, Color.GRAY);
250252

251253
this.textRenderer.setGlobalScale(ThinGL.getWindowFramebufferWidth() / 2745F); // 0,7
252254
final float nameWidth = this.textRenderer.calculateWidth(noteName);
253-
this.textRenderer.renderString(positionMatrix, GlobalObjects.GLOBAL_BATCH, this.getNoteName(nbsKey), x + whiteKeyWidth / 2 - nameWidth / 2, height - keyLineOffset - KEY_LINE_HEIGHT + pressOffset - this.textRenderer.getPaddedHeight(), 0, Color.BLACK);
255+
this.textRenderer.renderString(positionMatrix, GlobalObjects.GLOBAL_BATCH, this.getNoteName(nbsKey), x + whiteKeyWidth / 2 - nameWidth / 2, height - whiteKeyLineOffset - KEY_LINE_HEIGHT + pressOffset - this.textRenderer.getPaddedHeight(), 0, Color.BLACK);
254256
this.textRenderer.setGlobalScale(1F);
255257
} else {
256258
positionMatrix.pushMatrix();
@@ -260,11 +262,11 @@ private void drawPiano(final Matrix4fStack positionMatrix) {
260262
if (this.pianoKeyLastColors[nbsKey] != null) {
261263
Renderer2D.INSTANCE.filledRect(positionMatrix, x, pressOffset - height / KEY_PRESS_DEPTH_RATIO / 2, x + blackKeyWidth, height * BLACK_KEY_HEIGHT_RATIO, this.pianoKeyLastColors[nbsKey].withAlpha(Math.round(PRESSED_KEY_COLOR_ALPHA * (1 - colorProgress))));
262264
}
263-
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);
265+
Renderer2D.INSTANCE.filledRect(positionMatrix, x, height * BLACK_KEY_HEIGHT_RATIO - blackKeyLineOffset + pressOffset, x + blackKeyWidth, height * BLACK_KEY_HEIGHT_RATIO - blackKeyLineOffset - KEY_LINE_HEIGHT + pressOffset, Color.GRAY);
264266

265267
this.textRenderer.setGlobalScale(ThinGL.getWindowFramebufferWidth() / 4000F); // 0,48
266268
final float nameWidth = this.textRenderer.calculateWidth(noteName);
267-
this.textRenderer.renderString(positionMatrix, GlobalObjects.GLOBAL_BATCH, this.getNoteName(nbsKey), x + blackKeyWidth / 2 - nameWidth / 2, height * BLACK_KEY_HEIGHT_RATIO - keyLineOffset - KEY_LINE_HEIGHT + pressOffset - this.textRenderer.getPaddedHeight(), 0, Color.WHITE);
269+
this.textRenderer.renderString(positionMatrix, GlobalObjects.GLOBAL_BATCH, this.getNoteName(nbsKey), x + blackKeyWidth / 2 - nameWidth / 2, height * BLACK_KEY_HEIGHT_RATIO - blackKeyLineOffset - KEY_LINE_HEIGHT + pressOffset - this.textRenderer.getPaddedHeight(), 0, Color.WHITE);
268270
this.textRenderer.setGlobalScale(1F);
269271

270272
positionMatrix.popMatrix();

0 commit comments

Comments
 (0)