forked from External/mage
- reworked skip and phase buttons to use layouts instead IDE designer; - added GUI scale support skip and phase buttons (depend on dialogs font size from preferences settings);
This commit is contained in:
parent
8186b35dfb
commit
1d701df0e8
8 changed files with 274 additions and 144 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package mage.client.components;
|
||||
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
@ -12,19 +13,25 @@ import java.awt.*;
|
|||
*/
|
||||
public class KeyboundButton extends JButton {
|
||||
|
||||
private float guiScale = 1.0f;
|
||||
private final String key;
|
||||
private boolean showKey;
|
||||
private String drawingText;
|
||||
private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
|
||||
private Font keyFont;
|
||||
|
||||
private boolean tinting = false;
|
||||
|
||||
public KeyboundButton(String key, boolean showKey) {
|
||||
this.key = key;
|
||||
this.showKey = showKey;
|
||||
updateFont();
|
||||
updateDrawingText();
|
||||
}
|
||||
|
||||
private void updateFont() {
|
||||
this.keyFont = new Font(Font.SANS_SERIF, Font.BOLD, sizeMod(13));
|
||||
}
|
||||
|
||||
private void updateDrawingText() {
|
||||
if (this.showKey) {
|
||||
this.drawingText = PreferencesDialog.getCachedKeyText(key);
|
||||
|
|
@ -33,6 +40,12 @@ public class KeyboundButton extends JButton {
|
|||
}
|
||||
}
|
||||
|
||||
public void updateGuiScale(float guiScale) {
|
||||
this.guiScale = guiScale;
|
||||
updateFont();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setShowKey(boolean showKey) {
|
||||
this.showKey = showKey;
|
||||
updateDrawingText();
|
||||
|
|
@ -48,7 +61,7 @@ public class KeyboundButton extends JButton {
|
|||
|
||||
if (tinting) {
|
||||
sg.setColor(new Color(0, 0, 0, 32));
|
||||
sg.fillRoundRect(2, 2, getWidth() - 4, getHeight() - 4, 6, 6);
|
||||
sg.fillRoundRect(sizeMod(2), sizeMod(2), getWidth() - sizeMod(4), getHeight() - sizeMod(4), sizeMod(6), sizeMod(6));
|
||||
}
|
||||
sg.setColor(tinting ? Color.lightGray : Color.white);
|
||||
|
||||
|
|
@ -58,7 +71,7 @@ public class KeyboundButton extends JButton {
|
|||
int textWidth = sg.getFontMetrics(keyFont).stringWidth(this.drawingText);
|
||||
int centerX = (getWidth() - textWidth) / 2;
|
||||
|
||||
sg.drawString(this.drawingText, centerX, 28);
|
||||
sg.drawString(this.drawingText, centerX, sizeMod(28));
|
||||
}
|
||||
} finally {
|
||||
sg.dispose();
|
||||
|
|
@ -70,4 +83,12 @@ public class KeyboundButton extends JButton {
|
|||
this.tinting = tinting;
|
||||
repaint();
|
||||
}
|
||||
|
||||
private int sizeMod(int value) {
|
||||
return GUISizeHelper.guiSizeScale(value, this.guiScale);
|
||||
}
|
||||
|
||||
private float sizeMod(float value) {
|
||||
return GUISizeHelper.guiSizeScale(value, this.guiScale);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue