Exemplo n.º 1
0
  /**
   * Konstruktøren. Initierer rammen og canvaset som det skal tegnes i.
   *
   * @param gameName : String - Tittel på JFrame
   */
  public DisplayManager(String gameName) {
    frame = new JFrame(gameName);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.setIgnoreRepaint(true);
    frame.setSize(WIDTH, HEIGHT);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setCursor(getInvisibleCursor());
    frame.setIconImage(new ImageIcon("images/ico.ico").getImage());

    // Oppretter en buffer for å hindre "tearing" i grafikken.
    try {
      EventQueue.invokeAndWait(
          new Runnable() {
            @Override
            public void run() {
              frame.createBufferStrategy(2);
            }
          });
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  // ---------- Constructor ----------
  public DrawWindow() {

    // Create Main DrawWindow JFrame
    frame = new JFrame(TreeGen.getTitle());

    frame.setVisible(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setLocation(0, 0);

    // Sets Settings For FullSCreen Mode
    if (TreeGen.isFullScreen()) {
      frame.setSize(
          Toolkit.getDefaultToolkit().getScreenSize().width,
          Toolkit.getDefaultToolkit().getScreenSize().height);
      frame.setUndecorated(true);
      frame.setIgnoreRepaint(true);
      // vc.setFullScreenWindow();
    }
    // Sets Settings For Standard Mode
    else {
      frame.setSize(
          Toolkit.getDefaultToolkit().getScreenSize().width - 200,
          Toolkit.getDefaultToolkit().getScreenSize().height - 100);
    }

    if (TreeGen.getFPSCap() > 0) {
      maxWaitTime = 1000 / TreeGen.getFPSCap();
      fpsCap = true;
    }
  }
  public FrameRenderer(final JFrame target, boolean isFullscreen, RenderFitMode renderFitMode) {
    m_renderTarget = target;
    m_renderFitMode = renderFitMode;

    m_renderTarget.setSize(target.getSize());

    m_canvasRenderWidth = target.getWidth();
    m_canvasRenderHeight = target.getHeight();

    target.setIgnoreRepaint(true);
    target.createBufferStrategy(2);
    m_bufferStrategy = target.getBufferStrategy();

    BufferCapabilities cap = m_bufferStrategy.getCapabilities();

    if (!cap.getBackBufferCapabilities().isAccelerated())
      m_logger.warn("Backbuffer is not accelerated, may result in poorer render performance.");

    if (!cap.isPageFlipping())
      m_logger.warn(
          "Page flipping is not supported by this device. This may result in increased image flicker or tearing.");

    if (!cap.isMultiBufferAvailable())
      m_logger.warn(
          "Multiple buffering for page flipping is not supported by this device. This may result in poorer performance.");

    if (cap.isFullScreenRequired() && !isFullscreen)
      m_logger.warn(
          "Full screen required for hardware acceleration - not running in fullscreen may cause performance issues.");

    if (isFullscreen) {
      enterFullscreen();

      target.addKeyListener(
          new KeyListener() {

            @Override
            public void keyTyped(KeyEvent e) {}

            @Override
            public void keyReleased(KeyEvent e) {}

            @Override
            public void keyPressed(KeyEvent e) {
              if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                GraphicsDevice device = target.getGraphicsConfiguration().getDevice();

                Window fullscreen = device.getFullScreenWindow();

                if (fullscreen != target) fullscreen = null;

                if (fullscreen == null) enterFullscreen();
                else exitFullscreen();
              }
            }
          });
    }
  }
Exemplo n.º 4
0
  // make frame full screen
  public void setFullScreen(DisplayMode dm) {
    JFrame f = new JFrame();
    f.setUndecorated(true);
    f.setIgnoreRepaint(true);
    f.setResizable(false);
    vc.setFullScreenWindow(f);

    if (dm != null && vc.isDisplayChangeSupported()) {
      try {
        vc.setDisplayMode(dm);
      } catch (Exception ex) {
      }
    }
    f.createBufferStrategy(2);
  }
Exemplo n.º 5
0
  /**
   * Esta funcion simplemente pondra la aplicacion a pantalla completa.
   *
   * @param dm
   */
  protected void setFullScreen(DisplayMode dm) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setFont(new Font("Dialog", Font.PLAIN, 13));
    frame.setBackground(Color.BLACK);
    frame.setForeground(Color.white);
    frame.setUndecorated(true);
    frame.setIgnoreRepaint(true);
    frame.setResizable(false);
    frame.setVisible(true);
    frame.setFocusTraversalKeysEnabled(false);
    device.setFullScreenWindow(frame);

    if (dm != null && device.isDisplayChangeSupported()) {
      try {
        device.setDisplayMode(dm);
      } catch (IllegalArgumentException ex) {
        System.out.println("No se ha podido poner a pantalla completa.");
      }
    }
    frame.createBufferStrategy(2);
  }