Exemple #1
0
  public static DisplayMode[] getDisplayModes() {
    GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = genv.getDefaultScreenDevice();
    java.awt.DisplayMode desktopMode = device.getDisplayMode();
    java.awt.DisplayMode[] displayModes = device.getDisplayModes();
    ArrayList<DisplayMode> modes = new ArrayList<DisplayMode>();
    int idx = 0;
    for (java.awt.DisplayMode mode : displayModes) {
      boolean duplicate = false;
      for (int i = 0; i < modes.size(); i++) {
        if (modes.get(i).width == mode.getWidth()
            && modes.get(i).height == mode.getHeight()
            && modes.get(i).bitsPerPixel == mode.getBitDepth()) {
          duplicate = true;
          break;
        }
      }
      if (duplicate) continue;
      if (mode.getBitDepth() != desktopMode.getBitDepth()) continue;
      modes.add(
          new LwjglApplicationConfigurationDisplayMode(
              mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth()));
    }

    return modes.toArray(new DisplayMode[modes.size()]);
  }
 /** @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */
 public int compare(DisplayMode a, DisplayMode b) {
   // Width
   if (a.getWidth() != b.getWidth()) return (a.getWidth() > b.getWidth()) ? 1 : -1;
   // Height
   if (a.getHeight() != b.getHeight()) return (a.getHeight() > b.getHeight()) ? 1 : -1;
   // Bit depth
   if (a.getBitDepth() != b.getBitDepth()) return (a.getBitDepth() > b.getBitDepth()) ? 1 : -1;
   // Refresh rate
   if (a.getRefreshRate() != b.getRefreshRate())
     return (a.getRefreshRate() > b.getRefreshRate()) ? 1 : -1;
   // All fields are equal
   return 0;
 }
 DisplayMode findmode(int w, int h) {
   GraphicsDevice dev = getGraphicsConfiguration().getDevice();
   if (!dev.isFullScreenSupported()) return (null);
   DisplayMode b = null;
   for (DisplayMode m : dev.getDisplayModes()) {
     int d = m.getBitDepth();
     if ((m.getWidth() == w)
         && (m.getHeight() == h)
         && ((d == 24) || (d == 32) || (d == DisplayMode.BIT_DEPTH_MULTI))) {
       if ((b == null)
           || (d > b.getBitDepth())
           || ((d == b.getBitDepth()) && (m.getRefreshRate() > b.getRefreshRate()))) b = m;
     }
   }
   return (b);
 }
Exemple #4
0
 public static DisplayMode getDesktopDisplayMode() {
   GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
   GraphicsDevice device = genv.getDefaultScreenDevice();
   java.awt.DisplayMode mode = device.getDisplayMode();
   return new LwjglApplicationConfigurationDisplayMode(
       mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth());
 }
Exemple #5
0
  /**
   * Retorna si 2 modos son iguales.
   *
   * @param mode1
   * @param mode2
   * @return True en caso de que ambos sean iguales.
   */
  private boolean sonIguales(DisplayMode mode1, DisplayMode mode2) {
    if (mode1.getWidth() != mode2.getWidth() || mode1.getHeight() != mode2.getHeight()) {
      return false;
    }

    if (mode1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI
        && mode2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI
        && mode1.getBitDepth() != mode2.getBitDepth()) {
      return false;
    }

    if (mode1.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN
        && mode2.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN
        && mode1.getRefreshRate() != mode2.getRefreshRate()) {
      return false;
    }

    return true;
  }
  private void enterFullscreen() {
    GraphicsDevice device = m_renderTarget.getGraphicsConfiguration().getDevice();

    if (!device.isFullScreenSupported())
      m_logger.error("Cannot enter full-screen. Device does not support full-screen mode");
    else {
      device.setFullScreenWindow(m_renderTarget);

      DisplayMode best = device.getDisplayMode();

      if (!device.isDisplayChangeSupported())
        m_logger.error(
            "Device does not support change of display modes. Using default display mode.");
      else {
        for (DisplayMode d : device.getDisplayModes()) {
          int dDeltaWidth = d.getWidth() - m_canvasRenderWidth;
          int dDeltaHeight = d.getHeight() - m_canvasRenderHeight;
          int dDeltaBitDepth = d.getBitDepth() - PREFERRED_BIT_DEPTH;

          int bestDeltaWidth = best.getWidth() - m_canvasRenderWidth;
          int bestDeltaHeight = best.getHeight() - m_canvasRenderHeight;
          int bestDeltaBitDepth = best.getBitDepth() - PREFERRED_BIT_DEPTH;

          if (dDeltaWidth == bestDeltaWidth && dDeltaHeight == bestDeltaHeight) {
            if (d.getBitDepth() > MIN_BIT_DEPTH
                && (Math.abs(dDeltaBitDepth) < Math.abs(bestDeltaBitDepth))) best = d;
          } else if (dDeltaWidth == 0
              || (dDeltaWidth > 0 && dDeltaWidth < bestDeltaWidth) && dDeltaHeight == 0
              || (dDeltaHeight > 0 && dDeltaHeight < bestDeltaWidth)) {
            best = d;
          }
        }
        device.setDisplayMode(best);
      }

      m_renderTarget.setBounds(
          new Rectangle(
              m_renderTarget.getLocation(), new Dimension(best.getWidth(), best.getHeight())));
    }
  }
Exemple #7
0
  public boolean displayModesMatch(DisplayMode m1, DisplayMode m2) {

    if (m1.getWidth() != m2.getWidth() || m1.getHeight() != m2.getHeight()) {
      return false;
    } else {
    }

    if (m1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI
        && m2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI
        && m1.getBitDepth() != m2.getBitDepth()) {
      return false;
    } else {
    }

    if (m1.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN
        && m2.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN
        && m1.getRefreshRate() != m2.getRefreshRate()) {
      return false;
    } else {
    }

    return true;
  }