@Override public void drawMesh(Mesh mesh, Material material, Rect2i region, Quat4f rotation, Vector3f offset, float scale) { if (material == null) { logger.warn("Attempted to draw with nonexistent material"); return; } if (mesh == null) { logger.warn("Attempted to draw nonexistent mesh"); return; } Rect2i drawRegion = relativeToAbsolute(region); if (!state.cropRegion.overlaps(drawRegion)) { return; } renderer.drawMesh(mesh, material, drawRegion, drawRegion.intersect(state.cropRegion), rotation, offset, scale, state.getAlpha()); }
@Override public void addInteractionRegion(InteractionListener listener, UIWidget tooltip, Rect2i region) { Vector2i offset = state.drawRegion.min(); Rect2i finalRegion = state.cropRegion.intersect(relativeToAbsolute(region)); if (!finalRegion.isEmpty()) { listener.setFocusManager(nuiManager); if (state.drawOnTop) { drawOnTopOperations.add(new DrawInteractionRegionOperation(finalRegion, offset, listener, state.element, tooltip)); } else { interactionRegions.addLast(new InteractionRegion(finalRegion, offset, listener, state.element, tooltip)); } } }
@Override public void drawTextRawShadowed(String text, Font font, Color color, Color shadowColor, boolean underline, Rect2i region, HorizontalAlign hAlign, VerticalAlign vAlign) { Rect2i absoluteRegion = relativeToAbsolute(region); Rect2i cropRegion = absoluteRegion.intersect(state.cropRegion); if (!cropRegion.isEmpty()) { if (state.drawOnTop) { drawOnTopOperations.add(new DrawTextOperation(text, font, hAlign, vAlign, absoluteRegion, cropRegion, color, shadowColor, state.getAlpha(), underline)); } else { renderer.drawText(text, font, hAlign, vAlign, absoluteRegion, color, shadowColor, state.getAlpha(), underline); } } }
@Override public void drawTextureRaw(TextureRegion texture, Rect2i region, Color color, ScaleMode mode, float ux, float uy, float uw, float uh) { if (!state.cropRegion.overlaps(relativeToAbsolute(region))) { return; } Rect2i absoluteRegion = relativeToAbsolute(region); Rect2i cropRegion = absoluteRegion.intersect(state.cropRegion); if (!cropRegion.isEmpty()) { if (state.drawOnTop) { drawOnTopOperations.add(new DrawTextureOperation(texture, color, mode, absoluteRegion, cropRegion, ux, uy, uw, uh, state.getAlpha())); } else { renderer.drawTexture(texture, color, mode, absoluteRegion, ux, uy, uw, uh, state.getAlpha()); } } }
@Override public void drawTextureRawBordered(TextureRegion texture, Rect2i region, Border border, boolean tile, float ux, float uy, float uw, float uh) { if (!state.cropRegion.overlaps(relativeToAbsolute(region))) { return; } Rect2i absoluteRegion = relativeToAbsolute(region); Rect2i cropRegion = absoluteRegion.intersect(state.cropRegion); if (!cropRegion.isEmpty()) { if (state.drawOnTop) { drawOnTopOperations.add(new DrawBorderedTextureOperation(texture, absoluteRegion, border, tile, cropRegion, ux, uy, uw, uh, state.getAlpha())); } else { renderer.drawTextureBordered(texture, absoluteRegion, border, tile, ux, uy, uw, uh, state.getAlpha()); } } }
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; } }
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); } }