Search in sources :

Example 31 with Rectangle

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

the class Timeline method getRGB.

/**
 * {@inheritDoc}
 */
public int[] getRGB() {
    Image i = Image.createImage(getWidth(), getHeight());
    paint(i.getGraphics(), new Rectangle(0, 0, getWidth(), getHeight()));
    return i.getRGB();
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Image(com.codename1.ui.Image)

Example 32 with Rectangle

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

the class CodenameOneImplementation method paintDirty.

/**
 * Invoked by the EDT to paint the dirty regions
 */
public void paintDirty() {
    int size = 0;
    synchronized (displayLock) {
        size = paintQueueFill;
        Animation[] array = paintQueue;
        paintQueue = paintQueueTemp;
        paintQueueTemp = array;
        paintQueueFill = 0;
    }
    if (size > 0) {
        Graphics wrapper = getCodenameOneGraphics();
        int dwidth = getDisplayWidth();
        int dheight = getDisplayHeight();
        int topX = dwidth;
        int topY = dheight;
        int bottomX = 0;
        int bottomY = 0;
        for (int iter = 0; iter < size; iter++) {
            Animation ani = paintQueueTemp[iter];
            // might happen due to paint queue removal
            if (ani == null) {
                continue;
            }
            paintQueueTemp[iter] = null;
            wrapper.translate(-wrapper.getTranslateX(), -wrapper.getTranslateY());
            wrapper.setClip(0, 0, dwidth, dheight);
            if (ani instanceof Component) {
                Component cmp = (Component) ani;
                Rectangle dirty = cmp.getDirtyRegion();
                if (dirty != null) {
                    Dimension d = dirty.getSize();
                    wrapper.setClip(dirty.getX(), dirty.getY(), d.getWidth(), d.getHeight());
                    cmp.setDirtyRegion(null);
                }
                cmp.paintComponent(wrapper);
                getPaintableBounds(cmp, paintDirtyTmpRect);
                int cmpAbsX = paintDirtyTmpRect.getX();
                topX = Math.min(cmpAbsX, topX);
                bottomX = Math.max(cmpAbsX + paintDirtyTmpRect.getWidth(), bottomX);
                int cmpAbsY = paintDirtyTmpRect.getY();
                topY = Math.min(cmpAbsY, topY);
                bottomY = Math.max(cmpAbsY + paintDirtyTmpRect.getHeight(), bottomY);
            } else {
                bottomX = dwidth;
                bottomY = dheight;
                topX = 0;
                topY = 0;
                ani.paint(wrapper);
            }
        }
        paintOverlay(wrapper);
        // Log.p("Flushing graphics : "+topX+","+topY+","+bottomX+","+bottomY);
        flushGraphics(topX, topY, bottomX - topX, bottomY - topY);
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Animation(com.codename1.ui.animations.Animation) Dimension(com.codename1.ui.geom.Dimension)

Example 33 with Rectangle

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

the class CodenameOneImplementation method clipRect.

/**
 * Changes the current clipping rectangle to subset the current clipping with
 * the given clipping.
 *
 * @param graphics the graphics context
 * @param rect rectangle representing the new clipping area
 */
public void clipRect(Object graphics, Rectangle rect) {
    Dimension d = rect.getSize();
    clipRect(graphics, rect.getX(), rect.getY(), d.getWidth(), d.getHeight());
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 34 with Rectangle

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

the class Border method setImageBorderSpecialTile.

/**
 * This method is designed mainly for the purpose of creating an arrow that will track a specific component using the image border
 * the tile given would be an arrow like image just like the ones used for the top/bottom/left/right images. This image would be positioned
 * so it points at the center of the track component
 *
 * @param tileTop an image that will replace one of the tiles on the top if the track component is there
 * @param tileBottom an image that will replace one of the tiles on the bottom if the track component is there
 * @param tileLeft an image that will replace one of the tiles on the left if the track component is there
 * @param tileRight an image that will replace one of the tiles on the right if the track component is there
 * @param trackComponent the component that will be tracked for the positioning of the tile
 */
public void setImageBorderSpecialTile(Image tileTop, Image tileBottom, Image tileLeft, Image tileRight, Component trackComponent) {
    specialTile = new Image[] { tileTop, tileBottom, tileLeft, tileRight };
    this.trackComponent = new Rectangle(trackComponent.getAbsoluteX(), trackComponent.getAbsoluteY(), trackComponent.getWidth(), trackComponent.getHeight());
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 35 with Rectangle

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

the class RoundRectBorder 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 = Display.getInstance().convertToPixels(shadowSpread);
    if (shadowOpacity > 0) {
        shapeW -= shadowSpreadL;
        shapeH -= shadowSpreadL;
        shapeX += Math.round(((float) shadowSpreadL) * shadowX);
        shapeY += Math.round(((float) shadowSpreadL) * 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);
    GeneralPath gp = createShape(shapeW, shapeH);
    Style s = c.getStyle();
    if (s.getBgImage() == null) {
        byte type = s.getBackgroundType();
        if (type == Style.BACKGROUND_IMAGE_SCALED || type == Style.BACKGROUND_NONE) {
            byte bgt = c.getStyle().getBgTransparency();
            if (bgt != 0) {
                tg.setAlpha(bgt & 0xff);
                tg.setColor(s.getBgColor());
                tg.fillShape(gp);
            }
            if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
                tg.setAlpha(strokeOpacity);
                tg.setColor(strokeColor);
                tg.drawShape(gp, this.stroke);
            }
            return target;
        }
    }
    c.getStyle().setBorder(Border.createEmpty());
    tg.setClip(gp);
    s.getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
    if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
        tg.setClip(0, 0, w, h);
        tg.setAlpha(strokeOpacity);
        tg.setColor(strokeColor);
        tg.drawShape(gp, this.stroke);
    }
    c.getStyle().setBorder(this);
    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)

Aggregations

Rectangle (com.codename1.ui.geom.Rectangle)41 Dimension (com.codename1.ui.geom.Dimension)16 Style (com.codename1.ui.plaf.Style)13 Image (com.codename1.ui.Image)10 ActionEvent (com.codename1.ui.events.ActionEvent)5 Border (com.codename1.ui.plaf.Border)5 Component (com.codename1.ui.Component)4 Graphics (com.codename1.ui.Graphics)4 UIManager (com.codename1.ui.plaf.UIManager)4 Form (com.codename1.ui.Form)3 Label (com.codename1.ui.Label)3 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Paint (com.codename1.charts.compat.Paint)2 Button (com.codename1.ui.Button)2 EncodedImage (com.codename1.ui.EncodedImage)2 Painter (com.codename1.ui.Painter)2 ActionListener (com.codename1.ui.events.ActionListener)2 RoundBorder (com.codename1.ui.plaf.RoundBorder)2