Skip to content

Commit

Permalink
Follow-up to #307 (minor code style changes).
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Jul 1, 2017
1 parent da5a366 commit 481b3a1
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions src/itdelatrisu/opsu/ui/InputOverlayKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

/**
* Input overlay key.
*
* @author yugecin (https://github.com/yugecin)
*/
public class InputOverlayKey {
/** Time, in ms, of the shrink/expand key animation. */
private static final int ANIMTIME = 100;
private static final int ANIMATION_TIME = 100;
/** The final scale of the input keys when the key is pressed. */
private static final float ACTIVESCALE = 0.75f;
private static final float ACTIVE_SCALE = 0.75f;

/** The bits in the keystate that corresponds to this key. */
private final int targetKey;
Expand All @@ -48,10 +53,11 @@ public class InputOverlayKey {
private int presses;

/**
* @param initialText The initial text of the button
* @param targetKey The bits in the keystate that corresponds to this key
* @param ignoredKey The bits that may not be set for this key to be down
* @param activeColor The color of the button when the key is down
* Constructor.
* @param initialText the initial text of the button
* @param targetKey the bits in the keystate that corresponds to this key
* @param ignoredKey the bits that may not be set for this key to be down
* @param activeColor the color of the button when the key is down
*/
public InputOverlayKey(String initialText, int targetKey, int ignoredKey, Color activeColor) {
this.initialText = initialText;
Expand All @@ -60,9 +66,7 @@ public InputOverlayKey(String initialText, int targetKey, int ignoredKey, Color
this.activeColor = activeColor;
}

/**
* Resets all data
*/
/** Resets all data. */
public void reset() {
down = false;
downtime = 0;
Expand All @@ -71,9 +75,10 @@ public void reset() {
}

/**
* Update this key
* Updates this key by a delta interval.
* @param keystates the current key states
* @param delta framedelta
* @param countkeys whether to increment the key count
* @param delta the delta interval since the last call
*/
public void update(int keystates, boolean countkeys, int delta) {
boolean wasdown = down;
Expand All @@ -83,41 +88,41 @@ public void update(int keystates, boolean countkeys, int delta) {
presses++;
text = Integer.toString(presses);
}
if (down && downtime < ANIMTIME)
downtime = Math.min(ANIMTIME, downtime + delta);
if (down && downtime < ANIMATION_TIME)
downtime = Math.min(ANIMATION_TIME, downtime + delta);
else if (!down && downtime > 0)
downtime = Math.max(0, downtime - delta);
}

/**
* Render this key
* @param g graphics context
* @param x x position
* @param y y position
* Renders this key.
* @param g the graphics context
* @param x the x position
* @param y the y position
* @param baseImage the key image
*/
public void render(Graphics g, int x, int y, Image baseImage) {
g.pushTransform();
float scale = 1f;
if (downtime > 0) {
float progress = downtime / (float) ANIMTIME;
scale -= (1f - ACTIVESCALE) * progress;
float progress = downtime / (float) ANIMATION_TIME;
scale -= (1f - ACTIVE_SCALE) * progress;
g.scale(scale, scale);
x /= scale;
y /= scale;
}
baseImage.drawCentered(x, y, down ? activeColor : Color.white);
x -= Fonts.MEDIUMBOLD.getWidth(text) / 2;
y -= Fonts.MEDIUMBOLD.getLineHeight() / 2;
/*
// shadow
g.pushTransform();
g.scale (1.1f, 1.1f);
float shadowx = x / 1.1f - Fonts.MEDIUMBOLD.getWidth(text) * 0.05f;
float shadowy = y / 1.1f - Fonts.MEDIUMBOLD.getLineHeight() * 0.05f;
Fonts.MEDIUMBOLD.drawString(shadowx, shadowy, text, Color.black);
g.popTransform();
*/
/*
// shadow (TODO)
g.pushTransform();
g.scale(1.1f, 1.1f);
float shadowx = x / 1.1f - Fonts.MEDIUMBOLD.getWidth(text) * 0.05f;
float shadowy = y / 1.1f - Fonts.MEDIUMBOLD.getLineHeight() * 0.05f;
Fonts.MEDIUMBOLD.drawString(shadowx, shadowy, text, Color.black);
g.popTransform();
*/
Fonts.MEDIUMBOLD.drawString(x, y, text, Options.getSkin().getInputOverlayText());
g.popTransform();
}
Expand Down

0 comments on commit 481b3a1

Please sign in to comment.