mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
gui: cover scale style option for background images (#14049)
This commit is contained in:
parent
7e34363954
commit
1327fe2b99
3 changed files with 26 additions and 2 deletions
|
|
@ -82,7 +82,7 @@ public class ThemePluginImpl implements ThemePlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) {
|
if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) {
|
||||||
ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanelStyle.TILED);
|
ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanelStyle.COVER);
|
||||||
|
|
||||||
// TODO: research - is all components used? And why it make transparent?
|
// TODO: research - is all components used? And why it make transparent?
|
||||||
unsetOpaque(ui.get("splitChatAndLogs"));
|
unsetOpaque(ui.get("splitChatAndLogs"));
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,9 @@ public class ImagePanel extends JPanel {
|
||||||
case ACTUAL:
|
case ACTUAL:
|
||||||
drawActual(g);
|
drawActual(g);
|
||||||
break;
|
break;
|
||||||
|
case COVER:
|
||||||
|
drawCover(g);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,4 +102,25 @@ public class ImagePanel extends JPanel {
|
||||||
float y = (d.height - image.getHeight(null)) * alignmentY;
|
float y = (d.height - image.getHeight(null)) * alignmentY;
|
||||||
g.drawImage(image, (int) x, (int) y, this);
|
g.drawImage(image, (int) x, (int) y, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawCover(Graphics g) {
|
||||||
|
Dimension d = getSize();
|
||||||
|
int imageWidth = image.getWidth(null);
|
||||||
|
int imageHeight = image.getHeight(null);
|
||||||
|
|
||||||
|
// Calculate scale to cover the entire panel while maintaining aspect ratio
|
||||||
|
double scaleX = (double) d.width / imageWidth;
|
||||||
|
double scaleY = (double) d.height / imageHeight;
|
||||||
|
double scale = Math.max(scaleX, scaleY);
|
||||||
|
|
||||||
|
// Calculate the scaled dimensions
|
||||||
|
int scaledWidth = (int) (imageWidth * scale);
|
||||||
|
int scaledHeight = (int) (imageHeight * scale);
|
||||||
|
|
||||||
|
// Center the image
|
||||||
|
int x = (d.width - scaledWidth) / 2;
|
||||||
|
int y = (d.height - scaledHeight) / 2;
|
||||||
|
|
||||||
|
g.drawImage(image, x, y, scaledWidth, scaledHeight, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ package mage.components;
|
||||||
* Created by IGOUDT on 7-3-2017.
|
* Created by IGOUDT on 7-3-2017.
|
||||||
*/
|
*/
|
||||||
public enum ImagePanelStyle {
|
public enum ImagePanelStyle {
|
||||||
TILED, SCALED, ACTUAL
|
TILED, SCALED, ACTUAL, COVER
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue