From 2987ff5b5f67ef92790ceebfbf32663ed397cb74 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sun, 15 Mar 2015 15:12:40 -0700 Subject: [PATCH 1/2] Add scaling for themed fonts and graphics (hires displays) --- app/src/processing/app/Base.java | 21 ++++++++++++++++---- app/src/processing/app/EditorLineStatus.java | 2 +- app/src/processing/app/EditorToolbar.java | 10 +++++----- app/src/processing/app/Preferences.java | 2 +- app/src/processing/app/Theme.java | 4 ++++ build/shared/lib/theme/theme.txt | 3 +++ 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d136277a58f..bea16c7cb0f 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -99,8 +99,6 @@ static public void main(String args[]) throws Exception { BaseNoGui.initParameters(args); - System.setProperty("swing.aatext", Preferences.get("editor.antialias", "true")); - BaseNoGui.initVersion(); // if (System.getProperty("mrj.version") != null) { @@ -149,6 +147,7 @@ static public void main(String args[]) throws Exception { // setup the theme coloring fun Theme.init(); + System.setProperty("swing.aatext", Preferences.get("editor.antialias", "true")); // Set the look and feel before opening the window try { @@ -1525,9 +1524,11 @@ public void paint(Graphics g) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - g.setFont(new Font("SansSerif", Font.PLAIN, 11)); + int scale = Theme.getInteger("gui.scalePercent"); + Font f = new Font("SansSerif", Font.PLAIN, 11 * scale / 100); + g.setFont(f); g.setColor(Color.white); - g.drawString(BaseNoGui.VERSION_NAME, 50, 30); + g.drawString(BaseNoGui.VERSION_NAME, 50 * scale / 100, 30 * scale / 100); } }; window.addMouseListener(new MouseAdapter() { @@ -2176,6 +2177,9 @@ static public Image getLibImage(String name, Component who) { Image image = null; Toolkit tk = Toolkit.getDefaultToolkit(); + int scale = Theme.getInteger("gui.scalePercent"); + // TODO: create high-res enlarged copies and load those if + // the scale is more than 125% File imageLocation = new File(getContentFile("lib"), name); image = tk.getImage(imageLocation.getAbsolutePath()); MediaTracker tracker = new MediaTracker(who); @@ -2183,6 +2187,15 @@ static public Image getLibImage(String name, Component who) { try { tracker.waitForAll(); } catch (InterruptedException e) { } + if (scale != 100) { + int width = image.getWidth(null) * scale / 100; + int height = image.getHeight(null) * scale / 100; + image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH); + tracker.addImage(image, 1); + try { + tracker.waitForAll(); + } catch (InterruptedException e) { } + } return image; } diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java index 8420ddd4c20..a8277a4faf0 100644 --- a/app/src/processing/app/EditorLineStatus.java +++ b/app/src/processing/app/EditorLineStatus.java @@ -62,7 +62,7 @@ public EditorLineStatus(JEditTextArea textarea) { background = Theme.getColor("linestatus.bgcolor"); font = Theme.getFont("linestatus.font"); foreground = Theme.getColor("linestatus.color"); - high = Theme.getInteger("linestatus.height"); + high = Theme.getInteger("linestatus.height") * Theme.getInteger("gui.scalePercent") / 100; if (OSUtils.isMacOS()) { resize = Base.getThemeImage("resize.gif", this); diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index e33789b36ea..e5c702c3f6f 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -48,13 +48,13 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key static final int BUTTON_COUNT = title.length; /** Width of each toolbar button. */ - static final int BUTTON_WIDTH = 27; + static final int BUTTON_WIDTH = 27 * Theme.getInteger("gui.scalePercent") / 100; /** Height of each toolbar button. */ - static final int BUTTON_HEIGHT = 32; + static final int BUTTON_HEIGHT = 32 * Theme.getInteger("gui.scalePercent") / 100; /** The amount of space between groups of buttons on the toolbar. */ - static final int BUTTON_GAP = 5; + static final int BUTTON_GAP = 5 * Theme.getInteger("gui.scalePercent") / 100; /** Size of the button image being chopped up. */ - static final int BUTTON_IMAGE_SIZE = 33; + static final int BUTTON_IMAGE_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100; static final int RUN = 0; @@ -393,7 +393,7 @@ public Dimension getMinimumSize() { public Dimension getMaximumSize() { - return new Dimension(3000, BUTTON_HEIGHT); + return new Dimension(3000 * Theme.getInteger("gui.scalePercent") / 100, BUTTON_HEIGHT); } diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index c0c1e3160c6..5c27aab2cbf 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -205,7 +205,7 @@ public String toString() { // value for the size bars, buttons, etc - static final int GRID_SIZE = 33; + static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100; // indents and spacing standards. these probably need to be modified diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java index 7f23d3c4602..f9398974027 100644 --- a/app/src/processing/app/Theme.java +++ b/app/src/processing/app/Theme.java @@ -101,6 +101,10 @@ static public Font getFont(String attr) { 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; } diff --git a/build/shared/lib/theme/theme.txt b/build/shared/lib/theme/theme.txt index 98a8ef7a58e..80fe76d2237 100644 --- a/build/shared/lib/theme/theme.txt +++ b/build/shared/lib/theme/theme.txt @@ -1,3 +1,6 @@ +# GUI - Scaling, edit this to scale to higher dots-per-inch displays +gui.scalePercent = 100 + # GUI - STATUS status.notice.fgcolor = #002325 status.notice.bgcolor = #17A1A5 From 8c92a3301135a1b437333b9ee720252d82d27130 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Mon, 16 Mar 2015 09:30:14 -0700 Subject: [PATCH 2/2] Fix scaling build test --- app/src/processing/app/EditorHeader.java | 11 +++++++---- app/src/processing/app/EditorStatus.java | 7 +++++-- app/src/processing/app/Preferences.java | 5 ----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/processing/app/EditorHeader.java b/app/src/processing/app/EditorHeader.java index ba96382a55f..bb145c8f8b6 100644 --- a/app/src/processing/app/EditorHeader.java +++ b/app/src/processing/app/EditorHeader.java @@ -69,6 +69,9 @@ 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 Image[][] pieces; // @@ -383,16 +386,16 @@ public Dimension getPreferredSize() { public Dimension getMinimumSize() { if (OSUtils.isMacOS()) { - return new Dimension(300, Preferences.GRID_SIZE); + return new Dimension(300, GRID_SIZE); } - return new Dimension(300, Preferences.GRID_SIZE - 1); + return new Dimension(300, GRID_SIZE - 1); } public Dimension getMaximumSize() { if (OSUtils.isMacOS()) { - return new Dimension(3000, Preferences.GRID_SIZE); + return new Dimension(3000, GRID_SIZE); } - return new Dimension(3000, Preferences.GRID_SIZE - 1); + return new Dimension(3000, GRID_SIZE - 1); } } diff --git a/app/src/processing/app/EditorStatus.java b/app/src/processing/app/EditorStatus.java index 1d90760f140..671dc5b20cf 100644 --- a/app/src/processing/app/EditorStatus.java +++ b/app/src/processing/app/EditorStatus.java @@ -56,6 +56,9 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { static final String NO_MESSAGE = ""; + // value for the size bars, buttons, etc + static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100; + Editor editor; int mode; @@ -524,11 +527,11 @@ public Dimension getPreferredSize() { } public Dimension getMinimumSize() { - return new Dimension(300, Preferences.GRID_SIZE); + return new Dimension(300, GRID_SIZE); } public Dimension getMaximumSize() { - return new Dimension(3000, Preferences.GRID_SIZE); + return new Dimension(3000, GRID_SIZE); } diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 5c27aab2cbf..6f2da1d6beb 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -203,11 +203,6 @@ public String toString() { */ static public int BUTTON_HEIGHT = 24; - // value for the size bars, buttons, etc - - static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100; - - // indents and spacing standards. these probably need to be modified // per platform as well, since macosx is so huge, windows is smaller, // and linux is all over the map