Search in sources :

Example 66 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class LinesLayer method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g, Tile screenTile) {
    g.setColor(_lineColor);
    g.setAntiAliased(true);
    int segmentsNo = _lineSegments.size();
    for (int i = 0; i < segmentsNo; i++) {
        paintSegment(g, (Coord[]) _lineSegments.elementAt(i), screenTile);
    }
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point)

Example 67 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class List method paintFocus.

private void paintFocus(Graphics g, int width, Rectangle pos, Dimension rendererSize) {
    if (ignoreFocusComponentWhenUnfocused && !hasFocus()) {
        return;
    }
    if (!shouldRenderSelection()) {
        return;
    }
    calculateComponentPosition(getCurrentSelected(), width, pos, rendererSize, getElementSize(true, true), true);
    Dimension size = pos.getSize();
    Component cmp = renderer.getListFocusComponent(this);
    if (cmp != null) {
        cmp.setCellRenderer(true);
        int x = pos.getX();
        int y = pos.getY();
        // prevent focus animation from working during a drag operation
        if (orientation != HORIZONTAL) {
            y -= (animationPosition + fixedDraggedAnimationPosition);
        } else {
            x -= (animationPosition + fixedDraggedAnimationPosition);
        }
        renderComponentBackground(g, cmp, x, y, size.getWidth(), size.getHeight());
        renderComponent(g, cmp, x, y, size.getWidth(), size.getHeight());
    }
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 68 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class List method renderComponentBackground.

private void renderComponentBackground(Graphics g, Component cmp, int x, int y, int width, int height) {
    Style s = cmp.getStyle();
    int left = s.getMarginLeft(isRTL());
    int top = s.getMarginTop();
    cmp.setWidth(width - left - s.getMarginRight(isRTL()));
    cmp.setHeight(height - top - s.getMarginBottom());
    cmp.setX(x + left);
    cmp.setY(y + top);
    int cX = g.getClipX();
    int cY = g.getClipY();
    int cW = g.getClipWidth();
    int cH = g.getClipHeight();
    // g.pushClip();
    g.clipRect(cmp.getX(), cmp.getY(), cmp.getWidth(), cmp.getHeight());
    cmp.paintComponentBackground(g);
    g.setClip(cX, cY, cW, cH);
// g.popClip();
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 69 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class List method renderComponent.

/**
 * Renders the current component on the screen
 */
private void renderComponent(Graphics g, Component cmp, int x, int y, int width, int height) {
    Style s = cmp.getStyle();
    int left = s.getMarginLeft(isRTL());
    int top = s.getMarginTop();
    cmp.setWidth(width - left - s.getMarginRight(isRTL()));
    cmp.setHeight(height - top - s.getMarginBottom());
    cmp.setX(x + left);
    cmp.setY(y + top);
    int oX = g.getClipX();
    int oY = g.getClipY();
    int oWidth = g.getClipWidth();
    int oHeight = g.getClipHeight();
    // g.pushClip();
    g.clipRect(cmp.getX(), cmp.getY(), cmp.getWidth(), cmp.getHeight());
    cmp.paint(g);
    Border b = s.getBorder();
    if (b != null && !b.isBackgroundPainter()) {
        cmp.paintBorder(g);
    }
    g.setClip(oX, oY, oWidth, oHeight);
// g.popClip();
}
Also used : Style(com.codename1.ui.plaf.Style) Border(com.codename1.ui.plaf.Border)

Example 70 with Graphics

use of com.codename1.ui.Graphics in project CodenameOne by codenameone.

the class List method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    getUIManager().getLookAndFeel().drawList(g, this);
    Style style = getStyle();
    int width = getWidth() - style.getHorizontalPadding() - getSideGap();
    if (isScrollableX()) {
        width = Math.max(width, getScrollDimension().getWidth() - style.getHorizontalPadding() - getSideGap());
    }
    int numOfcomponents = model.getSize();
    if (numOfcomponents == 0) {
        paintHint(g);
        return;
    }
    int xTranslate = getX();
    int yTranslate = getY();
    g.translate(xTranslate, yTranslate);
    Rectangle pos = new Rectangle();
    Dimension rendererSize = getElementSize(false, true);
    if (fixedSelection > FIXED_NONE_BOUNDRY) {
        if (animationPosition != 0 || isDragActivated()) {
            if (orientation != HORIZONTAL) {
                yTranslate += (animationPosition + fixedDraggedAnimationPosition);
                g.translate(0, animationPosition + fixedDraggedAnimationPosition);
            } else {
                xTranslate += (animationPosition + fixedDraggedAnimationPosition);
                g.translate(animationPosition + fixedDraggedAnimationPosition, 0);
            }
        }
    }
    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipWidth = g.getClipWidth();
    int clipHeight = g.getClipHeight();
    // this flag is for preformance improvements
    // if we figured out that the list items are not visible anymore
    // we should break from the List loop
    boolean shouldBreak = false;
    // improve performance for browsing the end of a very large list
    int startingPoint = 0;
    if (fixedSelection < FIXED_NONE_BOUNDRY) {
        int startX = clipX + getAbsoluteX();
        if (isRTL()) {
            // In RTL the start of the list is not in the left side of the viewport, but rather the right side
            startX += getWidth();
        }
        startingPoint = Math.max(0, pointerSelect(startX, clipY + getAbsoluteY()) - 1);
    }
    int startOffset = 0;
    int endOffset = numOfcomponents;
    if (mutableRendererBackgrounds) {
        for (int i = startingPoint; i < numOfcomponents; i++) {
            // skip on the selected
            if (i == getCurrentSelected() && animationPosition == 0 && fixedDraggedAnimationPosition == 0) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                shouldBreak = true;
                continue;
            }
            calculateComponentPosition(i, width, pos, rendererSize, getElementSize(true, true), i <= getCurrentSelected());
            // if the renderer is in the clipping region
            if (pos.intersects(clipX, clipY, clipWidth, clipHeight)) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                Dimension size = pos.getSize();
                Component selectionCmp = renderer.getListCellRendererComponent(this, getModel().getItemAt(i), i, i == getCurrentSelected());
                renderComponentBackground(g, selectionCmp, pos.getX(), pos.getY(), size.getWidth(), size.getHeight());
                shouldBreak = true;
            } else {
                // this is relevant only if the List is not fixed.
                if (shouldBreak && (fixedSelection < FIXED_NONE_BOUNDRY)) {
                    break;
                }
            }
        }
    } else {
        T valueAt0 = getModel().getItemAt(0);
        Component selectionCmp;
        int selectedIndex = getSelectedIndex();
        if (selectedIndex > -1 && selectedIndex < numOfcomponents) {
            // this is essential otherwise we constantly ticker based on the value of the first entry
            selectionCmp = renderer.getListCellRendererComponent(this, getModel().getItemAt(selectedIndex), 0, true);
        } else {
            selectionCmp = renderer.getListCellRendererComponent(this, valueAt0, 0, true);
        }
        Component unselectedCmp = renderer.getListCellRendererComponent(this, valueAt0, 0, false);
        for (int i = startingPoint; i < numOfcomponents; i++) {
            // skip on the selected
            if (i == getCurrentSelected() && animationPosition == 0) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                shouldBreak = true;
                continue;
            }
            calculateComponentPosition(i, width, pos, rendererSize, getElementSize(true, true), i <= getCurrentSelected());
            // if the renderer is in the clipping region
            if (pos.intersects(clipX, clipY, clipWidth, clipHeight)) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                if (i == getCurrentSelected()) {
                    Dimension size = pos.getSize();
                    renderComponentBackground(g, selectionCmp, pos.getX(), pos.getY(), size.getWidth(), size.getHeight());
                } else {
                    Dimension size = pos.getSize();
                    renderComponentBackground(g, unselectedCmp, pos.getX(), pos.getY(), size.getWidth(), size.getHeight());
                }
                shouldBreak = true;
            } else {
                // this is relevant only if the List is not fixed.
                if (shouldBreak && (fixedSelection < FIXED_NONE_BOUNDRY)) {
                    break;
                }
            }
        }
    }
    boolean shouldRendererSelectedEntry = (renderer.getListFocusComponent(this) == null && (fixedSelection < FIXED_NONE_BOUNDRY)) || animationPosition == 0 && model.getSize() > 0;
    Rectangle selectedPos = new Rectangle();
    calculateComponentPosition(getCurrentSelected(), width, selectedPos, rendererSize, getElementSize(true, true), true);
    Dimension size = selectedPos.getSize();
    int curSel = getCurrentSelected();
    if (shouldRendererSelectedEntry && curSel > -1 && curSel < model.getSize()) {
        Component selected = renderer.getListCellRendererComponent(this, model.getItemAt(getCurrentSelected()), getCurrentSelected(), true);
        renderComponentBackground(g, selected, selectedPos.getX(), selectedPos.getY(), size.getWidth(), size.getHeight());
    }
    if (paintFocusBehindList) {
        paintFocus(g, width, pos, rendererSize);
    }
    for (int i = startOffset; i <= endOffset; i++) {
        // skip on the selected
        if (i == getCurrentSelected() && animationPosition == 0) {
            continue;
        }
        calculateComponentPosition(i, width, pos, rendererSize, getElementSize(true, true), i <= getCurrentSelected());
        if (pos.intersects(clipX, clipY, clipWidth, clipHeight)) {
            T value = model.getItemAt(i);
            Component cmp = renderer.getListCellRendererComponent(this, value, i, false);
            cmp.setCellRenderer(true);
            Dimension sizeC = pos.getSize();
            renderComponent(g, cmp, pos.getX(), pos.getY(), sizeC.getWidth(), sizeC.getHeight());
        }
    }
    // if the animation has finished draw the selected element
    if (shouldRendererSelectedEntry) {
        Component selected = renderer.getListCellRendererComponent(this, model.getItemAt(getCurrentSelected()), getCurrentSelected(), true);
        renderComponent(g, selected, selectedPos.getX(), selectedPos.getY(), size.getWidth(), size.getHeight());
    }
    if (!paintFocusBehindList) {
        paintFocus(g, width, pos, rendererSize);
    }
    g.translate(-xTranslate, -yTranslate);
    if (spinnerOverlay != null) {
        if (spinnerOverlay.getBorder() != null) {
            spinnerOverlay.getBorder().paintBorderBackground(g, this);
            spinnerOverlay.getBorder().paint(g, this);
        } else {
            spinnerOverlay.getBgPainter().paint(g, getBounds());
        }
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Image (com.codename1.ui.Image)18 Component (com.codename1.ui.Component)17 Point (com.codename1.ui.geom.Point)16 Style (com.codename1.ui.plaf.Style)15 Graphics (com.codename1.ui.Graphics)14 Form (com.codename1.ui.Form)12 Font (com.codename1.ui.Font)11 GeneralPath (com.codename1.ui.geom.GeneralPath)9 Rectangle (com.codename1.ui.geom.Rectangle)9 Animation (com.codename1.ui.animations.Animation)8 Dialog (com.codename1.ui.Dialog)7 Dimension (com.codename1.ui.geom.Dimension)6 Painter (com.codename1.ui.Painter)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 FontImage (com.codename1.ui.FontImage)4 RGBImage (com.codename1.ui.RGBImage)4 Motion (com.codename1.ui.animations.Motion)4 ActionListener (com.codename1.ui.events.ActionListener)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 IOException (java.io.IOException)4