Translucent Window in Processing
in
Share your Work
•
2 years ago
To get a Translucent / Transparent window like this:
Here yo have the code:
- // http://xavierstechno.blogspot.com/
- //http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
- import com.sun.awt.AWTUtilities;
- import java.awt.*;
- import javax.swing.JFrame;
- JFrame topFrame = null;
- PGraphics pg3D;
- int framePosX = 800;
- int framePosY = 300;
- int frameWidth = 300;
- int frameHeight = 300;
- float opacitatTopFrame = 0.9f;
- public void init(){
- frame.removeNotify();
- frame.setUndecorated(true);
- AWTUtilities.setWindowOpaque(frame, false);
- AWTUtilities.setWindowOpacity(frame, 0.0f);
- //frame.setOpacity(0.0f);
- frame.setBackground(new Color(0.0f,0.0f,0.0f,0.0f));
- frame.setVisible(false);
- frame.setLayout( null );
- frame.addNotify();
- GraphicsConfiguration translucencyCapableGC;
- translucencyCapableGC = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
- topFrame = new JFrame(translucencyCapableGC);
- topFrame.setUndecorated(true);
- //topFrame.setOpacity(opacitatTopFrame);
- AWTUtilities.setWindowOpaque(topFrame, false);
- AWTUtilities.setWindowOpacity(topFrame, opacitatTopFrame);
- topFrame.setAlwaysOnTop(false);
- topFrame.setLocationRelativeTo(null);
- topFrame.setLocation(framePosX, framePosY);
- topFrame.setSize(frameWidth, frameHeight);
- topFrame.setBackground(new Color(0,0,0,0));
- topFrame.setVisible(true);
- topFrame.setTitle( frame == null? "":frame.getTitle() );
- topFrame.setIconImage( frame.getIconImage() );
- topFrame.setLayout( null );
- topFrame.addNotify();
- super.init();
- g.format = ARGB;
- g.setPrimary(false);
- }
- void setup() {
- size(frameWidth, frameHeight);
- colorMode(RGB,255,255,255,255);
- pg3D = createGraphics(frameWidth, frameHeight,P3D);
- pg3D.colorMode(RGB,255,255,255,255);
- }
- float angle = 0;
- void draw() {
- background(0,0,255,135);
- fill(0,255,0,55);
- int mX = MouseInfo.getPointerInfo().getLocation().x-framePosX;
- int mY = MouseInfo.getPointerInfo().getLocation().y-framePosY;
- rectMode(CENTER);
- rect(mX, mY,50,50);
- pg3D.beginDraw();
- pg3D.background(0,0,0,0);
- pg3D.stroke(0);
- pg3D.fill(255,0,0,255);
- pg3D.translate(100,100); pg3D.rotateZ(angle); pg3D.rotateX(angle); pg3D.rotateY(angle);
- pg3D.rectMode(CENTER);
- pg3D.rect(0,0,50,50);
- pg3D.endDraw();
- image(pg3D,0,0);
- frame.setVisible(false);
- topFrame.add(this);
- angle+=0.02;
- }
3