use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class RowLayoutTest method testAllRelativeWidths.
@Test
public void testAllRelativeWidths() throws Exception {
// Set relative width for all 3 widgets
rowLayout.setColumnRatios(0.4f, 0.5f, 0.1f);
rowLayout.setHorizontalSpacing(0);
Vector2i result = rowLayout.getPreferredContentSize(canvas, canvas.size());
// Preferred width should be width of canvas
assertEquals(CANVAS_WIDTH, result.x);
// Preferred height should be the height of the tallest widget
assertEquals(15, result.y);
rowLayout.onDraw(canvas);
// Width split according to the relative widths of the widgets
// Gets 4/10 of the entire area
final int width1 = CANVAS_WIDTH * 4 / 10;
// Gets 1/2 of the entire area
final int width2 = CANVAS_WIDTH / 2;
// Gets 1/10 of the entire area
final int width3 = CANVAS_WIDTH / 10;
verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, width1, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(width1, 0, width2, CANVAS_HEIGHT));
verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(width1 + width2, 0, width3, CANVAS_HEIGHT));
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class RowLayoutTest method setup.
@Before
public void setup() {
rowLayout = new RowLayout();
itemAt1x1 = mock(UIWidget.class);
itemAt1x2 = mock(UIWidget.class);
itemAt1x3 = mock(UIWidget.class);
canvas = mock(Canvas.class);
// +-----------------------------------+ +---+ +-------+
// | | |1x2| | |
// | 1x1 | +---+ | |
// | | | 1x3 |
// +-----------------------------------+ | |
// | |
// +-------+
when(canvas.calculateRestrictedSize(eq(itemAt1x1), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
when(canvas.calculateRestrictedSize(eq(itemAt1x2), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
when(canvas.calculateRestrictedSize(eq(itemAt1x3), any(Vector2i.class))).thenReturn(new Vector2i(10, 15));
Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
when(canvas.size()).thenReturn(availableSize);
rowLayout.addWidget(itemAt1x1, null);
rowLayout.addWidget(itemAt1x2, null);
rowLayout.addWidget(itemAt1x3, null);
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class CanvasImpl method calculateRestrictedSize.
@Override
public Vector2i calculateRestrictedSize(UIWidget widget, Vector2i sizeRestrictions) {
if (widget == null) {
return sizeRestrictions;
}
String family = (widget.getFamily() != null) ? widget.getFamily() : state.family;
UISkin skin = (widget.getSkin() != null) ? widget.getSkin() : state.skin;
UIStyle elementStyle = skin.getStyleFor(family, widget.getClass(), UIWidget.BASE_PART, widget.getMode());
Rect2i region = applyStyleToSize(Rect2i.createFromMinAndSize(Vector2i.zero(), sizeRestrictions), elementStyle);
try (SubRegion ignored = subRegionForWidget(widget, region, false)) {
Vector2i preferredSize = widget.getPreferredContentSize(this, elementStyle.getMargin().shrink(sizeRestrictions));
preferredSize = elementStyle.getMargin().grow(preferredSize);
return applyStyleToSize(preferredSize, elementStyle);
}
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class CanvasImpl method preRender.
@Override
public void preRender() {
interactionRegions.clear();
Vector2i size = renderer.getTargetSize();
state = new CanvasState(null, Rect2i.createFromMinAndSize(0, 0, size.x, size.y));
renderer.preRender();
renderer.crop(state.cropRegion);
focusDrawn = false;
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class CanvasImpl method processMouseWheel.
@Override
public boolean processMouseWheel(int wheelTurns, Vector2i pos) {
for (InteractionRegion next : mouseOverRegions) {
if (next.region.contains(pos)) {
Vector2i relPos = new Vector2i(pos);
relPos.sub(next.region.min());
if (next.listener.onMouseWheel(new NUIMouseWheelEvent(mouse, keyboard, relPos, wheelTurns))) {
clickedRegion = next;
nuiManager.setFocus(next.element);
return true;
}
}
}
return false;
}
Aggregations