Jump to content
  • Advertisement
Sign in to follow this  
Pufftek

Making a resizable display and menu in lwjgl?

This topic is 2404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This seems like it should be easy, but I must be missing something. I am trying to make it so that if the display is resized, the buttons will resize and keep to scale. Here is the code for the buttons:

import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
public class MenuButton
{
private int x, y, w,h;
private boolean selected=false;
private String text;
private Room requestedRoom;
private boolean clickedOutside=false;
private boolean requestingChange=false;

public MenuButton(int x, int y, int w, int h, String text, Room requestedRoom)
{
this.x=x;
this.y=y;
this.w=w;
this.h=h;
this.requestedRoom=requestedRoom;
}

public void render()
{
if (selected)
glColor3f(.5f,.5f,.5f);
else
glColor3f(1f,1f,1f);
glBegin(GL_QUADS);
glVertex2i(x,y);
glVertex2i(x+w,y);
glVertex2i(x+w,y+h);
glVertex2i(x,y+h);
glEnd();
}

public void update()
{
//update the size and if they are selected/clicked
x=(int)((Display.getWidth()/2)-(w/2));
y=(int)((Display.getHeight()*.5)-(h/2));
//w=(int)(Display.getWidth()*.2);
//h=(int)(Display.getHeight()*.1);
selected=checkSelected(Mouse.getX(),480-Mouse.getY());

//check if the player clicked outside the button
if (Mouse.isButtonDown(0))
{
if(!selected)
clickedOutside=true;
}
else
{
if (clickedOutside)
clickedOutside=false;
}

//check if the player clicked inside and not outside
if (selected)
{
if (!clickedOutside && Mouse.isButtonDown(0))
requestingChange=true;
}
}

private boolean checkSelected(int mousex,int mousey)
{
if (mousex>x && mousey>y && mousex<x+w && mousey<y+h)
return true;
else
return false;
}

public Room getRequestedState()
{
return requestedRoom;
}

public boolean isRequestingStateChange()
{
if (requestingChange)
return true;
else
return false;
}
}


I have two problems: the x position works perfect until the Display gets really big, then the buttons begin to get narrower for some reason. Making the height of the display smaller causes the y to change correctly, but it is rendered up instead of down (wrong direction). Also, how can I make them resize in real time rather than after the user lets go of the display resizer?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!