Guest User

Arduino IDE HiDPI patch

a guest
Dec 3rd, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.45 KB | None | 0 0
  1. From fc0017dfc8dff905d47dcc27684c9776bc69577e Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Niccol=C3=B2=20Maggioni?= <[email protected]>
  3. Date: Thu, 3 Dec 2015 23:39:39 +0100
  4. Subject: [PATCH] HiDPI Support
  5.  
  6. ---
  7. app/src/processing/app/Base.java             | 18 ++++++++++++++++--
  8.  app/src/processing/app/EditorHeader.java     | 10 ++++++----
  9.  app/src/processing/app/EditorLineStatus.java |  2 +-
  10.  app/src/processing/app/EditorStatus.java     |  6 ++++--
  11.  app/src/processing/app/EditorToolbar.java    | 10 +++++-----
  12.  app/src/processing/app/Preferences.java      |  5 -----
  13.  app/src/processing/app/Theme.java            |  4 ++++
  14.  build/shared/lib/theme/theme.txt             |  3 +++
  15.  8 files changed, 39 insertions(+), 19 deletions(-)
  16.  
  17. diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java
  18. index f7af1aa..b9dc3d3 100644
  19. --- a/app/src/processing/app/Base.java
  20. +++ b/app/src/processing/app/Base.java
  21. @@ -1763,9 +1763,11 @@ public class Base {
  22.          g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
  23.                  RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
  24.  
  25. -        g.setFont(new Font("SansSerif", Font.PLAIN, 11));
  26. +        int scale = Theme.getInteger("gui.scalePercent");
  27. +        Font f = new Font("SansSerif", Font.PLAIN, 11 * scale / 100);
  28. +        g.setFont(f);
  29.          g.setColor(Color.white);
  30. -        g.drawString(BaseNoGui.VERSION_NAME_LONG, 33, 20);
  31. +        g.drawString(BaseNoGui.VERSION_NAME_LONG, 33 * scale / 100, 20 * scale / 100);
  32.        }
  33.      };
  34.      window.addMouseListener(new MouseAdapter() {
  35. @@ -2061,6 +2063,9 @@ public class Base {
  36.    static public Image getLibImage(String name, Component who) {
  37.      Toolkit tk = Toolkit.getDefaultToolkit();
  38.  
  39. +    int scale = Theme.getInteger("gui.scalePercent");
  40. +    // TODO: create high-res enlarged copies and load those if
  41. +    //       the scale is more than 125%
  42.      File imageLocation = new File(getContentFile("lib"), name);
  43.      Image image = tk.getImage(imageLocation.getAbsolutePath());
  44.      MediaTracker tracker = new MediaTracker(who);
  45. @@ -2069,6 +2074,15 @@ public class Base {
  46.        tracker.waitForAll();
  47.      } catch (InterruptedException e) {
  48.      }
  49. +    if (scale != 100) {
  50. +      int width = image.getWidth(null) * scale / 100;
  51. +      int height = image.getHeight(null) * scale / 100;
  52. +      image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
  53. +      tracker.addImage(image, 1);
  54. +      try {
  55. +        tracker.waitForAll();
  56. +      } catch (InterruptedException e) { }
  57. +    }
  58.      return image;
  59.    }
  60.  
  61. diff --git a/app/src/processing/app/EditorHeader.java b/app/src/processing/app/EditorHeader.java
  62. index a1e100a..49e9a22 100644
  63. --- a/app/src/processing/app/EditorHeader.java
  64. +++ b/app/src/processing/app/EditorHeader.java
  65. @@ -69,6 +69,8 @@ public class EditorHeader extends JComponent {
  66.    static final int MENU = 3;
  67.  
  68.    static final int PIECE_WIDTH = 4;
  69. +  // value for the size bars, buttons, etc
  70. +  static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
  71.  
  72.    static Image[][] pieces;
  73.  
  74. @@ -388,16 +390,16 @@ public class EditorHeader extends JComponent {
  75.  
  76.    public Dimension getMinimumSize() {
  77.      if (OSUtils.isMacOS()) {
  78. -      return new Dimension(300, Preferences.GRID_SIZE);
  79. +      return new Dimension(300, GRID_SIZE);
  80.      }
  81. -    return new Dimension(300, Preferences.GRID_SIZE - 1);
  82. +    return new Dimension(300, GRID_SIZE - 1);
  83.    }
  84.  
  85.  
  86.    public Dimension getMaximumSize() {
  87.      if (OSUtils.isMacOS()) {
  88. -      return new Dimension(3000, Preferences.GRID_SIZE);
  89. +      return new Dimension(3000, GRID_SIZE);
  90.      }
  91. -    return new Dimension(3000, Preferences.GRID_SIZE - 1);
  92. +    return new Dimension(3000, GRID_SIZE - 1);
  93.    }
  94.  }
  95. diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java
  96. index b1ad221..e704c86 100644
  97. --- a/app/src/processing/app/EditorLineStatus.java
  98. +++ b/app/src/processing/app/EditorLineStatus.java
  99. @@ -54,7 +54,7 @@ public class EditorLineStatus extends JComponent {
  100.      background = Theme.getColor("linestatus.bgcolor");
  101.      font = Theme.getFont("linestatus.font");
  102.      foreground = Theme.getColor("linestatus.color");
  103. -    high = Theme.getInteger("linestatus.height");
  104. +    high = Theme.getInteger("linestatus.height") * Theme.getInteger("gui.scalePercent") / 100;
  105.  
  106.      if (OSUtils.isMacOS()) {
  107.        resize = Base.getThemeImage("resize.gif", this);
  108. diff --git a/app/src/processing/app/EditorStatus.java b/app/src/processing/app/EditorStatus.java
  109. index abf8987..3ef1fed 100644
  110. --- a/app/src/processing/app/EditorStatus.java
  111. +++ b/app/src/processing/app/EditorStatus.java
  112. @@ -45,6 +45,8 @@ public class EditorStatus extends JPanel {
  113.    private static final int EDIT = 2;
  114.    private static final int PROGRESS = 5;
  115.    private static final String NO_MESSAGE = "";
  116. +  //value for the size bars, buttons, etc
  117. +  static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
  118.  
  119.    private static final Color[] BGCOLOR;
  120.    private static final Color[] FGCOLOR;
  121. @@ -395,11 +397,11 @@ public class EditorStatus extends JPanel {
  122.    }
  123.  
  124.    public Dimension getMinimumSize() {
  125. -    return new Dimension(300, Preferences.GRID_SIZE);
  126. +    return new Dimension(300, GRID_SIZE);
  127.    }
  128.  
  129.    public Dimension getMaximumSize() {
  130. -    return new Dimension(3000, Preferences.GRID_SIZE);
  131. +    return new Dimension(3000, GRID_SIZE);
  132.    }
  133.  
  134.    public boolean isErr() {
  135. diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java
  136. index e433d37..1ace4e7 100644
  137. --- a/app/src/processing/app/EditorToolbar.java
  138. +++ b/app/src/processing/app/EditorToolbar.java
  139. @@ -56,19 +56,19 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
  140.    /**
  141.     * Width of each toolbar button.
  142.     */
  143. -  private static final int BUTTON_WIDTH = 27;
  144. +  private static final int BUTTON_WIDTH = 27 * Theme.getInteger("gui.scalePercent") / 100;
  145.    /**
  146.     * Height of each toolbar button.
  147.     */
  148. -  private static final int BUTTON_HEIGHT = 32;
  149. +  private static final int BUTTON_HEIGHT = 32 * Theme.getInteger("gui.scalePercent") / 100;
  150.    /**
  151.     * The amount of space between groups of buttons on the toolbar.
  152.     */
  153. -  private static final int BUTTON_GAP = 5;
  154. +  private static final int BUTTON_GAP = 5 * Theme.getInteger("gui.scalePercent") / 100;
  155.    /**
  156.     * Size of the button image being chopped up.
  157.     */
  158. -  private static final int BUTTON_IMAGE_SIZE = 33;
  159. +  private static final int BUTTON_IMAGE_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
  160.  
  161.  
  162.    private static final int RUN = 0;
  163. @@ -437,7 +437,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
  164.  
  165.  
  166.    public Dimension getMaximumSize() {
  167. -    return new Dimension(3000, BUTTON_HEIGHT);
  168. +    return new Dimension(3000 * Theme.getInteger("gui.scalePercent") / 100, BUTTON_HEIGHT);
  169.    }
  170.  
  171.  
  172. diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java
  173. index d53f5b0..9472dda 100644
  174. --- a/app/src/processing/app/Preferences.java
  175. +++ b/app/src/processing/app/Preferences.java
  176. @@ -69,11 +69,6 @@ public class Preferences {
  177.     */
  178.    static public int BUTTON_HEIGHT = 24;
  179.  
  180. -  // value for the size bars, buttons, etc
  181. -
  182. -  static final int GRID_SIZE = 33;
  183. -
  184. -
  185.    // indents and spacing standards. these probably need to be modified
  186.    // per platform as well, since macosx is so huge, windows is smaller,
  187.    // and linux is all over the map
  188. diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java
  189. index 893050d..16a6f03 100644
  190. --- a/app/src/processing/app/Theme.java
  191. +++ b/app/src/processing/app/Theme.java
  192. @@ -122,6 +122,10 @@ public class Theme {
  193.        set(attr, value);
  194.        font = PreferencesHelper.getFont(table, attr);
  195.      }
  196. +    int scale = getInteger("gui.scalePercent");
  197. +    if (scale != 100) {
  198. +      font = font.deriveFont((float)(font.getSize()) * (float)scale / (float)100.0);
  199. +    }
  200.      return font;
  201.    }
  202.  
  203. diff --git a/build/shared/lib/theme/theme.txt b/build/shared/lib/theme/theme.txt
  204. index 67ac3d3..26404e0 100644
  205. --- a/build/shared/lib/theme/theme.txt
  206. +++ b/build/shared/lib/theme/theme.txt
  207. @@ -1,3 +1,6 @@
  208. +# GUI - Scaling, edit this to scale to higher dots-per-inch displays
  209. +gui.scalePercent = 100
  210. +
  211.  #FUNCTIONS COLOR           #D35400 - ORANGE            KEYWORD1
  212.  #FUNCTIONS COLOR           #D35400 - ORANGE            KEYWORD2
  213.  #STRUCTURE COLORS          #5E6D03 - GREEN         KEYWORD3
  214. --
  215. 2.6.2
Advertisement
Add Comment
Please, Sign In to add comment