@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()) ); } } }
@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); }
@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); }
@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); }
@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); }
@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(); }
@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; }
@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; }
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()); } }
@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()); } }
public static void setResolution(Dimension resolution) { if (Options.resolution.equals(resolution)) { return; } else { Options.resolution = resolution; resolutionChanged = true; } }
@Override protected ReadableDimension calcMinSize() { return new Dimension(0, 0); }
public T setMinSize(ReadableDimension minSize) { this.minSize = new Dimension(minSize); return getThis(); }
public T setMaxSize(ReadableDimension maxSize) { this.maxSize = new Dimension(maxSize); return getThis(); }
public T setSize(int width, int height) { return setSize(new Dimension(width, height)); }
@Override public ReadableDimension getMaxSize() { return maxSize == null ? new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE) : maxSize; }
@Override public ReadableDimension calcMinSize() { FontRenderer fontRenderer = getMinecraft().fontRendererObj; return new Dimension(fontRenderer.getStringWidth(label), 20); }
@Override public ReadableDimension calcMinSize() { FontRenderer fontRenderer = getMinecraft().fontRendererObj; return new Dimension(fontRenderer.getStringWidth(text), fontRenderer.FONT_HEIGHT); }
@Override public ReadableDimension calcMinSize() { return new Dimension(0, 0); }
@Override public ReadableDimension calcMinSize(GuiContainer container) { return new Dimension(300, 200); }
@Override public ReadableDimension calcMinSize(GuiContainer<?> container) { ReadableDimension size = popup.calcMinSize(); return new Dimension(size.getWidth() + 20, size.getHeight() + 20); }
@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; }
@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); }
private Pair<Point, Dimension> entry(GuiElement element) { return result.get(element); }
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); }
@Override public ReadableDimension calcMinSize(GuiContainer<?> container) { return new Dimension(0, 0); }
@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(); } }
public Dimension getCaptureDimension() { return dim; }
private Dimension getCurrentDimension() { return new Dimension(MC.displayWidth, MC.displayHeight); }
public static void initOptions(AppGameContainer agc) { game = agc; resolution = new Dimension(game.getScreenWidth(), game.getScreenHeight()); }
public static Dimension getResolution() { return resolution; }