Search in sources :

Example 6 with Paint

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

the class LinesLayer method paintSegment.

/**
 * Paint a segment.
 *
 * @param g a Graphics Object to paint on
 * @param segment array of Coord to draw a Line.
 * @param tile
 */
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
    int pointsNo = segment.length;
    for (int i = 1; i < pointsNo; i++) {
        Coord start = (Coord) segment[i - 1];
        Coord end = (Coord) segment[i];
        Point s = tile.pointPosition(start);
        Point e = tile.pointPosition(end);
        g.drawLine(s.getX(), s.getY(), e.getX(), e.getY());
        // lame & simple way to make line thicker
        g.drawLine(s.getX() - 1, s.getY(), e.getX() - 1, e.getY());
        g.drawLine(s.getX() + 1, s.getY(), e.getX() + 1, e.getY());
        g.drawLine(s.getX(), s.getY() - 1, e.getX(), e.getY() - 1);
        g.drawLine(s.getX(), s.getY() + 1, e.getX(), e.getY() + 1);
    }
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point) Point(com.codename1.ui.geom.Point)

Example 7 with Paint

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

the class ResetableTextWatcher method hideTextEditor.

/**
 * Hides the native text editor while keeping the active async edit session going.
 * This will effectively hide the native text editor, and show the light-weight text area
 * with cursor still in the correct position.
 */
private void hideTextEditor() {
    if (!mIsEditing || textEditorHidden || mEditText == null) {
        return;
    }
    textEditorHidden = true;
    final TextArea ta = mEditText.mTextArea;
    // Since this may be called off the UI thread, we need to issue async request on UI thread
    // to hide the text area.
    impl.getActivity().runOnUiThread(new Runnable() {

        public void run() {
            if (mEditText != null && mEditText.mTextArea == ta) {
                // Note:  Setting visibility to GONE doesn't work here because the TextWatcher
                // will stop receiving input from the keyboard, so we don't have a way to
                // reactivate the text editor when the user starts typing again.  Using the margin
                // to move it off screen keeps the text editor active.
                mEditLayoutParams.setMargins(-Display.getInstance().getDisplayWidth(), 0, 0, 0);
                InPlaceEditView.this.requestLayout();
                final int cursorPos = mEditText.getSelectionStart();
                // Since we are going to be displaying the CN1 text area now, we need to update
                // the cursor.  That needs to happen on the EDT.
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        if (mEditText != null && mEditText.mTextArea == ta && mIsEditing && textEditorHidden) {
                            if (ta instanceof TextField) {
                                ((TextField) ta).setCursorPosition(cursorPos);
                            }
                        }
                    }
                });
            }
        }
    });
    // Repaint the CN1 text area on the EDT.  This is necessary because while the native editor
    // was shown, the cn1 text area paints only its background.  Now that the editor is hidden
    // it should paint its foreground also.
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            if (mEditText != null && mEditText.mTextArea != null) {
                mEditText.mTextArea.repaint();
            }
        }
    });
// repaintTextEditor(true);
}
Also used : TextArea(com.codename1.ui.TextArea) TextField(com.codename1.ui.TextField)

Example 8 with Paint

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

the class AndroidGraphics method setStroke.

/**
 * Sets the stroke of the current Paint object.
 * @param stroke The stroke to set.
 * @return The old stroke.
 */
private Stroke setStroke(Stroke stroke) {
    Stroke old = new Stroke(paint.getStrokeWidth(), convertStrokeCap(paint.getStrokeCap()), convertStrokeJoin(paint.getStrokeJoin()), paint.getStrokeMiter());
    paint.setStrokeCap(convertStrokeCap(stroke.getCapStyle()));
    paint.setStrokeJoin(convertStrokeJoin(stroke.getJoinStyle()));
    paint.setStrokeMiter(stroke.getMiterLimit());
    paint.setStrokeWidth(stroke.getLineWidth());
    return old;
}
Also used : Stroke(com.codename1.ui.Stroke)

