Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Commit

Permalink
determine tooltip location based on skin cursor images
Browse files Browse the repository at this point in the history
  • Loading branch information
yugecin committed Jan 30, 2020
1 parent afdb2bd commit 18928ac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/itdelatrisu/opsu/ui/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import itdelatrisu.opsu.beatmap.BeatmapParser;
import itdelatrisu.opsu.ui.animations.AnimatedValue;
import itdelatrisu.opsu.ui.animations.AnimationEquation;
import yugecin.opsudance.options.Options;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
Expand Down Expand Up @@ -154,6 +156,31 @@ public static void updateTooltip(int delta, String s, boolean newlines) {
}
}

private static int tooltipOffset;

public static void updateTooltipLocation()
{
int p1 = calcTooltipLocationForImage(GameImage.CURSOR_MIDDLE);
int p2 = calcTooltipLocationForImage(GameImage.CURSOR);
tooltipOffset = Math.max(p1, p2) + 5;
}

private static int calcTooltipLocationForImage(GameImage gi)
{
Image img = gi.getImage();
int w2 = img.getWidth() / 2;
int h2 = img.getHeight() / 2;
for (int i = 10; i > 0; i--) {
float p = i / 10.0f;
float a = img.getAlphaAt(w2 + (int) (w2 * p), h2 + (int) (h2 * p));
System.out.printf("%f: %f%n", p, a);
if (a > .7f) {
return (int) (gi.getWidth() / 2.0f * p);
}
}
return 0;
}

/**
* Draws a tooltip, if any, near the current mouse coordinates,
* bounded by the container dimensions.
Expand All @@ -164,7 +191,6 @@ public static void drawTooltip(Graphics g) {
return;

int margin = width / 100, textMarginX = 2;
int offset = GameImage.CURSOR_MIDDLE.getWidth() / 2;
int lineHeight = Fonts.SMALL.getLineHeight();
int textWidth = textMarginX * 2, textHeight = lineHeight;
if (tooltipNewlines) {
Expand All @@ -181,6 +207,7 @@ public static void drawTooltip(Graphics g) {
textWidth += Fonts.SMALL.getWidth(tooltip);

// get drawing coordinates
int offset = (int) (tooltipOffset * Options.OPTION_CURSOR_SIZE.val / 100.0f);
int x = mouseX + offset;
int y = mouseY + offset;
if (x + textWidth > width - margin)
Expand Down
3 changes: 3 additions & 0 deletions src/org/newdawn/slick/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,9 @@ public float getAlphaAt(int x, int y) {
pixelData = texture.getTextureData();

// scale coordinates based on the image scale
if (width == 0 || height == 0) {
return 1.0f;
}
x = x * texture.getImageWidth() / width;
y = y * texture.getImageHeight() / height;

Expand Down
1 change: 1 addition & 0 deletions src/yugecin/opsudance/core/DisplayContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void onSkinChanged(String stringName)
this.skinChangeTimestamp = System.currentTimeMillis();
destroyImages();
reinit();
UI.updateTooltipLocation();
}

private void reinit() {
Expand Down

0 comments on commit 18928ac

Please sign in to comment.