Skip to content

Commit

Permalink
reimplement default non-bold font
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Dec 11, 2023
1 parent e7c45a8 commit b58481a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public Theme(LookAndFeel lookAndFeel) {
public final Fonts fonts = new Fonts();

public static class Fonts extends ReflectiveConfig.Section {
@SerializedName("default")
public final TrackedValue<SerializableFont> defaultFont = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD)));
@SerializedName("default_bold")
public final TrackedValue<SerializableFont> defaultBold = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD)));
@SerializedName("default_normal")
public final TrackedValue<SerializableFont> defaultNormal = this.value(new SerializableFont(Font.decode(Font.DIALOG)));
@SerializedName("small")
public final TrackedValue<SerializableFont> small = this.value(new SerializableFont(Font.decode(Font.DIALOG)));
@SerializedName("editor")
Expand Down Expand Up @@ -63,6 +65,9 @@ public ComplexConfigValue copy() {
}
}

/**
* Default values are for light themes.
*/
public static class Colors extends ReflectiveConfig.Section {
@SerializedName("line_numbers_foreground")
public final TrackedValue<SerializableColor> lineNumbersForeground = this.value(new SerializableColor(0xFF333300));
Expand All @@ -76,7 +81,7 @@ public static class Colors extends ReflectiveConfig.Section {
public final TrackedValue<SerializableColor> obfuscatedOutline = this.value(new SerializableColor(0xFFA05050));

@SerializedName("proposed")
public final TrackedValue<SerializableColor> proposed = this.value(new SerializableColor(0xFF000000));
public final TrackedValue<SerializableColor> proposed = this.value(new SerializableColor(0x27000000));
@SerializedName("proposed_outline")
public final TrackedValue<SerializableColor> proposedOutline = this.value(new SerializableColor(0xBF000000));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.quiltmc.enigma.gui.config.theme;

import org.quiltmc.enigma.gui.config.Config;
import org.quiltmc.enigma.gui.event.ThemeChangeListener;
import org.quiltmc.enigma.gui.highlight.BoxHighlightPainter;
import org.quiltmc.enigma.gui.util.ScaleUtil;
import org.quiltmc.enigma.api.source.TokenType;
import org.quiltmc.syntaxpain.JavaSyntaxKit;

import java.awt.Font;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.swing.JEditorPane;
import javax.swing.UIManager;

Expand All @@ -31,47 +28,48 @@ public static void setupTheme() {

private static void setFonts() {
Font small = Config.currentFonts().small.value();
Font bold = Config.currentFonts().defaultFont.value();
Font bold = Config.currentFonts().defaultBold.value();
Font normal = Config.currentFonts().defaultNormal.value();

UIManager.put("CheckBox.font", bold);
UIManager.put("CheckBoxMenuItem.font", bold);
UIManager.put("CheckBoxMenuItem.acceleratorFont", small);
UIManager.put("ColorChooser.font", bold); //
UIManager.put("ColorChooser.font", normal);
UIManager.put("ComboBox.font", bold);
UIManager.put("DesktopIcon.font", bold);
UIManager.put("EditorPane.font", bold); //
UIManager.put("EditorPane.font", normal);
UIManager.put("InternalFrame.titleFont", bold);
UIManager.put("FormattedTextField.font", bold); //
UIManager.put("FormattedTextField.font", normal);
UIManager.put("Label.font", bold);
UIManager.put("List.font", bold);
UIManager.put("Menu.acceleratorFont", small);
UIManager.put("Menu.font", bold);
UIManager.put("MenuBar.font", bold);
UIManager.put("MenuItem.acceleratorFont", small);
UIManager.put("MenuItem.font", bold);
UIManager.put("OptionPane.font", bold); //
UIManager.put("Panel.font", bold); //
UIManager.put("PasswordField.font", bold); //
UIManager.put("OptionPane.font", normal);
UIManager.put("Panel.font", normal);
UIManager.put("PasswordField.font", normal);
UIManager.put("PopupMenu.font", bold);
UIManager.put("ProgressBar.font", bold);
UIManager.put("RadioButton.font", bold);
UIManager.put("RadioButtonMenuItem.acceleratorFont", small);
UIManager.put("RadioButtonMenuItem.font", bold);
UIManager.put("ScrollPane.font", bold); //
UIManager.put("ScrollPane.font", normal);
UIManager.put("Slider.font", bold);
UIManager.put("Spinner.font", bold);
UIManager.put("TabbedPane.font", bold);
UIManager.put("Table.font", bold); //
UIManager.put("TableHeader.font", bold); //
UIManager.put("TextArea.font", bold); //
UIManager.put("TextField.font", bold); //
UIManager.put("TextPane.font", bold); //
UIManager.put("Table.font", normal);
UIManager.put("TableHeader.font", normal);
UIManager.put("TextArea.font", normal);
UIManager.put("TextField.font", normal);
UIManager.put("TextPane.font", normal);
UIManager.put("TitledBorder.font", bold);
UIManager.put("ToggleButton.font", bold);
UIManager.put("ToolBar.font", bold);
UIManager.put("ToolTip.font", bold); //
UIManager.put("Tree.font", bold); //
UIManager.put("Viewport.font", bold); //
UIManager.put("ToolTip.font", normal);
UIManager.put("Tree.font", normal);
UIManager.put("Viewport.font", normal);
UIManager.put("Button.font", bold);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,42 @@
import org.quiltmc.enigma.util.I18n;
import org.drjekyll.fontchooser.FontChooser;

import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JList;

public class FontDialog extends JDialog {
private static final List<TrackedValue<Theme.Fonts.SerializableFont>> FONTS = List.of(
Config.currentFonts().defaultFont,
Config.currentFonts().defaultNormal,
Config.currentFonts().defaultBold,
Config.currentFonts().small,
Config.currentFonts().editor
);

private static final List<String> CATEGORY_TEXTS = List.of(
"fonts.cat.default",
"fonts.cat.default_normal",
"fonts.cat.default_bold",
"fonts.cat.small",
"fonts.cat.editor"
);

private final JList<String> entries = new JList<>(CATEGORY_TEXTS.stream().map(I18n::translate).toArray(String[]::new));
private final FontChooser chooser = new FontChooser(Font.decode(Font.DIALOG));
private final JCheckBox customCheckBox = new JCheckBox(I18n.translate("fonts.use_custom"));
private final Theme.Fonts.SerializableFont[] fontValues = new Theme.Fonts.SerializableFont[]{FONTS.get(0).value(), FONTS.get(1).value(), FONTS.get(2).value()};
private final Theme.Fonts.SerializableFont[] fontValues = FONTS.stream().map(TrackedValue::value).toArray(Theme.Fonts.SerializableFont[]::new);

public FontDialog(Frame owner) {
super(owner, "Fonts", true);

this.customCheckBox.setSelected(Config.main().useCustomFonts.value());

this.entries.setPreferredSize(ScaleUtil.getDimension(100, 0));

this.entries.addListSelectionListener(e -> this.categoryChanged());
this.chooser.addChangeListener(e -> this.selectedFontChanged());
this.customCheckBox.addActionListener(e -> this.customFontsClicked());
JButton okButton = new JButton(I18n.translate("prompt.ok"));
okButton.addActionListener(e -> this.apply());
JButton cancelButton = new JButton(I18n.translate("prompt.cancel"));
Expand All @@ -59,24 +55,16 @@ public FontDialog(Frame owner) {
GridBagConstraintsBuilder cb = GridBagConstraintsBuilder.create()
.insets(2);

contentPane.add(this.entries, cb.pos(0, 0).weight(0.0, 1.0).fill(GridBagConstraints.BOTH).build());
contentPane.add(this.entries, cb.pos(0, 0).weight(0.1, 1.0).fill(GridBagConstraints.BOTH).build());
contentPane.add(this.chooser, cb.pos(1, 0).weight(1.0, 1.0).fill(GridBagConstraints.BOTH).size(2, 1).build());
contentPane.add(this.customCheckBox, cb.pos(0, 1).anchor(GridBagConstraints.WEST).size(2, 1).build());
contentPane.add(okButton, cb.pos(1, 1).anchor(GridBagConstraints.EAST).weight(1.0, 0.0).build());
contentPane.add(cancelButton, cb.pos(2, 1).anchor(GridBagConstraints.EAST).weight(0.0, 0.0).build());

this.updateUiState();

this.setSize(ScaleUtil.getDimension(640, 360));
this.setLocationRelativeTo(owner);
}

private void customFontsClicked() {
this.updateUiState();
}

private void categoryChanged() {
this.updateUiState();
int selectedIndex = this.entries.getSelectedIndex();
if (selectedIndex != -1) {
this.chooser.setSelectedFont(this.fontValues[selectedIndex]);
Expand All @@ -90,17 +78,11 @@ private void selectedFontChanged() {
}
}

private void updateUiState() {
recursiveSetEnabled(this.chooser, this.entries.getSelectedIndex() != -1 && this.customCheckBox.isSelected());
this.entries.setEnabled(this.customCheckBox.isSelected());
}

private void apply() {
for (int i = 0; i < FONTS.size(); i++) {
FONTS.get(i).setValue(this.fontValues[i], true);
}

Config.main().useCustomFonts.setValue(this.customCheckBox.isSelected(), true);
ChangeDialog.show(this);
this.dispose();
}
Expand All @@ -113,14 +95,4 @@ public static void display(Frame parent) {
FontDialog d = new FontDialog(parent);
d.setVisible(true);
}

private static void recursiveSetEnabled(Component self, boolean enabled) {
if (self instanceof Container container) {
for (Component component : container.getComponents()) {
recursiveSetEnabled(component, enabled);
}

self.setEnabled(enabled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void paint(Graphics g) {

// setup text
String translatedText = this.textSupplier.get();
Font font = Config.currentFonts().defaultFont.value();
Font font = Config.currentFonts().defaultNormal.value();
if (Config.activeLookAndFeel.equals(LookAndFeel.SYSTEM)) {
font = font.deriveFont(Font.BOLD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static void setScaleFactor(float scaleFactor) {
float oldScale = Config.main().scaleFactor.value();
float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f);
Config.main().scaleFactor.setValue(clamped, true);
rescaleFontInConfig(Config.currentFonts().defaultFont, oldScale);
rescaleFontInConfig(Config.currentFonts().defaultBold, oldScale);
rescaleFontInConfig(Config.currentFonts().defaultNormal, oldScale);
rescaleFontInConfig(Config.currentFonts().small, oldScale);
rescaleFontInConfig(Config.currentFonts().editor, oldScale);
listeners.forEach(l -> l.onScaleChanged(clamped, oldScale));
Expand Down
2 changes: 0 additions & 2 deletions enigma/src/main/resources/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
"editor.decompile_error": "Ein Fehler ist während des Dekompilierens aufgetreten.",
"editor.remap_error": "Ein Fehler ist während des Remappens aufgetreten.",

"fonts.cat.default": "Standard",
"fonts.cat.small": "Klein",
"fonts.cat.editor": "Editor",
"fonts.use_custom": "Benutzerdefinierte Schriftarten verwenden",

"prompt.ok": "OK",
"prompt.cancel": "Abbrechen",
Expand Down
4 changes: 2 additions & 2 deletions enigma/src/main/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@
"javadocs.edit": "Edit Javadocs",
"javadocs.instruction": "Edit javadocs here.",

"fonts.cat.default": "Default",
"fonts.cat.default_normal": "Default (normal)",
"fonts.cat.default_bold": "Default (bold)",
"fonts.cat.small": "Small",
"fonts.cat.editor": "Editor",
"fonts.use_custom": "Use Custom Fonts",

"prompt.ok": "OK",
"prompt.cancel": "Cancel",
Expand Down
2 changes: 0 additions & 2 deletions enigma/src/main/resources/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@
"javadocs.edit": "Éditer les Javadocs",
"javadocs.instruction": "Éditer les Javadocs ici.",

"fonts.cat.default": "Par défaut",
"fonts.cat.small": "Petit",
"fonts.cat.editor": "Éditeur",
"fonts.use_custom": "Utiliser des polices personnalisées",

"prompt.ok": "OK",
"prompt.cancel": "Annuler",
Expand Down
2 changes: 0 additions & 2 deletions enigma/src/main/resources/lang/ja_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@
"javadocs.edit": "Javadocを編集",
"javadocs.instruction": "このJavadocを編集",

"fonts.cat.default": "デフォルト",
"fonts.cat.small": "スモール",
"fonts.cat.editor": "エディタ",
"fonts.use_custom": "カスタムフォントを使う",

"prompt.ok": "OK",
"prompt.cancel": "キャンセル",
Expand Down

0 comments on commit b58481a

Please sign in to comment.