Exemplo n.º 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()]);
  }
Exemplo n.º 2
0
 public void toggleToFullscreen() {
   GraphicsDevice device =
       GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
   DisplayMode[] modes = device.getDisplayModes();
   int i = 0; // note: there are usually several, let's pick the first
   settings.setResolution(modes[i].getWidth(), modes[i].getHeight());
   settings.setFrequency(modes[i].getRefreshRate());
   settings.setDepthBits(modes[i].getBitDepth());
   settings.setFullscreen(device.isFullScreenSupported());
   restart();
 }
Exemplo n.º 3
0
 /**
  * Esta funcion devolverá el mejor modo disponible de nuestra lista.
  *
  * @param modes Array de modos.
  * @return Retorna el mejor modo compatible de nuestra lista de modos {@link #MODOS_POSIBLES}
  */
 protected DisplayMode findFirstCompatibleMode(DisplayMode modes[]) {
   DisplayMode modosDisponibles[] = device.getDisplayModes();
   for (int i = 0; i < modes.length; i++) {
     for (int j = 0; j < modosDisponibles.length; j++) {
       if (sonIguales(modes[i], modosDisponibles[j])) {
         return modes[i];
       }
     }
   }
   return null;
 }
Exemplo n.º 4
0
 /**
  * Devuelve un vector con todos los modos de nuestra lista que sean compatibles
  *
  * @param modes Array de modos
  * @return Vector de modos posibles.
  */
 public Vector<DisplayMode> getAllCompatibles(DisplayMode modes[]) {
   DisplayMode goodModes[] = device.getDisplayModes();
   Vector<DisplayMode> v = new Vector<DisplayMode>();
   for (int i = 0; i < modes.length; i++) {
     for (int j = 0; j < goodModes.length; j++) {
       if (sonIguales(modes[i], goodModes[j])) {
         v.add(modes[i]);
       }
     }
   }
   return v;
 }
Exemplo n.º 5
0
 private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
   for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) {
     DisplayMode[] modes = device.getDisplayModes();
     for (int i = 0; i < modes.length; i++) {
       if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth()
           && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight()
           && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth()) {
         return BEST_DISPLAY_MODES[x];
       }
     }
   }
   return null;
 }
Exemplo n.º 6
0
  // compares DM passed in to vc DM and see if they match
  public DisplayMode findFirstCompatibleMode(DisplayMode modes[]) {

    DisplayMode goodModes[] = vc.getDisplayModes();

    for (int x = 0; x < modes.length; x++) {
      for (int y = 0; y < goodModes.length; y++) {
        if (displayModesMatch(modes[x], goodModes[y])) {
          return modes[x];
        }
      }
    }

    return null;
  }
Exemplo n.º 7
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);
 }
  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())));
    }
  }
Exemplo n.º 9
0
 // Get all comatible DM's // not necessary?
 public DisplayMode[] getCompatibleDisplayModes() {
   return vc.getDisplayModes();
 }
Exemplo n.º 10
0
 /**
  * Esta funcion retorna un array de modos disponible
  *
  * @return DisplayModes Modos disponibles en la máquina actual.
  */
 protected DisplayMode[] getCompatibleDisplayModes() {
   return device.getDisplayModes();
 }