Search in sources :

Example 16 with Motion

use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.

the class FlipTransition method initTransition.

@Override
public void initTransition() {
    flipState = 0f;
    transitionState = STATE_MOVE_AWAY;
    zNear = 1600;
    zFar = zNear + 3000;
    Component source = getSource();
    Component destination = getDestination();
    int w = source.getWidth();
    int h = source.getHeight();
    // improper replace() calls, this may still be valid and shouldn't fail
    if (w <= 0 || h <= 0) {
        return;
    }
    sourceBuffer = createMutableImage(source.getWidth(), source.getHeight());
    paint(sourceBuffer.getGraphics(), source, -source.getAbsoluteX(), -source.getAbsoluteY());
    destBuffer = createMutableImage(destination.getWidth(), destination.getHeight());
    paint(destBuffer.getGraphics(), destination, -destination.getAbsoluteX(), -destination.getAbsoluteY());
    if (source instanceof Form) {
        setBgColor(0);
    }
    motion = Motion.createLinearMotion(0, 100, duration);
    motion.start();
}
Also used : Form(com.codename1.ui.Form) Component(com.codename1.ui.Component)

Example 17 with Motion

use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.

the class Component method growShrink.

/**
 * Grows or shrinks this component to its new preferred size, this method
 * essentially takes a component whose preferred size has changed and creates a "growing"
 * effect that lasts for the duration. Notice that some components (such as text areas)
 * don't report proper preferred size untill they are laid out once. Hence the first time
 * around a text area (or container containing a text area) will not produce the expected
 * effect. This can be solved by invoking revalidate before the call to this method only the
 * first time around!
 *
 * @param duration the duration in milliseconds for the grow/shrink animation
 */
public void growShrink(int duration) {
    Motion wMotion = Motion.createSplineMotion(getWidth(), getPreferredW(), duration);
    Motion hMotion = Motion.createSplineMotion(getHeight(), getPreferredH(), duration);
    wMotion.start();
    hMotion.start();
    setPreferredSize(new Dimension(getWidth(), getHeight()));
    // we are using bgpainter just to save the cost of creating another class
    getComponentForm().registerAnimated(new BGPainter(wMotion, hMotion));
    getComponentForm().revalidate();
}
Also used : Motion(com.codename1.ui.animations.Motion) Dimension(com.codename1.ui.geom.Dimension)

Example 18 with Motion

use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.

the class Component method animate.

/**
 * {@inheritDoc}
 */
