We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have made the window translucent, but that removes the ability to grab the outside of the window to move it (maybe there is a way to allow that?). I get the location of surface and relocate it with the mouse coordinates, but I need the location of the mouse in relationship to the monitor screen. Any ideas on this?
import processing.awt.PSurfaceAWT;
import javax.swing.JFrame;
JFrame frame;
void setup() {
size(250, 140);
frame = getJFrame();
frame.removeNotify();
frame.setUndecorated(true);
frame.setOpacity(0.5f);
frame.addNotify();
}
void draw() {
}
void keyPressed() {
if (keyCode == 112) { //F1
frame.setOpacity(1.0f);
}
if (keyCode == 113) { //F2
frame.setOpacity(0.5f);
}
}
void mousePressed() {
if (mouseButton == LEFT) {
fill(0);
ellipse(mouseX, mouseY, 5, 5);
} else if (mouseButton == RIGHT) {
surface.setLocation(mouseX, mouseY);
}
}
void mouseDragged() {
if (mouseButton == LEFT) {
ellipse(mouseX, mouseY, 5, 5);
} else if (mouseButton == RIGHT) {
surface.setLocation(mouseX, mouseY);
}
}
JFrame getJFrame() {
PSurfaceAWT surf = (PSurfaceAWT) getSurface();
PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surf.getNative();
return (JFrame) canvas.getFrame();
}
Answers
Do remember that it may not work with other renderers.
Is setUndecorated necessary to make it work?
Try using setUndecorated(false) after setting opacity.
I get the error "Buffers have not been created" when I try to setUndecorated(false).
http://StackOverflow.com/questions/30141423/how-to-make-a-transparent-jframe-resizable
http://StackOverflow.com/questions/30610881/how-do-i-make-a-jframe-transparent-opaque-without-having-to-setundecoratedtru
This works:
Really nice "hack" job there, @Bird! <:-P
Just a small tip: In Processing, we don't need to suffix literals w/
f
to forcefloat
.PDE's pre-processor already does that for us automatically for ".pde" tabs. :-bd
Now if we need for
double
, we've gotta suffix them w/d
for ".pde" tabs. L-)And of course, it's the opposite for ".java" tabs. :P
Thanks! Yes, thank you for the clarification. When I'm bouncing around and "borrowing" other people's code I usually just leave the 'f's until I refactor. This is an effect I've been wanting to achieve for a while and, though not perfect, finally allows me to move on.
So this approach works because the user can click on the window top bar and move the window around?
Kf
A lil' refactoring of mine: :P
Cool hacking from @Bird and @GoToLoop here. ^:)^ \m/
Hello, I feel like it's good for this feature to be implemented as an internal feature of Processing so that anybody can easily decorate their app windows without having to know much deeper implementation details like this. I would like to implement this feature in PSurfaceAWT.java. Any comments/suggestions would be appreciated. Thanks :)