@Override public void onDraw(Canvas canvas) { if (contents != null) { canvas.drawWidget(contents, canvas.getRegion()); } }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) { return canvas.getRegion().size(); }
private Rect2i getTargetRegion(String id, Canvas canvas) { if (id != null && !id.isEmpty()) { if (loopDetectionId.equals(id)) { logger.warn("Infinite loop detected resolving layout of element {}", loopDetectionId); loopDetectionId = ""; return canvas.getRegion(); } else if (loopDetectionId.isEmpty()) { loopDetectionId = id; } WidgetInfo target = contentLookup.get(id); if (target != null) { try { Rect2i region = getRegion(target, canvas); loopDetectionId = ""; return region; } catch (StackOverflowError e) { logger.error("Stack Overflow detected resolving layout of element {}, unable to render", loopDetectionId); } } } loopDetectionId = ""; return canvas.getRegion(); }
@Override public void draw(DependencyInfo value, Canvas canvas) { canvas.drawText(getString(value), canvas.getRegion()); }
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.addInteractionRegion(interactionListener, icon.getTooltip(), canvas.getRegion()); }
private void initialise(Canvas canvas) { final double circleToSquare = 0.707106781; Rect2i region = canvas.getRegion(); int sectionWidth = region.width() / 4; double offset = sectionWidth * 1.5; radius = sectionWidth * 2; sectionAngle = (Math.PI * 2) / sections.size(); int infoSquareSize = (int) (radius * circleToSquare); int sectionSquareSize = (int) (sectionWidth * circleToSquare); Rect2i infoRegion = Rect2i.createFromMinAndSize( sectionWidth + infoSquareSize / 4, sectionWidth + infoSquareSize / 4, infoSquareSize, infoSquareSize); for (int i = 0; i < sections.size(); i++) { sections.get(i).setDrawRegion(Rect2i.createFromMinAndSize( (int) (Math.cos(i * sectionAngle + sectionAngle / 2) * offset + sectionWidth * 1.5), (int) (Math.sin(i * sectionAngle + sectionAngle / 2) * offset + sectionWidth * 1.5), sectionWidth, sectionWidth)); sections.get(i).setInnerRegion(Rect2i.createFromMinAndSize( (int) (Math.cos(i * sectionAngle + sectionAngle / 2) * offset + sectionWidth * 1.5 + sectionSquareSize / 4), (int) (Math.sin(i * sectionAngle + sectionAngle / 2) * offset + sectionWidth * 1.5 + sectionSquareSize / 4), sectionSquareSize, sectionSquareSize)); sections.get(i).setInfoRegion(infoRegion); } }
@Override public void draw(Biome value, Canvas canvas) { if (value.getId().contains("Core:")) { canvas.setMode("internal"); } else { canvas.setMode("external"); } canvas.drawText(getString(value), canvas.getRegion()); }
@Override public void draw(TooltipLine value, Canvas canvas) { Font font = getFont(value); Color color = getColor(value); canvas.drawTextRaw(value.getText(), font, color, canvas.getRegion()); }
/** * Handles how the widget is drawn. * * @param canvas The canvas on which the widget resides. */ @Override public void onDraw(Canvas canvas) { lastWidth = canvas.size().x; if (isEnabled()) { canvas.addInteractionRegion(interactionListener, canvas.getRegion()); } drawAll(canvas, canvas.size().x); }
@Override public void onDraw(Canvas canvas) { if (!contents.isEmpty()) { Rect2i region = canvas.getRegion(); Rect2i buttonRegion = Rect2i.createFromMinAndSize(region.minX(), region.minY(), region.width(), tabBarHeight); Rect2i boxRegion = Rect2i.createFromMinAndMax(region.minX(), region.minY() + tabBarHeight, region.width(), region.height()); canvas.drawWidget(contents.get(currentTab), boxRegion); canvas.drawWidget(buttonLayout, buttonRegion); } }
/** * Draws the widget * * @param canvas The canvas to draw on. */ public void onDraw(Canvas canvas) { canvas.getRegion(); canvas.drawTexture(sectionTexture, sectionRegion); if (icon != null) { canvas.drawTexture(icon, innerRegion); } if (text != null) { canvas.drawText(text, innerRegion); } if (isSelected) { canvas.drawTexture(selectedTexture, sectionRegion); if (widget != null) { canvas.drawWidget(widget, infoRegion); } } }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) { if (displayedPage != null) { return DocumentRenderer.getDocumentPreferredSize(displayedPage, canvas.getCurrentStyle().getFont(), canvas.getCurrentStyle().getTextColor(), canvas.getRegion().sizeX()); } else { return new Vector2i(0, 0); } }
@Override public void onDraw(Canvas canvas) { Rect2i region = animationSystem.animateRegion(canvas.getRegion()); if (isModal()) { canvas.addInteractionRegion(getScreenListener(), region); } if (getContents() != null) { canvas.drawWidget(getContents(), region); } }
@Override public void draw(ModuleSelectionInfo value, Canvas canvas) { if (value.isStrictVersion()) { canvas.setMode("strict"); } else if (value.isLatestVersion()) { canvas.setMode("latest"); } else { canvas.setMode("invalid"); } canvas.drawText(getString(value), canvas.getRegion()); }
@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.addX(currentWidth); } Rect2i region = Rect2i.createFromMinAndSize(currentPosition, canvas.calculatePreferredSize(level)); double percentageThreshold = 0.9; if (region.maxY() > canvas.getRegion().height() * percentageThreshold) { region = Rect2i.createFromMinAndMax(region.minX(), region.minY() - (region.maxY() - canvas.getRegion().height()) - (int) (canvas.getRegion().height() * (1 - percentageThreshold)), region.maxX(), canvas.getRegion().height()); } currentWidth = canvas.calculatePreferredSize(level).getX() - 8; canvas.drawWidget(level, region); } } }
@Override public void onDraw(Canvas canvas) { if (getIcon() != null) { canvas.drawTexture(getIcon()); } else if (getMesh() != null && getMeshTexture() != null) { Quat4f rot = new Quat4f(TeraMath.PI / 6, -TeraMath.PI / 12, 0); canvas.drawMesh(getMesh(), getMeshTexture(), canvas.getRegion(), rot, new Vector3f(), 1.0f); } if (getQuantity() > 1) { canvas.drawText(Integer.toString(getQuantity())); } List<TooltipLine> tooltipLines = tooltip.getList(); if (tooltipLines != null && !tooltipLines.isEmpty()) { canvas.addInteractionRegion(listener); } }
@Override public void draw(T value, Canvas canvas) { // Drawing the icon TextureRegion texture = getTexture(value); if (texture != null) { if (marginTop + texture.getHeight() + marginBottom > canvas.size().y) { // Icon does not fit within the canvas - vertically shrinking it int iconHeight = canvas.size().y - marginTop - marginBottom; canvas.drawTexture(texture, Rect2i.createFromMinAndSize(marginLeft, marginTop, texture.getWidth(), iconHeight)); } else { // Icon fits within the canvas - vertically centering it int iconVerticalPosition = (canvas.size().y - texture.getHeight()) / 2; canvas.drawTexture(texture, Rect2i.createFromMinAndSize(marginLeft, iconVerticalPosition, texture.getWidth(), texture.getHeight())); } } // Drawing the text, adjusting for icon width String text = getString(value); int iconWidth; if (texture != null) { iconWidth = marginLeft + texture.getWidth() + marginRight; } else { iconWidth = 0; } Rect2i textRegion = Rect2i.createFromMinAndSize(iconWidth, 0, canvas.getRegion().width() - iconWidth, canvas.getRegion().height()); canvas.drawText(text, textRegion); }
public static void drawDocumentInRegion(DocumentData documentData, Canvas canvas, Font defaultFont, Color defaultColor, Vector2i size, ParagraphRenderable.HyperlinkRegister register) { DefaultDocumentRenderStyle defaultDocumentRenderStyle = new DefaultDocumentRenderStyle(defaultFont, defaultColor); DocumentRenderStyle documentRenderStyle = getDocumentRenderStyle(defaultDocumentRenderStyle, documentData); int documentWidth = size.x; int documentMarginLeft = documentRenderStyle.getDocumentMarginLeft().getValue(documentWidth); int documentMarginRight = documentRenderStyle.getDocumentMarginRight().getValue(documentWidth); int documentMarginTop = documentRenderStyle.getDocumentMarginTop().getValue(documentWidth); Color backgroundColor = documentRenderStyle.getBackgroundColor(); if (backgroundColor != null) { canvas.drawFilledRectangle(canvas.getRegion(), backgroundColor); } Collection<ParagraphData> paragraphs = documentData.getParagraphs(); ContainerFlowContainerRenderSpace renderSpace = new ContainerFlowContainerRenderSpace(documentWidth); renderParagraphs(canvas, register, documentRenderStyle, documentMarginLeft, documentMarginTop, documentMarginLeft, documentMarginRight, paragraphs, renderSpace); }
@Override public void draw(ModuleSelectionInfo value, Canvas canvas) { if (isSelectedGameplayModule(value) && value.isValidToSelect()) { canvas.setMode("gameplay"); } else if (value.isSelected() && value.isExplicitSelection()) { canvas.setMode("enabled"); } else if (value.isSelected()) { canvas.setMode("dependency"); } else if (!value.isPresent()) { canvas.setMode("disabled"); } else if (!value.isValidToSelect()) { canvas.setMode("invalid"); } else { canvas.setMode("available"); } canvas.drawText(getString(value), canvas.getRegion()); }
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()))); } }