Package org.terasology.math

Examples of org.terasology.math.Rect2i


                    selectionString = innerLine;
                }
                if (!selectionString.isEmpty()) {
                    int selectionWidth = font.getWidth(selectionString);
                    Vector2i selectionTopLeft = new Vector2i(offsetX, (lineOffset) * font.getLineHeight());
                    Rect2i region = Rect2i.createFromMinAndSize(selectionTopLeft.x, selectionTopLeft.y, selectionWidth, font.getLineHeight());

                    canvas.drawTexture(cursorTexture, region, textColor);
                    canvas.drawTextRaw(FontColor.stripColor(selectionString), font, textColor.inverse(), region);
                }
                currentChar += innerLine.length();
View Full Code Here


            List<String> lines = TextLineBuilder.getLines(font, beforeCursor, canvas.size().x);

            // TODO: Support different alignments

            int lastLineWidth = font.getWidth(lines.get(lines.size() - 1));
            Rect2i region = Rect2i.createFromMinAndSize(lastLineWidth, (lines.size() - 1) * font.getLineHeight(),
                    1, font.getLineHeight());
            canvas.drawTexture(cursorTexture, region, canvas.getCurrentStyle().getTextColor());
        }
    }
View Full Code Here

                int cellOffsetY = columnOffsetY;
                for (int i = 0; i < column.size(); ++i) {
                    UIWidget widget = column.get(i);
                    int columnWidth = columnInfo.width;
                    if (widget != null) {
                        Rect2i drawRegion = Rect2i.createFromMinAndSize(columnOffsetX, cellOffsetY, columnWidth, minHeights[i]);
                        canvas.drawWidget(widget, drawRegion);
                    }
                    cellOffsetY += minHeights[i] + verticalSpacing;
                }
                columnOffsetX += columnInfo.width + horizontalSpacing;
View Full Code Here

            int scrollbarWidth = canvas.calculateRestrictedSize(scrollbar, canvas.size()).x;
            contentHeight = canvas.calculateRestrictedSize(content, new Vector2i(canvas.size().x - scrollbarWidth, Integer.MAX_VALUE)).y;

            boolean atBottom = scrollbar.getRange() == scrollbar.getValue();

            Rect2i contentRegion = Rect2i.createFromMinAndSize(0, 0, canvas.size().x - scrollbarWidth, canvas.size().y);
            scrollbar.setRange(contentHeight - contentRegion.height());
            if ((stickToBottom && atBottom) || moveToBottomPending) {
                scrollbar.setValue(scrollbar.getRange());
                moveToBottomPending = false;
            }
            if (moveToTopPending) {
View Full Code Here

        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);
        }
    }
View Full Code Here

    }

    @Override
    public void onDraw(Canvas canvas) {
        for (WidgetInfo element : contents) {
            Rect2i drawRegion = getRegion(element, canvas);
            canvas.drawWidget(element.widget, drawRegion);
        }
        cachedRegions.clear();
    }
