GenuineSounds

Screen Resize

Oct 30th, 2012
188
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. public void setInGameScreenSize(int width, int height) {
  2.     int widthDif = Window.getWindows()[0].getWidth() - Display.getParent().getWidth();
  3.     int heightDif = Window.getWindows()[0].getHeight() - Display.getParent().getHeight();
  4.     if (Display.isFullscreen()) {
  5.         try {
  6.             int x = 100000;
  7.             int y = 100000;
  8.             DisplayMode mode = null;
  9.             for (DisplayMode dm : Display.getAvailableDisplayModes()) {
  10.                 if ((Math.abs(dm.getWidth() - width) <= x) && (Math.abs(dm.getHeight() - height) <= y)) {
  11.                     x = Math.abs(dm.getWidth() - width);
  12.                     y = Math.abs(dm.getHeight() - height);
  13.                     mode = dm;
  14.                 }
  15.             }
  16.             for (DisplayMode dm : Display.getAvailableDisplayModes())
  17.                 if ((Math.abs(dm.getWidth() - width) == x) && (Math.abs(dm.getHeight() - height) == y) && mode.getBitsPerPixel() <= dm.getBitsPerPixel()
  18.                         && mode.getFrequency() <= dm.getFrequency())
  19.                     mode = dm;
  20.             if (mode != null) {
  21.                 Display.setDisplayMode(mode);
  22.                 mc.displayWidth = Display.getDisplayMode().getWidth();
  23.                 mc.displayHeight = Display.getDisplayMode().getHeight();
  24.                 if (mc.displayWidth <= 0)
  25.                     mc.displayWidth = 1;
  26.                 if (mc.displayHeight <= 0)
  27.                     mc.displayHeight = 1;
  28.                 Display.update();
  29.                 Method method = null;
  30.                 try {
  31.                     method = Minecraft.class.getDeclaredMethod("a", int.class, int.class);
  32.                 }
  33.                 catch (NoSuchMethodException e) {
  34.                     try {
  35.                         method = Minecraft.class.getDeclaredMethod("resize", int.class, int.class);
  36.                     }
  37.                     catch (NoSuchMethodException e1) {
  38.                     }
  39.                 }
  40.                 if (method != null) {
  41.                     method.setAccessible(true);
  42.                     method.invoke(mc, mc.displayWidth, mc.displayHeight);
  43.                 }
  44.             }
  45.         }
  46.         catch (LWJGLException e) {
  47.             e.printStackTrace();
  48.         }
  49.         catch (IllegalArgumentException e) {
  50.             e.printStackTrace();
  51.         }
  52.         catch (SecurityException e) {
  53.             e.printStackTrace();
  54.         }
  55.         catch (IllegalAccessException e) {
  56.             e.printStackTrace();
  57.         }
  58.         catch (InvocationTargetException e) {
  59.             e.printStackTrace();
  60.         }
  61.     }
  62.     else {
  63.         if (width == 10000 && height == 10000)
  64.             Frame.getFrames()[0].setExtendedState(Frame.MAXIMIZED_BOTH);
  65.         Window.getWindows()[0].setSize(width + widthDif, height + heightDif);
  66.     }
  67. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment