@Override public void onDraw(Canvas canvas) { if (content != null) { canvas.drawWidget(content); } }
/** * Draws the currently displayed widget, as defined in {@code currentDisplayedCard}. * This is called every frame. * * @param canvas The {@link Canvas} on which this {@code CardLayout} is drawn */ @Override public void onDraw(Canvas canvas) { if (currentlyDisplayedCard != null) { UIWidget widget = widgets.get(currentlyDisplayedCard); if (widget != null) { canvas.drawWidget(widget); } } }
@Override public void onDraw(Canvas canvas) { if (contents != null) { canvas.drawWidget(contents, canvas.getRegion()); } }
@Override public void onDraw(Canvas canvas) { for (WidgetInfo element : contents) { Rect2i drawRegion = getRegion(element, canvas); canvas.drawWidget(element.widget, drawRegion); } cachedRegions.clear(); }
@Override public void onDraw(Canvas canvas) { if (!hasInitialised) { hasInitialised = true; initialise(canvas); } canvas.addInteractionRegion(baseInteractionListener); for (UIRadialSection section : sections) { canvas.drawWidget(section); } }
/** * Draws the widget with neither a horizontal or vertical scrollbar. * <p> * If the widget is too large in either axis, it will be cropped * * @param canvas The canvas to use * @param availableSize The available size for the layout */ private void drawWithNeither(Canvas canvas, Vector2i availableSize) { canvas.drawWidget(content, Rect2i.createFromMinAndSize(Vector2i.zero(), availableSize)); }
@Override public void onDraw(Canvas canvas) { int filledWidth = 0; int filledHeight = 0; int heightOffset = 0; for (UIWidget widget : contents) { Vector2i size = canvas.calculatePreferredSize(widget); if (filledWidth != 0 && filledWidth + size.x > canvas.size().x) { heightOffset += filledHeight; filledWidth = 0; filledHeight = 0; } canvas.drawWidget(widget, Rect2i.createFromMinAndSize(filledWidth, heightOffset, size.x, size.y)); filledWidth += size.x; filledHeight = Math.max(filledHeight, size.y); } }
/** * Draws the widgets contained in this layout's widget list, * according to the widths calculated in {@link #calcWidths(Canvas)}. * This is called every frame. * * @param canvas The {@link Canvas} on which this {@code RowLayout} is drawn */ @Override public void onDraw(Canvas canvas) { TIntList widths = calcWidths(canvas); if (!contents.isEmpty()) { int xOffset = 0; for (int i = 0; i < contents.size(); ++i) { int itemWidth = widths.get(i); Rect2i region = Rect2i.createFromMinAndSize(xOffset, 0, itemWidth, canvas.size().y); canvas.drawWidget(contents.get(i), region); xOffset += itemWidth; xOffset += horizontalSpacing; } } }
@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); } }
@Override public void onDraw(Canvas canvas) { int numSlots = getNumSlots(); if (numSlots == 0 || cells.isEmpty()) { return; } Vector2i cellSize = canvas.calculatePreferredSize(cells.get(0)); if (cellSize.getX() == 0 || cellSize.getY() == 0) { return; } canvas.addInteractionRegion(interactionListener); int horizontalCells = Math.max(1, Math.min(maxHorizontalCells, canvas.size().getX() / cellSize.getX())); for (int i = 0; i < numSlots && i < cells.size(); ++i) { int horizPos = i % horizontalCells; int vertPos = i / horizontalCells; canvas.drawWidget(cells.get(i), Rect2i.createFromMinAndSize(horizPos * cellSize.x, vertPos * cellSize.y, cellSize.x, cellSize.y)); } }
@Test public void testThreeColumnsAutosizedMinimallySized() throws Exception { columnLayout.setAutoSizeColumns(true); columnLayout.setFillVerticalSpace(false); Vector2i result = columnLayout.getPreferredContentSize(canvas, canvas.size()); assertEquals(75, result.x); assertEquals(20, result.y); columnLayout.onDraw(canvas); verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2), 50, 10)); verify(canvas).drawWidget(itemAt2x1, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2), 5, 10)); verify(canvas).drawWidget(itemAt3x1, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2), 20, 10)); verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2) + 10, 50, 10)); verify(canvas).drawWidget(itemAt2x2, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2) + 10, 5, 10)); verify(canvas).drawWidget(itemAt3x2, Rect2i.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2) + 10, 20, 10)); }
@Override public void onDraw(Canvas canvas) { getTargetItem().send(new BeforeInventoryCellRendered(canvas)); canvas.drawWidget(icon); getTargetItem().send(new InventoryCellRendered(canvas)); }
@Test public void testNoRelativeWidths() throws Exception { 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 equally among 3 widgets as they have no relative widths verify(canvas).drawWidget(itemAt1x1, Rect2i.createFromMinAndSize(0, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT)); verify(canvas).drawWidget(itemAt1x2, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 3, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT)); verify(canvas).drawWidget(itemAt1x3, Rect2i.createFromMinAndSize(CANVAS_WIDTH / 3 + CANVAS_WIDTH / 3, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT)); }
@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 onDraw(Canvas canvas) { for (HUDElement element : elementsLookup.values()) { int minX = TeraMath.floorToInt(element.region.minX() * canvas.size().x); int minY = TeraMath.floorToInt(element.region.minY() * canvas.size().y); int sizeX = TeraMath.floorToInt(element.region.width() * canvas.size().x); int sizeY = TeraMath.floorToInt(element.region.height() * canvas.size().y); Rect2i region = Rect2i.createFromMinAndSize(minX, minY, sizeX, sizeY); canvas.drawWidget(element.widget, region); } }
protected void drawWidget(Canvas canvas, PositionalWidget widget) { if (!widget.isVisible()) { return; } Vector2i screenStart = worldToScreen(widget.getPosition()); Vector2f worldEnd = new Vector2f(widget.getPosition()); worldEnd.add(widget.getSize()); Vector2i screenEnd = worldToScreen(worldEnd); canvas.drawWidget(widget, Rect2i.createFromMinAndMax(screenStart, screenEnd)); }
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()))); } }
@Test public void testScaling() throws Exception { zoomableLayout.onDraw(canvas); //world size scaled to fit ratio of screen size - world size now 200 x 100 assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2, WORLD_HEIGHT)); assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT)); assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2), CANVAS_HEIGHT / WORLD_HEIGHT)); //coordinates on widgets scaled down by half verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x / 2), ceilToInt(pos1.y / 2)), new Vector2i(ceilToInt((pos1.x + size1.x) / 2), ceilToInt((pos1.y + size1.y) / 2)))); verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x / 2), ceilToInt(pos2.y / 2)), new Vector2i(ceilToInt((pos2.x + size2.x) / 2), ceilToInt((pos2.y + size2.y) / 2)))); verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x / 2), ceilToInt(pos3.y / 2)), new Vector2i(ceilToInt((pos3.x + size3.x) / 2), ceilToInt((pos3.y + size3.y) / 2)))); }
@Test public void testZoomOut() throws Exception { zoomableLayout.onDraw(canvas); //zoom out 2x from top left corner zoomableLayout.zoom(2, 2, new Vector2i(0, 0)); zoomableLayout.onDraw(canvas); //world size doubled assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2 * 2, WORLD_HEIGHT * 2)); assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT)); assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2 * 2), CANVAS_HEIGHT / (WORLD_HEIGHT * 2))); verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x / 4), ceilToInt(pos1.y / 4)), new Vector2i(ceilToInt((pos1.x + size1.x) / 4), ceilToInt((pos1.y + size1.y) / 4)))); verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x / 4), ceilToInt(pos2.y / 4)), new Vector2i(ceilToInt((pos2.x + size2.x) / 4), ceilToInt((pos2.y + size2.y) / 4)))); verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x / 4), ceilToInt(pos3.y / 4)), new Vector2i(ceilToInt((pos3.x + size3.x) / 4), ceilToInt((pos3.y + size3.y) / 4)))); }
@Override public void onDraw(Canvas canvas) { int[] bounds = {0, 0, canvas.size().x, canvas.size().y}; layoutContainer(canvas, bounds); for (ComponentWrapper wrapper : wrappers.values()) { UIWidget component = (UIWidget) wrapper.getComponent(); Rect2i region = Rect2i.createFromMinAndSize(wrapper.getX(), wrapper.getY(), wrapper.getWidth(), wrapper.getHeight()); canvas.drawWidget(component, region); } if (debug) { grid.paintDebug(); } for (Rect2i region : debugRects) { canvas.drawLine(region.minX(), region.minY(), region.maxX(), region.minY(), Color.WHITE); canvas.drawLine(region.maxX(), region.minY(), region.maxX(), region.maxY(), Color.WHITE); canvas.drawLine(region.maxX(), region.maxY(), region.minX(), region.maxY(), Color.WHITE); canvas.drawLine(region.minX(), region.maxY(), region.minX(), region.minY(), Color.WHITE); } }