Skip to content

Commit 967153f

Browse files
committed
Factored out scaling formula into an helper method
Also use a default value of 100 in case "gui.scalePercent" is not set.
1 parent f239f5b commit 967153f

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,11 +1752,10 @@ public void paint(Graphics g) {
17521752
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
17531753
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
17541754

1755-
int scale = Theme.getInteger("gui.scalePercent");
1756-
Font f = new Font("SansSerif", Font.PLAIN, 11 * scale / 100);
1755+
Font f = new Font("SansSerif", Font.PLAIN, Theme.scale(11));
17571756
g.setFont(f);
17581757
g.setColor(Color.white);
1759-
g.drawString(BaseNoGui.VERSION_NAME_LONG, 33 * scale / 100, 20 * scale / 100);
1758+
g.drawString(BaseNoGui.VERSION_NAME_LONG, Theme.scale(33), Theme.scale(20));
17601759
}
17611760
};
17621761
window.addMouseListener(new MouseAdapter() {

app/src/processing/app/EditorHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class EditorHeader extends JComponent {
7474
static final int PIECE_WIDTH = 4;
7575

7676
// value for the size bars, buttons, etc
77-
static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
77+
static final int GRID_SIZE = Theme.scale(33);
7878

7979
static Image[][] pieces;
8080

app/src/processing/app/EditorLineStatus.java

Lines changed: 1 addition & 1 deletion
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") * Theme.getInteger("gui.scalePercent") / 100;
58+
high = Theme.scale(Theme.getInteger("linestatus.height"));
5959

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

app/src/processing/app/EditorStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class EditorStatus extends JPanel {
6868
}
6969

7070
// value for the size bars, buttons, etc
71-
static final int GRID_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
71+
static final int GRID_SIZE = Theme.scale(33);
7272

7373
private final Editor editor;
7474
private final Font font;

app/src/processing/app/EditorToolbar.java

Lines changed: 5 additions & 5 deletions
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 * Theme.getInteger("gui.scalePercent") / 100;
59+
private static final int BUTTON_WIDTH = Theme.scale(27);
6060
/**
6161
* Height of each toolbar button.
6262
*/
63-
private static final int BUTTON_HEIGHT = 32 * Theme.getInteger("gui.scalePercent") / 100;
63+
private static final int BUTTON_HEIGHT = Theme.scale(32);
6464
/**
6565
* The amount of space between groups of buttons on the toolbar.
6666
*/
67-
private static final int BUTTON_GAP = 5 * Theme.getInteger("gui.scalePercent") / 100;
67+
private static final int BUTTON_GAP = Theme.scale(5);
6868
/**
6969
* Size of the button image being chopped up.
7070
*/
71-
private static final int BUTTON_IMAGE_SIZE = 33 * Theme.getInteger("gui.scalePercent") / 100;
71+
private static final int BUTTON_IMAGE_SIZE = Theme.scale(33);
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 * Theme.getInteger("gui.scalePercent") / 100, BUTTON_HEIGHT);
440+
return new Dimension(Theme.scale(3000), BUTTON_HEIGHT);
441441
}
442442

443443

app/src/processing/app/Theme.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ static public void setInteger(String key, int value) {
9797
set(key, String.valueOf(value));
9898
}
9999

100+
static public int getScale() {
101+
if (get("gui.scalePercent") == null)
102+
return 100;
103+
return getInteger("gui.scalePercent");
104+
}
105+
106+
static public int scale(int size) {
107+
return size * getScale() / 100;
108+
}
109+
100110
static public Color getColorCycleColor(String name, int i) {
101111
int cycleSize = getInteger(name + ".size");
102112
name = String.format("%s.%02d", name, i % cycleSize);
@@ -125,12 +135,7 @@ static public Font getFont(String attr) {
125135
set(attr, value);
126136
font = PreferencesHelper.getFont(table, attr);
127137
}
128-
int scale = getInteger("gui.scalePercent");
129-
if (scale != 100) {
130-
font = font
131-
.deriveFont((float) (font.getSize()) * (float) scale / (float) 100.0);
132-
}
133-
return font;
138+
return font.deriveFont((float) scale(font.getSize()));
134139
}
135140

136141
/**
@@ -199,7 +204,7 @@ static public Image getLibImage(String filename, Component who) {
199204
Toolkit tk = Toolkit.getDefaultToolkit();
200205

201206
SplitFile name = FileUtils.splitFilename(filename);
202-
int scale = getInteger("gui.scalePercent");
207+
int scale = getScale();
203208
File libFolder = Base.getContentFile("lib");
204209
File imageFile1x = new File(libFolder, name.basename + "." + name.extension);
205210
File imageFile2x = new File(libFolder, name.basename + "@2x." + name.extension);

0 commit comments

Comments
 (0)