Example 9 with Paint

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

the class AndroidGraphics method drawPath.

public void drawPath(Path p, Stroke stroke) {
    paint.setStyle(Paint.Style.STROKE);
    Stroke old = setStroke(stroke);
    // System.out.println("Transform semaphore "+transformSemaphore);
    if (getTransform().isIdentity()) {
        canvas.drawPath(p, paint);
    } else {
        RectF bounds = new RectF();
        p.computeBounds(bounds, false);
        Path p2 = new Path();
        p.transform(getTransformMatrix(), p2);
        RectF bounds2 = new RectF();
        p2.computeBounds(bounds2, false);
        float b2w = bounds2.width();
        float bw = bounds.width();
        float bw2 = Math.max(1, b2w) / Math.max(1, bw);
        float bh2 = Math.max(1, bounds2.height()) / Math.max(1, bounds.height());
        float ratio = Math.max(bw2, bh2);
        if (ratio > 2 && !isMutableImageGraphics) {
            // If the canvas is hardware accelerated, then it will rasterize the path
            // first, then apply the transform which leads to blurry paths if the transform does
            // significant scaling.
            // In such cases, we
            float strokeWidthUpperBound = ratio * stroke.getLineWidth();
            int ww = Math.max(1, (int) (bounds2.width() + 2 * strokeWidthUpperBound));
            int hh = Math.max(1, (int) (bounds2.height() + 2 * strokeWidthUpperBound));
            Bitmap nativeBuffer = Bitmap.createBitmap(ww, hh, Bitmap.Config.ARGB_8888);
            // int restorePoint = canvas.saveLayer(bounds2, paint, Canvas.ALL_SAVE_FLAG);
            Canvas c = new Canvas(nativeBuffer);
            Matrix translateM = new Matrix();
            translateM.set(getTransformMatrix());
            translateM.postTranslate(-bounds2.left + strokeWidthUpperBound, -bounds2.top + strokeWidthUpperBound);
            c.concat(translateM);
            c.drawPath(p, paint);
            canvas.drawBitmap(nativeBuffer, bounds2.left - strokeWidthUpperBound, bounds2.top - strokeWidthUpperBound, paint);
        } else {
            canvas.save();
            applyTransform();
            canvas.drawPath(p, paint);
            unapplyTransform();
            canvas.restore();
        }
    }
    setStroke(old);
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) Stroke(com.codename1.ui.Stroke) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 10 with Paint

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

the class BlackBerryCanvas method paint.

public void paint(Graphics g) {
    int f = getFieldCount();
    if (f > 0) {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
        Form currentForm = Display.getInstance().getCurrent();
        for (int iter = 0; iter < f; iter++) {
            Field fld = getField(iter);
            int pops = 0;
            if (currentForm != null) {
                PeerComponent p = findPeer(currentForm.getContentPane(), fld);
                if (p != null) {
                    pops = clipOnLWUITBounds(p, g);
                } else {
                    Component cmp = currentForm.getFocused();
                    // we are now editing an edit field
                    if (cmp != null && cmp instanceof TextArea && cmp.hasFocus() && fld instanceof EditField) {
                        pops = clipOnLWUITBounds(cmp, g);
                        int x = fld.getLeft();
                        int y = fld.getTop();
                        g.clear(x, y, Math.max(cmp.getWidth(), fld.getWidth()), Math.max(cmp.getHeight(), fld.getHeight()));
                    }
                }
            }
            paintChild(g, fld);
            while (pops > 0) {
                g.popContext();
                pops--;
            }
        }
    } else {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
    }
    g.setColor(0);
    g.drawText(debug, 0, 0);
    painted = true;
}
Also used : EditField(net.rim.device.api.ui.component.EditField) Field(net.rim.device.api.ui.Field) PeerComponent(com.codename1.ui.PeerComponent) EditField(net.rim.device.api.ui.component.EditField) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

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