Search in sources :

Example 36 with Dimension

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

the class MorphTransition method initTransition.

/**
 * {@inheritDoc}
 */
public final void initTransition() {
    animationMotion = Motion.createEaseInOutMotion(0, 255, duration);
    animationMotion.start();
    Container s = (Container) getSource();
    Container d = (Container) getDestination();
    Iterator<String> keyIterator = fromTo.keySet().iterator();
    int size = fromTo.size();
    fromToComponents = new CC[size];
    Form destForm = d.getComponentForm();
    Form sourceForm = s.getComponentForm();
    for (int iter = 0; iter < size; iter++) {
        String k = keyIterator.next();
        String v = fromTo.get(k);
        Component sourceCmp = findByName(s, k);
        Component destCmp = findByName(d, v);
        if (sourceCmp == null || destCmp == null) {
            continue;
        }
        CC cc = new CC(sourceCmp, destCmp, sourceForm, destForm);
        fromToComponents[iter] = cc;
        cc.placeholderDest = new Label();
        cc.placeholderDest.setVisible(false);
        Container destParent = cc.dest.getParent();
        cc.placeholderDest.setX(cc.dest.getX());
        cc.placeholderDest.setY(cc.dest.getY() - destForm.getContentPane().getY());
        cc.placeholderDest.setWidth(cc.dest.getWidth());
        cc.placeholderDest.setHeight(cc.dest.getHeight());
        cc.placeholderDest.setPreferredSize(new Dimension(cc.dest.getWidth(), cc.dest.getHeight()));
        destParent.replace(cc.dest, cc.placeholderDest, null);
        destForm.getLayeredPane().addComponent(cc.dest);
        cc.placeholderSrc = new Label();
        cc.placeholderSrc.setVisible(false);
        cc.placeholderSrc.setX(cc.source.getX());
        cc.placeholderSrc.setY(cc.source.getY() - sourceForm.getContentPane().getY());
        cc.placeholderSrc.setWidth(cc.source.getWidth());
        cc.placeholderSrc.setHeight(cc.source.getHeight());
        cc.placeholderSrc.setPreferredSize(new Dimension(cc.source.getWidth(), cc.source.getHeight()));
        cc.originalContainer = cc.source.getParent();
        cc.originalConstraint = cc.originalContainer.getLayout().getComponentConstraint(cc.source);
        cc.originalOffset = cc.originalContainer.getComponentIndex(cc.source);
        cc.originalContainer.replace(cc.source, cc.placeholderSrc, null);
        cc.originalContainer.getComponentForm().getLayeredPane().addComponent(cc.source);
    }
}
Also used : Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 37 with Dimension

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

the class Timeline method scaled.

/**
 * {@inheritDoc}
 */
public Image scaled(int width, int height) {
    Timeline t = new Timeline();
    t.animationDelay = animationDelay;
    t.animations = animations;
    t.currentTime = currentTime;
    t.duration = duration;
    t.size = size;
    t.time = time;
    t.scaledTo = new Dimension(width, height);
    return t;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 38 with Dimension

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

the class LayeredLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    int numOfcomponents = parent.getComponentCount();
    tmpLaidOut.clear();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        calcPreferredValues(cmp);
        LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
        int vInsets = 0;
        int hInsets = 0;
        if (constraint != null) {
            vInsets += constraint.insets[Component.TOP].preferredValue + constraint.insets[Component.BOTTOM].preferredValue;
            hInsets += constraint.insets[Component.LEFT].preferredValue + constraint.insets[Component.RIGHT].preferredValue;
        }
        maxHeight = Math.max(maxHeight, cmp.getPreferredH() + cmp.getStyle().getMarginTop() + cmp.getStyle().getMarginBottom() + vInsets);
        maxWidth = Math.max(maxWidth, cmp.getPreferredW() + cmp.getStyle().getMarginLeftNoRTL() + cmp.getStyle().getMarginRightNoRTL() + hInsets);
    }
    Style s = parent.getStyle();
    Dimension d = new Dimension(maxWidth + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), maxHeight + s.getPaddingTop() + s.getPaddingBottom());
    if (preferredWidthMM > 0) {
        int minW = Display.getInstance().convertToPixels(preferredWidthMM);
        if (d.getWidth() < minW) {
            d.setWidth(minW);
        }
    }
    if (preferredHeightMM > 0) {
        int minH = Display.getInstance().convertToPixels(preferredHeightMM);
        if (d.getHeight() < Display.getInstance().convertToPixels(preferredHeightMM)) {
            d.setHeight(minH);
        }
    }
    return d;
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 39 with Dimension

use of com.codename1.ui.geom.Dimension 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 40 with Dimension

use of com.codename1.ui.geom.Dimension 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)

Aggregations

Dimension (com.codename1.ui.geom.Dimension)74 Style (com.codename1.ui.plaf.Style)27 Component (com.codename1.ui.Component)16 Image (com.codename1.ui.Image)16 Rectangle (com.codename1.ui.geom.Rectangle)9 EncodedImage (com.codename1.ui.EncodedImage)8 Label (com.codename1.ui.Label)7 Container (com.codename1.ui.Container)6 FileEncodedImage (com.codename1.components.FileEncodedImage)5 StorageImage (com.codename1.components.StorageImage)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 Form (com.codename1.ui.Form)4 Dimension (java.awt.Dimension)4 Font (com.codename1.ui.Font)3 FontImage (com.codename1.ui.FontImage)3 TextArea (com.codename1.ui.TextArea)3 ActionListener (com.codename1.ui.events.ActionListener)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Border (com.codename1.ui.plaf.Border)3