Search in sources :

Example 6 with Rectangle2D

use of com.codename1.ui.geom.Rectangle2D in project CodenameOne by codenameone.

the class AbstractChart method drawString.

/**
 * Draw a multiple lines string.
 *
 * @param canvas the canvas to paint to
 * @param text the text to be painted
 * @param x the x value of the area to draw to
 * @param y the y value of the area to draw to
 * @param paint the paint to be used for drawing
 */
protected void drawString(Canvas canvas, String text, float x, float y, Paint paint) {
    if (text != null) {
        String[] lines = split(text, "\n");
        Rectangle2D rect = new Rectangle2D();
        int yOff = 0;
        int llen = lines.length;
        for (int i = 0; i < llen; ++i) {
            canvas.drawText(lines[i], x, y + yOff, paint);
            paint.getTextBounds(lines[i], 0, lines[i].length(), rect);
            // space between lines is 5
            yOff = yOff + (int) rect.getHeight() + 5;
        }
    }
}
Also used : Rectangle2D(com.codename1.ui.geom.Rectangle2D) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 7 with Rectangle2D

use of com.codename1.ui.geom.Rectangle2D in project CodenameOne by codenameone.

the class Paint method getCN1TextBounds.

void getCN1TextBounds(String string, int start, int count, Rectangle2D rect) {
    Font f = getTypeface();
    if (f != null) {
        int w = f.substringWidth(string, start, count);
        int h = f.getHeight();
        rect.setBounds(0, 0, w, h);
    }
}
Also used : Font(com.codename1.ui.Font)

Aggregations

Paint (com.codename1.charts.compat.Paint)5 Rectangle2D (com.codename1.ui.geom.Rectangle2D)5 Point (com.codename1.charts.models.Point)4 ArrayList (java.util.ArrayList)3 Font (com.codename1.ui.Font)2 GradientDrawable (com.codename1.charts.compat.GradientDrawable)1 XYSeries (com.codename1.charts.models.XYSeries)1 SimpleSeriesRenderer (com.codename1.charts.renderers.SimpleSeriesRenderer)1 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)1 XYSeriesRenderer (com.codename1.charts.renderers.XYSeriesRenderer)1 com.codename1.ui (com.codename1.ui)1 Rectangle (com.codename1.ui.geom.Rectangle)1 Color (java.awt.Color)1 FontMetrics (java.awt.FontMetrics)1 Graphics2D (java.awt.Graphics2D)1 FontRenderContext (java.awt.font.FontRenderContext)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1