Slick Forums

Discuss the Slick 2D Library
It is currently Sun Dec 17, 2017 6:04 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Resizing the GUI
PostPosted: Sun Mar 18, 2012 3:42 pm 
Offline

Joined: Tue Mar 06, 2012 4:17 am
Posts: 6
Hi,

I'm working on integrating TWL into my game which is written with LWJGL. My game window is resizalble:

Code:
Display.setResizable(true);


I've added a button to my display, like this:

Code:
button = new Button("!!");
button.setTheme("button");
button.setEnabled(true);
button.setVisible(true);

add(button);


And in my "draw" loop, I have the following code:

Code:
if (Display.wasResized()) {
  GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
  gui.adjustSize();
}


And I also have the following layout() function defined:

Code:
@Override
protected void layout() {
  button.setPosition(15, this.getHeight() - 50);
  button.setSize(35, 35);
}


But when I resize my game window, the button (including the text) stretches. (See the attached screen shot to see what I mean.) I'd like the button to stay the same size instead. How do I go about doing that?


Attachments:
resized-button.png
resized-button.png [ 12.52 KiB | Viewed 5597 times ]
Top
 Profile  
 
 Post subject: Re: Resizing the GUI
PostPosted: Sun Mar 18, 2012 3:47 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
You should not call gui.adjustSize() but instead call
Code:
renderer.setViewport(0, 0, Display.getWidth(), Display.getHeight());
this will automatically cause a new layout for all UI widgets.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Resizing the GUI
PostPosted: Sun Mar 18, 2012 3:51 pm 
Offline

Joined: Tue Mar 06, 2012 4:17 am
Posts: 6
Here's a tidbit more information: it appears that the layout() function is never being called. I put added the following:

Code:
System.err.println(button.setSize(35, 35));


And I only ever see one "true" in the debug output, which means that layout is only getting called once, not each time I resize the window as I expected it would.


Top
 Profile  
 
 Post subject: Re: Resizing the GUI
PostPosted: Sun Mar 18, 2012 3:53 pm 
Offline

Joined: Tue Mar 06, 2012 4:17 am
Posts: 6
MatthiasM wrote:
You should not call gui.adjustSize() but instead call
Code:
renderer.setViewport(0, 0, Display.getWidth(), Display.getHeight());
this will automatically cause a new layout for all UI widgets.


Awesome, that did the trick. Thanks!


Top
 Profile  
 
 Post subject: Re: Resizing the GUI
PostPosted: Fri May 18, 2012 7:15 pm 
Offline
Regular

Joined: Sun Oct 25, 2009 5:24 pm
Posts: 118
This should be stickied or mentioned somewhere. Your TWL based GUI won't work if you change Slick's DisplayMode and don't update the renderer.


Top
 Profile  
 
 Post subject: Re: Resizing the GUI
PostPosted: Wed Oct 10, 2012 4:14 pm 
Offline

Joined: Mon Jan 23, 2012 9:14 pm
Posts: 71
Location: France
Hi, is there a way to access the renderer and its setViewport method while using Slick ?
I only have access to getGUI() apparently, which has a getRenderer() method but I think it's not the right one because it doesn't have the setViewport method.
The GameContainer class doesn't have it either.

Any idea about how I could fix this ?


Top
 Profile  
 
 Post subject: Re: Resizing the GUI
PostPosted: Wed Oct 10, 2012 6:23 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
You could always cast the result of getRenderer() to LWJGLRenderer.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re: Resizing the GUI
PostPosted: Wed Oct 10, 2012 8:31 pm 
Offline

Joined: Mon Jan 23, 2012 9:14 pm
Posts: 71
Location: France
Oh, I didn't think it was possible to cast it to LWJGLRenderer.
Works perfectly now, thanks !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group