GUI: improved gui scale support (part of #969, #6887):

- added GUI scale support for dialog titles;
- added GUI scale support for hints tool;
- fixed broken font in chat and game logs on settings change;
- fixed wrong size of pick choice dialog in some use cases;
This commit is contained in:
Oleg Agafonov 2024-07-28 11:47:12 +04:00
parent 1578ab7946
commit 8186b35dfb
9 changed files with 56 additions and 26 deletions

View file

@ -92,9 +92,6 @@ public class ChatPanelBasic extends javax.swing.JPanel {
protected boolean startMessageDone = false;
/**
* Creates new form ChatPanel
*/
public ChatPanelBasic() {
initComponents();
txtConversation.enableHyperlinksAndCardPopups();
@ -117,7 +114,7 @@ public class ChatPanelBasic extends javax.swing.JPanel {
}
public void changeGUISize(Font font) {
txtConversation.setFont(font);
txtConversation.changeGUISize(font);
txtMessage.setFont(font);
if (jScrollPaneTxt != null) {
jScrollPaneTxt.setFont(font);

View file

@ -24,6 +24,7 @@ public class ColorPane extends MageEditorPane {
* @param color
*/
public void setExtBackgroundColor(Color color) {
// TODO: research, maybe no needs in good opaque + background settings
setBackground(new Color(0, 0, 0, 0));
JPanel jPanel = new JPanel();
jPanel.setBackground(color);
@ -32,6 +33,7 @@ public class ColorPane extends MageEditorPane {
}
public void setExtBackgroundColor(BackgroundPainter backgroundPainter) {
// TODO: research, maybe no needs in good opaque + background settings
setBackground(new Color(0, 0, 0, 0));
JXPanel jPanel = new JXPanel();
jPanel.setBackgroundPainter(backgroundPainter);
@ -46,6 +48,7 @@ public class ColorPane extends MageEditorPane {
*/
@Override
public void paintChildren(Graphics g) {
// TODO: research, maybe no needs in good opaque + background settings
super.paintComponent(g);
}
@ -56,6 +59,7 @@ public class ColorPane extends MageEditorPane {
*/
@Override
public void paintComponent(Graphics g) {
// TODO: research, maybe no needs in good opaque + background settings
super.paintChildren(g);
}
}

View file

@ -17,7 +17,10 @@ import mage.view.PlaneView;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.text.html.CSS;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -52,6 +55,19 @@ public class MageEditorPane extends JEditorPane {
// improved style: browser's url style with underline on mouse over and hand cursor
kit.getStyleSheet().addRule(" a { text-decoration: none; } ");
changeGUISize(this.getFont());
}
public void changeGUISize(Font font) {
this.setFont(font);
// workaround to change editor's font at runtime
String bodyRule = "body { "
+ " font-family: " + font.getFamily() + "; "
+ " font-size: " + font.getSize() + "pt; "
+ "}";
kit.getStyleSheet().addRule(bodyRule);
}
/**
@ -264,6 +280,4 @@ public class MageEditorPane extends JEditorPane {
hyperlinkEnabled = true;
addHyperlinkHandlers();
}
}

View file

@ -517,7 +517,15 @@ public class CardHintsHelperDialog extends MageDialog implements MageDesktopIcon
}
private void setGUISize(Font font) {
this.hintsView.setFont(font);
this.comboFilterBy.setFont(font);
this.comboGroupBy.setFont(font);
this.search.setFont(font);
this.searchClear.setFont(font);
// workaround to auto-size button
// TODO: add support of big/HQ button image
this.searchClear.setPreferredSize(GUISizeHelper.dialogGuiScaleSize(this.searchClear.getPreferredSize()));
this.hintsView.changeGUISize(font);
this.scrollView.setFont(font);
this.scrollView.getVerticalScrollBar().setPreferredSize(new Dimension(GUISizeHelper.scrollBarSize, 0));
this.scrollView.getHorizontalScrollBar().setPreferredSize(new Dimension(0, GUISizeHelper.scrollBarSize));

View file

@ -52,11 +52,7 @@ public class PickChoiceDialog extends MageDialog {
this.textSubMessage.enableTextLabelMode();
// pick choice shared in multiple dialogs, so modify window size only one time
// TODO: implement global window size settings and runtime theme support by gui scale logic (interface like MageThemeSupported:onSizeChanged,onThemeChanged,etc)
float guiScale = GUISizeHelper.gameFeedbackPanelFont.getSize2D() / GUISizeHelper.gameDialogAreaDefaultFontSize;
int newWidth = GUISizeHelper.guiSizeScale(this.getSize().width, guiScale);
int newHeight = GUISizeHelper.guiSizeScale(this.getSize().height, guiScale);
this.setSize(newWidth, newHeight);
this.setSize(GUISizeHelper.dialogGuiScaleSize(this.getSize()));
this.listChoices.setModel(new DefaultListModel<KeyValueItem>());
this.setModal(true);

View file

@ -436,6 +436,7 @@ public final class GamePanel extends javax.swing.JPanel {
handContainer.setPreferredSize(newDimension);
handContainer.setMaximumSize(newDimension);
// stack
newDimension = new Dimension(
newStackWidth,
MageActionCallback.getHandOrStackMargins(Zone.STACK).getHeight() + GUISizeHelper.handCardDimension.height + GUISizeHelper.scrollBarSize
@ -446,6 +447,11 @@ public final class GamePanel extends javax.swing.JPanel {
stackObjects.setMaximumSize(newDimension);
stackObjects.changeGUISize(); // must call to cards fit
// game logs and chat
userChatPanel.changeGUISize(GUISizeHelper.chatFont);
gameChatPanel.changeGUISize(GUISizeHelper.chatFont);
// skip buttons
newDimension = new Dimension(newStackWidth, (int) pnlShortCuts.getPreferredSize().getHeight());
pnlShortCuts.setPreferredSize(newDimension);
pnlShortCuts.setMinimumSize(newDimension);
@ -1401,6 +1407,7 @@ public final class GamePanel extends javax.swing.JPanel {
// open new
CardHintsHelperDialog newDialog = new CardHintsHelperDialog();
newDialog.setSize(GUISizeHelper.dialogGuiScaleSize(newDialog.getSize()));
newDialog.setGameData(this.lastGameData.game, this.gameId, this.bigCard);
cardHintsWindows.put(code + UUID.randomUUID(), newDialog);
MageFrame.getDesktop().add(newDialog, JLayeredPane.PALETTE_LAYER);

View file

@ -11,8 +11,6 @@ import mage.view.PlayerView;
import mage.view.UserRequestMessage;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.*;
@ -77,10 +75,6 @@ public class PlayAreaPanel extends javax.swing.JPanel {
battlefieldPanel.cleanUp();
playerPanel.cleanUp();
for (ActionListener al : btnCheat.getActionListeners()) {
btnCheat.removeActionListener(al);
}
// Taken form : https://community.oracle.com/thread/2183145
// removed the internal focus of a popupMenu data to allow GC before another popup menu is selected
for (ChangeListener listener : MenuSelectionManager.defaultManager().getChangeListeners()) {
@ -514,7 +508,6 @@ public class PlayAreaPanel extends javax.swing.JPanel {
this.playerId = player.getPlayerId();
this.playerName = player.getName();
this.isMe = player.getControlled();
this.btnCheat.setVisible(SessionHandler.isTestMode());
}
public final void update(GameView game, PlayerView player, Set<UUID> possibleTargets) {
@ -536,17 +529,14 @@ public class PlayAreaPanel extends javax.swing.JPanel {
private void initComponents() {
setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0, 0)));
playerPanel = new PlayerPanelExt(GUISizeHelper.playerPanelGuiScale);
btnCheat = new javax.swing.JButton(); // TODO: not used? Delete
battlefieldPanel = new mage.client.game.BattlefieldPanel();
battlefieldPanel.setTopPanelBattlefield(options.topRow);
battlefieldPanel.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
btnCheat.setText("Cheat");
btnCheat.addActionListener(evt -> btnCheatActionPerformed(evt));
this.setLayout(new BorderLayout());
this.add(playerPanel, BorderLayout.WEST);
this.add(battlefieldPanel, BorderLayout.CENTER);
this.add(Box.createRigidArea(new Dimension(0, 10)), BorderLayout.SOUTH); // bottom free space
}
private void btnCheatActionPerformed(java.awt.event.ActionEvent evt) {
@ -577,8 +567,6 @@ public class PlayAreaPanel extends javax.swing.JPanel {
}
private mage.client.game.BattlefieldPanel battlefieldPanel;
private javax.swing.JButton btnCheat;
//private javax.swing.JScrollPane jScrollPane1;
private PlayerPanelExt playerPanel;
}

View file

@ -125,6 +125,10 @@ public class PlayersChatPanel extends javax.swing.JPanel {
jTabbedPaneText.setFont(GUISizeHelper.tableFont);
jSplitPane1.setDividerSize(GUISizeHelper.dividerBarSize);
// chats and logs
colorPaneSystem.changeGUISize(GUISizeHelper.chatFont);
jScrollPaneTalk.changeGUISize(GUISizeHelper.chatFont);
}
public void setSplitDividerLocation(int location) {

View file

@ -104,6 +104,10 @@ public final class GUISizeHelper {
// for auto-sizeable dialogs - use scale logic (example: player panel, pick choice, pick ability, etc)
dialogGuiScale = dialogFontSize / 14.0f;
// app - frame/window title
// nimbus's LaF limited to static title size, so font can't be too big (related code in SynthInternalFrameTitlePane, BasicInternalFrameTitlePane)
UIManager.put("InternalFrame.titleFont", dialogFont.deriveFont(Font.BOLD, Math.min(17, 0.8f * dialogFont.getSize())));
// app - tables
tableFont = new java.awt.Font("Arial", 0, dialogFontSize);
tableRowHeight = dialogFontSize + 4;
@ -233,6 +237,14 @@ public final class GUISizeHelper {
return value * scaleMod;
}
public static int dialogGuiScaleSize(int value) {
return guiSizeScale(value, dialogGuiScale);
}
public static Dimension dialogGuiScaleSize(Dimension dimension) {
return new Dimension(dialogGuiScaleSize(dimension.width), dialogGuiScaleSize(dimension.height));
}
public static String textToHtmlWithSize(String text, Font font) {
return textToHtmlWithSize(text, font.getSize());
}