示例#1
0
  public static DisplayDeviceArea[] getPresentationAndImageDeviceAreas() {
    DisplayDeviceArea[] displayDeviceAreas = null;
    GraphicsDevice[] gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    if (gs.length == 1) {
      DisplayMode dm = gs[0].getDisplayMode();
      int width = dm.getWidth();
      int height = dm.getHeight();
      float presentationAspectRatio = 5f / 4; // usual screen for presentations
      float imageAspectRatio = 3f / 4 * 2; // pair of portrait monitors

      float presentationHorizontalProportion = 0.33f;

      int presentationWidth = (int) (width * presentationHorizontalProportion);

      int presentationHeight = (int) (presentationWidth / presentationAspectRatio);
      if (presentationHeight > height) {
        presentationHeight = height;
      }
      int presentationX = 0;
      int presentationY = height - presentationHeight;

      int imageWidth = width - presentationWidth;
      int imageHeight = (int) (imageWidth / imageAspectRatio);
      if (imageHeight > height) {
        imageHeight = height;
      }
      int imageX = presentationWidth;
      int imageY = height - imageHeight;

      displayDeviceAreas = new DisplayDeviceArea[2];
      displayDeviceAreas[0] =
          new DisplayDeviceArea(
              gs[0], presentationX, presentationY, presentationWidth, presentationHeight);
      displayDeviceAreas[1] = new DisplayDeviceArea(gs[0], imageX, imageY, imageWidth, imageHeight);
    } else if (gs.length == 2) {
      DisplayMode dm1 = gs[0].getDisplayMode();
      DisplayMode dm2 = gs[1].getDisplayMode();
      int width1 = dm1.getWidth();
      int width2 = dm2.getWidth();
      int height1 = dm1.getHeight();
      int height2 = dm2.getHeight();
      GraphicsDevice presentationDevice;
      GraphicsDevice imageDevice;
      if (width1 * height1 > width2 * height2) {
        presentationDevice = gs[1];
        imageDevice = gs[0];
      } else {
        presentationDevice = gs[0];
        imageDevice = gs[1];
      }
      displayDeviceAreas = new DisplayDeviceArea[2];
      displayDeviceAreas[0] = new DisplayDeviceArea(presentationDevice);
      displayDeviceAreas[1] = new DisplayDeviceArea(imageDevice);
    }
    return displayDeviceAreas;
  }
