use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class UIIconBar method getIconSize.
private Vector2i getIconSize(Canvas canvas) {
UIStyle iconStyle = canvas.getCurrentStyle();
int width = iconStyle.getFixedWidth();
int height = iconStyle.getFixedHeight();
if (width == 0) {
width = iconStyle.getMinWidth();
}
if (height == 0) {
height = iconStyle.getMinHeight();
}
if (width == 0) {
width = icon.getWidth();
}
if (height == 0) {
height = icon.getHeight();
}
return new Vector2i(width, height);
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class UISlider method getPreferredContentSize.
@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) {
Vector2i result = new Vector2i();
canvas.setPart(SLIDER);
result.x = canvas.getCurrentStyle().getFixedWidth();
if (result.x == 0) {
result.x = canvas.getCurrentStyle().getMinWidth();
}
result.y = canvas.getCurrentStyle().getFixedHeight();
if (result.y == 0) {
result.y = canvas.getCurrentStyle().getMinHeight();
}
canvas.setPart(TICKER);
int tickerWidth = canvas.getCurrentStyle().getFont().getWidth(getDisplayText());
tickerWidth += canvas.getCurrentStyle().getMargin().getTotalWidth();
result.x = Math.max(result.x, tickerWidth);
if (canvas.getCurrentStyle().getFixedWidth() != 0) {
result.x = Math.max(result.x, canvas.getCurrentStyle().getFixedWidth());
} else {
result.x = Math.max(result.x, canvas.getCurrentStyle().getMinWidth());
}
if (canvas.getCurrentStyle().getFixedHeight() != 0) {
result.y = Math.max(result.y, canvas.getCurrentStyle().getFixedHeight());
} else {
result.y = Math.max(result.y, canvas.getCurrentStyle().getMinHeight());
}
return result;
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class DocumentRenderer method renderParagraph.
public static int renderParagraph(Canvas canvas, ParagraphRenderable.HyperlinkRegister register, ParagraphRenderStyle baseRenderStyle, int xShift, int leftIndent, int rightIndent, ContainerRenderSpace containerRenderSpace, int containerWidth, int startY, ParagraphData paragraphData) {
int yShift = startY;
ParagraphRenderable paragraphContents = paragraphData.getParagraphContents();
ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseRenderStyle, paragraphData);
ParagraphRenderStyle.ClearStyle clearStyle = paragraphRenderStyle.getClearStyle();
if (clearStyle != ParagraphRenderStyle.ClearStyle.NONE) {
yShift = Math.max(yShift, containerRenderSpace.getNextClearYPosition(clearStyle));
}
ParagraphRenderStyle.FloatStyle floatStyle = paragraphRenderStyle.getFloatStyle();
if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT || floatStyle == ParagraphRenderStyle.FloatStyle.RIGHT) {
int leftParagraphIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth);
int rightParagraphIndent = paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
int paragraphWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(containerWidth), paragraphContents.getContentsMinWidth(paragraphRenderStyle) + leftParagraphIndent + rightParagraphIndent);
int height = paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
int paragraphHeight = paragraphContents.getPreferredContentsHeight(paragraphRenderStyle, 0, new ContainerFlowContainerRenderSpace(paragraphWidth), leftParagraphIndent + rightParagraphIndent);
height += paragraphHeight;
height += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
Rect2i position;
if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
position = containerRenderSpace.addLeftFloat(yShift, paragraphWidth, height);
} else {
position = containerRenderSpace.addRightFloat(yShift, paragraphWidth, height);
}
Rect2i paragraphBorderRegion = Rect2i.createFromMinAndMax(position.minX() + paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth), position.minY() + paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth), position.maxX() - paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) - 1, position.maxY() - paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth) - 1);
Color paragraphBackground = paragraphRenderStyle.getParagraphBackground();
if (paragraphBackground != null) {
canvas.drawFilledRectangle(paragraphBorderRegion, paragraphBackground);
}
Vector2i paragraphStart = new Vector2i(position.minX(), position.minY() + paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth));
paragraphContents.renderContents(canvas, paragraphStart, new ContainerFlowContainerRenderSpace(paragraphWidth), leftParagraphIndent, rightParagraphIndent, paragraphRenderStyle, paragraphRenderStyle.getHorizontalAlignment(), register);
yShift = position.minY();
} else {
yShift += paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth);
int leftParagraphIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth);
int rightParagraphIndent = paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
int paragraphHeight = paragraphContents.getPreferredContentsHeight(paragraphRenderStyle, yShift + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth), containerRenderSpace, leftIndent + leftParagraphIndent + rightParagraphIndent + rightIndent);
Color paragraphBackground = paragraphRenderStyle.getParagraphBackground();
if (paragraphBackground != null) {
int borderAdvance = 0;
int borderHeight = paragraphHeight + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth);
while (borderAdvance < borderHeight) {
int backgroundStart = yShift + borderAdvance;
int availableBackgroundWidth = containerRenderSpace.getWidthForVerticalPosition(backgroundStart);
int backgroundAdvance = containerRenderSpace.getAdvanceForVerticalPosition(backgroundStart);
int maxSpace = containerRenderSpace.getNextWidthChange(backgroundStart);
Rect2i backgroundRegion = Rect2i.createFromMinAndSize(xShift + paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + backgroundAdvance, backgroundStart, availableBackgroundWidth - 1, Math.min(maxSpace, borderHeight - borderAdvance) - 1);
canvas.drawFilledRectangle(backgroundRegion, paragraphBackground);
borderAdvance += maxSpace - backgroundStart;
}
}
yShift += paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
paragraphContents.renderContents(canvas, new Vector2i(xShift, yShift), containerRenderSpace, leftIndent + leftParagraphIndent, rightIndent + rightParagraphIndent, paragraphRenderStyle, paragraphRenderStyle.getHorizontalAlignment(), register);
yShift += paragraphHeight;
yShift += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth);
yShift += paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
}
return yShift - startY;
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class InputSystem method processMouseInput.
private void processMouseInput(float delta) {
if (!isCapturingMouse()) {
return;
}
Vector2i deltaMouse = mouse.getDelta();
// process mouse movement x axis
if (deltaMouse.x != 0) {
float xValue = deltaMouse.x * inputDeviceConfig.getMouseSensitivity();
MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.X, xValue, delta);
send(event);
}
// process mouse movement y axis
if (deltaMouse.y != 0) {
int yMovement = inputDeviceConfig.isMouseYAxisInverted() ? deltaMouse.y * -1 : deltaMouse.y;
float yValue = yMovement * inputDeviceConfig.getMouseSensitivity();
MouseAxisEvent event = MouseAxisEvent.create(MouseAxis.Y, yValue, delta);
send(event);
}
// process mouse clicks
for (MouseAction action : mouse.getInputQueue()) {
switch(action.getInput().getType()) {
case MOUSE_BUTTON:
processMouseButtonInput(delta, action);
break;
case MOUSE_WHEEL:
processMouseWheelInput(delta, action);
break;
default:
break;
}
}
}
use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class BehaviorEditor method drawConnection.
private void drawConnection(Canvas canvas, Vector2f from, Vector2f to, Color color) {
Vector2i s = worldToScreen(from);
Vector2i e = worldToScreen(to);
canvas.drawLine(s.x, s.y, e.x, e.y, color);
}
Aggregations