getting to work on the new gui, plus much-improved text drawing

This commit is contained in:
Ben Fry
2015-01-25 09:40:09 -05:00
parent 22f58671aa
commit 342c6958ab
9 changed files with 82 additions and 90 deletions
+2
View File
@@ -1522,6 +1522,7 @@ public class Base {
}
/*
static private Boolean usableOracleJava;
// Make sure this is Oracle Java 7u40 or later. This is temporary.
@@ -1543,6 +1544,7 @@ public class Base {
}
return usableOracleJava;
}
*/
/**
+8 -12
View File
@@ -253,21 +253,17 @@ public class EditorHeader extends JComponent {
fontAscent = (int) Toolkit.getAscent(g);
}
Graphics2D g2 = (Graphics2D) g;
Graphics2D g2 = Toolkit.prepareGraphics(g);
/*
if (Toolkit.highResDisplay()) {
// scale everything 2x, will be scaled down when drawn to the screen
g2.scale(2, 2);
if (Base.isUsableOracleJava()) {
// Oracle Java looks better with anti-aliasing turned on
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
} else {
// don't anti-alias text in retina mode w/ Apple Java
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
}
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
*/
// set the background for the offscreen
g.setColor(hiding ? hideColor : bgColor);
+1 -14
View File
@@ -24,7 +24,6 @@
package processing.app;
import java.awt.*;
//import java.awt.event.*;
import javax.swing.*;
@@ -195,19 +194,7 @@ public class EditorStatus extends JPanel {
}
Graphics g = offscreen.getGraphics();
Graphics2D g2 = (Graphics2D) g;
if (Toolkit.highResDisplay()) {
g2.scale(2, 2);
if (Base.isUsableOracleJava()) {
// Oracle Java looks better with anti-aliasing turned on
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
} else {
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
/*Graphics2D g2 =*/ Toolkit.prepareGraphics(g);
g.setFont(font);
if (metrics == null) {
+2 -16
View File
@@ -205,22 +205,8 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
// offsetX = x2[i];
// }
}
Graphics g = offscreen.getGraphics();
Graphics2D g2 = (Graphics2D) g;
if (Toolkit.highResDisplay()) {
// scale everything 2x, will be scaled down when drawn to the screen
g2.scale(2, 2);
if (Base.isUsableOracleJava()) {
// Oracle Java looks better with anti-aliasing turned on
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
} else {
// don't anti-alias text in retina mode w/ Apple Java
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
Graphics g = offscreen.getGraphics();
/*Graphics2D g2 =*/ Toolkit.prepareGraphics(g);
g.setColor(hiding ? hideColor : bgColor);
g.fillRect(0, 0, width, height);
+39 -32
View File
@@ -32,6 +32,7 @@ import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Window;
import java.awt.datatransfer.Clipboard;
import java.awt.event.ActionEvent;
@@ -488,8 +489,32 @@ public class Toolkit {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Handles scaling for high-res displays, also sets text anti-aliasing
* options. Moved to a utility function because it's used in several classes.
* @param g
* @return a Graphics2D object, as a bit o sugar
*/
static public Graphics2D prepareGraphics(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (Toolkit.highResDisplay()) {
// scale everything 2x, will be scaled down when drawn to the screen
g2.scale(2, 2);
}
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
return g2;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static Boolean highResProp;
@@ -501,43 +526,25 @@ public class Toolkit {
}
// This should probably be reset each time there's a display change.
// A 5-minute search didn't turn up any such event in the Java API.
// Also, should we use the Toolkit associated with the editor window?
static private boolean checkRetina() {
if (Base.isMacOS()) {
// This should probably be reset each time there's a display change.
// A 5-minute search didn't turn up any such event in the Java API.
// Also, should we use the Toolkit associated with the editor window?
// String javaVendor = System.getProperty("java.vendor");
// if (javaVendor.contains("Apple")) {
if (System.getProperty("java.vendor").contains("Apple")) {
Float prop = (Float)
awtToolkit.getDesktopProperty("apple.awt.contentScaleFactor");
if (prop != null) {
return prop == 2;
}
// } else if (javaVendor.contains("Oracle")) {
// String version = System.getProperty("java.version"); // 1.7.0_40
// String[] m = PApplet.match(version, "1.(\\d).*_(\\d+)");
//
// // Make sure this is Oracle Java 7u40 or later
// if (m != null &&
// PApplet.parseInt(m[1]) >= 7 &&
// PApplet.parseInt(m[1]) >= 40) {
} else if (Base.isUsableOracleJava()) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
try {
Field field = device.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(device);
try {
Field field = device.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(device);
if (scale instanceof Integer && ((Integer)scale).intValue() == 2) {
return true;
}
if (scale instanceof Integer && ((Integer)scale).intValue() == 2) {
return true;
}
} catch (Exception ignore) { }
}
}
} catch (Exception ignore) { }
}
return false;
}
+3 -4
View File
@@ -5,6 +5,9 @@ X hint(ENABLE_RETINA_PIXELS) or hint(ENABLE_HIDPI_PIXELS)
X hint(ENABLE_2X_PIXELS)?
X hidpi is Apple's name as well
X mostly getting away from this
X bezierSegment() function to do equal-length segments
X https://github.com/processing/processing/issues/2919
X handled instead as an example
_ textAlign(RIGHT) including spaces at the end of each line
_ https://github.com/processing/processing/issues/3028
@@ -134,10 +137,6 @@ _ save the constructor for the version that actually copies data
_ the table pointer version will be speedy and allow chaining
_ bezierSegment() function to do equal-length segments
_ https://github.com/processing/processing/issues/2919
high
_ Closing opengl sketch from the PDE doesn't stop java process on windows
_ https://github.com/processing/processing/issues/2335
+12 -3
View File
@@ -91,7 +91,6 @@ public class DebugTray extends JFrame {
scrollPane = new JScrollPane();
tree = new Outline();
scrollPane.setViewportView(tree);
GroupLayout layout = new GroupLayout(getContentPane());
@@ -99,11 +98,16 @@ public class DebugTray extends JFrame {
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)));
.addComponent(scrollPane,
GroupLayout.DEFAULT_SIZE,
400, Short.MAX_VALUE)));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(scrollPane, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)));
.addComponent(scrollPane,
GroupLayout.Alignment.TRAILING,
GroupLayout.DEFAULT_SIZE,
300, Short.MAX_VALUE)));
pack();
// setup Outline
@@ -138,6 +142,11 @@ public class DebugTray extends JFrame {
}
class TrayToolbar extends JComponent {
}
/** Keeps the debug window adjacent the editor at all times. */
class EditorFollower implements ComponentListener {
@@ -922,6 +922,7 @@ public class Debugger implements VMEventListener {
return "";
}
return t.frame(0).thisObject().referenceType().name();
} catch (IncompatibleThreadStateException ex) {
log(Level.SEVERE, null, ex);
return "";
+14 -9
View File
@@ -9,6 +9,7 @@ X don't add a ^M to files when writing
X https://github.com/processing/processing/issues/3014
X add more bulletproofing to the save process
X https://github.com/processing/processing/issues/2923
X serious text improvements (at least on retina)
update components
X moving to Java 8 because Java 7 will be discontinued
@@ -84,14 +85,22 @@ X https://github.com/processing/processing/pull/3048
integration of pdex
X changed JLS4 to JLS8 (but make sure it doesn't introduce anything too weird)
X change build scripts, get things running
X rename TextArea and TextAreaPainter to JavaTextArea
X DebugEditor.createTextArea() is copy & pasted from JavaEditor
X this whole setup is really gross at the moment
X finish Ant task to download JRE and JDK from Oracle
_ remove public 'ta' object in DebugEditor, also dmode
_ rename TextArea and TextAreaPainter to JavaTextArea
_ DebugEditor.createTextArea() is copy & pasted from JavaEditor
_ this whole setup is really gross at the moment
_ auto-insert after antlr @SuppressWarnings({ "unused", "unchecked", "cast" })
_ crashed on startup w/ JavaScript mode as default b/c PdeKeyListener not found
_ because it's in the other ClassLoader, can no longer rely on it
jre download/install
_ update build scripts for Windows and Linux to use JRE downloader Ant Task
_ https://github.com/processing/processing/issues/3059
_ add method to prompt OS X developers to download the JDK update
_ make sure the file downloads correctly before renaming
_ https://github.com/processing/processing/issues/2960
_ fix file change detection on OS X
_ https://github.com/processing/processing/issues/2852
@@ -102,11 +111,7 @@ _ otherwise redoing the design for 2 modes
_ add span screens pref (near the display pref)
_ add checkbox for spans to export dialog
_ remove "save before running" message
X finish Ant task to download JRE and JDK from Oracle
_ add method to prompt OS X developers to download the JDK update
_ make sure the file downloads correctly before renaming
_ https://github.com/processing/processing/issues/2960
_ auto-insert after antlr @SuppressWarnings({ "unused", "unchecked", "cast" })
from the todo list