diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index e52626c2b..4bab20028 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -25,8 +25,8 @@ package processing.core; -//import java.awt.*; import java.awt.Color; +import java.awt.Image; import java.util.HashMap; import java.util.WeakHashMap; @@ -501,12 +501,12 @@ public class PGraphics extends PImage implements PConstants { // ........................................................ -// /** -// * Java AWT Image object associated with this renderer. For the 1.0 version -// * of P2D and P3D, this was be associated with their MemoryImageSource. -// * For PGraphicsJava2D, it will be the offscreen drawing buffer. -// */ -// public Image image; + /** + * Java AWT Image object associated with this renderer. For the 1.0 version + * of P2D and P3D, this was associated with their MemoryImageSource. + * For PGraphicsJava2D, it will be the offscreen drawing buffer. + */ + public Image image; // ........................................................ diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index f8f4c8748..487c70120 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -52,7 +52,7 @@ import processing.data.XML; public class PGraphicsJava2D extends PGraphics { BufferStrategy strategy; BufferedImage bimage; - VolatileImage vimage; +// VolatileImage vimage; Canvas canvas; // boolean useCanvas = true; boolean useCanvas = false; @@ -60,13 +60,6 @@ public class PGraphicsJava2D extends PGraphics { // boolean useOffscreen = true; // ~40fps boolean useOffscreen = false; - /** - * Java AWT Image object associated with this renderer. For the 1.0 version - * of P2D and P3D, this was be associated with their MemoryImageSource. - * For PGraphicsJava2D, it will be the offscreen drawing buffer. - */ - public Image image; // moved from PGraphics, not sure about this yet - public Graphics2D g2; protected BufferedImage offscreen; @@ -255,8 +248,8 @@ public class PGraphicsJava2D extends PGraphics { // and 2) minimal overhead, however. Instinct suggests #1 may be true, // but #2 seems a problem. if (primarySurface && !useOffscreen) { + GraphicsConfiguration gc = canvas.getGraphicsConfiguration(); if (false) { - GraphicsConfiguration gc = parent.getGraphicsConfiguration(); if (image == null || ((VolatileImage) image).validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) { image = gc.createCompatibleVolatileImage(width, height); g2 = (Graphics2D) image.getGraphics(); @@ -264,18 +257,12 @@ public class PGraphicsJava2D extends PGraphics { } } else { if (image == null) { - GraphicsConfiguration gc = parent.getGraphicsConfiguration(); image = gc.createCompatibleImage(width, height); PApplet.debug("created new image, type is " + image); g2 = (Graphics2D) image.getGraphics(); reapplySettings = true; } } - //g2 = (Graphics2D) image.getGraphics(); -// if (g2 != g2old) { -// System.out.println("new g2: " + g2); -// g2old = g2; -// } } if (useCanvas && primarySurface) { @@ -291,10 +278,6 @@ public class PGraphicsJava2D extends PGraphics { "/" + caps.getBackBufferCapabilities().isAccelerated()); } GraphicsConfiguration gc = canvas.getGraphicsConfiguration(); -// if (vimage == null || vimage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) { -// vimage = gc.createCompatibleVolatileImage(width, height); -// } -// g2 = (Graphics2D) vimage.getGraphics(); if (bimage == null || bimage.getWidth() != width || @@ -375,10 +358,10 @@ public class PGraphicsJava2D extends PGraphics { PApplet.debug("PGraphicsJava2D.redraw() top of inner do { } block"); PApplet.debug("strategy is " + strategy); Graphics bsg = strategy.getDrawGraphics(); - if (vimage != null) { - bsg.drawImage(vimage, 0, 0, null); - } else { - bsg.drawImage(bimage, 0, 0, null); +// if (vimage != null) { +// bsg.drawImage(vimage, 0, 0, null); +// } else { + bsg.drawImage(bimage, 0, 0, null); // if (parent.frameCount == 0) { // try { // ImageIO.write(image, "jpg", new java.io.File("/Users/fry/Desktop/buff.jpg")); @@ -386,7 +369,7 @@ public class PGraphicsJava2D extends PGraphics { // e.printStackTrace(); // } // } - } +// } bsg.dispose(); // the strategy version @@ -1691,7 +1674,7 @@ public class PGraphicsJava2D extends PGraphics { Font font = (Font) textFont.getNative(); if (font != null) { - FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(font); + FontMetrics metrics = canvas.getFontMetrics(font); return metrics.getAscent(); } return super.textAscent(); @@ -1706,7 +1689,7 @@ public class PGraphicsJava2D extends PGraphics { Font font = (Font) textFont.getNative(); //if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { - FontMetrics metrics = parent.getFontMetrics(font); + FontMetrics metrics = canvas.getFontMetrics(font); return metrics.getDescent(); } return super.textDescent(); diff --git a/core/src/processing/core/PSurface.java b/core/src/processing/core/PSurface.java index 14fa5183f..c5469f6a9 100644 --- a/core/src/processing/core/PSurface.java +++ b/core/src/processing/core/PSurface.java @@ -1,3 +1,25 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2014 The Processing Foundation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation, version 2.1. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA +*/ + package processing.core; import java.awt.Color; diff --git a/core/src/processing/core/PSurfaceAWT.java b/core/src/processing/core/PSurfaceAWT.java index c860579d0..b8ba9b7e4 100644 --- a/core/src/processing/core/PSurfaceAWT.java +++ b/core/src/processing/core/PSurfaceAWT.java @@ -1,25 +1,32 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2014 The Processing Foundation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation, version 2.1. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA +*/ + package processing.core; -import java.applet.*; import java.awt.*; -import java.awt.event.WindowStateListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; +import java.awt.event.*; import java.awt.geom.Rectangle2D; import java.awt.image.*; -import java.lang.reflect.Field; -import java.lang.reflect.Method; +import java.lang.reflect.*; import java.net.URL; import java.util.ArrayList; @@ -46,6 +53,7 @@ public class PSurfaceAWT implements PSurface { Canvas canvas; PApplet sketch; + PGraphics pg; Thread thread; boolean paused; @@ -65,11 +73,14 @@ public class PSurfaceAWT implements PSurface { useActive = false; } + createCanvas(); + addListeners(); } void createCanvas() { canvas = new SmoothCanvas(); + //canvas.setIgnoreRepaint(true); // ?? } @@ -124,6 +135,7 @@ public class PSurfaceAWT implements PSurface { private Dimension oldSize = new Dimension(0, 0); private Dimension newSize = new Dimension(0, 0); + @Override public void validate() { super.validate(); @@ -230,16 +242,16 @@ public class PSurfaceAWT implements PSurface { protected synchronized void render() { - if (canvas == null) { - removeListeners(this); - canvas = new Canvas(); - add(canvas); - setIgnoreRepaint(true); - canvas.setIgnoreRepaint(true); - addListeners(canvas); -// add(canvas, BorderLayout.CENTER); -// doLayout(); - } +// if (canvas == null) { +// removeListeners(this); +// canvas = new Canvas(); +// add(canvas); +// setIgnoreRepaint(true); +// canvas.setIgnoreRepaint(true); +// addListeners(canvas); +//// add(canvas, BorderLayout.CENTER); +//// doLayout(); +// } canvas.setBounds(0, 0, sketch.width, sketch.height); // System.out.println("render(), canvas bounds are " + canvas.getBounds()); if (canvas.getBufferStrategy() == null) { // whole block [121222] @@ -256,7 +268,7 @@ public class PSurfaceAWT implements PSurface { // are consistent in case the underlying surface was recreated do { Graphics draw = strategy.getDrawGraphics(); - draw.drawImage(g.image, 0, 0, sketch.width, sketch.height, null); + draw.drawImage(pg.image, 0, 0, sketch.width, sketch.height, null); draw.dispose(); // Repeat the rendering if the drawing buffer contents @@ -328,6 +340,8 @@ public class PSurfaceAWT implements PSurface { public void blit() { + canvas.repaint(); + /* if (canvas.getGraphicsConfiguration() != null) { GraphicsDevice device = canvas.getGraphicsConfiguration().getDevice(); if (device != displayDevice) { @@ -348,6 +362,7 @@ public class PSurfaceAWT implements PSurface { canvas.repaint(); } // getToolkit().sync(); // force repaint now (proper method) + */ } @@ -469,7 +484,7 @@ public class PSurfaceAWT implements PSurface { // been overridden by numbers we calculated above if fullScreen and/or // spanScreens was in use. //sketch.makePrimaryGraphics(sketchWidth, sketchHeight); - sketch.makePrimaryGraphics(); + pg = sketch.makePrimaryGraphics(); if (fullScreen) { frame.invalidate(); @@ -526,10 +541,10 @@ public class PSurfaceAWT implements PSurface { (screenRect.height - sketch.height) / 2, sketch.width, sketch.height); - if (PApplet.platform == PConstants.MACOSX) { - macosxFullScreenEnable(frame); - macosxFullScreenToggle(frame); - } +// if (PApplet.platform == PConstants.MACOSX) { +// macosxFullScreenEnable(frame); +// macosxFullScreenToggle(frame); +// } if (stopColor != null) { Label label = new Label("stop"); @@ -945,53 +960,52 @@ public class PSurfaceAWT implements PSurface { } } frame.setIconImages(iconImages); - } catch (Exception e) { - //e.printStackTrace(); // more or less harmless; don't spew errors - } + + } catch (Exception e) { } // harmless; keep this to ourselves } } - /** - * (No longer in use) Use reflection to call - * com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(window, true); - */ - static void macosxFullScreenEnable(Window window) { - try { - Class util = Class.forName("com.apple.eawt.FullScreenUtilities"); - Class params[] = new Class[] { Window.class, Boolean.TYPE }; - Method method = util.getMethod("setWindowCanFullScreen", params); - method.invoke(util, window, true); - - } catch (ClassNotFoundException cnfe) { - // ignored - } catch (Exception e) { - e.printStackTrace(); - } - } - - - /** - * (No longer in use) Use reflection to call - * com.apple.eawt.Application.getApplication().requestToggleFullScreen(window); - */ - static void macosxFullScreenToggle(Window window) { - try { - Class appClass = Class.forName("com.apple.eawt.Application"); - - Method getAppMethod = appClass.getMethod("getApplication"); - Object app = getAppMethod.invoke(null, new Object[0]); - - Method requestMethod = - appClass.getMethod("requestToggleFullScreen", Window.class); - requestMethod.invoke(app, window); - - } catch (ClassNotFoundException cnfe) { - // ignored - } catch (Exception e) { - e.printStackTrace(); - } - } +// /** +// * (No longer in use) Use reflection to call +// * com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(window, true); +// */ +// static void macosxFullScreenEnable(Window window) { +// try { +// Class util = Class.forName("com.apple.eawt.FullScreenUtilities"); +// Class params[] = new Class[] { Window.class, Boolean.TYPE }; +// Method method = util.getMethod("setWindowCanFullScreen", params); +// method.invoke(util, window, true); +// +// } catch (ClassNotFoundException cnfe) { +// // ignored +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// +// +// /** +// * (No longer in use) Use reflection to call +// * com.apple.eawt.Application.getApplication().requestToggleFullScreen(window); +// */ +// static void macosxFullScreenToggle(Window window) { +// try { +// Class appClass = Class.forName("com.apple.eawt.Application"); +// +// Method getAppMethod = appClass.getMethod("getApplication"); +// Object app = getAppMethod.invoke(null, new Object[0]); +// +// Method requestMethod = +// appClass.getMethod("requestToggleFullScreen", Window.class); +// requestMethod.invoke(app, window); +// +// } catch (ClassNotFoundException cnfe) { +// // ignored +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } ////////////////////////////////////////////////////////////// @@ -1147,8 +1161,8 @@ public class PSurfaceAWT implements PSurface { } - public void addListeners() { - // lots of listeners, for all my men! + // listeners, for all my men! + protected void addListeners() { canvas.addMouseListener(new MouseListener() { @@ -1288,9 +1302,10 @@ public class PSurfaceAWT implements PSurface { // Don't resize the renderer from the EDT (i.e. from a ComponentEvent), // otherwise it may attempt a resize mid-render. // if (g != null) { - Dimension currentSize = getSize(); - if (currentSize.width != g.width || currentSize.height != g.height) { - resizeRenderer(currentSize.width, currentSize.height); + Dimension currentSize = canvas.getSize(); + if (currentSize.width != pg.width || currentSize.height != pg.height) { + //resizeRenderer(currentSize.width, currentSize.height); + System.err.format("need to resize from %s to %d, %d", currentSize, pg.width, pg.height); } // }