Search in sources :

Example 56 with Paint

use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.

the class RoundBorder method createTargetImage.

private Image createTargetImage(Component c, int w, int h, boolean fast) {
    Image target = Image.createImage(w, h, 0);
    int shapeX = 0;
    int shapeY = 0;
    int shapeW = w;
    int shapeH = h;
    Graphics tg = target.getGraphics();
    tg.setAntiAliased(true);
    int shadowSpreadL = shadowSpread;
    if (shadowMM) {
        shadowSpreadL = Display.getInstance().convertToPixels(shadowSpreadL);
    }
    if (shadowOpacity > 0) {
        shapeW -= shadowSpreadL;
        shapeW -= (shadowBlur / 2);
        shapeH -= shadowSpreadL;
        shapeH -= (shadowBlur / 2);
        shapeX += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowX);
        shapeY += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowY);
        // draw a gradient of sort for the shadow
        for (int iter = shadowSpreadL - 1; iter >= 0; iter--) {
            tg.translate(iter, iter);
            fillShape(tg, 0, shadowOpacity / shadowSpreadL, w - (iter * 2), h - (iter * 2), false);
            tg.translate(-iter, -iter);
        }
        if (Display.getInstance().isGaussianBlurSupported() && !fast) {
            Image blured = Display.getInstance().gaussianBlurImage(target, shadowBlur / 2);
            target = Image.createImage(w, h, 0);
            tg = target.getGraphics();
            tg.drawImage(blured, 0, 0);
            tg.setAntiAliased(true);
        }
    }
    tg.translate(shapeX, shapeY);
    if (uiid && tg.isShapeClipSupported()) {
        c.getStyle().setBorder(Border.createEmpty());
        GeneralPath gp = new GeneralPath();
        if (rectangle) {
            float sw = this.stroke != null ? this.stroke.getLineWidth() : 0;
            gp.moveTo(shapeH / 2.0, sw);
            gp.lineTo(shapeW - (shapeH / 2.0), sw);
            gp.arcTo(shapeW - (shapeH / 2.0), shapeH / 2.0, shapeW - (shapeH / 2.0), shapeH - sw, true);
            gp.lineTo(shapeH / 2.0, shapeH - sw);
            gp.arcTo(shapeH / 2.0, shapeH / 2.0, shapeH / 2.0, sw, true);
            gp.closePath();
        } else {
            int size = shapeW;
            int xPos = 0;
            int yPos = 0;
            if (shapeW != shapeH) {
                if (shapeW > shapeH) {
                    size = shapeH;
                    xPos = (shapeW - shapeH) / 2;
                } else {
                    size = shapeW;
                    yPos = (shapeH - shapeW) / 2;
                }
            }
            gp.arc(xPos, yPos, size, size, 0, 2 * Math.PI);
        }
        tg.setClip(gp);
        c.getStyle().getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
        c.getStyle().setBorder(this);
    } else {
        fillShape(tg, color, opacity, shapeW, shapeH, true);
    }
    return target;
}
Also used : Graphics(com.codename1.ui.Graphics) GeneralPath(com.codename1.ui.geom.GeneralPath) Rectangle(com.codename1.ui.geom.Rectangle) Image(com.codename1.ui.Image)

Example 57 with Paint

use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.

the class SwipeBackSupport method bind.

/**
 * Binds support for swiping to the given forms
 *
 * @param currentForm the current form
 * @param destination the destination form which can be created lazily
 */