示例#2
0
  @Override
  public final synchronized void render() {
    final Graphics graphics = buffer.getDrawGraphics();
    if (smoothScale) {
      ((Graphics2D) graphics)
          .setRenderingHint(
              RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    }
    if (inFullScreen) {
      graphics.setColor(Color.BLACK);
      DisplayMode dm = gd.getDisplayMode();
      int scrnheight = dm.getHeight();
      int scrnwidth = dm.getWidth();
      // don't ask why this needs to be done every frame,
      // but it does b/c the canvas keeps resizing itself
      canvas.setSize(scrnwidth, scrnheight);
      graphics.fillRect(0, 0, scrnwidth, scrnheight);
      if (PrefsSingleton.get().getBoolean("maintainAspect", true)) {
        double scalefactor = getmaxscale(scrnwidth, scrnheight);
        int height = (int) (NES_HEIGHT * scalefactor);
        int width = (int) (256 * scalefactor * 1.1666667);
        graphics.drawImage(
            frame,
            ((scrnwidth / 2) - (width / 2)),
            ((scrnheight / 2) - (height / 2)),
            width,
            height,
            null);
      } else {
        graphics.drawImage(frame, 0, 0, scrnwidth, scrnheight, null);
      }
      graphics.setColor(Color.DARK_GRAY);
      graphics.drawString(this.getTitle(), 16, 16);

    } else {
      graphics.drawImage(
          frame, 0, 0, NES_WIDTH * screenScaleFactor, NES_HEIGHT * screenScaleFactor, null);
    }

    graphics.dispose();
    buffer.show();
  }
示例#3
0
  /** creates the lobby. */
  public ClientLobby(User u) {
    this.user = u;

    /*
     * Get Infos about the screen
     * */
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screen = ge.getDefaultScreenDevice();
    DisplayMode disp = screen.getDisplayMode();
    screenX = disp.getWidth();
    screenY = disp.getHeight();

    JPanel bg = createBackground();

    /*
     * Set up lobby / inputs
     * */
    lobbyParent = new JFrame("SwissDefcon Lobby");
    lobbyParent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    lobbyParent.setSize(iLobbyX, iLobbyY);
    lobbyParent.setResizable(false);
    lobbyParent.setLocation(screenX / 2 - iLobbyX / 2, screenY / 2 - iLobbyY / 2);
    lobbyParent.setContentPane(bg);

    s = new SelectServer(user);
    s.addServerSelectedListener(
        new ServerSelectedListener() {
          public void serverSelected(final ServerSelectedEvent ev) {
            ServerAddress server = ev.getServer();
            String desiredNick = ev.getUsername();
            try {
              Log.InformationLog(
                  "-->Connecting to "
                      + ev.getServer().getServerName()
                      + "("
                      + server.getAddress().getHostAddress()
                      + ") as "
                      + ev.getUsername()
                      + "(desired Username)");

              // stop discovery
              s.stopSearch();
              s.setVisible(false);

              // make Connection
              socket = new Clientsocket(server);
              // JOptionPane.showMessageDialog(lobbyParent, "Verbunden mit Server");

              l = new InnerLobby(socket, user);
              lobbyParent.add(l);

              // request nick
              socket.sendData(Protocol.CON_NICK.str() + desiredNick);

              // TODO Game Listener to start game here.

              socket.addInfoEventListener(
                  new InfoEventListener() {
                    @Override
                    public void received(final InfoEvent evt) {
                      if (evt.getId() == -1) {
                        Log.InformationLog("Connection to server broken, starting ServerSelect");
                        JOptionPane.showMessageDialog(
                            lobbyParent,
                            "Verbindungsunterbruch",
                            "Connection Error",
                            JOptionPane.ERROR_MESSAGE);
                        // TODO remove the game if it exists.
                        socket.disconnect();
                        lobbyParent.remove(l);
                        lobbyParent.validate();
                        lobbyParent.repaint();
                        s.setVisible(true);
                        s.startSearch();
                      }
                    }
                  });

            } catch (Exception e) {
              // e.printStackTrace();
              Log.WarningLog("-->connection broken, could not connect");
              JOptionPane.showMessageDialog(
                  lobbyParent,
                  "Konnte nicht mit Server verbinden: ",
                  "Connection Error",
                  JOptionPane.ERROR_MESSAGE);
              if (socket != null) {
                socket.disconnect();
              }
              s.setVisible(true);
              s.startSearch();
            }
          }
        });
    lobbyParent.add(s);
    Log.InformationLog("you can now select a server");

    lobbyParent.setVisible(true);
  }
示例#4
0
  public void createWindow(DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y)
      throws LWJGLException {
    close_requested = false;
    is_dirty = false;
    isMinimized = false;
    isFocused = false;
    redoMakeContextCurrent = false;
    maximized = false;
    this.parent = parent;
    hasParent = parent != null;
    parent_hwnd = parent != null ? getHwnd(parent) : 0;
    this.hwnd =
        nCreateWindow(
            x,
            y,
            mode.getWidth(),
            mode.getHeight(),
            Display.isFullscreen() || isUndecorated(),
            parent != null,
            parent_hwnd);
    this.resizable = false;
    if (hwnd == 0) {
      throw new LWJGLException("Failed to create window");
    }
    this.hdc = getDC(hwnd);
    if (hdc == 0) {
      nDestroyWindow(hwnd);
      throw new LWJGLException("Failed to get dc");
    }

    try {
      if (drawable instanceof DrawableGL) {
        int format =
            WindowsPeerInfo.choosePixelFormat(
                getHdc(),
                0,
                0,
                (PixelFormat) drawable.getPixelFormat(),
                null,
                true,
                true,
                false,
                true);
        WindowsPeerInfo.setPixelFormat(getHdc(), format);
      } else {
        peer_info = new WindowsDisplayPeerInfo(true);
        ((DrawableGLES) drawable)
            .initialize(
                hwnd,
                hdc,
                EGL.EGL_WINDOW_BIT,
                (org.lwjgl.opengles.PixelFormat) drawable.getPixelFormat());
      }
      peer_info.initDC(getHwnd(), getHdc());
      showWindow(getHwnd(), SW_SHOWDEFAULT);

      updateWidthAndHeight();

      if (parent == null) {
        if (Display.isResizable()) {
          setResizable(true);
        }
        setForegroundWindow(getHwnd());
      } else {
        parent_focused = new AtomicBoolean(false);
        parent.addFocusListener(
            parent_focus_tracker =
                new FocusAdapter() {
                  public void focusGained(FocusEvent e) {
                    parent_focused.set(true);
                    clearAWTFocus();
                  }
                });
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                clearAWTFocus();
              }
            });
      }
      grabFocus();
    } catch (LWJGLException e) {
      nReleaseDC(hwnd, hdc);
      nDestroyWindow(hwnd);
      throw e;
    }
  }