Skip to content

Commit eb6127b

Browse files
committed
basic retina support for the PDE itself
1 parent f721892 commit eb6127b

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed

app/src/processing/app/EditorHeader.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void paintComponent(Graphics screen) {
163163
offscreen = null;
164164

165165
} else {
166-
// who cares, just resize
166+
// if the image is larger than necessary, no need to change
167167
sizeW = size.width;
168168
sizeH = size.height;
169169
}
@@ -174,7 +174,11 @@ public void paintComponent(Graphics screen) {
174174
sizeH = size.height;
175175
imageW = sizeW;
176176
imageH = sizeH;
177-
offscreen = createImage(imageW, imageH);
177+
if (Toolkit.isRetina()) {
178+
offscreen = createImage(imageW*2, imageH*2);
179+
} else {
180+
offscreen = createImage(imageW, imageH);
181+
}
178182
}
179183

180184
Graphics g = offscreen.getGraphics();
@@ -183,8 +187,15 @@ public void paintComponent(Graphics screen) {
183187
fontAscent = metrics.getAscent();
184188

185189
Graphics2D g2 = (Graphics2D) g;
186-
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
187-
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
190+
191+
if (Toolkit.isRetina()) {
192+
// scale everything 2x, will be scaled down when drawn to the screen
193+
g2.scale(2, 2);
194+
} else {
195+
// don't anti-alias text in retina mode
196+
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
197+
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
198+
}
188199

189200
// set the background for the offscreen
190201
g.setColor(backgroundColor);
@@ -288,7 +299,7 @@ public void paintComponent(Graphics screen) {
288299
g.drawImage(pieces[popup.isVisible() ? SELECTED : UNSELECTED][MENU],
289300
menuLeft, 0, null);
290301

291-
screen.drawImage(offscreen, 0, 0, null);
302+
screen.drawImage(offscreen, 0, 0, imageW, imageH, null);
292303
}
293304

294305

app/src/processing/app/EditorToolbar.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ public void paintComponent(Graphics screen) {
185185
Dimension size = getSize();
186186
if ((offscreen == null) ||
187187
(size.width != width) || (size.height != height)) {
188-
offscreen = createImage(size.width, size.height);
188+
if (Toolkit.isRetina()) {
189+
offscreen = createImage(size.width*2, size.height*2);
190+
} else {
191+
offscreen = createImage(size.width, size.height);
192+
}
193+
189194
width = size.width;
190195
height = size.height;
191196

@@ -205,19 +210,26 @@ public void paintComponent(Graphics screen) {
205210
// offsetX = x2[i];
206211
// }
207212
}
208-
Graphics g = offscreen.getGraphics();
213+
Graphics g = offscreen.getGraphics();
214+
Graphics2D g2 = (Graphics2D) g;
215+
216+
if (Toolkit.isRetina()) {
217+
// scale everything 2x, will be scaled down when drawn to the screen
218+
g2.scale(2, 2);
219+
} else {
220+
// don't anti-alias text in retina mode
221+
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
222+
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
223+
}
224+
209225
g.setColor(bgcolor); //getBackground());
210226
g.fillRect(0, 0, width, height);
211227

212-
Graphics2D g2 = (Graphics2D) g;
213-
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
214-
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
215-
216228
// for (int i = 0; i < buttonCount; i++) {
217229
// g.drawImage(stateImage[i], x1[i], y1, null);
218230
// }
219231
for (Button b : buttons) {
220-
g.drawImage(b.stateImage, b.left, TOP, null);
232+
g.drawImage(b.stateImage, b.left, TOP, BUTTON_WIDTH, BUTTON_HEIGHT, null);
221233
}
222234

223235
g.setColor(statusColor);
@@ -259,10 +271,11 @@ public void paintComponent(Graphics screen) {
259271
g.drawRect(modeX1, modeY1, modeX2 - modeX1, modeY2 - modeY1);
260272
g.drawString(modeTitle, modeX1 + modeGapH, modeY2 - modeGapV);
261273

262-
screen.drawImage(offscreen, 0, 0, null);
263-
274+
screen.drawImage(offscreen, 0, 0, size.width, size.height, null);
275+
276+
// dim things out when not enabled (not currently in use)
264277
if (!isEnabled()) {
265-
screen.setColor(new Color(0,0,0,100));
278+
screen.setColor(new Color(0, 0, 0, 100));
266279
screen.fillRect(0, 0, getWidth(), getHeight());
267280
}
268281
}

app/src/processing/app/Toolkit.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,22 @@ static public void beep() {
212212
static public Clipboard getSystemClipboard() {
213213
return awtToolkit.getSystemClipboard();
214214
}
215+
216+
217+
static Boolean retinaProp;
218+
219+
static public boolean isRetina() {
220+
if (Base.isMacOS()) {
221+
// This should probably be reset each time there's a display change.
222+
// A 5-minute search didn't turn up any such event in the Java API.
223+
// Also, should we use the Toolkit associated with the editor window?
224+
if (retinaProp == null) {
225+
Float prop = (Float)
226+
awtToolkit.getDesktopProperty("apple.awt.contentScaleFactor");
227+
retinaProp = prop == 2;
228+
}
229+
return retinaProp;
230+
}
231+
return false;
232+
}
215233
}

build/macosx/template.app/Contents/Info.plist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<key>LSMinimumSystemVersion</key>
6060
<string>10.6.8</string>
6161

62+
<key>NSHighResolutionCapable</key>
63+
<true/>
64+
6265
<key>Java</key>
6366
<dict>
6467
<key>SplashFile</key>

0 commit comments

Comments
 (0)