Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From fc0017dfc8dff905d47dcc27684c9776bc69577e Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= <[email protected]>
- Date: Thu, 3 Dec 2015 23:39:39 +0100
- Subject: [PATCH] HiDPI Support
- ---
- app/src/processing/app/Base.java | 18 ++++++++++++++++--
- app/src/processing/app/EditorHeader.java | 10 ++++++----
- app/src/processing/app/EditorLineStatus.java | 2 +-
- app/src/processing/app/EditorStatus.java | 6 ++++--
- app/src/processing/app/EditorToolbar.java | 10 +++++-----
- app/src/processing/app/Preferences.java | 5 -----
- app/src/processing/app/Theme.java | 4 ++++
- build/shared/lib/theme/theme.txt | 3 +++
- 8 files changed, 39 insertions(+), 19 deletions(-)
- diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java
- index f7af1aa..b9dc3d3 100644
- --- a/app/src/processing/app/Base.java
- +++ b/app/src/processing/app/Base.java
- @@ -1763,9 +1763,11 @@ public class Base {
- 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_LONG, 33, 20);
- + g.drawString(BaseNoGui.VERSION_NAME_LONG, 33 * scale / 100, 20 * scale / 100);
- }
- };
- window.addMouseListener(new MouseAdapter() {
- @@ -2061,6 +2063,9 @@ public class Base {
- static public Image getLibImage(String name, Component who) {
- 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 image = tk.getImage(imageLocation.getAbsolutePath());
- MediaTracker tracker = new MediaTracker(who);
- @@ -2069,6 +2074,15 @@ public class Base {
- 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/EditorHeader.java b/app/src/processing/app/EditorHeader.java
- index a1e100a..49e9a22 100644
- --- a/app/src/processing/app/EditorHeader.java
- +++ b/app/src/processing/app/EditorHeader.java
- @@ -69,6 +69,8 @@ public class EditorHeader extends JComponent {
- static final int MENU = 3;
- 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;
- @@ -388,16 +390,16 @@ public class EditorHeader extends JComponent {
- 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/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java
- index b1ad221..e704c86 100644
- --- a/app/src/processing/app/EditorLineStatus.java
- +++ b/app/src/processing/app/EditorLineStatus.java
- @@ -54,7 +54,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");
- + 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/EditorStatus.java b/app/src/processing/app/EditorStatus.java
- index abf8987..3ef1fed 100644
- --- a/app/src/processing/app/EditorStatus.java
- +++ b/app/src/processing/app/EditorStatus.java
- @@ -45,6 +45,8 @@ public class EditorStatus extends JPanel {
- private static final int EDIT = 2;
- private static final int PROGRESS = 5;
- private static final String NO_MESSAGE = "";
- + //value for the size bars, buttons, etc
- + static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
- private static final Color[] BGCOLOR;
- private static final Color[] FGCOLOR;
- @@ -395,11 +397,11 @@ public class EditorStatus extends JPanel {
- }
- 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);
- }
- public boolean isErr() {
- diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java
- index e433d37..1ace4e7 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;
- + private static final int BUTTON_WIDTH = 27 * Theme.getInteger("gui.scalePercent") / 100;
- /**
- * Height of each toolbar button.
- */
- - private static final int BUTTON_HEIGHT = 32;
- + private static final int BUTTON_HEIGHT = 32 * Theme.getInteger("gui.scalePercent") / 100;
- /**
- * The amount of space between groups of buttons on the toolbar.
- */
- - private static final int BUTTON_GAP = 5;
- + private static final int BUTTON_GAP = 5 * Theme.getInteger("gui.scalePercent") / 100;
- /**
- * Size of the button image being chopped up.
- */
- - private static final int BUTTON_IMAGE_SIZE = 33;
- + private static final int BUTTON_IMAGE_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
- 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, 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 d53f5b0..9472dda 100644
- --- a/app/src/processing/app/Preferences.java
- +++ b/app/src/processing/app/Preferences.java
- @@ -69,11 +69,6 @@ public class Preferences {
- */
- static public int BUTTON_HEIGHT = 24;
- - // value for the size bars, buttons, etc
- -
- - static final int GRID_SIZE = 33;
- -
- -
- // 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
- diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java
- index 893050d..16a6f03 100644
- --- a/app/src/processing/app/Theme.java
- +++ b/app/src/processing/app/Theme.java
- @@ -122,6 +122,10 @@ 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;
- }
- diff --git a/build/shared/lib/theme/theme.txt b/build/shared/lib/theme/theme.txt
- index 67ac3d3..26404e0 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
- +
- #FUNCTIONS COLOR #D35400 - ORANGE KEYWORD1
- #FUNCTIONS COLOR #D35400 - ORANGE KEYWORD2
- #STRUCTURE COLORS #5E6D03 - GREEN KEYWORD3
- --
- 2.6.2
Advertisement
Add Comment
Please, Sign In to add comment