public boolean animate() {
    if (!visible) {
        return false;
    }
    Image bgImage = getStyle().getBgImage();
    boolean animateBackground = bgImage != null && bgImage.isAnimation() && bgImage.animate();
    Motion m = getAnimationMotion();
    // perform regular scrolling
    if (m != null && destScrollY != -1 && destScrollY != getScrollY()) {
        // change the variable directly for efficiency both in removing redundant
        // repaints and scroll checks
        setScrollY(m.getValue());
        if (destScrollY == scrollY) {
            destScrollY = -1;
            deregisterAnimatedInternal();
            updateTensileHighlightIntensity(0, 0, m != null);
        }
        return true;
    }
    boolean animateY = false;
    boolean animateX = false;
    // perform the dragging motion if exists
    if (draggedMotionY != null) {
        // change the variable directly for efficiency both in removing redundant
        // repaints and scroll checks
        int dragVal = draggedMotionY.getValue();
        // this can't be a part of the parent if since we need the last value to arrive
        if (draggedMotionY.isFinished()) {
            if (dragVal < 0) {
                startTensile(dragVal, 0, true);
            } else {
                int iv = getInvisibleAreaUnderVKB();
                int edge = (getScrollDimension().getHeight() - getHeight() + iv);
                if (dragVal > edge && edge > 0) {
                    startTensile(dragVal, getScrollDimension().getHeight() - getHeight() + iv, true);
                } else {
                    if (snapToGrid && getScrollY() < edge && getScrollY() > 0) {
                        boolean tVal = tensileDragEnabled;
                        tensileDragEnabled = true;
                        int dest = getGridPosY();
                        int scroll = getScrollY();
                        if (dest != scroll) {
                            startTensile(scroll, dest, true);
                        } else {
                            draggedMotionY = null;
                        }
                        tensileDragEnabled = tVal;
                    } else {
                        draggedMotionY = null;
                    }
                }
            }
            // special callback to scroll Y to allow developers to override the setScrollY method effectively
            setScrollY(dragVal);
            updateTensileHighlightIntensity(dragVal, getScrollDimension().getHeight() - getHeight() + getInvisibleAreaUnderVKB(), false);
        }
        if (scrollListeners != null) {
            scrollListeners.fireScrollEvent(this.scrollX, dragVal, this.scrollX, this.scrollY);
        }
        scrollY = dragVal;
        onScrollY(scrollY);
        updateTensileHighlightIntensity(0, 0, false);
        animateY = true;
    }
    if (draggedMotionX != null) {
        // change the variable directly for efficiency both in removing redundant
        // repaints and scroll checks
        int dragVal = draggedMotionX.getValue();
        // this can't be a part of the parent if since we need the last value to arrive
        if (draggedMotionX.isFinished()) {
            if (dragVal < 0) {
                startTensile(dragVal, 0, false);
            } else {
                int edge = (getScrollDimension().getWidth() - getWidth());
                if (dragVal > edge && edge > 0) {
                    startTensile(dragVal, getScrollDimension().getWidth() - getWidth(), false);
                } else {
                    if (snapToGrid && getScrollX() < edge && getScrollX() > 0) {
                        boolean tVal = tensileDragEnabled;
                        tensileDragEnabled = true;
                        int dest = getGridPosX();
                        int scroll = getScrollX();
                        if (dest != scroll) {
                            startTensile(scroll, dest, false);
                        } else {
                            draggedMotionX = null;
                        }
                        tensileDragEnabled = tVal;
                    } else {
                        draggedMotionX = null;
                    }
                }
            }
            // special callback to scroll X to allow developers to override the setScrollY method effectively
            setScrollX(dragVal);
        }
        if (scrollListeners != null) {
            scrollListeners.fireScrollEvent(dragVal, this.scrollY, this.scrollX, this.scrollY);
        }
        scrollX = dragVal;
        onScrollX(scrollX);
        animateX = true;
    }
    if (animateY || animateX) {
        return true;
    }
    if (getClientProperty("$pullToRelease") != null) {
        return true;
    }
    Painter bgp = getStyle().getBgPainter();
    boolean animateBackgroundB = bgp != null && bgp.getClass() != BGPainter.class && bgp instanceof Animation && (bgp != this) && ((Animation) bgp).animate();
    animateBackground = animateBackgroundB || animateBackground;
    if (getUIManager().getLookAndFeel().isFadeScrollBar()) {
        if (tensileHighlightIntensity > 0) {
            tensileHighlightIntensity = Math.max(0, tensileHighlightIntensity - (scrollOpacityChangeSpeed * 2));
        }
        if (scrollOpacity > 0 && !dragActivated) {
            scrollOpacity = Math.max(0, scrollOpacity - scrollOpacityChangeSpeed);
            return true;
        }
    }
    if (!animateBackground && (destScrollY == -1 || destScrollY == scrollY) && !animateBackground && m == null && draggedMotionY == null && draggedMotionX == null && !dragActivated) {
        tryDeregisterAnimated();
    }
    return animateBackground;
}
Also used : Motion(com.codename1.ui.animations.Motion) Animation(com.codename1.ui.animations.Animation) ComponentAnimation(com.codename1.ui.animations.ComponentAnimation) Point(com.codename1.ui.geom.Point)

Example 19 with Motion

use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.

the class Component method initScrollMotion.

private void initScrollMotion() {
    // the component might not be registered for animation if it started off
    // as smaller than the screen and grew (e.g. by adding components to the container
    // once it is visible).
    Form f = getComponentForm();
    if (f != null) {
        f.registerAnimatedInternal(this);
    }
    Motion m = Motion.createLinearMotion(initialScrollY, destScrollY, getScrollAnimationSpeed());
    setAnimationMotion(m);
    m.start();
}
Also used : Motion(com.codename1.ui.animations.Motion)

Aggregations

Motion (com.codename1.ui.animations.Motion)14 Component (com.codename1.ui.Component)5 Form (com.codename1.ui.Form)5 Graphics (com.codename1.ui.Graphics)5 Animation (com.codename1.ui.animations.Animation)3 Container (com.codename1.ui.Container)2 Image (com.codename1.ui.Image)2 RGBImage (com.codename1.ui.RGBImage)2 AnimationObject (com.codename1.ui.animations.AnimationObject)2 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)2 Point (com.codename1.ui.geom.Point)2 Style (com.codename1.ui.plaf.Style)2 Vector (java.util.Vector)2 BufferedOutputStream (com.codename1.io.BufferedOutputStream)1 BrowserComponent (com.codename1.ui.BrowserComponent)1 Dialog (com.codename1.ui.Dialog)1 Display (com.codename1.ui.Display)1 Painter (com.codename1.ui.Painter)1 PeerComponent (com.codename1.ui.PeerComponent)1 CommonTransitions (com.codename1.ui.animations.CommonTransitions)1