Search in sources :

Example 76 with Paint

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

the class AbstractChart method drawLegend.

/**
 * Draws the chart legend.
 *
 * @param canvas the canvas to paint to
 * @param renderer the series renderer
 * @param titles the titles to go to the legend
 * @param left the left X value of the area to draw to
 * @param right the right X value of the area to draw to
 * @param y the y value of the area to draw to
 * @param width the width of the area to draw to
 * @param height the height of the area to draw to
 * @param legendSize the legend size
 * @param paint the paint to be used for drawing
 * @param calculate if only calculating the legend size
 *
 * @return the legend height
 */
protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate) {
    float size = 32;
    if (renderer.isShowLegend()) {
        float currentX = left;
        float currentY = y + height - legendSize + size;
        paint.setTextAlign(Component.LEFT);
        paint.setTextSize(renderer.getLegendTextSize());
        int sLength = Math.min(titles.length, renderer.getSeriesRendererCount());
        for (int i = 0; i < sLength; i++) {
            SimpleSeriesRenderer r = renderer.getSeriesRendererAt(i);
            final float lineSize = getLegendShapeWidth(i);
            if (r.isShowLegendItem()) {
                String text = titles[i];
                if (titles.length == renderer.getSeriesRendererCount()) {
                    paint.setColor(r.getColor());
                } else {
                    paint.setColor(ColorUtil.LTGRAY);
                }
                float[] widths = new float[text.length()];
                paint.getTextWidths(text, widths);
                float sum = 0;
                for (float value : widths) {
                    sum += value;
                }
                float extraSize = lineSize + 10 + sum;
                float currentWidth = currentX + extraSize;
                if (i > 0 && getExceed(currentWidth, renderer, right, width)) {
                    currentX = left;
                    currentY += renderer.getLegendTextSize();
                    size += renderer.getLegendTextSize();
                    currentWidth = currentX + extraSize;
                }
                if (getExceed(currentWidth, renderer, right, width)) {
                    float maxWidth = right - currentX - lineSize - 10;
                    if (isVertical(renderer)) {
                        maxWidth = width - currentX - lineSize - 10;
                    }
                    int nr = paint.breakText(text, true, maxWidth, widths);
                    text = text.substring(0, nr) + "...";
                }
                if (!calculate) {
                    drawLegendShape(canvas, r, currentX, currentY, i, paint);
                    drawString(canvas, text, currentX + lineSize + 5, currentY + 5, paint);
                }
                currentX += extraSize;
            }
        }
    }
    return Math.round(size + renderer.getLegendTextSize());
}
Also used : SimpleSeriesRenderer(com.codename1.charts.renderers.SimpleSeriesRenderer) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 77 with Paint

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

the class ChartUtil method paintChart.

/**
 * Draws the given chart onto the given graphics
 *
 * @param g the graphics object
 * @param chart the chart object
 * @param bounds the bounds in which the chart should be drawn within the graphics
 * @param absX
 * @param absY
 */
public void paintChart(Graphics g, AbstractChart chart, Rectangle bounds, int absX, int absY) {
    c.g = g;
    c.bounds = bounds;
    c.absoluteX = absX;
    c.absoluteY = absY;
    chart.draw(c, bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), new Paint());
}
Also used : Paint(com.codename1.charts.compat.Paint)

Example 78 with Paint

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

the class Canvas method applyPaint.

private void applyPaint(Paint paint, boolean forText) {
    // Log.p("Applyingn paint : "+paint);
    g.setColor(paint.getColor());
    int alpha = ColorUtil.alpha(paint.getColor());
    g.setAlpha(alpha);
    if (forText) {
        Font typeFace = paint.getTypeface();
        if (typeFace != null) {
            if (typeFace.getSize() != (int) paint.getTextSize()) {
                typeFace = typeFace.derive(paint.getTextSize(), Font.STYLE_PLAIN);
            }
            g.setFont(typeFace);
        } else {
            g.setFont(null);
        }
    }
}
Also used : Font(com.codename1.ui.Font)

Example 79 with Paint

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

the class Component method paintComponent.

/**
 * <p>Paints this component as a root by going to all the parent components and
 * setting the absolute translation based on coordinates and scroll status.
 * Restores translation when the painting is finished.<br>
 * One of the uses of this method is to create a "screenshot" as is demonstrated in the code below
 * that creates an image for sharing on social media</p>
 * <script src="https://gist.github.com/codenameone/6bf5e68b329ae59a25e3.js"></script>
 *
 * @param g the graphics to paint this Component on
 * @param background if true paints all parents background
 */
public final void paintComponent(Graphics g, boolean background) {
    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipW = g.getClipWidth();
    int clipH = g.getClipHeight();
    // g.pushClip();
    Container parent = getParent();
    int translateX = 0;
    int translateY = 0;
    while (parent != null) {
        translateX += parent.getX();
        translateY += parent.getY();
        // if (parent.isScrollable()) {
        if (parent.isScrollableX()) {
            translateX -= parent.getScrollX();
        }
        if (parent.isScrollableY()) {
            translateY -= parent.getScrollY();
        }
        // since scrollability can translate everything... we should clip based on the
        // current scroll
        int parentX = parent.getAbsoluteX() + parent.getScrollX();
        if (isRTL()) {
            parentX += parent.getSideGap();
        }
        g.clipRect(parentX, parent.getAbsoluteY() + parent.getScrollY(), parent.getWidth() - parent.getSideGap(), parent.getHeight() - parent.getBottomGap());
        parent = parent.getParent();
    }
    g.clipRect(translateX + getX(), translateY + getY(), getWidth(), getHeight());
    if (background) {
        paintBackgrounds(g);
    }
    g.translate(translateX, translateY);
    paintInternal(g);
    g.translate(-translateX, -translateY);
    paintGlassImpl(g);
    g.setClip(clipX, clipY, clipW, clipH);
// g.popClip();
}
Also used : Point(com.codename1.ui.geom.Point)

Example 80 with Paint

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

the class Component method paintBackgroundImpl.

private void paintBackgroundImpl(Graphics g) {
    if (isBorderPainted()) {
        Border b = getBorder();
        if (b != null && b.isBackgroundPainter()) {
            b.paintBorderBackground(g, this);
            paintRippleEffect(g);
            return;
        }
    }
    if (getStyle().getBgPainter() != null) {
        getStyle().getBgPainter().paint(g, bounds);
    }
    paintBackground(g);
    paintRippleEffect(g);
}
Also used : Border(com.codename1.ui.plaf.Border)

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