com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics Java Examples

The following examples show how to use com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientMouseDeltaFixer.java    From Cubes with MIT License 6 votes vote down vote up
static void setup() {
  // Log.debug("Setting up Client Mouse Delta Fixer");

  try {
    deltaXField = Lwjgl3Input.class.getDeclaredField("deltaX");
    deltaXField.setAccessible(true);
    deltaYField = Lwjgl3Input.class.getDeclaredField("deltaY");
    deltaYField.setAccessible(true);

    Field f = Lwjgl3Input.class.getDeclaredField("cursorPosCallback");
    f.setAccessible(true);
    libgdxCallback = (GLFWCursorPosCallback) f.get(Gdx.input);
  } catch (ReflectiveOperationException | ClassCastException e) {
    throw new CubesException("Failed to setup reflection to inject correct delta mouse values!", e);
  }

  GLFW.glfwSetCursorPosCallback(((Lwjgl3Graphics) Gdx.graphics).getWindow().getWindowHandle(), cursorPosCallback);
}
 
Example #2
Source File: ClientCompatibility.java    From Cubes with MIT License 6 votes vote down vote up
private boolean fullscreenMode() {
  Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();

  windowWidth = Gdx.graphics.getWidth();
  windowHeight = Gdx.graphics.getHeight();
  windowX = window.getPositionX();
  windowY = window.getPositionY();

  Graphics.Monitor monitor = Gdx.graphics.getMonitor();
  Graphics.DisplayMode mode = getBestDisplayMode(monitor);
  if (mode == null) return false;

  if ("windowedBorderless".equals(((DropDownSetting) Settings.getSetting("client.graphics.fullscreen")).getSelected())) {
    Gdx.graphics.setUndecorated(true);
    Gdx.graphics.setResizable(false);
    window.setPosition(monitor.virtualX, monitor.virtualY);
    return Gdx.graphics.setWindowedMode(mode.width, mode.height);
  } else {
    return Gdx.graphics.setFullscreenMode(mode);
  }
}
 
Example #3
Source File: ClientCompatibility.java    From Cubes with MIT License 5 votes vote down vote up
private void resizeWindowFromScaleFactor(float newScaleFactor) {
  final float scaleFactor = Math.max(newScaleFactor, 1f);

  final Graphics.Monitor monitor = Gdx.graphics.getMonitor();
  final Graphics.DisplayMode mode = getBestDisplayMode(monitor);
  if (mode == null || fullscreen.isEnabled()) return;

  // Client may not be setup yet, delaying to end of the frame ensures it is
  Gdx.app.postRunnable(() -> {
    int wantedMinWidth = (int) Math.min(MINIMUM_WINDOW_WIDTH * scaleFactor, mode.width * 0.8f);
    int wantedMinHeight = (int) Math.min(MINIMUM_WINDOW_HEIGHT * scaleFactor, mode.height * 0.8f);
    int resizeWidth = (int) (DEFAULT_WINDOW_WIDTH * scaleFactor);
    int resizeHeight = (int) (DEFAULT_WINDOW_HEIGHT * scaleFactor);

    Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();

    if (resizeWidth > 0.8 * mode.width || resizeHeight > 0.8 * mode.height) {
      // if window would almost fill screen, maximize
      window.maximizeWindow();
    } else if (resizeWidth >= Gdx.graphics.getWidth() && resizeHeight >= Gdx.graphics.getHeight()) {
      // maintain center of window if possible without going off edge of screen
      int posX = MathUtils.clamp(
          window.getPositionX() - ((resizeWidth - Gdx.graphics.getWidth()) / 2),
          monitor.virtualX + 32,
          monitor.virtualX + mode.width - resizeWidth - 32);
      int posY = MathUtils.clamp(
          window.getPositionY() - ((resizeHeight - Gdx.graphics.getHeight()) / 2),
          monitor.virtualY + 32,
          monitor.virtualY + mode.height - resizeHeight - 32);
      window.setPosition(posX, posY);

      // first set minimum size to desired size to force expansion, then reset to desired minimum size
      window.setSizeLimits(resizeWidth, resizeHeight, -1, -1);
    }

    window.setSizeLimits(wantedMinWidth, wantedMinHeight, -1, -1);
  });
}
 
Example #4
Source File: ClientCompatibility.java    From Cubes with MIT License 5 votes vote down vote up
private boolean windowedMode() {
  Gdx.graphics.setUndecorated(false);
  Gdx.graphics.setResizable(true);
  ((Lwjgl3Graphics) Gdx.graphics).getWindow().setPosition(windowX, windowY);

  return Gdx.graphics.setWindowedMode(windowWidth, windowHeight);
}
 
Example #5
Source File: Installer.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public void dragWindow(int x, int y) {
    Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
    window.setPosition(x, y);
}
 
Example #6
Source File: Installer.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public int getWindowX() {
    return ((Lwjgl3Graphics) Gdx.graphics).getWindow().getPositionX();
}
 
Example #7
Source File: Installer.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public int getWindowY() {
    return ((Lwjgl3Graphics) Gdx.graphics).getWindow().getPositionY();
}
 
Example #8
Source File: Uninstaller.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public void dragWindow(int x, int y) {
    Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
    window.setPosition(x, y);
}
 
Example #9
Source File: Uninstaller.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public int getWindowX() {
    return ((Lwjgl3Graphics) Gdx.graphics).getWindow().getPositionX();
}
 
Example #10
Source File: Uninstaller.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public int getWindowY() {
    return ((Lwjgl3Graphics) Gdx.graphics).getWindow().getPositionY();
}