Skip to content

Commit 08d3510

Browse files
committed
Add scaling for themed fonts and graphics (hires displays) (Paul Stoffregen)
1 parent c3d2bbd commit 08d3510

File tree

8 files changed

+41
-21
lines changed

8 files changed

+41
-21
lines changed

Diff for: app/src/processing/app/Base.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ static public void guardedMain(String args[]) throws Exception {
157157

158158
BaseNoGui.initParameters(args);
159159

160-
System.setProperty("swing.aatext", PreferencesData.get("editor.antialias", "true"));
161-
162160
BaseNoGui.initVersion();
163161

164162
// if (System.getProperty("mrj.version") != null) {
@@ -207,6 +205,7 @@ static public void guardedMain(String args[]) throws Exception {
207205

208206
// setup the theme coloring fun
209207
Theme.init();
208+
System.setProperty("swing.aatext", PreferencesData.get("editor.antialias", "true"));
210209

211210
// Set the look and feel before opening the window
212211
try {
@@ -1751,9 +1750,11 @@ public void paint(Graphics g) {
17511750
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
17521751
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
17531752

1754-
g.setFont(new Font("SansSerif", Font.PLAIN, 11));
1753+
int scale = Theme.getInteger("gui.scalePercent");
1754+
Font f = new Font("SansSerif", Font.PLAIN, 11 * scale / 100);
1755+
g.setFont(f);
17551756
g.setColor(Color.white);
1756-
g.drawString(BaseNoGui.VERSION_NAME_LONG, 33, 20);
1757+
g.drawString(BaseNoGui.VERSION_NAME_LONG, 33 * scale / 100, 20 * scale / 100);
17571758
}
17581759
};
17591760
window.addMouseListener(new MouseAdapter() {
@@ -2049,6 +2050,9 @@ static public Image getThemeImage(String name, Component who) {
20492050
static public Image getLibImage(String name, Component who) {
20502051
Toolkit tk = Toolkit.getDefaultToolkit();
20512052

2053+
int scale = Theme.getInteger("gui.scalePercent");
2054+
// TODO: create high-res enlarged copies and load those if
2055+
// the scale is more than 125%
20522056
File imageLocation = new File(getContentFile("lib"), name);
20532057
Image image = tk.getImage(imageLocation.getAbsolutePath());
20542058
MediaTracker tracker = new MediaTracker(who);
@@ -2057,6 +2061,15 @@ static public Image getLibImage(String name, Component who) {
20572061
tracker.waitForAll();
20582062
} catch (InterruptedException e) {
20592063
}
2064+
if (scale != 100) {
2065+
int width = image.getWidth(null) * scale / 100;
2066+
int height = image.getHeight(null) * scale / 100;
2067+
image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
2068+
tracker.addImage(image, 1);
2069+
try {
2070+
tracker.waitForAll();
2071+
} catch (InterruptedException e) { }
2072+
}
20602073
return image;
20612074
}
20622075

Diff for: app/src/processing/app/EditorHeader.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public class EditorHeader extends JComponent {
7373

7474
static final int PIECE_WIDTH = 4;
7575

76+
// value for the size bars, buttons, etc
77+
static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
78+
7679
static Image[][] pieces;
7780

7881
Image offscreen;
@@ -338,16 +341,16 @@ public Dimension getPreferredSize() {
338341

339342
public Dimension getMinimumSize() {
340343
if (OSUtils.isMacOS()) {
341-
return new Dimension(300, Preferences.GRID_SIZE);
344+
return new Dimension(300, GRID_SIZE);
342345
}
343-
return new Dimension(300, Preferences.GRID_SIZE - 1);
346+
return new Dimension(300, GRID_SIZE - 1);
344347
}
345348

346349

347350
public Dimension getMaximumSize() {
348351
if (OSUtils.isMacOS()) {
349-
return new Dimension(3000, Preferences.GRID_SIZE);
352+
return new Dimension(3000, GRID_SIZE);
350353
}
351-
return new Dimension(3000, Preferences.GRID_SIZE - 1);
354+
return new Dimension(3000, GRID_SIZE - 1);
352355
}
353356
}

Diff for: app/src/processing/app/EditorLineStatus.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public EditorLineStatus() {
5555
background = Theme.getColor("linestatus.bgcolor");
5656
font = Theme.getFont("linestatus.font");
5757
foreground = Theme.getColor("linestatus.color");
58-
high = Theme.getInteger("linestatus.height");
58+
high = Theme.getInteger("linestatus.height") * Theme.getInteger("gui.scalePercent") / 100;
5959

6060
if (OSUtils.isMacOS()) {
6161
resize = Base.getThemeImage("resize.gif", this);

Diff for: app/src/processing/app/EditorStatus.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public class EditorStatus extends JPanel {
6767
FGCOLOR[5] = Theme.getColor("status.notice.fgcolor");
6868
}
6969

70+
// value for the size bars, buttons, etc
71+
static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
72+
7073
private final Editor editor;
7174
private final Font font;
7275

@@ -395,11 +398,11 @@ public Dimension getPreferredSize() {
395398
}
396399

397400
public Dimension getMinimumSize() {
398-
return new Dimension(300, Preferences.GRID_SIZE);
401+
return new Dimension(300, GRID_SIZE);
399402
}
400403

401404
public Dimension getMaximumSize() {
402-
return new Dimension(3000, Preferences.GRID_SIZE);
405+
return new Dimension(3000, GRID_SIZE);
403406
}
404407

405408
public boolean isErr() {

Diff for: app/src/processing/app/EditorToolbar.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
5656
/**
5757
* Width of each toolbar button.
5858
*/
59-
private static final int BUTTON_WIDTH = 27;
59+
private static final int BUTTON_WIDTH = 27 * Theme.getInteger("gui.scalePercent") / 100;
6060
/**
6161
* Height of each toolbar button.
6262
*/
63-
private static final int BUTTON_HEIGHT = 32;
63+
private static final int BUTTON_HEIGHT = 32 * Theme.getInteger("gui.scalePercent") / 100;
6464
/**
6565
* The amount of space between groups of buttons on the toolbar.
6666
*/
67-
private static final int BUTTON_GAP = 5;
67+
private static final int BUTTON_GAP = 5 * Theme.getInteger("gui.scalePercent") / 100;
6868
/**
6969
* Size of the button image being chopped up.
7070
*/
71-
private static final int BUTTON_IMAGE_SIZE = 33;
71+
private static final int BUTTON_IMAGE_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
7272

7373

7474
private static final int RUN = 0;
@@ -437,7 +437,7 @@ public Dimension getMinimumSize() {
437437

438438

439439
public Dimension getMaximumSize() {
440-
return new Dimension(3000, BUTTON_HEIGHT);
440+
return new Dimension(3000 * Theme.getInteger("gui.scalePercent") / 100, BUTTON_HEIGHT);
441441
}
442442

443443

Diff for: app/src/processing/app/Preferences.java

-5
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ public class Preferences {
6969
*/
7070
static public int BUTTON_HEIGHT = 24;
7171

72-
// value for the size bars, buttons, etc
73-
74-
static final int GRID_SIZE = 33;
75-
76-
7772
// indents and spacing standards. these probably need to be modified
7873
// per platform as well, since macosx is so huge, windows is smaller,
7974
// and linux is all over the map

Diff for: app/src/processing/app/Theme.java

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ static public Font getFont(String attr) {
122122
set(attr, value);
123123
font = PreferencesHelper.getFont(table, attr);
124124
}
125+
int scale = getInteger("gui.scalePercent");
126+
if (scale != 100) {
127+
font = font.deriveFont((float)(font.getSize()) * (float)scale / (float)100.0);
128+
}
125129
return font;
126130
}
127131

Diff for: build/shared/lib/theme/theme.txt

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#COMMENTS // COLOR #95A5A6 - LIGHT GREY
88
#COMMENTS /**/ COLOR #434F54 - DARK GREY
99

10+
# GUI - Scaling, edit this to scale to higher dots-per-inch displays
11+
gui.scalePercent = 100
1012

1113
# GUI - STATUS
1214
status.notice.fgcolor = #002325

0 commit comments

Comments
 (0)