Transparent sketch

@GoToLoop

I’m just following an old thread and stumbled upon some of your code

https://forum.processing.org/two/discussion/20499/moving-a-translucent-window-around-the-screen/p1

/**
 * Opacity + WindowDecoration (v2.0)
 * Bird (2017-Jan-27)
 * mod GoToLoop
 *
 * forum.Processing.org/two/discussion/20499/
 * moving-a-translucent-window-around-the-screen#Item_8
 */
 
import processing.awt.PSurfaceAWT.SmoothCanvas;
import com.sun.awt.AWTUtilities;
 
import javax.swing.JFrame;
import javax.swing.JRootPane;
 
static final float STEP = .05;
JFrame jframe;
 
void setup() {
  size(300, 200);
  //noLoop();
 
  jframe = getJFrame(getSurface());
 
  jframe.removeNotify();
  jframe.setUndecorated(true);
  jframe.addNotify();
 
  //jframe.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
  jframe.setOpacity(.5);
}
 
void draw() {
  jframe.setTitle(nf(jframe.getOpacity(), 1, 2));
  //background(1000,0,1000,255);
  fill(1000,0,1000,255);
  rect(0,0,width+10,height+30);
} 
 
void mousePressed() {
  final int btn = mouseButton;
  float opac = 1;
 
  if (btn == CENTER)  AWTUtilities.setWindowOpacity(jframe, 1);
  else {
    final float step = btn == LEFT? -STEP : STEP;
    opac = constrain(jframe.getOpacity() + step, .1, .95);
    jframe.setOpacity(opac);
  }
 
  redraw = true;
  println(opac);
}
 
static final JFrame getJFrame(final PSurface surf) {
  return (JFrame) ((SmoothCanvas) surf.getNative()).getFrame();
}

now this does indeed set the surface transparency, but it also makes everything transparent. Is there any way to set the background transparency of the sketch but still have the other items have regular transparency?

also when removing the window decorations it also add another issue which is canvas overflow, as you can see the grey lines at the bottom and on the right

Thanks

That’s just a refactoring I’ve made. I didn’t write the original code. :woozy_face:

And I dunno much about how a JFrame works either, sorry. :confounded:

1 Like