Skip to content

Commit

Permalink
Merge pull request #53 from Jasper1467/master
Browse files Browse the repository at this point in the history
Fixed hover not being smooth on main menu screen
  • Loading branch information
cvs0 authored Aug 6, 2024
2 parents 4f41bc2 + 294ca69 commit 97a2eb4
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class AobaButtonWidget extends PressableWidget {
private Consumer<AobaButtonWidget> pressAction;
private long hoverStartTime = 0;
private static final long HOVER_ANIMATION_DURATION = 200;
private static final long HOVER_ANIMATION_DURATION = 200000000;

public AobaButtonWidget(int x, int y, int width, int height, Text message) {
super(x, y, width, height, message);
Expand All @@ -44,12 +44,12 @@ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float d
Matrix4f matrix = context.getMatrices().peek().getPositionMatrix();

if (isHovered() && hoverStartTime == 0) {
hoverStartTime = System.currentTimeMillis();
hoverStartTime = System.nanoTime();
} else if (!isHovered()) {
hoverStartTime = 0;
}

long currentTime = System.currentTimeMillis();
long currentTime = System.nanoTime();
float hoverProgress = hoverStartTime > 0 ? (currentTime - hoverStartTime) / (float) HOVER_ANIMATION_DURATION : 0;
hoverProgress = Math.min(hoverProgress, 1.0f);
hoverProgress = (float) Math.sin(hoverProgress * Math.PI / 2);
Expand Down Expand Up @@ -77,4 +77,4 @@ protected void appendClickableNarrations(NarrationMessageBuilder builder) {
// For brevity, we'll just skip this for now - if you want to add narration to your widget, you can do so here.
return;
}
}
}

0 comments on commit 97a2eb4

Please sign in to comment.