Java 类org.lwjgl.util.Dimension 实例源码

项目:jGui    文件:AbstractGuiElement.java   
@Override
public ReadableDimension getMinSize() {
    ReadableDimension calcSize = calcMinSize();
    if (minSize == null) {
        return calcSize;
    } else {
        if (minSize.getWidth() >= calcSize.getWidth() && minSize.getHeight() >= calcSize.getHeight()) {
            return minSize;
        } else {
            return new Dimension(
                    Math.max(calcSize.getWidth(), minSize.getWidth()),
                    Math.max(calcSize.getHeight(), minSize.getHeight())
            );
        }
    }
}
项目:jGui    文件:VerticalLayout.java   
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    int maxWidth = 0;
    int height = 0;
    int spacing = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        height += spacing;
        spacing = this.spacing;

        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();
        int width = minSize.getWidth();
        if (width > maxWidth) {
            maxWidth = width;
        }
        height += minSize.getHeight();
    }
    return new Dimension(maxWidth, height);
}
项目:jGui    文件:HorizontalLayout.java   
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    int maxHeight = 0;
    int width = 0;
    int spacing = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        width += spacing;
        spacing = this.spacing;

        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();
        int height = minSize.getHeight();
        if (height > maxHeight) {
            maxHeight = height;
        }
        width += minSize.getWidth();
    }
    return new Dimension(width, maxHeight);
}
项目:jGui    文件:AbstractGuiCheckbox.java   
@Override
public ReadableDimension calcMinSize() {
    FontRenderer fontRenderer = getMinecraft().fontRendererObj;
    int height = fontRenderer.FONT_HEIGHT + 2;
    int width = height + 2 + fontRenderer.getStringWidth(label);
    return new Dimension(width, height);
}
项目:jGui    文件:AbstractGuiTooltip.java   
@Override
public ReadableDimension calcMinSize() {
    FontRenderer fontRenderer = getMinecraft().fontRendererObj;
    int height = 1 + LINE_SPACING + text.length * (fontRenderer.FONT_HEIGHT + LINE_SPACING);
    int width = 0;
    for (String line : text) {
        int w = fontRenderer.getStringWidth(line);
        if (w > width) {
            width = w;
        }
    }
    width+=4 * 2;
    return new Dimension(width, height);
}
项目:jGui    文件:AbstractGuiScreen.java   
@Override
public void initGui() {
    active = false;
    if (enabledRepeatedKeyEvents) {
        Keyboard.enableRepeatEvents(true);
    }
    screenSize = new Dimension(width, height);
    renderer = new MinecraftGuiRenderer(new ScaledResolution(mc, mc.displayWidth, mc.displayHeight));
    forEach(Loadable.class).load();
}
项目:jGui    文件:VerticalLayout.java   
@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
    int y = 0;
    int spacing = 0;
    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        y += spacing;
        spacing = this.spacing;

        GuiElement element  = entry.getKey();
        Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
        Dimension elementSize = new Dimension(element.getMinSize());
        ReadableDimension elementMaxSize = element.getMaxSize();
        elementSize.setHeight(Math.min(size.getHeight() - y, Math.min(elementSize.getHeight(), elementMaxSize.getHeight())));
        elementSize.setWidth(Math.min(size.getWidth(), (data.maximizeWidth ? elementMaxSize : elementSize).getWidth()));
        int remainingWidth = size.getWidth() - elementSize.getWidth();
        int x = (int) (data.alignment * remainingWidth);
        map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        y += elementSize.getHeight();
    }
    if (alignment != Alignment.TOP) {
        int remaining = size.getHeight() - y;
        if (alignment == Alignment.CENTER) {
            remaining /= 2;
        }
        for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
            ((Point) pair.getLeft()).translate(0, remaining);
        }
    }
    return map;
}
项目:jGui    文件:HorizontalLayout.java   
@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
    int x = 0;
    int spacing = 0;
    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        x += spacing;
        spacing = this.spacing;

        GuiElement element  = entry.getKey();
        Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
        Dimension elementSize = new Dimension(element.getMinSize());
        ReadableDimension elementMaxSize = element.getMaxSize();
        elementSize.setWidth(Math.min(size.getWidth() - x, Math.min(elementSize.getWidth(), elementMaxSize.getWidth())));
        elementSize.setHeight(Math.min(size.getHeight(), elementMaxSize.getHeight()));
        int remainingHeight = size.getHeight() - elementSize.getHeight();
        int y = (int) (data.alignment * remainingHeight);
        map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        x += elementSize.getWidth();
    }
    if (alignment != Alignment.LEFT) {
        int remaining = size.getWidth() - x;
        if (alignment == Alignment.CENTER) {
            remaining /= 2;
        }
        for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
            ((Point) pair.getLeft()).translate(remaining, 0);
        }
    }
    return map;
}
项目:mineshot    文件:FramebufferWriter.java   
public void write() throws IOException {
    fbc.setFlipColors(true);
    fbc.setFlipLines(false);
    fbc.capture();

    Dimension dim = fbc.getCaptureDimension();
    try (FileChannel fc = FileChannel.open(file, CREATE, WRITE)) {
        fc.write(buildTargaHeader(dim.getWidth(), dim.getHeight(), fbc.getBytesPerPixel() * 8));
        fc.write(fbc.getByteBuffer());
    }
}
项目:Oberien    文件:SettingsScreenController.java   
@NiftyEventSubscriber(pattern = ".*TextField")
public void textFieldUpdate(String id, TextFieldChangedEvent ev) {
    System.out.println(ev.getText());
    if (id.equals("resolutionXTextField")) {
        Options.setResolution(new Dimension(Integer.parseInt(ev.getText()), Options.getResolution().getHeight()));
    } else if (id.equals("resolutionYTextField")) {
        Options.setResolution(new Dimension(Options.getResolution().getWidth(), Integer.parseInt(ev.getText())));
    } else {
        throw new UnsupportedOperationException("TextField with id: " + id + " returned unexpected result: " + ev.getText());
    }
}
项目:Oberien    文件:Options.java   
public static void setResolution(Dimension resolution) {
    if (Options.resolution.equals(resolution)) {
        return;
    } else {
        Options.resolution = resolution;
        resolutionChanged = true;
    }
}
项目:jGui    文件:AbstractGuiSlider.java   
@Override
protected ReadableDimension calcMinSize() {
    return new Dimension(0, 0);
}
项目:jGui    文件:AbstractGuiElement.java   
public T setMinSize(ReadableDimension minSize) {
    this.minSize = new Dimension(minSize);
    return getThis();
}
项目:jGui    文件:AbstractGuiElement.java   
public T setMaxSize(ReadableDimension maxSize) {
    this.maxSize = new Dimension(maxSize);
    return getThis();
}
项目:jGui    文件:AbstractGuiElement.java   
public T setSize(int width, int height) {
    return setSize(new Dimension(width, height));
}
项目:jGui    文件:AbstractGuiElement.java   
@Override
public ReadableDimension getMaxSize() {
    return maxSize == null ? new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE) : maxSize;
}
项目:jGui    文件:AbstractGuiTextField.java   
@Override
protected ReadableDimension calcMinSize() {
    return new Dimension(0, 0);
}
项目:jGui    文件:AbstractGuiButton.java   
@Override
public ReadableDimension calcMinSize() {
    FontRenderer fontRenderer = getMinecraft().fontRendererObj;
    return new Dimension(fontRenderer.getStringWidth(label), 20);
}
项目:jGui    文件:AbstractGuiHorizontalScrollbar.java   
@Override
protected ReadableDimension calcMinSize() {
    return new Dimension(0, 0);
}
项目:jGui    文件:AbstractGuiLabel.java   
@Override
public ReadableDimension calcMinSize() {
    FontRenderer fontRenderer = getMinecraft().fontRendererObj;
    return new Dimension(fontRenderer.getStringWidth(text), fontRenderer.FONT_HEIGHT);
}
项目:jGui    文件:AbstractGuiImage.java   
@Override
public ReadableDimension calcMinSize() {
    return new Dimension(0, 0);
}
项目:jGui    文件:AbstractGuiTimelineTime.java   
@Override
public ReadableDimension calcMinSize() {
    return new Dimension(0, 0);
}
项目:jGui    文件:AbstractGuiTextArea.java   
@Override
protected ReadableDimension calcMinSize() {
    return new Dimension(0, 0);
}
项目:jGui    文件:AbstractGuiProgressBar.java   
@Override
public ReadableDimension calcMinSize() {
    return new Dimension(0, 0);
}
项目:jGui    文件:GuiFileChooserPopup.java   
@Override
public ReadableDimension calcMinSize(GuiContainer container) {
    return new Dimension(300, 200);
}
项目:jGui    文件:AbstractGuiPopup.java   
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    ReadableDimension size = popup.calcMinSize();
    return new Dimension(size.getWidth() + 20, size.getHeight() + 20);
}
项目:jGui    文件:GridLayout.java   
@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
    Preconditions.checkState(columns != 0, "Columns may not be 0.");
    int elements = container.getElements().size();
    int rows = (elements - 1 + columns) / columns;
    if (rows < 1) {
        return Collections.emptyMap();
    }
    int cellWidth = (size.getWidth() + spacingX) / columns - spacingX;
    int cellHeight = (size.getHeight() + spacingY) / rows - spacingY;

    Pair<int[], int[]> maxCellSize = null;

    if(!cellsEqualSize) {
        maxCellSize = calcNeededCellSize(container);
    }

    Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
    Iterator<Map.Entry<GuiElement, LayoutData>> iter = container.getElements().entrySet().iterator();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            if (!iter.hasNext()) {
                return map;
            }
            int x = j * (cellWidth + spacingX);
            int y = i * (cellHeight + spacingY);

            if (maxCellSize != null) {
                cellWidth = maxCellSize.getLeft()[j];
                cellHeight = maxCellSize.getRight()[i];

                x = 0;
                for (int x1 = 0; x1 < j; x1++) {
                    x += maxCellSize.getLeft()[x1];
                    x += spacingX;
                }

                y = 0;
                for (int y1 = 0; y1 < i; y1++) {
                    y += maxCellSize.getRight()[y1];
                    y += spacingY;
                }
            }

            Map.Entry<GuiElement, LayoutData> entry = iter.next();
            GuiElement element  = entry.getKey();
            Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
            Dimension elementSize = new Dimension(element.getMinSize());
            ReadableDimension elementMaxSize = element.getMaxSize();
            elementSize.setWidth(Math.min(cellWidth, elementMaxSize.getWidth()));
            elementSize.setHeight(Math.min(cellHeight, elementMaxSize.getHeight()));

            int remainingWidth = cellWidth - elementSize.getWidth();
            int remainingHeight = cellHeight - elementSize.getHeight();
            x += (int) (data.alignmentX * remainingWidth);
            y += (int) (data.alignmentY * remainingHeight);
            map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
        }
    }
    return map;
}
项目:jGui    文件:GridLayout.java   
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    Preconditions.checkState(columns != 0, "Columns may not be 0.");
    int maxWidth = 0, maxHeight = 0;

    int elements = 0;
    for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
        GuiElement element = entry.getKey();
        ReadableDimension minSize = element.getMinSize();

        int width = minSize.getWidth();
        if (width > maxWidth) {
            maxWidth = width;
        }

        int height = minSize.getHeight();
        if (height > maxHeight) {
            maxHeight = height;
        }
        elements++;
    }
    int rows = (elements - 1 + columns) / columns;

    int totalWidth = maxWidth * columns;
    int totalHeight = maxHeight * rows;

    if (!cellsEqualSize) {
        Pair<int[], int[]> maxCellSize = calcNeededCellSize(container);

        totalWidth = 0;
        for (int w : maxCellSize.getLeft()) {
            totalWidth += w;
        }

        totalHeight = 0;
        for (int h : maxCellSize.getRight()) {
            totalHeight += h;
        }
    }

    if (elements > 0) {
        totalWidth+=spacingX * (columns - 1);
    }
    if (elements > columns) {
        totalHeight+=spacingY * (rows - 1);
    }
    return new Dimension(totalWidth, totalHeight);
}
项目:jGui    文件:CustomLayout.java   
private Pair<Point, Dimension> entry(GuiElement element) {
    return result.get(element);
}
项目:jGui    文件:CustomLayout.java   
protected void set(GuiElement element, int x, int y, int width, int height) {
    Pair<Point, Dimension> entry = entry(element);
    entry.getLeft().setLocation(x, y);
    entry.getRight().setSize(width, height);
}
项目:jGui    文件:CustomLayout.java   
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
    return new Dimension(0, 0);
}
项目:mineshot    文件:FramebufferTiledWriter.java   
@Override
public void write() throws IOException {
    Dimension dim = fbc.getCaptureDimension();
    int widthViewport = dim.getWidth();
    int heightViewport = dim.getHeight();
    int bpp = fbc.getBytesPerPixel();

    double tilesX = widthTiled / (double) widthViewport;
    double tilesY = heightTiled / (double) heightViewport;

    int numTilesX = (int) Math.ceil(tilesX);
    int numTilesY = (int) Math.ceil(tilesY);

    Projection.zoom = tilesX <= tilesY ? tilesY : tilesX;

    EntityRenderer entityRenderer = MC.entityRenderer;
    Timer timer = getTimer(MC);

    fbc.setFlipColors(true);
    fbc.setFlipLines(false);

    modifySettings();

    try (FileChannel fc = FileChannel.open(file, READ, WRITE, CREATE)) {
        fc.write(buildTargaHeader(widthTiled, heightTiled, bpp * 8));

        long nanoTime = System.nanoTime();
        float partialTicks = timer == null ? 0 : timer.renderPartialTicks;

        for (int y = 0; y < numTilesY; y++) {
            for (int x = 0; x < numTilesX; x++) {
                // clip the captured frame if too big
                int tileWidth = Math.min(widthViewport, widthTiled - (widthViewport * x));
                int tileHeight = Math.min(heightViewport, heightTiled - (heightViewport * y));

                // update camera offset and zoom
                Projection.offsetX = (widthTiled - widthViewport - (widthViewport * x) * 2) / (double) widthViewport;
                Projection.offsetY = (heightTiled - heightViewport - (heightViewport * (tilesY - y - 1)) * 2) / (double) heightViewport;

                // render the tile
                entityRenderer.updateCameraAndRender(partialTicks, nanoTime);

                // get framebuffer
                fbc.capture();
                ByteBuffer frameBuffer = fbc.getByteBuffer();

                // copy viewport buffer into the tile buffer, row by row
                for (int i = 0; i < tileHeight; i++) {
                    // read row from viewport buffer
                    frameBuffer.clear();
                    frameBuffer.position(i * widthViewport * bpp);
                    frameBuffer.limit((i * widthViewport + tileWidth) * bpp);

                    // write row at tiled position
                    long o1 = (long) widthTiled * i;
                    long o2 = (long) widthTiled * heightViewport * y;
                    long o3 = (long) widthViewport * x;
                    fc.position((o1 + o2 + o3) * bpp + HEADER_SIZE);
                    fc.write(frameBuffer);
                }
            }
        }
    } finally {
        // restore camera settings
        Projection.zoom = 1;
        Projection.offsetX = 0;
        Projection.offsetY = 0;

        // restore game settings
        restoreSettings();
    }
}
项目:mineshot    文件:FramebufferCapturer.java   
public Dimension getCaptureDimension() {
    return dim;
}
项目:mineshot    文件:FramebufferCapturer.java   
private Dimension getCurrentDimension() {
    return new Dimension(MC.displayWidth, MC.displayHeight);
}
项目:Oberien    文件:Options.java   
public static void initOptions(AppGameContainer agc) {
    game = agc;
    resolution = new Dimension(game.getScreenWidth(), game.getScreenHeight());
}
项目:Oberien    文件:Options.java   
public static Dimension getResolution() {
    return resolution;
}