Hey, I’m in the process of writing a windowed environment in processing. An issue that I’ve struggled with for a while now is being able to mask the contents of a window to the window. Say if I wanted to scroll some text in the window, I would always have to either show or hide the text completely to avoid it overlapping the edge. This looks acceptable with text but with things like large images, the pop-in and out is really noticeable.
So far, I’ve tried a few things.
- Large PGraphics elements arent performant in the default renderer, but resizing them is instant
- In the P2D renderer large PGraphics elements run MUCH faster, but resizing causes the fps to tank
To mitigate this i’ve tried:
- creating a full screen PGraphics element for each window, and a mask PGraphics element that is drawn to by each window and then used to mask the window’s PGraphics element. This solves the resizing issue but also causes perfomance issues due to multiple large canvases and mask() being slow
- only resizing the PGraphics element every 15 frames instead of every frame. To make up for the slow refresh rate custom drawing methods are used to maintain the scale of everything when the image is drawn at a stretched scale. This is okay, but it will not work for text and looks bad when going from very small to large window sizes.
Example method for how I scale rectangles when the window is resized:
void relativeRect(int tx, int ty, int tw, int th,PGraphics p){
float rw = w;
float rh = h-titlebarh;
if(resizing){
rw=preresizew;
rh=preresizeh;
}
float newx = (map(tx,0,w,0,rw));
float newy = (map(ty,0,h-titlebarh,0,rh));
float neww = (map(tw,0,w,0,rw));
float newh = (map(th,0,h-titlebarh,0,rh));
p.rect(newx,newy,neww,newh);
}
If anyone could suggest anything else that would be awesome. I feel like I’ve tried everything at this point but maybe some other peoples minds can help me see something i’m not seeing.
Thank you