@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()) )); } }
@Override public void updateRect() { rect = Rect2f.createFromMinAndSize(4.5f, 0.05f, 1f, 1f); }
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); } } }
private void process(FreeformDefinition freeform, Texture texture, Vector2i size, Map<Name, SubtextureData> out) { if (freeform.getName() == null || freeform.getName().isEmpty()) { logger.error("Bad subimage definition - missing mandatory property name"); return; } if (freeform.getMin() == null) { logger.error("Bad subimage definition '{}' - missing mandatory property min", freeform.getName()); return; } if (freeform.getSize() == null && freeform.getMax() == null) { logger.error("Bad subimage definition '{}' - requires one of max or size", freeform.getName()); return; } Vector2f min = new Vector2f((float) freeform.getMin().x / size.x, (float) freeform.getMin().y / size.y); if (freeform.getSize() != null) { Vector2f itemSize = new Vector2f((float) freeform.getSize().x / size.x, (float) freeform.getSize().y / size.y); out.put(new Name(freeform.getName()), new SubtextureData(texture, Rect2f.createFromMinAndSize(min, itemSize))); } else if (freeform.getMax() != null) { Vector2f max = new Vector2f((float) freeform.getMax().x / size.x, (float) freeform.getMax().y / size.y); out.put(new Name(freeform.getName()), new SubtextureData(texture, Rect2f.createFromMinAndMax(min, max))); } }
@Override public int getWidth() { return TeraMath.ceilToInt(texture.getWidth() * region.width()); }
@Override public int getHeight() { return TeraMath.ceilToInt(texture.getHeight() * region.height()); }
@Override public PersistedData serialize(Rect2f value, SerializationContext context) { if (value == null) { return context.createNull(); } else { Map<String, PersistedData> map = Maps.newLinkedHashMap(); map.put(MIN_FIELD, context.create(value.min(), Vector2f.class)); map.put(SIZE_FIELD, context.create(value.size(), Vector2f.class)); return context.create(map); } }
@Override public int getWidth() { return TeraMath.ceilToInt(texture.getWidth() * subregion.width()); }
@Override public int getHeight() { return TeraMath.ceilToInt(texture.getHeight() * subregion.height()); }
@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()))); } }
private void initialize() { Tessellator tessellator = new Tessellator(); TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1, 1, 1, 1f), textureRegion.min(), textureRegion.size(), 1.001f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f); overlayMesh = tessellator.generateMesh(); tessellator = new Tessellator(); TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1, 1, 1, .2f), textureRegion.min(), textureRegion.size(), 1.001f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f); overlayMesh2 = tessellator.generateMesh(); defaultTextured = Assets.getMaterial("engine:prog.defaultTextured").get(); }
public BasicTextureRegion(Texture texture, Vector2f offset, Vector2f size) { this(texture, Rect2f.createFromMinAndSize(offset, size)); }
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; float texBorderY = (scale.y - absoluteRegion.height()) / scale.y * uh; textureMat.setFloat2("texOffset", textureArea.minX() + (ux + 0.5f * texBorderX) * textureArea.width(), 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;
@Override public void updateRect() { this.rect = Rect2f.createFromMinAndSize( index() + 0.4f, 4.05f, 0.6f, 0.9f); }
addTiles(builder, Rect2i.createFromMinAndSize(border.getLeft(), 0, centerHoriz, border.getTop()), Rect2f.createFromMinAndMax(left, 0, right, top), new Vector2i(textureSize.x - border.getTotalWidth(), border.getTop()), Rect2f.createFromMinAndMax(leftTex, 0, rightTex, topTex)); } else { addRectPoly(builder, left, 0, right, top, leftTex, 0, rightTex, topTex); addTiles(builder, Rect2i.createFromMinAndSize(0, border.getTop(), border.getLeft(), centerVert), Rect2f.createFromMinAndMax(0, top, left, bottom), new Vector2i(border.getLeft(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(0, topTex, leftTex, bottomTex)); } else { addRectPoly(builder, 0, top, left, bottom, 0, topTex, leftTex, bottomTex); Rect2f.createFromMinAndMax(left, top, right, bottom), new Vector2i(textureSize.x - border.getTotalWidth(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(leftTex, topTex, rightTex, bottomTex)); } else { addRectPoly(builder, left, top, right, bottom, leftTex, topTex, rightTex, bottomTex); if (tile) { addTiles(builder, Rect2i.createFromMinAndSize(region.width() - border.getRight(), border.getTop(), border.getRight(), centerVert), Rect2f.createFromMinAndMax(right, top, 1, bottom), new Vector2i(border.getRight(), textureSize.y - border.getTotalHeight()), Rect2f.createFromMinAndMax(rightTex, topTex, 1, bottomTex)); } else { addRectPoly(builder, right, top, 1, bottom, rightTex, topTex, 1, bottomTex); Rect2f.createFromMinAndMax(left, bottom, right, 1), new Vector2i(textureSize.x - border.getTotalWidth(), border.getBottom()), Rect2f.createFromMinAndMax(leftTex, bottomTex, rightTex, 1));
@Override public void updateRect() { this.rect = Rect2f.createFromMinAndSize( index(), 4.05f, 0.4f, 0.9f); }