From 967153fe879bcfce01b0798c22757a3e4965268f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Dec 2015 16:15:19 +0100 Subject: [PATCH] Factored out scaling formula into an helper method Also use a default value of 100 in case "gui.scalePercent" is not set. --- app/src/processing/app/Base.java | 5 ++--- app/src/processing/app/EditorHeader.java | 2 +- app/src/processing/app/EditorLineStatus.java | 2 +- app/src/processing/app/EditorStatus.java | 2 +- app/src/processing/app/EditorToolbar.java | 10 +++++----- app/src/processing/app/Theme.java | 19 ++++++++++++------- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 32ab81486..c018702fe 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1752,11 +1752,10 @@ public class Base { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - int scale = Theme.getInteger("gui.scalePercent"); - Font f = new Font("SansSerif", Font.PLAIN, 11 * scale / 100); + Font f = new Font("SansSerif", Font.PLAIN, Theme.scale(11)); g.setFont(f); g.setColor(Color.white); - g.drawString(BaseNoGui.VERSION_NAME_LONG, 33 * scale / 100, 20 * scale / 100); + g.drawString(BaseNoGui.VERSION_NAME_LONG, Theme.scale(33), Theme.scale(20)); } }; window.addMouseListener(new MouseAdapter() { diff --git a/app/src/processing/app/EditorHeader.java b/app/src/processing/app/EditorHeader.java index 1a54c502c..8f7402496 100644 --- a/app/src/processing/app/EditorHeader.java +++ b/app/src/processing/app/EditorHeader.java @@ -74,7 +74,7 @@ public class EditorHeader extends JComponent { static final int PIECE_WIDTH = 4; // value for the size bars, buttons, etc - static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100; + static final int GRID_SIZE = Theme.scale(33); static Image[][] pieces; diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java index 2e559162d..68f49a958 100644 --- a/app/src/processing/app/EditorLineStatus.java +++ b/app/src/processing/app/EditorLineStatus.java @@ -55,7 +55,7 @@ public class EditorLineStatus extends JComponent { background = Theme.getColor("linestatus.bgcolor"); font = Theme.getFont("linestatus.font"); foreground = Theme.getColor("linestatus.color"); - high = Theme.getInteger("linestatus.height") * Theme.getInteger("gui.scalePercent") / 100; + high = Theme.scale(Theme.getInteger("linestatus.height")); if (OSUtils.isMacOS()) { resize = Theme.getThemeImage("resize.png", this); diff --git a/app/src/processing/app/EditorStatus.java b/app/src/processing/app/EditorStatus.java index 659606bcb..4ccfbab52 100644 --- a/app/src/processing/app/EditorStatus.java +++ b/app/src/processing/app/EditorStatus.java @@ -68,7 +68,7 @@ public class EditorStatus extends JPanel { } // value for the size bars, buttons, etc - static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100; + static final int GRID_SIZE = Theme.scale(33); private final Editor editor; private final Font font; diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 1f0e371d1..b69c55a28 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -56,19 +56,19 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key /** * Width of each toolbar button. */ - private static final int BUTTON_WIDTH = 27 * Theme.getInteger("gui.scalePercent") / 100; + private static final int BUTTON_WIDTH = Theme.scale(27); /** * Height of each toolbar button. */ - private static final int BUTTON_HEIGHT = 32 * Theme.getInteger("gui.scalePercent") / 100; + private static final int BUTTON_HEIGHT = Theme.scale(32); /** * The amount of space between groups of buttons on the toolbar. */ - private static final int BUTTON_GAP = 5 * Theme.getInteger("gui.scalePercent") / 100; + private static final int BUTTON_GAP = Theme.scale(5); /** * Size of the button image being chopped up. */ - private static final int BUTTON_IMAGE_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100; + private static final int BUTTON_IMAGE_SIZE = Theme.scale(33); private static final int RUN = 0; @@ -437,7 +437,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key public Dimension getMaximumSize() { - return new Dimension(3000 * Theme.getInteger("gui.scalePercent") / 100, BUTTON_HEIGHT); + return new Dimension(Theme.scale(3000), BUTTON_HEIGHT); } diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java index 751073240..523c3150b 100644 --- a/app/src/processing/app/Theme.java +++ b/app/src/processing/app/Theme.java @@ -97,6 +97,16 @@ public class Theme { set(key, String.valueOf(value)); } + static public int getScale() { + if (get("gui.scalePercent") == null) + return 100; + return getInteger("gui.scalePercent"); + } + + static public int scale(int size) { + return size * getScale() / 100; + } + static public Color getColorCycleColor(String name, int i) { int cycleSize = getInteger(name + ".size"); name = String.format("%s.%02d", name, i % cycleSize); @@ -125,12 +135,7 @@ public class Theme { set(attr, value); font = PreferencesHelper.getFont(table, attr); } - int scale = getInteger("gui.scalePercent"); - if (scale != 100) { - font = font - .deriveFont((float) (font.getSize()) * (float) scale / (float) 100.0); - } - return font; + return font.deriveFont((float) scale(font.getSize())); } /** @@ -199,7 +204,7 @@ public class Theme { Toolkit tk = Toolkit.getDefaultToolkit(); SplitFile name = FileUtils.splitFilename(filename); - int scale = getInteger("gui.scalePercent"); + int scale = getScale(); File libFolder = Base.getContentFile("lib"); File imageFile1x = new File(libFolder, name.basename + "." + name.extension); File imageFile2x = new File(libFolder, name.basename + "@2x." + name.extension);