View Full Code Here

        }
        cachedRegions.clear();
    }

    private Rect2i getRegion(WidgetInfo element, Canvas canvas) {
        Rect2i cachedRegion = cachedRegions.get(element);
        if (cachedRegion != null) {
            return cachedRegion;
        }

        int left = 0;
        int right = canvas.size().x;
        int center = canvas.size().x / 2;
        if (element.layoutHint.getPositionCenterHorizontal() != null) {
            HorizontalInfo info = element.layoutHint.getPositionCenterHorizontal();
            Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
            HorizontalAlign align = (info.getTarget() != null) ? info.getTarget() : HorizontalAlign.CENTER;
            center = align.getStart(targetRegion) + info.getOffset();
        }
        if (element.layoutHint.getPositionLeft() != null) {
            HorizontalInfo info = element.layoutHint.getPositionLeft();
            Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
            HorizontalAlign align = (info.getTarget() != null) ? info.getTarget() : HorizontalAlign.LEFT;
            left = align.getStart(targetRegion) + info.getOffset();
        }
        if (element.layoutHint.getPositionRight() != null) {
            HorizontalInfo info = element.layoutHint.getPositionRight();
            Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
            HorizontalAlign align = (info.getTarget() != null) ? info.getTarget() : HorizontalAlign.RIGHT;
            right = align.getStart(targetRegion) - info.getOffset();
        }

        int top = 0;
        int bottom = canvas.size().y;
        int vcenter = canvas.size().y / 2;
        if (element.layoutHint.getPositionCenterVertical() != null) {
            VerticalInfo info = element.layoutHint.getPositionCenterVertical();
            Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
            VerticalAlign align = (info.getTarget() != null) ? info.getTarget() : VerticalAlign.MIDDLE;
            vcenter = align.getStart(targetRegion) + info.getOffset();
        }
        if (element.layoutHint.getPositionTop() != null) {
            VerticalInfo info = element.layoutHint.getPositionTop();
            Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
            VerticalAlign align = (info.getTarget() != null) ? info.getTarget() : VerticalAlign.TOP;
            top = align.getStart(targetRegion) + info.getOffset();
        }
        if (element.layoutHint.getPositionBottom() != null) {
            VerticalInfo info = element.layoutHint.getPositionBottom();
            Rect2i targetRegion = getTargetRegion(info.getWidget(), canvas);
            VerticalAlign align = (info.getTarget() != null) ? info.getTarget() : VerticalAlign.BOTTOM;
            bottom = align.getStart(targetRegion) - info.getOffset();
        }

        int width = element.layoutHint.getWidth();
        if (width == 0 && element.layoutHint.isUsingContentWidth()) {
            width = canvas.calculateRestrictedSize(element.widget, new Vector2i(right - left, bottom - top)).x;
        }
        if (width == 0) {
            width = right - left;
        } else {
            if (element.layoutHint.getPositionCenterHorizontal() != null) {
                left = center - width / 2;
            } else if (element.layoutHint.getPositionRight() != null) {
                if (element.layoutHint.getPositionLeft() != null) {
                    center = left + (right - left) / 2;
                    left = center - width / 2;
                } else {
                    left = right - width;
                }
            }
        }

        int height = element.layoutHint.getHeight();
        if (height == 0 && element.layoutHint.isUsingContentHeight()) {
            height = canvas.calculateRestrictedSize(element.widget, new Vector2i(width, bottom - top)).y;
        }
        if (height == 0) {
            height = bottom - top;
        } else {
            if (element.layoutHint.getPositionCenterVertical() != null) {
                top = vcenter - height / 2;
            } else if (element.layoutHint.getPositionBottom() != null) {
                if (element.layoutHint.getPositionTop() != null) {
                    vcenter = top + (bottom - top) / 2;
                    top = vcenter - height / 2;
                } else {
                    top = bottom - height;
                }
            }
        }
        Rect2i region = Rect2i.createFromMinAndSize(left, top, width, height);
        cachedRegions.put(element, region);
        return region;
    }
View Full Code Here

            } else if (loopDetectionId.isEmpty()) {
                loopDetectionId = id;
            }
            WidgetInfo target = contentLookup.get(id);
            if (target != null) {
                Rect2i region = getRegion(target, canvas);
                loopDetectionId = "";
                return region;
            }
        }
        loopDetectionId = "";
View Full Code Here

            } else if (ratio - fullIcons > 0) {
                halfIcon = true;
            }
            Vector2i offset = new Vector2i();
            for (int i = 0; i < maxIcons; ++i) {
                Rect2i iconRegion = Rect2i.createFromMinAndSize(offset, iconSize);
                canvas.drawBackground(iconRegion);
                if (ratio - i >= 0.5f) {
                    canvas.drawTexture(icon, iconRegion);
                } else if (ratio - i > 0f) {
                    switch (halfIconMode) {
View Full Code Here

TOP

Related Classes of org.terasology.math.Rect2i

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.