Created GuiReplayManager to allow users to manage their assets. Created BoundingUtils class to provide a simple method to fit an image into given bounds. This implementation fixes https://trello.com/c/WTnicWkJ/
26 lines
617 B
Java
26 lines
617 B
Java
package eu.crushedpixel.replaymod.utils;
|
|
|
|
import org.lwjgl.util.Dimension;
|
|
|
|
public class BoundingUtils {
|
|
|
|
public static Dimension fitIntoBounds(Dimension toFit, Dimension bounds) {
|
|
int width = toFit.getWidth();
|
|
int height = toFit.getHeight();
|
|
|
|
float w = (float)width/bounds.getWidth();
|
|
float h = (float)height/bounds.getHeight();
|
|
|
|
if(w > h) {
|
|
height = (int)(height/w);
|
|
width = (int)(width/w);
|
|
} else {
|
|
height = (int)(height/h);
|
|
width = (int)(width/h);
|
|
}
|
|
|
|
return new Dimension(width, height);
|
|
}
|
|
|
|
}
|