use of org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle 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);
Rectanglei position;
if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
position = containerRenderSpace.addLeftFloat(yShift, paragraphWidth, height);
} else {
position = containerRenderSpace.addRightFloat(yShift, paragraphWidth, height);
}
Rectanglei paragraphBorderRegion = new Rectanglei(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);
Rectanglei backgroundRegion = RectUtility.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.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle in project Terasology by MovingBlocks.
the class DocumentRenderer method getParagraphsMinimumWidth.
public static int getParagraphsMinimumWidth(int availableWidth, ParagraphRenderStyle baseParagraphRenderStyle, Collection<ParagraphData> paragraphs) {
int minParagraphsWidth = 0;
for (ParagraphData paragraphData : paragraphs) {
ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseParagraphRenderStyle, paragraphData);
int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(availableWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(availableWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(availableWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(availableWidth);
int paragraphMinWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(availableWidth), paragraphData.getParagraphContents().getContentsMinWidth(paragraphRenderStyle));
minParagraphsWidth = Math.max(minParagraphsWidth, paragraphSideIndent + paragraphMinWidth);
}
return minParagraphsWidth;
}
use of org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle in project Terasology by MovingBlocks.
the class HTMLUtils method createParagraphRenderStyleFromCommonAttributes.
public static ParagraphRenderStyle createParagraphRenderStyleFromCommonAttributes(Attributes attributes) {
Color textColor = getTextColor(attributes);
ParagraphRenderStyle.FloatStyle floatStyle = getFloatStyle(attributes);
ParagraphRenderStyle.ClearStyle clearStyle = getClearStyle(attributes);
HorizontalAlign horizontalAlign = getHorizontalAlign(attributes);
Color backgroundColor = getBackgroundColor(attributes);
ContainerInteger paragraphMarginTop = getParagraphMarginTop(attributes);
ContainerInteger paragraphMarginBottom = getParagraphMarginBottom(attributes);
ContainerInteger paragraphMarginLeft = getParagraphMarginLeft(attributes);
ContainerInteger paragraphMarginRight = getParagraphMarginRight(attributes);
ContainerInteger paragraphPaddingTop = getParagraphPaddingTop(attributes);
ContainerInteger paragraphPaddingBottom = getParagraphPaddingBottom(attributes);
ContainerInteger paragraphPaddingLeft = getParagraphPaddingLeft(attributes);
ContainerInteger paragraphPaddingRight = getParagraphPaddingRight(attributes);
ContainerInteger minimumWidth = getMinimumWidth(attributes);
return new ParagraphRenderStyle() {
@Override
public Color getColor(boolean hyperlink) {
return textColor;
}
@Override
public FloatStyle getFloatStyle() {
return floatStyle;
}
@Override
public ClearStyle getClearStyle() {
return clearStyle;
}
@Override
public HorizontalAlign getHorizontalAlignment() {
return horizontalAlign;
}
@Override
public Color getParagraphBackground() {
return backgroundColor;
}
@Override
public ContainerInteger getParagraphMarginTop() {
return paragraphMarginTop;
}
@Override
public ContainerInteger getParagraphMarginBottom() {
return paragraphMarginBottom;
}
@Override
public ContainerInteger getParagraphMarginLeft() {
return paragraphMarginLeft;
}
@Override
public ContainerInteger getParagraphMarginRight() {
return paragraphMarginRight;
}
@Override
public ContainerInteger getParagraphPaddingTop() {
return paragraphPaddingTop;
}
@Override
public ContainerInteger getParagraphPaddingBottom() {
return paragraphPaddingBottom;
}
@Override
public ContainerInteger getParagraphPaddingLeft() {
return paragraphPaddingLeft;
}
@Override
public ContainerInteger getParagraphPaddingRight() {
return paragraphPaddingRight;
}
@Override
public ContainerInteger getParagraphMinimumWidth() {
return minimumWidth;
}
};
}
use of org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle in project Terasology by MovingBlocks.
the class DocumentRenderer method getParagraphsPreferredHeight.
public static int getParagraphsPreferredHeight(ParagraphRenderStyle baseRenderStyle, Collection<ParagraphData> paragraphs, ContainerRenderSpace containerRenderSpace, int yStart) {
int containerWidth = containerRenderSpace.getContainerWidth();
int yShift = yStart;
for (ParagraphData paragraphData : paragraphs) {
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 paragraphMinWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(containerWidth), paragraphData.getParagraphContents().getContentsMinWidth(paragraphRenderStyle));
int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
int height = paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
height += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, 0, new ContainerFlowContainerRenderSpace(paragraphMinWidth), paragraphSideIndent);
height += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
Rectanglei position = containerRenderSpace.addLeftFloat(yShift, paragraphMinWidth, height);
yShift = position.minY;
} else {
Rectanglei position = containerRenderSpace.addRightFloat(yShift, paragraphMinWidth, height);
yShift = position.minY;
}
} else {
yShift += paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
yShift += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, yShift, containerRenderSpace, paragraphSideIndent);
yShift += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
}
}
return yShift - yStart;
}
Aggregations