@Override public int getAdvanceForVerticalPosition(int y) { Rect2i lastLeft = findLastAtYPosition(leftFloats, y); if (lastLeft != null) { return lastLeft.maxX(); } else { return 0; } }
private int getAvailableWidthAt(int y) { int width = containerWidth; Rect2i lastRight = findLastAtYPosition(rightFloats, y); if (lastRight != null) { width = lastRight.minX(); } Rect2i lastLeft = findLastAtYPosition(leftFloats, y); if (lastLeft != null) { width -= lastLeft.maxX(); } return width; }
@Override public void apply(float v) { consumer.accept(Rect2i.createFromMinAndMax( // rounds towards zero (int) (v * (to.minX() - from.minX()) + from.minX()), (int) (v * (to.minY() - from.minY()) + from.minY()), (int) (v * (to.maxX() - from.maxX()) + from.maxX()), (int) (v * (to.maxY() - from.maxY()) + from.maxY()) )); } }
public static LineCoordinates getLineCoordinates(int startX, int startY, int endX, int endY, Rect2i baseRegion, Rect2i cropRegion) { Rect2i region = Rect2i.createFromMinAndMax(Math.min(startX, endX), Math.min(startY, endY), Math.max(startX, endX), Math.max(startY, endY)); Rect2i absoluteRegion = relativeToAbsolute(region, baseRegion); Rect2i finalRegion = cropRegion.intersect(absoluteRegion); if (!finalRegion.isEmpty()) { int sx = startX > endX ? finalRegion.maxX() : finalRegion.minX(); int sy = startY > endY ? finalRegion.maxY() : finalRegion.minY(); int ex = startX > endX ? finalRegion.minX() : finalRegion.maxX(); int ey = startY > endY ? finalRegion.minY() : finalRegion.maxY(); return new LineCoordinates(new Vector2i(sx, sy), new Vector2i(ex, ey)); } else { return null; } }
private void drawDragHint(Canvas canvas, Rect2i nodeRegion) { if (state.getMouseOverType() == MouseOverType.TOP) { // Draw a line at the top of the node. canvas.drawLine(nodeRegion.minX(), nodeRegion.minY(), nodeRegion.maxX(), nodeRegion.minY(), Color.WHITE); } else if (state.getMouseOverType() == MouseOverType.CENTER) { // Draw a border around the node. canvas.drawLine(nodeRegion.minX(), nodeRegion.minY(), nodeRegion.maxX(), nodeRegion.minY(), Color.WHITE); canvas.drawLine(nodeRegion.maxX(), nodeRegion.minY(), nodeRegion.maxX(), nodeRegion.maxY(), Color.WHITE); canvas.drawLine(nodeRegion.minX(), nodeRegion.minY(), nodeRegion.minX(), nodeRegion.maxY(), Color.WHITE); canvas.drawLine(nodeRegion.minX(), nodeRegion.maxY(), nodeRegion.maxX(), nodeRegion.maxY(), Color.WHITE); } else { // MouseOverType.BOTTOM // Draw a line at the bottom of the node. canvas.drawLine(nodeRegion.minX(), nodeRegion.maxY(), nodeRegion.maxX(), nodeRegion.maxY(), Color.WHITE); } }
private Rect2i determineRequiredRegion(Rect2i region) { int newMinX = region.minX() - IntMath.mod(region.minX(), sampleRate); int newMinY = region.minY() - IntMath.mod(region.minY(), sampleRate); int newMaxX = region.maxX() + 4 - IntMath.mod(region.maxX(), sampleRate) - 1; int newMaxY = region.maxY() + 4 - IntMath.mod(region.maxY(), sampleRate) - 1; return Rect2i.createFromMinAndMax(newMinX, newMinY, newMaxX, newMaxY); }
for (int x = tileArea.minX(); x < tileArea.maxX(); x++) { ImmutableVector2i pos = new ImmutableVector2i(x, z); imageFutures.put(pos, threadPool.submit(() -> { for (int x = tileArea.minX(); x < tileArea.maxX(); x++) { ImmutableVector2i pos = new ImmutableVector2i(x, z); try { g.drawLine(worldArea.minX(), 0, worldArea.maxX(), 0); g.drawLine(0, worldArea.minY(), 0, worldArea.maxY());
@Override public void drawText(String text, Font font, HorizontalAlign hAlign, VerticalAlign vAlign, Rect2i absoluteRegion, Color color, Color shadowColor, float alpha, boolean underlined) { TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.width(), hAlign, color, shadowColor, underlined); usedText.add(key); Map<Material, Mesh> fontMesh = cachedText.get(key); List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.width()); if (fontMesh != null) { for (Mesh mesh : fontMesh.values()) { if (mesh.isDisposed()) { fontMesh = null; break; } } } if (fontMesh == null) { fontMesh = fontMeshBuilder.createTextMesh(font, lines, absoluteRegion.width(), hAlign, color, shadowColor, underlined); cachedText.put(key, fontMesh); } Vector2i offset = new Vector2i(absoluteRegion.minX(), absoluteRegion.minY()); offset.y += vAlign.getOffset(lines.size() * font.getLineHeight(), absoluteRegion.height()); fontMesh.entrySet().stream().filter(entry -> entry.getKey().isRenderable()).forEach(entry -> { entry.getKey().bindTextures(); entry.getKey().setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY()); entry.getKey().setFloat2("offset", offset.x, offset.y); entry.getKey().setFloat("alpha", alpha); entry.getValue().render(); }); }
private Rect2i determineRequiredRegion(Rect2i region) { int newMinX = region.minX() - IntMath.mod(region.minX(), sampleRate); int newMinY = region.minY() - IntMath.mod(region.minY(), sampleRate); int newMaxX = region.maxX() + 4 - IntMath.mod(region.maxX(), sampleRate) - 1; int newMaxY = region.maxY() + 4 - IntMath.mod(region.maxY(), sampleRate) - 1; return Rect2i.createFromMinAndMax(newMinX, newMinY, newMaxX, newMaxY); } }
@Override public void onDraw(Canvas canvas) { int[] bounds = {0, 0, canvas.size().x, canvas.size().y}; layoutContainer(canvas, bounds); for (ComponentWrapper wrapper : wrappers.values()) { UIWidget component = (UIWidget) wrapper.getComponent(); Rect2i region = Rect2i.createFromMinAndSize(wrapper.getX(), wrapper.getY(), wrapper.getWidth(), wrapper.getHeight()); canvas.drawWidget(component, region); } if (debug) { grid.paintDebug(); } for (Rect2i region : debugRects) { canvas.drawLine(region.minX(), region.minY(), region.maxX(), region.minY(), Color.WHITE); canvas.drawLine(region.maxX(), region.minY(), region.maxX(), region.maxY(), Color.WHITE); canvas.drawLine(region.maxX(), region.maxY(), region.minX(), region.maxY(), Color.WHITE); canvas.drawLine(region.minX(), region.maxY(), region.minX(), region.minY(), Color.WHITE); } }
@Override public Rect2i addLeftFloat(int y, int width, int height) { int posY = y; while (true) { int availableWidth = getAvailableWidthAt(posY); if (availableWidth >= width) { int x = 0; Rect2i lastLeft = findLastAtYPosition(leftFloats, posY); if (lastLeft != null) { x = lastLeft.maxX(); } Rect2i floatRect = Rect2i.createFromMinAndSize(x, posY, width, height); leftFloats.add(floatRect); return floatRect; } else { Rect2i lastLeft = findLastAtYPosition(leftFloats, posY); Rect2i lastRight = findLastAtYPosition(rightFloats, posY); if (lastLeft != null && lastRight != null) { posY = Math.min(lastLeft.maxY(), lastRight.maxY()); } else if (lastLeft != null) { posY = lastLeft.maxY(); } else if (lastRight != null) { posY = lastRight.maxY(); } } } }
private static Rect2i worldToTileArea(Rect2i area) { int chunkMinX = IntMath.divide(area.minX(), TILE_SIZE_X, RoundingMode.FLOOR); int chunkMinZ = IntMath.divide(area.minY(), TILE_SIZE_Y, RoundingMode.FLOOR); int chunkMaxX = IntMath.divide(area.maxX(), TILE_SIZE_X, RoundingMode.CEILING); int chunkMaxZ = IntMath.divide(area.maxY(), TILE_SIZE_Y, RoundingMode.CEILING); return Rect2i.createFromMinAndMax(chunkMinX, chunkMinZ, chunkMaxX, chunkMaxZ); }
@Test public void testLineCoordinatesNoIntersection() { //Line is located in the bottom left, outside the region int sx = cropRegion.minX() - 5; int sy = cropRegion.minY() - 5; int ex = cropRegion.minX() - 5; int ey = cropRegion.minY() - 5; assertNull(Line.getLineCoordinates(sx, sy, ex, ey, Rect2i.EMPTY, cropRegion)); // Top left sx = cropRegion.minX() - 5; sy = cropRegion.maxY() + 5; ex = cropRegion.minX() - 5; ey = cropRegion.maxY() + 5; assertNull(Line.getLineCoordinates(sx, sy, ex, ey, Rect2i.EMPTY, cropRegion)); // Bottom right sx = cropRegion.maxX() + 5; sy = cropRegion.minY() - 5; ex = cropRegion.maxX() + 5; ey = cropRegion.maxY() - 5; assertNull(Line.getLineCoordinates(sx, sy, ex, ey, Rect2i.EMPTY, cropRegion)); // Top right sx = cropRegion.maxX() + 5; sy = cropRegion.maxY() + 5; ex = cropRegion.maxX() + 5; ey = cropRegion.maxY() + 5; assertNull(Line.getLineCoordinates(sx, sy, ex, ey, Rect2i.EMPTY, cropRegion)); }
SubRegionImpl(Rect2i region, boolean crop) { previousState = state; int left = TeraMath.addClampAtMax(region.minX(), state.drawRegion.minX()); int right = TeraMath.addClampAtMax(region.maxX(), state.drawRegion.minX()); int top = TeraMath.addClampAtMax(region.minY(), state.drawRegion.minY()); int bottom = TeraMath.addClampAtMax(region.maxY(), state.drawRegion.minY()); Rect2i subRegion = Rect2i.createFromMinAndMax(left, top, right, bottom); if (crop) { Rect2i cropRegion = subRegion.intersect(state.cropRegion); if (cropRegion.isEmpty()) { state = new CanvasState(state, subRegion, cropRegion); } else if (!cropRegion.equals(state.cropRegion)) { state = new CanvasState(state, subRegion, cropRegion); renderer.crop(cropRegion); croppingRegion = true; } else { state = new CanvasState(state, subRegion); } } else { state = new CanvasState(state, subRegion); } }
CROPPING_BOUNDARIES_PARAM, cropRegion.minX() * uiScale, cropRegion.maxX() * uiScale, cropRegion.minY() * uiScale, cropRegion.maxY() * uiScale);
@Override public void onDraw(Canvas canvas) { canvas.addInteractionRegion(mainListener); Vector2i currentPosition = null; int currentWidth = 0; for (UIList<AbstractContextMenuItem> level : menuWidgets) { if (level.isVisible()) { if (currentPosition == null) { currentPosition = new Vector2i(position); } else { currentPosition.addX(currentWidth); } Rect2i region = Rect2i.createFromMinAndSize(currentPosition, canvas.calculatePreferredSize(level)); double percentageThreshold = 0.9; if (region.maxY() > canvas.getRegion().height() * percentageThreshold) { region = Rect2i.createFromMinAndMax(region.minX(), region.minY() - (region.maxY() - canvas.getRegion().height()) - (int) (canvas.getRegion().height() * (1 - percentageThreshold)), region.maxX(), canvas.getRegion().height()); } currentWidth = canvas.calculatePreferredSize(level).getX() - 8; canvas.drawWidget(level, region); } } }
@Override public void preRender() { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 0, 2048f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); modelView = new Matrix4f(); modelView.setIdentity(); modelView.setTranslation(new Vector3f(0, 0, -1024f)); MatrixUtils.matrixToFloatBuffer(modelView, matrixBuffer); glLoadMatrix(matrixBuffer); matrixBuffer.rewind(); glScalef(uiScale, uiScale, uiScale); requestedCropRegion = Rect2i.createFromMinAndSize(0, 0, Display.getWidth(), Display.getHeight()); currentTextureCropRegion = requestedCropRegion; textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY()); }
textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY()); currentTextureCropRegion = requestedCropRegion;
Rect2i.createFromMinAndMax(position.minX() + paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth), position.minY() + paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth), position.maxX() - paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) - 1, position.maxY() - paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth) - 1);
textureMat.setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX(), requestedCropRegion.maxX(), requestedCropRegion.minY(), requestedCropRegion.maxY()); currentTextureCropRegion = requestedCropRegion;