Skip to content

Commit 2a02ade

Browse files
committed
working on ui zoom support for high-res Windows/Linux displays
1 parent 31f1986 commit 2a02ade

File tree

11 files changed

+113
-65
lines changed

11 files changed

+113
-65
lines changed

app/src/processing/app/BaseSplash.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class BaseSplash {
1010
static public void main(String[] args) {
1111
try {
12-
final boolean hidpi = Toolkit.highResDisplay();
12+
final boolean hidpi = Toolkit.highResImages();
1313
final String filename = "lib/about-" + (hidpi ? 2 : 1) + "x.png";
1414
File splashFile = Platform.getContentFile(filename);
1515
SplashWindow.splash(splashFile.toURI().toURL(), hidpi);

app/src/processing/app/Mode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ public Image loadImage(String filename) {
753753

754754

755755
public Image loadImageX(String filename) {
756-
final int res = Toolkit.highResDisplay() ? 2 : 1;
756+
final int res = Toolkit.highResImages() ? 2 : 1;
757757
return loadImage(filename + "-" + res + "x.png");
758758
}
759759

app/src/processing/app/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public Font getFont(String attr) {
205205
style |= Font.ITALIC;
206206
}
207207
int size = PApplet.parseInt(pieces[2], 12);
208+
size = Toolkit.dpi(size);
208209

209210
// replace bad font with the default from lib/preferences.txt
210211
if (replace) {

app/src/processing/app/contrib/ManagerTabs.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,7 @@ public void paintComponent(Graphics screen) {
217217
sizeH = size.height;
218218
imageW = sizeW;
219219
imageH = sizeH;
220-
if (Toolkit.highResDisplay()) {
221-
offscreen = createImage(imageW*2, imageH*2);
222-
} else {
223-
offscreen = createImage(imageW, imageH);
224-
}
220+
offscreen = Toolkit.offscreenGraphics(this, imageW, imageH);
225221
}
226222

227223
Graphics g = offscreen.getGraphics();

app/src/processing/app/ui/Editor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.awt.BorderLayout;
4444
import java.awt.Color;
4545
import java.awt.Component;
46-
import java.awt.Dimension;
4746
import java.awt.EventQueue;
4847
import java.awt.Font;
4948
import java.awt.Frame;
@@ -79,9 +78,9 @@ public abstract class Editor extends JFrame implements RunnerListener {
7978
protected EditorState state;
8079
protected Mode mode;
8180

82-
static public final int LEFT_GUTTER = 44;
83-
static public final int RIGHT_GUTTER = 12;
84-
static public final int GUTTER_MARGIN = 3;
81+
static public final int LEFT_GUTTER = Toolkit.dpi(44);
82+
static public final int RIGHT_GUTTER = Toolkit.dpi(12);
83+
static public final int GUTTER_MARGIN = Toolkit.dpi(3);
8584

8685
protected MarkerColumn errorColumn;
8786

@@ -350,7 +349,8 @@ public void caretUpdate(CaretEvent e) {
350349
// Set the minimum size for the editor window
351350
int minWidth = Preferences.getInteger("editor.window.width.min");
352351
int minHeight = Preferences.getInteger("editor.window.height.min");
353-
setMinimumSize(new Dimension(minWidth, minHeight));
352+
//setMinimumSize(new Dimension(minWidth, minHeight));
353+
setMinimumSize(Toolkit.zoom(minWidth, minHeight));
354354

355355
// Bring back the general options for the editor
356356
applyPreferences();

app/src/processing/app/ui/EditorButton.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
abstract public class EditorButton extends JComponent
3232
implements MouseListener, MouseMotionListener, ActionListener {
33-
static public final int DIM = 30;
33+
static public final int DIM = Toolkit.dpi(30);
3434

3535
/** Button's description. */
3636
protected String title;
@@ -112,10 +112,13 @@ public void paintComponent(Graphics g) {
112112
} else if (rollover) {
113113
image = rolloverImage;
114114
}
115+
int dim = getSize().width; // width == height
115116
if (gradient != null) {
116-
g.drawImage(gradient, 0, 0, DIM, DIM, this);
117+
//g.drawImage(gradient, 0, 0, DIM, DIM, this);
118+
g.drawImage(gradient, 0, 0, dim, dim, this);
117119
}
118-
g.drawImage(image, 0, 0, DIM, DIM, this);
120+
//g.drawImage(image, 0, 0, DIM, DIM, this);
121+
g.drawImage(image, 0, 0, dim, dim, this);
119122
}
120123

121124

app/src/processing/app/ui/EditorFooter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,7 @@ public void paintComponent(Graphics screen) {
229229
sizeH = size.height;
230230
imageW = sizeW;
231231
imageH = sizeH;
232-
if (Toolkit.highResDisplay()) {
233-
offscreen = createImage(imageW*2, imageH*2);
234-
} else {
235-
offscreen = createImage(imageW, imageH);
236-
}
232+
offscreen = Toolkit.offscreenGraphics(this, imageW, imageH);
237233
}
238234

239235
Graphics g = offscreen.getGraphics();

app/src/processing/app/ui/EditorHeader.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,25 @@
4444
*/
4545
public class EditorHeader extends JComponent {
4646
// height of this tab bar
47-
static final int HIGH = 29;
47+
static final int HIGH = Toolkit.dpi(29);
4848

49-
static final int ARROW_TAB_WIDTH = 18;
50-
static final int ARROW_TOP = 11;
51-
static final int ARROW_BOTTOM = 18;
52-
static final int ARROW_WIDTH = 6;
49+
static final int ARROW_TAB_WIDTH = Toolkit.dpi(18);
50+
static final int ARROW_TOP = Toolkit.dpi(11);
51+
static final int ARROW_BOTTOM = Toolkit.dpi(18);
52+
static final int ARROW_WIDTH = Toolkit.dpi(6);
5353

54-
static final int CURVE_RADIUS = 6;
54+
static final int CURVE_RADIUS = Toolkit.dpi(6);
5555

5656
static final int TAB_TOP = 0;
57-
static final int TAB_BOTTOM = 27;
57+
static final int TAB_BOTTOM = Toolkit.dpi(27);
5858
// amount of extra space between individual tabs
59-
static final int TAB_BETWEEN = 3;
59+
static final int TAB_BETWEEN = Toolkit.dpi(3);
6060
// amount of margin on the left/right for the text on the tab
61-
static final int TEXT_MARGIN = 16;
61+
static final int TEXT_MARGIN = Toolkit.dpi(16);
6262
// width of the tab when no text visible
6363
// (total tab width will be this plus TEXT_MARGIN*2)
64-
static final int NO_TEXT_WIDTH = 16;
64+
static final int NO_TEXT_WIDTH = Toolkit.dpi(16);
6565

66-
// Color bgColor;
6766
Color textColor[] = new Color[2];
6867
Color tabColor[] = new Color[2];
6968
Color modifiedColor;
@@ -185,11 +184,7 @@ public void paintComponent(Graphics screen) {
185184
sizeH = size.height;
186185
imageW = sizeW;
187186
imageH = sizeH;
188-
if (Toolkit.highResDisplay()) {
189-
offscreen = createImage(imageW*2, imageH*2);
190-
} else {
191-
offscreen = createImage(imageW, imageH);
192-
}
187+
offscreen = Toolkit.offscreenGraphics(this, imageW, imageH);
193188
}
194189

195190
Graphics g = offscreen.getGraphics();
@@ -199,6 +194,7 @@ public void paintComponent(Graphics screen) {
199194
}
200195

201196
Graphics2D g2 = Toolkit.prepareGraphics(g);
197+
Toolkit.dpiStroke(g2);
202198

203199
g.drawImage(gradient, 0, 0, imageW, imageH, this);
204200

@@ -265,7 +261,8 @@ public void paintComponent(Graphics screen) {
265261
g.setColor(tabColor[SELECTED]);
266262
// can't be done with lines, b/c retina leaves tiny hairlines
267263
g.fillRect(Editor.LEFT_GUTTER, TAB_BOTTOM,
268-
editor.getTextArea().getWidth() - Editor.LEFT_GUTTER, 2);
264+
editor.getTextArea().getWidth() - Editor.LEFT_GUTTER,
265+
Toolkit.dpi(2));
269266

270267
// draw the tab for the menu
271268
g.setColor(tabColor[UNSELECTED]);

app/src/processing/app/ui/EditorStatus.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
* Panel just below the editing area that contains status messages.
4848
*/
4949
public class EditorStatus extends BasicSplitPaneDivider { //JPanel {
50-
static final int HIGH = 28;
50+
static final int HIGH = Toolkit.dpi(28);
5151
static final int LEFT_MARGIN = Editor.LEFT_GUTTER;
52-
static final int RIGHT_MARGIN = 20;
52+
static final int RIGHT_MARGIN = Toolkit.dpi(20);
5353

5454
Color urlColor;
5555
Color[] fgColor;
@@ -271,11 +271,7 @@ public void paint(Graphics screen) {
271271
sizeW = size.width;
272272
sizeH = size.height;
273273

274-
if (Toolkit.highResDisplay()) {
275-
offscreen = createImage(sizeW*2, sizeH*2);
276-
} else {
277-
offscreen = createImage(sizeW, sizeH);
278-
}
274+
offscreen = Toolkit.offscreenGraphics(this, sizeW, sizeH);
279275
}
280276

281277
Graphics g = offscreen.getGraphics();
@@ -332,11 +328,11 @@ public Dimension getPreferredSize() {
332328

333329

334330
public Dimension getMinimumSize() {
335-
return new Dimension(300, HIGH);
331+
return Toolkit.zoom(300, HIGH);
336332
}
337333

338334

339335
public Dimension getMaximumSize() {
340-
return new Dimension(super.getMaximumSize().width, HIGH);
336+
return Toolkit.zoom(super.getMaximumSize().width, HIGH);
341337
}
342338
}

app/src/processing/app/ui/EditorToolbar.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@
5252
abstract public class EditorToolbar extends JPanel implements KeyListener {
5353
// haven't decided how to handle this/how to make public/consistency
5454
// for components/does it live in theme.txt
55-
static final int HIGH = 53;
55+
static final int HIGH = Toolkit.dpi(53);
5656
// horizontal gap between buttons
57-
static final int GAP = 9;
57+
static final int GAP = Toolkit.dpi(9);
5858
// corner radius on the mode selector
59-
static final int RADIUS = 3;
59+
static final int RADIUS = Toolkit.dpi(3);
6060

6161
protected Editor editor;
6262
protected Base base;
@@ -78,8 +78,7 @@ public EditorToolbar(Editor editor) {
7878
base = editor.getBase();
7979
mode = editor.getMode();
8080

81-
gradient = mode.makeGradient("toolbar", 400, HIGH);
82-
// reverseGradient = mode.getGradient("reversed", 100, EditorButton.DIM);
81+
gradient = mode.makeGradient("toolbar", Toolkit.dpi(400), HIGH);
8382

8483
rebuild();
8584
}
@@ -286,11 +285,11 @@ class ModeSelector extends JPanel {
286285
int titleAscent;
287286
int titleWidth;
288287

289-
final int MODE_GAP_WIDTH = 13;
290-
final int ARROW_GAP_WIDTH = 6;
291-
final int ARROW_WIDTH = 6;
292-
final int ARROW_TOP = 12;
293-
final int ARROW_BOTTOM = 18;
288+
final int MODE_GAP_WIDTH = Toolkit.dpi(13);
289+
final int ARROW_GAP_WIDTH = Toolkit.dpi(6);
290+
final int ARROW_WIDTH = Toolkit.dpi(6);
291+
final int ARROW_TOP = Toolkit.dpi(12);
292+
final int ARROW_BOTTOM = Toolkit.dpi(18);
294293

295294
int[] triangleX = new int[3];
296295
int[] triangleY = new int[] { ARROW_TOP, ARROW_TOP, ARROW_BOTTOM };
@@ -328,11 +327,7 @@ public void paintComponent(Graphics screen) {
328327
Dimension size = getSize();
329328
width = 0;
330329
if (width != size.width || height != size.height) {
331-
if (Toolkit.highResDisplay()) {
332-
offscreen = createImage(size.width*2, size.height*2);
333-
} else {
334-
offscreen = createImage(size.width, size.height);
335-
}
330+
offscreen = Toolkit.offscreenGraphics(this, size.width, size.height);
336331
width = size.width;
337332
height = size.height;
338333
}
@@ -357,6 +352,7 @@ public void paintComponent(Graphics screen) {
357352

358353
// draw the outline for this feller
359354
g.setColor(outlineColor);
355+
Toolkit.dpiStroke(g2);
360356
g2.draw(Toolkit.createRoundRect(1, 1, width-1, height-1,
361357
RADIUS, RADIUS, RADIUS, RADIUS));
362358

0 commit comments

Comments
 (0)