@Override public void apply(float v) { consumer.accept(Rect2f.createFromMinAndMax( // rounds towards zero (v * (to.minX() - from.minX()) + from.minX()), (v * (to.minY() - from.minY()) + from.minY()), (v * (to.maxX() - from.maxX()) + from.maxX()), (v * (to.maxY() - from.maxY()) + from.maxY()) )); } }
private void addTiles(MeshBuilder builder, Rect2i drawRegion, Rect2f subDrawRegion, Vector2i textureSize, Rect2f subTextureRegion) { int tileW = textureSize.x; int tileH = textureSize.y; int horizTiles = TeraMath.fastAbs((drawRegion.width() - 1) / tileW) + 1; int vertTiles = TeraMath.fastAbs((drawRegion.height() - 1) / tileH) + 1; int offsetX = (drawRegion.width() - horizTiles * tileW) / 2; int offsetY = (drawRegion.height() - vertTiles * tileH) / 2; for (int tileY = 0; tileY < vertTiles; tileY++) { for (int tileX = 0; tileX < horizTiles; tileX++) { int left = offsetX + tileW * tileX; int top = offsetY + tileH * tileY; float vertLeft = subDrawRegion.minX() + subDrawRegion.width() * Math.max((float) left / drawRegion.width(), 0); float vertTop = subDrawRegion.minY() + subDrawRegion.height() * Math.max((float) top / drawRegion.height(), 0); float vertRight = subDrawRegion.minX() + subDrawRegion.width() * Math.min((float) (left + tileW) / drawRegion.width(), 1); float vertBottom = subDrawRegion.minY() + subDrawRegion.height() * Math.min((float) (top + tileH) / drawRegion.height(), 1); float texCoordLeft = subTextureRegion.minX() + subTextureRegion.width() * (Math.max(left, 0) - left) / tileW; float texCoordTop = subTextureRegion.minY() + subTextureRegion.height() * (Math.max(top, 0) - top) / tileH; float texCoordRight = subTextureRegion.minX() + subTextureRegion.width() * (Math.min(left + tileW, drawRegion.width()) - left) / tileW; float texCoordBottom = subTextureRegion.minY() + subTextureRegion.height() * (Math.min(top + tileH, drawRegion.height()) - top) / tileH; addRectPoly(builder, vertLeft, vertTop, vertRight, vertBottom, texCoordLeft, texCoordTop, texCoordRight, texCoordBottom); } } }
@Override public Rect2i getPixelRegion() { return Rect2i.createFromMinAndSize(TeraMath.floorToInt(subregion.minX() * texture.getWidth()), TeraMath.floorToInt(subregion.minY() * texture.getHeight()), getWidth(), getHeight()); }
@Override public Rect2i getPixelRegion() { return Rect2i.createFromMinAndSize(TeraMath.floorToInt(region.minX() * texture.getWidth()), TeraMath.floorToInt(region.minY() * texture.getHeight()), getWidth(), getHeight()); } }
@Override public void onDraw(Canvas canvas) { for (HUDElement element : elementsLookup.values()) { int minX = TeraMath.floorToInt(element.region.minX() * canvas.size().x); int minY = TeraMath.floorToInt(element.region.minY() * canvas.size().y); int sizeX = TeraMath.floorToInt(element.region.width() * canvas.size().x); int sizeY = TeraMath.floorToInt(element.region.height() * canvas.size().y); Rect2i region = Rect2i.createFromMinAndSize(minX, minY, sizeX, sizeY); canvas.drawWidget(element.widget, region); } }
public void onDraw(Canvas canvas) { Rect2i region = canvas.getRegion(); inputPort.updateRect(); canvas.drawWidget(inputPort, Rect2i.createFromMinAndMax( (int) (inputPort.rect.minX() / 10.f * region.width()), (int) (inputPort.rect.minY() / 5.f * region.height()), (int) (inputPort.rect.maxX() / 10.f * region.width()), (int) (inputPort.rect.maxY() / 5.f * region.height()))); for (Port port : ports) { port.updateRect(); canvas.drawWidget(port, Rect2i.createFromMinAndMax( (int) (port.rect.minX() / 10.f * region.width()), (int) (port.rect.minY() / 5.f * region.height()), (int) (port.rect.maxX() / 10.f * region.width()), (int) (port.rect.maxY() / 5.f * region.height()))); } }
absoluteRegion.minY()); textureMat.setFloat2("texOffset", textureArea.minX() + ux * textureArea.width(), textureArea.minY() + uy * textureArea.height()); textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height()); break; textureArea.minY() + (uy + 0.5f * texBorderY) * textureArea.height()); textureMat.setFloat2("texSize", (uw - texBorderX) * textureArea.width(), (uh - texBorderY) * textureArea.height()); break; absoluteRegion.minY() + 0.5f * (absoluteRegion.height() - scale.y)); textureMat.setFloat2("texOffset", textureArea.minX() + ux * textureArea.width(), textureArea.minY() + uy * textureArea.height()); textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height()); break;
textureMat.setFloat2("texOffset", textureArea.minX() + ux * textureArea.width(), textureArea.minY() + uy * textureArea.height()); textureMat.setFloat2("texSize", uw * textureArea.width(), uh * textureArea.height());