mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
more surface updates based on discussion in #3388
This commit is contained in:
@@ -772,18 +772,21 @@ public class PApplet implements PConstants {
|
||||
protected PSurface surface;
|
||||
|
||||
|
||||
/** The frame containing this sketch (if any) */
|
||||
/**
|
||||
* A dummy frame to keep compatibility with 2.x code
|
||||
* and encourage users to update.
|
||||
*/
|
||||
public Frame frame;
|
||||
|
||||
|
||||
public Frame getFrame() {
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
public void setFrame(Frame frame) {
|
||||
this.frame = frame;
|
||||
}
|
||||
// public Frame getFrame() {
|
||||
// return frame;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void setFrame(Frame frame) {
|
||||
// this.frame = frame;
|
||||
// }
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
@@ -4934,7 +4934,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public FontMetrics getFontMetrics(Font font) { // ignore
|
||||
Frame frame = parent.getFrame();
|
||||
Frame frame = parent.frame;
|
||||
if (frame != null) {
|
||||
return frame.getToolkit().getFontMetrics(font);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,16 @@ public interface PSurface {
|
||||
// int deviceIndex, boolean fullScreen, boolean spanDisplays);
|
||||
public void initFrame(PApplet sketch);
|
||||
|
||||
/**
|
||||
* Get the native window object associated with this drawing surface.
|
||||
* For Java2D, this will be an AWT Frame object. For OpenGL, the window.
|
||||
* The data returned here is subject to the whims of the renderer,
|
||||
* and using this method means you're willing to deal with underlying
|
||||
* implementation changes and that you won't throw a fit like a toddler
|
||||
* if your code breaks sometime in the future.
|
||||
*/
|
||||
public Object getNative();
|
||||
|
||||
//
|
||||
|
||||
// Just call these on an AWT Frame object stored in PApplet.
|
||||
@@ -61,6 +71,8 @@ public interface PSurface {
|
||||
/** Set true if we want to resize things (default is not resizable) */
|
||||
public void setResizable(boolean resizable);
|
||||
|
||||
public void setIcon(PImage icon);
|
||||
|
||||
//
|
||||
|
||||
// public void placeWindow(int[] location);
|
||||
@@ -78,6 +90,8 @@ public interface PSurface {
|
||||
// sets displayWidth/Height inside PApplet
|
||||
//public void checkDisplaySize();
|
||||
|
||||
public void setLocation(int x, int y);
|
||||
|
||||
public void setSize(int width, int height);
|
||||
|
||||
/**
|
||||
|
||||
@@ -149,6 +149,11 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
private Dimension newSize = new Dimension(0, 0);
|
||||
|
||||
|
||||
public Frame getFrame() {
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(sketchWidth, sketchHeight);
|
||||
@@ -531,7 +536,13 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
// http://code.google.com/p/processing/issues/detail?id=467
|
||||
frame.setResizable(false);
|
||||
|
||||
sketch.setFrame(frame);
|
||||
// sketch.setFrame(frame);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getNative() {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
||||
@@ -833,9 +844,9 @@ public class PSurfaceAWT extends PSurfaceNone {
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public void setSmooth(int level) {
|
||||
}
|
||||
// @Override
|
||||
// public void setSmooth(int level) {
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -68,6 +68,11 @@ public class PSurfaceFX implements PSurface {
|
||||
}
|
||||
|
||||
|
||||
public Object getNative() {
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
||||
class ResizableCanvas extends Canvas {
|
||||
|
||||
public ResizableCanvas() {
|
||||
@@ -141,6 +146,10 @@ public class PSurfaceFX implements PSurface {
|
||||
});
|
||||
}
|
||||
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResizable() {
|
||||
return true;
|
||||
@@ -248,6 +257,11 @@ public class PSurfaceFX implements PSurface {
|
||||
}
|
||||
|
||||
|
||||
public void setIcon(PImage icon) {
|
||||
// TODO implement this in JavaFX
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void placeWindow(int[] location) {
|
||||
@@ -386,6 +400,12 @@ public class PSurfaceFX implements PSurface {
|
||||
}
|
||||
|
||||
|
||||
public void setLocation(int x, int y) {
|
||||
stage.setX(x);
|
||||
stage.setY(y);
|
||||
}
|
||||
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
//System.out.format("%s.setSize(%d, %d)%n", getClass().getSimpleName(), width, height);
|
||||
stage.setWidth(width);
|
||||
|
||||
@@ -67,26 +67,38 @@ public class PSurfaceNone implements PSurface {
|
||||
}
|
||||
|
||||
|
||||
public Object getNative() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/** Set the window (and dock, or whatever necessary) title. */
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
// TODO ignored?
|
||||
// You're in a utopian PSurface implementation where titles don't exist.
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setIcon(PImage image) {
|
||||
// I ain't visible, man.
|
||||
}
|
||||
|
||||
|
||||
/** Show or hide the window. */
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
// TODO ignored?
|
||||
// I'm always invisible. You can't catch me.
|
||||
}
|
||||
|
||||
|
||||
/** Set true if we want to resize things (default is not resizable) */
|
||||
@Override
|
||||
public void setResizable(boolean resizable) {
|
||||
// TODO ignored?
|
||||
// I don't need size to know my worth.
|
||||
}
|
||||
|
||||
|
||||
// public void placeWindow(int[] location) { }
|
||||
|
||||
@Override
|
||||
public void placeWindow(int[] location, int[] editorLocation) { }
|
||||
|
||||
@@ -102,6 +114,12 @@ public class PSurfaceNone implements PSurface {
|
||||
//
|
||||
|
||||
|
||||
@Override
|
||||
public void setLocation(int x, int y) {
|
||||
// I'm everywhere, because I'm nowhere.
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setSize(int wide, int high) {
|
||||
if (PApplet.DEBUG) {
|
||||
@@ -136,10 +154,9 @@ public class PSurfaceNone implements PSurface {
|
||||
// }
|
||||
|
||||
|
||||
public void setSmooth(int level) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
// public void setSmooth(int level) {
|
||||
// // TODO Auto-generated method stub
|
||||
// }
|
||||
|
||||
// void requestFocus() {
|
||||
// }
|
||||
|
||||
@@ -111,6 +111,12 @@ public class PSurfaceJOGL implements PSurface {
|
||||
}
|
||||
|
||||
|
||||
public Object getNative() {
|
||||
System.err.println("PSurfaceJOGL.getNative() not implemented");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected void initScreen() {
|
||||
display = NewtFactory.createDisplay(null);
|
||||
display.addReference();
|
||||
@@ -336,22 +342,40 @@ public class PSurfaceJOGL implements PSurface {
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
window.setTitle(title);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
window.setVisible(visible);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setResizable(boolean resizable) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setIcon(PImage icon) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
||||
protected void initIcons() {
|
||||
final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
|
||||
String[] iconImages = new String[sizes.length];
|
||||
for (int i = 0; i < sizes.length; i++) {
|
||||
iconImages[i] = "/icon/icon-" + sizes[i] + ".png";
|
||||
}
|
||||
NewtFactory.setWindowIcons(new ClassResources(PApplet.class, iconImages));
|
||||
}
|
||||
|
||||
|
||||
// private void setFrameCentered() {
|
||||
// }
|
||||
|
||||
@@ -460,16 +484,6 @@ public class PSurfaceJOGL implements PSurface {
|
||||
}
|
||||
|
||||
|
||||
protected void initIcons() {
|
||||
final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
|
||||
String[] iconImages = new String[sizes.length];
|
||||
for (int i = 0; i < sizes.length; i++) {
|
||||
iconImages[i] = "/icon/icon-" + sizes[i] + ".png";
|
||||
}
|
||||
NewtFactory.setWindowIcons(new ClassResources(PApplet.class, iconImages));
|
||||
}
|
||||
|
||||
|
||||
public void setupExternalMessages() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@@ -523,6 +537,13 @@ public class PSurfaceJOGL implements PSurface {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setLocation(int x, int y) {
|
||||
// TODO implement me!
|
||||
System.err.println("PSurfaceJOGL.setLocation() not yet implemented.");
|
||||
}
|
||||
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
if (width == sketch.width && height == sketch.height) {
|
||||
return;
|
||||
|
||||
@@ -81,11 +81,11 @@ beta
|
||||
_ pixelDensity(BEST)? (messes with pixels, but for most sketches, helpful)
|
||||
_ surface.setXxx() handling
|
||||
_ https://github.com/processing/processing/issues/3388
|
||||
_ setResizable, setVisible, setTitle
|
||||
_ setIconImage(java.awt.Image) -> take a PImage instead?
|
||||
X setResizable, setVisible, setTitle
|
||||
X setIconImage(java.awt.Image) -> take a PImage instead?
|
||||
_ removeNotify(), addNotify(), setUndecorated(boolean)
|
||||
_ setting menubar will be surface-specific
|
||||
_ setLocation(int, int) and setSize(int, int)
|
||||
X setting menubar will be surface-specific
|
||||
X setLocation(int, int) and setSize(int, int)
|
||||
_ add the "don't use this" warning to the JFrame in PSurfaceAWT
|
||||
_ draw() executes twice when noLoop() called in setup()
|
||||
_ https://github.com/processing/processing/issues/3310
|
||||
@@ -126,6 +126,7 @@ _ move loadImage() into PGraphics, with AWT version the default?
|
||||
_ or pass createImage() through to renderer?
|
||||
_ implement frameRate()
|
||||
_ implement external messages (moving the window)
|
||||
_ implement PSurfaceFX.setIcon()
|
||||
|
||||
|
||||
opengl
|
||||
|
||||
Reference in New Issue
Block a user