use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.
the class TerasologyCanvasImpl method drawMesh.
public void drawMesh(Mesh mesh, Material material, Rectanglei region, Quaternionfc rotation, Vector3fc 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;
}
Rectanglei drawRegion = relativeToAbsolute(region);
if (!state.cropRegion.intersectsRectangle(drawRegion)) {
return;
}
((TerasologyCanvasRenderer) renderer).drawMesh(mesh, material, drawRegion, drawRegion.intersection(state.cropRegion), rotation, offset, scale, state.getAlpha());
}
use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.
the class ContextMenuScreen method onDraw.
@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.x += currentWidth;
}
Vector2i preferredSize = canvas.calculatePreferredSize(level);
Rectanglei region = new Rectanglei(currentPosition.x, currentPosition.y).setSize(preferredSize.x, preferredSize.y);
double percentageThreshold = 0.9;
int canvasHeight = canvas.getRegion().getSizeY();
if (region.maxY > canvasHeight * percentageThreshold) {
region = new Rectanglei(region.minX, region.minY - (region.maxY - canvasHeight) - (int) (canvasHeight * (1 - percentageThreshold))).setSize(region.maxX, canvasHeight);
}
currentWidth = canvas.calculatePreferredSize(level).x() - 8;
canvas.drawWidget(level, region);
}
}
}
use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.
the class PortList method onDraw.
public void onDraw(Canvas canvas) {
Rectanglei region = canvas.getRegion();
inputPort.updateRect();
canvas.drawWidget(inputPort, new Rectanglei((int) (inputPort.rect.minX() / 10.f * region.lengthX()), (int) (inputPort.rect.minY() / 5.f * region.lengthY()), (int) (inputPort.rect.maxX() / 10.f * region.lengthX()), (int) (inputPort.rect.maxY() / 5.f * region.lengthY())));
for (Port port : ports) {
port.updateRect();
canvas.drawWidget(port, new Rectanglei((int) (port.rect.minX() / 10.f * region.lengthX()), (int) (port.rect.minY() / 5.f * region.lengthY()), (int) (port.rect.maxX() / 10.f * region.lengthX()), (int) (port.rect.maxY() / 5.f * region.lengthY())));
}
}
use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.
the class ZoomableLayoutTest method testZoomInAndDrag.
@Test
public void testZoomInAndDrag() throws Exception {
zoomableLayout.onDraw(canvas);
// zoom in 2x towards left top corner
zoomableLayout.zoom(0.5f, 0.5f, new Vector2i(0, 0));
zoomableLayout.onDraw(canvas);
// world size halved
assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH, WORLD_HEIGHT / 2));
assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / WORLD_WIDTH, CANVAS_HEIGHT / (WORLD_HEIGHT / 2)));
verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x), ceilToInt(pos1.y)), new Vector2i(ceilToInt(pos1.x + size1.x), ceilToInt(pos1.y + size1.y))));
verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(ceilToInt(pos2.x), ceilToInt(pos2.y)), new Vector2i(ceilToInt(pos2.x + size2.x), ceilToInt(pos2.y + size2.y))));
verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x), ceilToInt(pos3.y)), new Vector2i(ceilToInt(pos3.x + size3.x), ceilToInt(pos3.y + size3.y))));
// simulate drag to item2
zoomableLayout.setWindowPosition(pos2);
zoomableLayout.onDraw(canvas);
// item1 out of canvas
verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x - pos2.x), ceilToInt(pos1.y - pos2.y)), new Vector2i(ceilToInt(pos1.x + size1.x - pos2.x), ceilToInt(pos1.y + size1.y - pos2.y))));
verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(), new Vector2i(ceilToInt(size2.x), ceilToInt(size2.y))));
verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x - pos2.x), ceilToInt(pos3.y - pos2.y)), new Vector2i(ceilToInt(pos3.x + size3.x - pos2.x), ceilToInt(pos3.y + size3.y - pos2.y))));
}
use of org.terasology.joml.geom.Rectanglei in project Terasology by MovingBlocks.
the class RectangleiTypeHandler method deserialize.
@Override
public Optional<Rectanglei> deserialize(PersistedData data) {
if (!data.isNull() && data.isValueMap()) {
PersistedDataMap map = data.getAsValueMap();
PersistedDataArray minDataArr = map.get(MIN_FIELD).getAsArray();
TIntList minArr = minDataArr.getAsIntegerArray();
if (map.has(SIZE_FIELD)) {
PersistedDataArray sizedataArray = map.get(SIZE_FIELD).getAsArray();
TIntList sizeArr = sizedataArray.getAsIntegerArray();
return Optional.of(new Rectanglei(minArr.get(0), minArr.get(1)).setSize(sizeArr.get(0), sizeArr.get(1)));
}
PersistedDataArray maxDataArr = map.get(MAX_FIELD).getAsArray();
TIntList maxArr = maxDataArr.getAsIntegerArray();
return Optional.of(new Rectanglei(minArr.get(0), minArr.get(1), maxArr.get(0), maxArr.get(1)));
}
return Optional.empty();
}
Aggregations