Modification temporaire - Correction du bug de taille des boutons
This commit is contained in:
@@ -2,9 +2,11 @@ package fr.monkhanny.dorfromantik.controller;
|
|||||||
|
|
||||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
import fr.monkhanny.dorfromantik.Options;
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
|
import fr.monkhanny.dorfromantik.gui.ButtonHoverAnimator;
|
||||||
|
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
|
||||||
public class MainMenuResizeHandler extends ComponentAdapter {
|
public class MainMenuResizeHandler extends ComponentAdapter {
|
||||||
|
|
||||||
@@ -16,11 +18,14 @@ public class MainMenuResizeHandler extends ComponentAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
|
int mainMenuWidth = mainMenu.getWidth();
|
||||||
|
|
||||||
// Ajuster la taille de la police du titre en fonction de la taille de la fenêtre
|
// Ajuster la taille de la police du titre en fonction de la taille de la fenêtre
|
||||||
float newFontSize = Options.BASE_TITLE_FONT_SIZE * (mainMenu.getWidth() / 900f);
|
float newFontSize = Options.BASE_TITLE_FONT_SIZE * (mainMenuWidth / 900f);
|
||||||
mainMenu.getTitleLabel().updateTitleFont(newFontSize);
|
mainMenu.getTitleLabel().updateTitleFont(newFontSize);
|
||||||
|
|
||||||
// Mettre à jour les polices des boutons
|
// Mettre à jour les polices des boutons
|
||||||
mainMenu.getButtonPanel().updateButtonFonts(mainMenu.getWidth());
|
mainMenu.getButtonPanel().updateButtonFonts(mainMenuWidth);
|
||||||
|
ButtonHoverAnimator.updateOriginalFont(mainMenuWidth / 30f); // On passe la nouvelle taille de police pour chaque bouton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ public class ButtonHoverAnimator {
|
|||||||
|
|
||||||
private final JButton button;
|
private final JButton button;
|
||||||
private final Color originalColor;
|
private final Color originalColor;
|
||||||
private final Font originalFont;
|
private static Font originalFont;
|
||||||
private Timer animationTimer;
|
private Timer animationTimer;
|
||||||
private float currentScale = 1.0f;
|
private float currentScale = 1.0f;
|
||||||
|
|
||||||
@@ -30,4 +30,9 @@ public class ButtonHoverAnimator {
|
|||||||
animationTimer = new Timer(Options.ANIMATION_DELAY, new ButtonHoverAnimationListener(entering, button, originalColor, originalFont));
|
animationTimer = new Timer(Options.ANIMATION_DELAY, new ButtonHoverAnimationListener(entering, button, originalColor, originalFont));
|
||||||
animationTimer.start();
|
animationTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateOriginalFont(float newFontSize) {
|
||||||
|
originalFont = originalFont.deriveFont(newFontSize);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,9 @@ import fr.monkhanny.dorfromantik.controller.MainMenuMouseController;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
public class ButtonPanel extends JPanel {
|
public class ButtonPanel extends JPanel {
|
||||||
|
|
||||||
@@ -68,6 +71,10 @@ public class ButtonPanel extends JPanel {
|
|||||||
return exitButton;
|
return exitButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<JButton> getButtons() {
|
||||||
|
return Arrays.asList(newGameButton, continueGameButton, howToPlayButton, settingsButton, exitButton);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateButtonFonts(int windowWidth) {
|
public void updateButtonFonts(int windowWidth) {
|
||||||
// Mettre à jour la police des boutons avec la taille ajustée
|
// Mettre à jour la police des boutons avec la taille ajustée
|
||||||
float newFontSize = windowWidth / 30f;
|
float newFontSize = windowWidth / 30f;
|
||||||
|
Reference in New Issue
Block a user