protected void bind(final Form currentForm, final LazyValue<Form> destination) {
    pointerDragged = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (sideSwipePotential) {
                final int x = evt.getX();
                final int y = evt.getY();
                if (Math.abs(y - initialDragY) > x - initialDragX) {
                    sideSwipePotential = false;
                    return;
                }
                evt.consume();
                if (dragActivated) {
                    currentX = x;
                    Display.getInstance().getCurrent().repaint();
                } else {
                    if (x - initialDragX > Display.getInstance().convertToPixels(currentForm.getUIManager().getThemeConstant("backGestureThresholdInt", 5), true)) {
                        dragActivated = true;
                        destinationForm = destination.get();
                        startBackTransition(currentForm, destinationForm);
                    }
                }
            }
        }
    };
    pointerReleased = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (dragActivated) {
                int destNumberX = Display.getInstance().getDisplayWidth();
                int incrementsX = Display.getInstance().convertToPixels(3, true);
                if (currentX < destNumberX / 2) {
                    destinationForm = currentForm;
                    destNumberX = 0;
                    incrementsX *= -1;
                }
                final int destNumber = destNumberX;
                final int increments = incrementsX;
                Display.getInstance().getCurrent().registerAnimated(new Animation() {

                    public boolean animate() {
                        currentX += increments;
                        if (currentX > 0 && currentX >= destNumber || currentX < 0 && currentX <= destNumber) {
                            currentX = destNumber;
                            Transition t = destinationForm.getTransitionInAnimator();
                            destinationForm.setTransitionInAnimator(CommonTransitions.createEmpty());
                            destinationForm.show();
                            destinationForm.setTransitionInAnimator(t);
                            destinationForm = null;
                            dragActivated = false;
                            return false;
                        }
                        return true;
                    }

                    public void paint(Graphics g) {
                    }
                });
            }
        }
    };
    pointerPressed = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            sideSwipePotential = false;
            int displayWidth = Display.getInstance().getDisplayWidth();
            sideSwipePotential = !transitionRunning && evt.getX() < displayWidth / currentForm.getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
            initialDragX = evt.getX();
            initialDragY = evt.getY();
        /*if (sideSwipePotential) {
                    Component c = Display.getInstance().getCurrent().getComponentAt(initialDragX, initialDragY);
                    if (c != null && c.shouldBlockSideSwipe()) {
                        sideSwipePotential = false;
                    }
                }*/
        }
    };
    currentForm.addPointerDraggedListener(pointerDragged);
    currentForm.addPointerReleasedListener(pointerReleased);
    currentForm.addPointerPressedListener(pointerPressed);
}
Also used : Graphics(com.codename1.ui.Graphics) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Transition(com.codename1.ui.animations.Transition) Animation(com.codename1.ui.animations.Animation)

Example 58 with Paint

use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.

the class PointLayer method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g, Tile tile) {
    Point pos = tile.pointPosition(this);
    int width = 6;
    int height = 6;
    if (icon != null) {
        width = icon.getWidth();
        height = icon.getHeight();
    }
    int x = pos.getX() - width / 2;
    int y = pos.getY() - height / 2;
    if (icon == null) {
        g.fillRect(x, y, width, height);
    } else {
        g.drawImage(icon, x, y);
    }
    if (name != null && displayName) {
        g.drawString(getName(), x + width + 1, pos.getY() - g.getFont().getHeight() / 2 - 1);
    }
}
Also used : Point(com.codename1.ui.geom.Point) Point(com.codename1.ui.geom.Point)

Example 59 with Paint

use of com.codename1.charts.compat.Paint 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 60 with Paint

use of com.codename1.charts.compat.Paint 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

Paint (com.codename1.charts.compat.Paint)28 Component (com.codename1.ui.Component)16 Point (com.codename1.charts.models.Point)14 Style (com.codename1.ui.plaf.Style)13 Form (com.codename1.ui.Form)12 Image (com.codename1.ui.Image)11 Graphics (com.codename1.ui.Graphics)10 Animation (com.codename1.ui.animations.Animation)10 Rectangle (com.codename1.ui.geom.Rectangle)9 Dialog (com.codename1.ui.Dialog)7 GeneralPath (com.codename1.ui.geom.GeneralPath)6 Point (com.codename1.ui.geom.Point)6 Paint (android.graphics.Paint)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 Rectangle2D (com.codename1.ui.geom.Rectangle2D)5 IOException (java.io.IOException)5 TextArea (com.codename1.ui.TextArea)4 ActionListener (com.codename1.ui.events.ActionListener)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 Motion (com.codename1.ui.animations.Motion)3