Search in sources :

Example 1 with MonitorDevice

use of com.jogamp.newt.MonitorDevice in project processing by processing.

the class PSurfaceJOGL method initDisplay.

protected void initDisplay() {
    Display tmpDisplay = NewtFactory.createDisplay(null);
    tmpDisplay.addReference();
    Screen tmpScreen = NewtFactory.createScreen(tmpDisplay, 0);
    tmpScreen.addReference();
    monitors = new ArrayList<MonitorDevice>();
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] awtDevices = environment.getScreenDevices();
    List<MonitorDevice> newtDevices = tmpScreen.getMonitorDevices();
    // tries to address the differences.
    if (PApplet.platform == PConstants.LINUX) {
        for (GraphicsDevice device : awtDevices) {
            String did = device.getIDstring();
            String[] parts = did.split("\\.");
            String id1 = "";
            if (1 < parts.length) {
                id1 = parts[1].trim();
            }
            MonitorDevice monitor = null;
            int id0 = newtDevices.size() > 0 ? newtDevices.get(0).getId() : 0;
            for (int i = 0; i < newtDevices.size(); i++) {
                MonitorDevice mon = newtDevices.get(i);
                String mid = String.valueOf(mon.getId() - id0);
                if (id1.equals(mid)) {
                    monitor = mon;
                    break;
                }
            }
            if (monitor != null) {
                monitors.add(monitor);
            }
        }
    } else if (PApplet.platform == PConstants.WINDOWS) {
        // NEWT display id is == (adapterId << 8 | monitorId),
        // should be in the same order as AWT
        monitors.addAll(newtDevices);
    } else {
        // MAC OSX and others
        for (GraphicsDevice device : awtDevices) {
            String did = device.getIDstring();
            String[] parts = did.split("Display");
            String id1 = "";
            if (1 < parts.length) {
                id1 = parts[1].trim();
            }
            MonitorDevice monitor = null;
            for (int i = 0; i < newtDevices.size(); i++) {
                MonitorDevice mon = newtDevices.get(i);
                String mid = String.valueOf(mon.getId());
                if (id1.equals(mid)) {
                    monitor = mon;
                    break;
                }
            }
            if (monitor == null) {
                // Didn't find a matching monitor, try using less stringent id check
                for (int i = 0; i < newtDevices.size(); i++) {
                    MonitorDevice mon = newtDevices.get(i);
                    String mid = String.valueOf(mon.getId());
                    if (-1 < did.indexOf(mid)) {
                        monitor = mon;
                        break;
                    }
                }
            }
            if (monitor != null) {
                monitors.add(monitor);
            }
        }
    }
    displayDevice = null;
    int displayNum = sketch.sketchDisplay();
    if (displayNum > 0) {
        // if -1, use the default device
        if (displayNum <= monitors.size()) {
            displayDevice = monitors.get(displayNum - 1);
        } else {
            System.err.format("Display %d does not exist, " + "using the default display instead.%n", displayNum);
            for (int i = 0; i < monitors.size(); i++) {
                System.err.format("Display %d is %s%n", i + 1, monitors.get(i));
            }
        }
    } else if (0 < monitors.size()) {
        displayDevice = monitors.get(0);
    }
    if (displayDevice != null) {
        screen = displayDevice.getScreen();
        display = screen.getDisplay();
    } else {
        screen = tmpScreen;
        display = tmpDisplay;
        displayDevice = screen.getPrimaryMonitor();
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Screen(com.jogamp.newt.Screen) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) Display(com.jogamp.newt.Display) MonitorDevice(com.jogamp.newt.MonitorDevice)

Aggregations

Display (com.jogamp.newt.Display)1 MonitorDevice (com.jogamp.newt.MonitorDevice)1 Screen (com.jogamp.newt.Screen)1 GraphicsDevice (java.awt.GraphicsDevice)1 GraphicsEnvironment (java.awt.GraphicsEnvironment)1 Point (java.awt.Point)1