forked from External/mage
GUI, preferences: improved theme switch at runtime (fixed skip and step buttons update);
This commit is contained in:
parent
6c0f7ebb90
commit
9864cdd46c
5 changed files with 186 additions and 155 deletions
|
|
@ -353,6 +353,10 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
this.isSelected = !this.isSelected;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
|
@ -365,13 +369,17 @@ public class HoverButton extends JPanel implements MouseListener {
|
|||
this.drawSet = true;
|
||||
}
|
||||
|
||||
public void update(String text, Image image) {
|
||||
update(text, image, this.hoverImage, this.selectedImage, this.disabledImage, this.imageSize);
|
||||
}
|
||||
|
||||
public void update(String text, Image image, Image hover, Image selected, Image disabled, Rectangle size) {
|
||||
this.text = text;
|
||||
this.image = image;
|
||||
this.hoverImage = hover;
|
||||
this.selectedImage = selected;
|
||||
this.disabledImage = disabled;
|
||||
this.imageSize = size;
|
||||
this.text = text;
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,43 @@
|
|||
package mage.client.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.JButton;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* GUI component: button with hotkey info on it
|
||||
*
|
||||
* @author Campbell Suter <znix@znix.xyz>
|
||||
* @author Campbell Suter <znix@znix.xyz>, JayDi85
|
||||
*/
|
||||
public class KeyboundButton extends JButton {
|
||||
|
||||
private final String text;
|
||||
private final String key;
|
||||
private boolean showKey;
|
||||
private String drawingText;
|
||||
private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
|
||||
|
||||
private boolean tinting = false;
|
||||
|
||||
public KeyboundButton(String key, boolean drawText) {
|
||||
if (drawText) {
|
||||
text = PreferencesDialog.getCachedKeyText(key);
|
||||
public KeyboundButton(String key, boolean showKey) {
|
||||
this.key = key;
|
||||
this.showKey = showKey;
|
||||
updateDrawingText();
|
||||
}
|
||||
|
||||
private void updateDrawingText() {
|
||||
if (this.showKey) {
|
||||
this.drawingText = PreferencesDialog.getCachedKeyText(key);
|
||||
} else {
|
||||
text = "";
|
||||
this.drawingText = "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setShowKey(boolean showKey) {
|
||||
this.showKey = showKey;
|
||||
updateDrawingText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
if (ui != null && g != null) {
|
||||
|
|
@ -34,17 +47,17 @@ 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(2, 2, getWidth() - 4, getHeight() - 4, 6, 6);
|
||||
}
|
||||
sg.setColor(tinting ? Color.lightGray : Color.white);
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
if (!this.drawingText.isEmpty()) {
|
||||
sg.setFont(keyFont);
|
||||
|
||||
int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
|
||||
int textWidth = sg.getFontMetrics(keyFont).stringWidth(this.drawingText);
|
||||
int centerX = (getWidth() - textWidth) / 2;
|
||||
|
||||
sg.drawString(text, centerX, 28);
|
||||
sg.drawString(this.drawingText, centerX, 28);
|
||||
}
|
||||
} finally {
|
||||
sg.dispose();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue