GenuineSounds

Screen Size GUI

Oct 30th, 2012
258
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.20 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.awt.Frame;
  4. import java.awt.Window;
  5. import java.lang.reflect.InvocationTargetException;
  6. import java.lang.reflect.Method;
  7. import net.minecraft.client.Minecraft;
  8. import org.lwjgl.LWJGLException;
  9. import org.lwjgl.input.Keyboard;
  10. import org.lwjgl.opengl.Display;
  11. import org.lwjgl.opengl.DisplayMode;
  12.  
  13. public class GenuineGuiScreenSize extends GuiScreen {
  14.  
  15.     private GuiTextField theGuiTextField;
  16.  
  17.     private String errorMessage1 = "";
  18.  
  19.     private String errorMessage2 = "";
  20.  
  21.     private String screenSize;
  22.  
  23.     private GuiScreen parent;
  24.  
  25.     public GenuineGuiScreenSize(GuiScreen parent) {
  26.         this.parent = parent;
  27.         screenSize = Integer.toString(Display.getParent().getWidth()) + "x" + Integer.toString(Display.getParent().getHeight());
  28.     }
  29.  
  30.     protected void actionPerformed(GuiButton par1GuiButton) {
  31.         if (par1GuiButton.enabled) {
  32.             if (par1GuiButton.id == 1) {
  33.                 this.mc.displayGuiScreen(null);
  34.             }
  35.             else if (par1GuiButton.id == 0) {
  36.                 String[] size = this.theGuiTextField.getText().split("[ -/xX]");
  37.                 if (size.length == 2) {
  38.                     try {
  39.                         int width = Integer.valueOf(size[0]);
  40.                         int height = Integer.valueOf(size[1]);
  41.                         if (width >= 400 && height >= 300) {
  42.                             setInGameScreenSize(width, height);
  43.                             this.mc.displayGuiScreen(null);
  44.                         }
  45.                         else {
  46.                             errorMessage1 = "\2474Error:\247f Must be > or = 400x300.";
  47.                             errorMessage2 = "(x can be anything on the numpad)";
  48.                         }
  49.                     }
  50.                     catch (NumberFormatException e) {
  51.                         errorMessage1 = "\2474Error:\247f Input must be numbers.";
  52.                         errorMessage2 = "";
  53.                     }
  54.                 }
  55.                 else {
  56.                     if (this.theGuiTextField.getText().equalsIgnoreCase("max")) {
  57.                         setInGameScreenSize(10000, 10000);
  58.                         this.mc.displayGuiScreen(parent);
  59.                     }
  60.                     errorMessage1 = "\2474Error:\247f Input must look like 800x600";
  61.                     errorMessage2 = "(x can be anything on the numpad)";
  62.                 }
  63.             }
  64.         }
  65.     }
  66.  
  67.     public void drawScreen(int par1, int par2, float par3) {
  68.         screenSize = Integer.toString(Display.getParent().getWidth()) + "x" + Integer.toString(Display.getParent().getHeight());
  69.         StringTranslate var4 = StringTranslate.getInstance();
  70.         this.drawDefaultBackground();
  71.         this.drawCenteredString(this.fontRenderer, "Set Screen Size", this.width / 2, this.height / 4 - 60 + 20, 16777215);
  72.         this.drawString(this.fontRenderer, var4.translateKey("Enter new size - Like: 1280x720, or max"), this.width / 2 - 100, this.height / 4 - 15, 10526880);
  73.         this.drawString(this.fontRenderer, errorMessage1, this.width / 2 - 100, this.height / 4 + 27, 10526880);
  74.         this.drawString(this.fontRenderer, errorMessage2, this.width / 2 - 100, this.height / 4 + 47, 10526880);
  75.         this.theGuiTextField.drawTextBox();
  76.         super.drawScreen(par1, par2, par3);
  77.     }
  78.  
  79.     public void initGui() {
  80.         Keyboard.enableRepeatEvents(true);
  81.         this.controlList.clear();
  82.         this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 108, StringTranslate.getInstance().translateKey("gui.done")));
  83.         this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 132, StringTranslate.getInstance().translateKey("gui.cancel")));
  84.         this.theGuiTextField = new GuiTextField(this.fontRenderer, this.width / 2 - 100, this.height / 4, 200, 20);
  85.         this.theGuiTextField.setFocused(true);
  86.         this.theGuiTextField.setText(screenSize);
  87.     }
  88.  
  89.     protected void keyTyped(char par1, int par2) {
  90.         if (par1 == '+')
  91.             return;
  92.         this.theGuiTextField.textboxKeyTyped(par1, par2);
  93.         ((GuiButton) this.controlList.get(0)).enabled = this.theGuiTextField.getText().trim().length() > 0;
  94.         if (par1 == 13 /* Enter */) {
  95.             this.actionPerformed((GuiButton) this.controlList.get(0));
  96.         }
  97.     }
  98.  
  99.     protected void mouseClicked(int par1, int par2, int par3) {
  100.         super.mouseClicked(par1, par2, par3);
  101.         this.theGuiTextField.mouseClicked(par1, par2, par3);
  102.     }
  103.  
  104.     public void onGuiClosed() {
  105.         Keyboard.enableRepeatEvents(false);
  106.     }
  107.  
  108.     public void setInGameScreenSize(int width, int height) {
  109.         int widthDif = Window.getWindows()[0].getWidth() - Display.getParent().getWidth();
  110.         int heightDif = Window.getWindows()[0].getHeight() - Display.getParent().getHeight();
  111.         if (Display.isFullscreen()) {
  112.             try {
  113.                 int x = 100000;
  114.                 int y = 100000;
  115.                 DisplayMode mode = null;
  116.                 for (DisplayMode dm : Display.getAvailableDisplayModes()) {
  117.                     if ((Math.abs(dm.getWidth() - width) <= x) && (Math.abs(dm.getHeight() - height) <= y)) {
  118.                         x = Math.abs(dm.getWidth() - width);
  119.                         y = Math.abs(dm.getHeight() - height);
  120.                         mode = dm;
  121.                     }
  122.                 }
  123.                 for (DisplayMode dm : Display.getAvailableDisplayModes())
  124.                     if ((Math.abs(dm.getWidth() - width) == x) && (Math.abs(dm.getHeight() - height) == y) && mode.getBitsPerPixel() <= dm.getBitsPerPixel()
  125.                             && mode.getFrequency() <= dm.getFrequency())
  126.                         mode = dm;
  127.                 if (mode != null) {
  128.                     Display.setDisplayMode(mode);
  129.                     mc.displayWidth = Display.getDisplayMode().getWidth();
  130.                     mc.displayHeight = Display.getDisplayMode().getHeight();
  131.                     if (mc.displayWidth <= 0)
  132.                         mc.displayWidth = 1;
  133.                     if (mc.displayHeight <= 0)
  134.                         mc.displayHeight = 1;
  135.                     Display.update();
  136.                     Method method = null;
  137.                     try {
  138.                         method = Minecraft.class.getDeclaredMethod("a", int.class, int.class);
  139.                     }
  140.                     catch (NoSuchMethodException e) {
  141.                         try {
  142.                             method = Minecraft.class.getDeclaredMethod("resize", int.class, int.class);
  143.                         }
  144.                         catch (NoSuchMethodException e1) {
  145.                         }
  146.                     }
  147.                     if (method != null) {
  148.                         method.setAccessible(true);
  149.                         method.invoke(mc, mc.displayWidth, mc.displayHeight);
  150.                     }
  151.                 }
  152.             }
  153.             catch (LWJGLException e) {
  154.                 e.printStackTrace();
  155.             }
  156.             catch (IllegalArgumentException e) {
  157.                 e.printStackTrace();
  158.             }
  159.             catch (SecurityException e) {
  160.                 e.printStackTrace();
  161.             }
  162.             catch (IllegalAccessException e) {
  163.                 e.printStackTrace();
  164.             }
  165.             catch (InvocationTargetException e) {
  166.                 e.printStackTrace();
  167.             }
  168.         }
  169.         else {
  170.             if (width == 10000 && height == 10000)
  171.                 Frame.getFrames()[0].setExtendedState(Frame.MAXIMIZED_BOTH);
  172.             Window.getWindows()[0].setSize(width + widthDif, height + heightDif);
  173.         }
  174.     }
  175.  
  176.     public void updateScreen() {
  177.         this.theGuiTextField.updateCursorCounter();
  178.     }
  179. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment