allow custom scale overrides on menubuttons
This commit is contained in:
parent
db73fc9e14
commit
474b40750e
|
@ -98,6 +98,9 @@ public class MenuButton {
|
||||||
/** The default max rotation angle of the button. */
|
/** The default max rotation angle of the button. */
|
||||||
private static final float DEFAULT_ANGLE_MAX = 30f;
|
private static final float DEFAULT_ANGLE_MAX = 30f;
|
||||||
|
|
||||||
|
/** The current scale of the drawn button */
|
||||||
|
private float currentScale = 1f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new button from an Image.
|
* Creates a new button from an Image.
|
||||||
* @param img the image
|
* @param img the image
|
||||||
|
@ -166,6 +169,11 @@ public class MenuButton {
|
||||||
*/
|
*/
|
||||||
public float getY() { return y; }
|
public float getY() { return y; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current scale.
|
||||||
|
*/
|
||||||
|
public float getCurrentScale() { return currentScale; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets text to draw in the middle of the button.
|
* Sets text to draw in the middle of the button.
|
||||||
* @param text the text to draw
|
* @param text the text to draw
|
||||||
|
@ -191,14 +199,21 @@ public class MenuButton {
|
||||||
/**
|
/**
|
||||||
* Draws the button.
|
* Draws the button.
|
||||||
*/
|
*/
|
||||||
public void draw() { draw(Color.white); }
|
public void draw() { draw(Color.white, 1f); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the button with a color filter.
|
||||||
|
* @param filter the color to filter with when drawing
|
||||||
|
*/
|
||||||
|
public void draw(Color filter) { draw(filter, 1f); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw the button with a color filter.
|
* Draw the button with a color filter.
|
||||||
* @param filter the color to filter with when drawing
|
* @param filter the color to filter with when drawing
|
||||||
|
* @param scaleOverride the scale to use when drawing, works only for normal images
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void draw(Color filter) {
|
public void draw(Color filter, float scaleOverride) {
|
||||||
// animations: get current frame
|
// animations: get current frame
|
||||||
Image image = this.img;
|
Image image = this.img;
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
|
@ -208,6 +223,14 @@ public class MenuButton {
|
||||||
|
|
||||||
// normal images
|
// normal images
|
||||||
if (imgL == null) {
|
if (imgL == null) {
|
||||||
|
float scalePosModX = 0;
|
||||||
|
float scalePosModY = 0;
|
||||||
|
if (scaleOverride != 1f) {
|
||||||
|
image = image.getScaledCopy(scaleOverride);
|
||||||
|
scalePosModX = image.getWidth() / 2 - xRadius;
|
||||||
|
scalePosModY = image.getHeight() / 2 - yRadius;
|
||||||
|
}
|
||||||
|
currentScale = scaleOverride;
|
||||||
if (hoverEffect == 0)
|
if (hoverEffect == 0)
|
||||||
image.draw(x - xRadius, y - yRadius, filter);
|
image.draw(x - xRadius, y - yRadius, filter);
|
||||||
else {
|
else {
|
||||||
|
@ -217,13 +240,16 @@ public class MenuButton {
|
||||||
if (scale.getValue() != 1f) {
|
if (scale.getValue() != 1f) {
|
||||||
image = image.getScaledCopy(scale.getValue());
|
image = image.getScaledCopy(scale.getValue());
|
||||||
image.setAlpha(oldAlpha);
|
image.setAlpha(oldAlpha);
|
||||||
|
scalePosModX = image.getWidth() / 2 - xRadius;
|
||||||
|
scalePosModY = image.getHeight() / 2 - yRadius;
|
||||||
|
currentScale *= scale.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((hoverEffect & EFFECT_FADE) > 0)
|
if ((hoverEffect & EFFECT_FADE) > 0)
|
||||||
image.setAlpha(alpha.getValue());
|
image.setAlpha(alpha.getValue());
|
||||||
if ((hoverEffect & EFFECT_ROTATE) > 0)
|
if ((hoverEffect & EFFECT_ROTATE) > 0)
|
||||||
image.setRotation(angle.getValue());
|
image.setRotation(angle.getValue());
|
||||||
image.draw(x - xRadius, y - yRadius, filter);
|
image.draw(x - xRadius - scalePosModX, y - yRadius - scalePosModY, filter);
|
||||||
if (image == this.img) {
|
if (image == this.img) {
|
||||||
image.setAlpha(oldAlpha);
|
image.setAlpha(oldAlpha);
|
||||||
image.setRotation(oldAngle);
|
image.setRotation(oldAngle);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user