We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › how to hide window frame or set background opacity
Pages: 1 2 
how to hide window frame or set background opacity (Read 9144 times)
how to hide window frame or set background opacity
Jun 23rd, 2009, 2:56pm
 
Hello

I would like to know (if is it possible) how to run app frame without background ?

simple: background(100,0); doesnt work, how to set background opacity to 0% or disable displaying window background.

also I am wondering.. It is possible to hide window frame and display only thing contained for ex. in processing draw() section ??

HELP Smiley
Re: how to hide window frame or set background opacity
Reply #1 - Jun 23rd, 2009, 6:22pm
 
I don't think it is possible to make the background transparent.  From what I've read, it ignores the alpha value.  So even if you did something like background(color(0,0,0,1));  It would still be black.  Not sure if it's possible to modify it in the main().

The second one should be pretty easy.  
Add this Code:


public void init(){
 // to make a frame not displayable, you can
 // use frame.removeNotify()

 frame.removeNotify();
 frame.setUndecorated(true);

 // addNotify, here i am not sure if you have
 // to add notify again.  
 frame.addNotify();
 super.init();
}


To position your frame, you can put this in setup():
Code:

frame.setLocation(0,0);
Re: how to hide window frame or set background opacity
Reply #2 - Jun 23rd, 2009, 9:56pm
 
Unless you want the sketch window to be totally transparent with regard to other windows on your system, it makes no sense to have a fully transparent background, as transparency means "show what is behind" and there is nothing behind, beside the base window color of your system.
Transparency of the sketch might be possible with latest Java versions (done for JavaFX), although I am not sure yet how to do it.

Note: if you want to save an image with transparent background, it is possible. AFAIK you just use a JAVA2D PGraphics without background() call.
Re: how to hide window frame or set background opacity
Reply #3 - Sep 24th, 2009, 10:50pm
 
Hi

I was kind of interested in this as well.
I found that the transparent window worked fine. Also the shaped window which is demonstrated here. If labbed with some more you should find that you could do pretty much all you want to do, by tweaking the shaped window or tweaking the setOpaque or setOpacity which is two different things. Depending on what you want to do and depending on platform. Note! This code does not work on MacOSX. Due to Java different implementations I guess. AND it's hackish. No exception handling and there is alot of stuff that can go wrong I guess.
Read more on the subject right here:
http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#Enabling-Per-Pixel-Translucency

http://java.sun.com/docs/books/tutorial/uiswing/misc/trans_shaped_windows.html

Heres the code I got working on Windows XP:

import com.sun.awt.AWTUtilities;
import  java.awt.GraphicsDevice.*; // PC only
import java.awt.Shape;
import java.awt.geom.*;
import javax.swing.*;

public void init(){
 // to make a frame not displayable, you can
 // use frame.removeNotify()

 frame.removeNotify();
 frame.setUndecorated(true);

 // addNotify, here i am not sure if you have
 // to add notify again.
 //  frame.addNotify();
 // frame.removeNotify();
 super.init();
}


void setup() {
 size(200, 200);
 noStroke();
 frame.setAlwaysOnTop(true); // Alltid på topp
 frame.setLocation(0,0);
 AWTUtilities.setWindowOpaque(frame, false);
 AWTUtilities.setWindowOpacity(frame, 0.9f);

Shape shape = null;
      //shape = new Ellipse2D.Float(0, 0, frame.getWidth(), frame.getHeight());
      //shape = new Ellipse2D.Float(0, 0, 200, 200);
    //  shape = new RoundRectangle2D.Float(0, 0, 200, 200, 20, 20);
      //shape = new Polygon(int[] xpoints, int[] ypoints, int npoints) ;
      int[] myXes = new int[4];
      myXes[0]=0;
      myXes[1]=150;
      myXes[2]=150;
      myXes[3]=0;
      int[] myYs = new int[4];
      myYs[0]=0;
      myYs[1]=20;
      myYs[2]=180;
      myYs[3]=0;
      shape = new Polygon(myXes, myYs, 4) ;
      AWTUtilities.setWindowShape(frame, shape);


}

void draw() {
 setBackground(new Color(0,0,0,255)); // should work with normal background(255) command
 //  frame.setVisible(true);

 fill(255, 0, 0, 255); // the alpha is not in play at this point - but it come into play when doing per-pixel translucency
 rect(23, 23, 54, 54);
}


/JohanWastring
http://visualinformation.org
Re: how to hide window frame or set background opacity
Reply #4 - Sep 25th, 2009, 1:15am
 
Hi Johan,
this is really cool. Thank you for working on that.

Pretty sure some nice programms will make use of it in the future.
We should definitely add it to the hacks section.

THX!
Re: how to hide window frame or set background opacity
Reply #5 - Sep 25th, 2009, 2:43am
 
Johan_Wastring wrote on Sep 24th, 2009, 10:50pm:
Note! This code does not work on MacOSX. Due to Java different implementations I guess.

Indeed, the feature have been "introduced in the Java SE 6u10 release", and Mac (in 32bit versions) didn't have Java 1.6 until Snow Leopard, and I don't know what is the release number (if Apple follows Sun numbering! or list of features) of this version.

Anyway, thanks for doing the research, it is cool.
Re: how to hide window frame or set background opacity
Reply #6 - Nov 20th, 2009, 10:12am
 
I just wrote a sketch that is based on a shaped window with a hidden window frame... You can drag, shake and rotate the  window , and see the liquid inside react ...

You can find it here:
openprocessing.org/visuals/?visualID=6170
Re: how to hide window frame or set background opacity
Reply #7 - Nov 20th, 2009, 10:29am
 
Nice demo of what is possible using these features.
Re: how to hide window frame or set background opacity
Reply #8 - Dec 10th, 2009, 6:01am
 
Weird. The MacOsX Java for 10.6 was updated today. To the latest version that is available on Windows anyway. Version ..._17 something.
Still the shaped windows doesn't work on the Mac.
Odd I think.

Is it AWT that differs on the Mac?

/JohanWastring
http://visualinformation.org
Re: how to hide window frame or set background opacity
Reply #9 - Dec 10th, 2009, 6:35am
 
Quote:
Is it AWT that differs on the Mac?

Necessarily, since that's the software layer responsible of abstracting (and implementing access to) native GUI. When possible...
Re: how to hide window frame or set background opacity
Reply #10 - Dec 10th, 2009, 11:25am
 
Johan, thanks for sharing! It's pretty cool.
Re: how to hide window frame or set background opacity
Reply #11 - Jan 23rd, 2010, 6:38am
 
Hi,

could somebody achieve to make windows with a per-pixel translucency? It should be able with java on win xp, as seen on a link at visualinformation.org:
http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#Enabling-Per-Pixel-Translucency

but somehow, i don't get it wokrin with processing. Somebody got an idea?

cheers
Re: how to hide window frame or set background opacity
Reply #12 - Feb 23rd, 2010, 3:47pm
 
Even on SnowLeopard (with JAVA 1.6):
the perpixelTranslucency is still not supported!!!
It is possible to apply a translucency to the entire frame but not for special areas or pixels...
Thats not fair
Re: how to hide window frame or set background opacity
Reply #13 - Mar 3rd, 2010, 6:27am
 
but it should be working... at least for windows. just check this link:

http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#...

this example worked on my machine... however i don't get, how to do it in processing.
Re: how to hide window frame or set background opacity
Reply #14 - Mar 3rd, 2010, 6:31am
 
http://processing.org/discourse/yabb2/num_1224367967.html#0
Pages: 1 2