3232import java .awt .GraphicsDevice ;
3333import java .awt .GraphicsEnvironment ;
3434import java .awt .Image ;
35+ import java .awt .RenderingHints ;
3536import java .awt .Window ;
3637import java .awt .datatransfer .Clipboard ;
3738import java .awt .event .ActionEvent ;
@@ -488,8 +489,32 @@ static public Clipboard getSystemClipboard() {
488489
489490
490491 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
492+
493+
494+ /**
495+ * Handles scaling for high-res displays, also sets text anti-aliasing
496+ * options. Moved to a utility function because it's used in several classes.
497+ * @param g
498+ * @return a Graphics2D object, as a bit o sugar
499+ */
500+ static public Graphics2D prepareGraphics (Graphics g ) {
501+ Graphics2D g2 = (Graphics2D ) g ;
502+
503+ if (Toolkit .highResDisplay ()) {
504+ // scale everything 2x, will be scaled down when drawn to the screen
505+ g2 .scale (2 , 2 );
506+ }
507+ g2 .setRenderingHint (RenderingHints .KEY_TEXT_ANTIALIASING ,
508+ RenderingHints .VALUE_TEXT_ANTIALIAS_ON );
509+ g2 .setRenderingHint (RenderingHints .KEY_TEXT_ANTIALIASING ,
510+ RenderingHints .VALUE_TEXT_ANTIALIAS_GASP );
511+ return g2 ;
512+ }
513+
491514
515+ // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
492516
517+
493518 static Boolean highResProp ;
494519
495520
@@ -501,43 +526,25 @@ static public boolean highResDisplay() {
501526 }
502527
503528
529+ // This should probably be reset each time there's a display change.
530+ // A 5-minute search didn't turn up any such event in the Java API.
531+ // Also, should we use the Toolkit associated with the editor window?
504532 static private boolean checkRetina () {
505533 if (Base .isMacOS ()) {
506- // This should probably be reset each time there's a display change.
507- // A 5-minute search didn't turn up any such event in the Java API.
508- // Also, should we use the Toolkit associated with the editor window?
509- // String javaVendor = System.getProperty("java.vendor");
510- // if (javaVendor.contains("Apple")) {
511- if (System .getProperty ("java.vendor" ).contains ("Apple" )) {
512- Float prop = (Float )
513- awtToolkit .getDesktopProperty ("apple.awt.contentScaleFactor" );
514- if (prop != null ) {
515- return prop == 2 ;
516- }
517- // } else if (javaVendor.contains("Oracle")) {
518- // String version = System.getProperty("java.version"); // 1.7.0_40
519- // String[] m = PApplet.match(version, "1.(\\d).*_(\\d+)");
520- //
521- // // Make sure this is Oracle Java 7u40 or later
522- // if (m != null &&
523- // PApplet.parseInt(m[1]) >= 7 &&
524- // PApplet.parseInt(m[1]) >= 40) {
525- } else if (Base .isUsableOracleJava ()) {
526- GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment ();
527- GraphicsDevice device = env .getDefaultScreenDevice ();
528-
529- try {
530- Field field = device .getClass ().getDeclaredField ("scale" );
531- if (field != null ) {
532- field .setAccessible (true );
533- Object scale = field .get (device );
534-
535- if (scale instanceof Integer && ((Integer )scale ).intValue () == 2 ) {
536- return true ;
537- }
534+ GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment ();
535+ GraphicsDevice device = env .getDefaultScreenDevice ();
536+
537+ try {
538+ Field field = device .getClass ().getDeclaredField ("scale" );
539+ if (field != null ) {
540+ field .setAccessible (true );
541+ Object scale = field .get (device );
542+
543+ if (scale instanceof Integer && ((Integer )scale ).intValue () == 2 ) {
544+ return true ;
538545 }
539- } catch ( Exception ignore ) { }
540- }
546+ }
547+ } catch ( Exception ignore ) { }
541548 }
542549 return false ;
543550 }
0 commit comments