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 › problems with window resize
Page Index Toggle Pages: 1
problems with window resize (Read 932 times)
problems with window resize
Jun 13th, 2009, 5:43pm
 
Hello,

I am wanting to design a user interface with a resizable window. I am having major refresh issues. Wondering if somone can give me some pointers?

here's some example code:
Code:
int canvasHeight = 500;
int canvasWidth = 500;
void setup(){
 frame.setResizable(true);
 size(canvasWidth,canvasHeight);
 background(300);
}

void draw(){
 resizeWin();
 rect(30, 20, 55, 55);
}

void resizeWin(){
 canvasHeight = frame.getHeight();
 canvasWidth = frame.getWidth();
 size(canvasWidth,canvasHeight);
}

try resizing the window and you should see lots of flickering.

Thanks in advance,

Dan.
Re: problems with window resize
Reply #1 - Jun 14th, 2009, 4:15am
 
The first thing to avoid is resizing in the draw() method this is bound to cause flickering. Also we only want to resize if the frame has actually been resized. Since Java does not provide a resize event then we need somewhere else to check for resizing. We can do this in the pre() method this method is called just before the draw() method every loop.

I can't think of a way to get rid of the flickering entirely but although not perfect this works reasonably well. Smiley
Code:
int canvasHeight = 500;
int canvasWidth = 500;

void setup(){
 size(canvasWidth,canvasHeight);
 frame.setResizable(true);
 background(300);
 registerPre(this);
}

void pre(){
 if(width != canvasWidth || frame.getHeight() != canvasHeight){
   resizeWin();
 }
}

void draw(){
 rect(30, 20, width - 60, height - 40);
}

void resizeWin(){
 canvasHeight = frame.getHeight();
 canvasWidth = frame.getWidth();
 setPreferredSize(new Dimension(canvasWidth, canvasHeight));
}

Re: problems with window resize
Reply #2 - Jul 5th, 2009, 6:20am
 
Hey Quark,

I just realised I never said thankyou for this. So.. Thanks!
It's not excactly what I had in mind, but it's much less distracting than what I had Wink

Dan.
Page Index Toggle Pages: 1