Search in sources :

Example 1 with AnimationObject

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

the class Resources method readTimeline.

Timeline readTimeline(DataInputStream input) throws IOException {
    int duration = input.readInt();
    int width = input.readInt();
    int height = input.readInt();
    AnimationObject[] animations = new AnimationObject[input.readShort()];
    int alen = animations.length;
    for (int iter = 0; iter < alen; iter++) {
        String name = input.readUTF();
        int startTime = input.readInt();
        int animDuration = input.readInt();
        int x = input.readInt();
        int y = input.readInt();
        Image i = getImage(name);
        if (i == null) {
            animations[iter] = AnimationObject.createAnimationImage(name, this, x, y);
        } else {
            animations[iter] = AnimationObject.createAnimationImage(i, x, y);
        }
        animations[iter].setStartTime(startTime);
        animations[iter].setEndTime(startTime + animDuration);
        int frameDelay = input.readInt();
        if (frameDelay > -1) {
            int frameWidth = input.readInt();
            int frameHeight = input.readInt();
            animations[iter].defineFrames(frameWidth, frameHeight, frameDelay);
        }
        if (input.readBoolean()) {
            animations[iter].defineMotionX(input.readInt(), startTime, animDuration, x, input.readInt());
        }
        if (input.readBoolean()) {
            animations[iter].defineMotionY(input.readInt(), startTime, animDuration, y, input.readInt());
        }
        if (input.readBoolean()) {
            animations[iter].defineWidth(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
        if (input.readBoolean()) {
            animations[iter].defineHeight(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
        if (input.readBoolean()) {
            animations[iter].defineOpacity(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
        if (input.readBoolean()) {
            animations[iter].defineOrientation(input.readInt(), startTime, animDuration, input.readInt(), input.readInt());
        }
    }
    Timeline tl = Timeline.createTimeline(duration, animations, new Dimension(width, height));
    return tl;
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Dimension(com.codename1.ui.geom.Dimension) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage)

Example 2 with AnimationObject

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

the class TimelineEditor method duplicateObjectActionPerformed.

// GEN-LAST:event_removeAnimationObjectActionPerformed
private void duplicateObjectActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_duplicateObjectActionPerformed
    Timeline t = cloneCurrentTimeline();
    AnimationObject o = AnimationAccessor.clone((AnimationObject) ((AnimationObjectTableModel) animationObjectList.getModel()).getElementAt(animationObjectList.getSelectedRow()));
    ((AnimationObjectTableModel) animationObjectList.getModel()).addElement(o);
    AnimationObject[] animations = new AnimationObject[t.getAnimationCount() + 1];
    for (int iter = 0; iter < animations.length - 1; iter++) {
        animations[iter] = t.getAnimation(iter);
    }
    animations[animations.length - 1] = o;
    Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    setImage(nt);
    animationObjectList.clearSelection();
    duplicateObject.setEnabled(false);
    moveDown.setEnabled(false);
    moveUp.setEnabled(false);
    removeAnimationObject.setEnabled(false);
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 3 with AnimationObject

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

the class TimelineEditor method addAnimationObjectActionPerformed.

private void addAnimationObjectActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_addAnimationObjectActionPerformed
    AnimationObjectEditor editor = new AnimationObjectEditor(res, null, getValue(duration));
    editor.setStartTime(timeline.getValue());
    int ok = JOptionPane.showConfirmDialog(this, editor, "Add", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (ok == JOptionPane.OK_OPTION) {
        ((AnimationObjectTableModel) animationObjectList.getModel()).addElement(editor.getAnimationObject());
        Timeline t = (Timeline) res.getImage(name);
        AnimationObject[] animations = new AnimationObject[t.getAnimationCount() + 1];
        for (int iter = 0; iter < animations.length - 1; iter++) {
            animations[iter] = t.getAnimation(iter);
        }
        animations[animations.length - 1] = editor.getAnimationObject();
        Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
        nt.setPause(t.isPause());
        nt.setTime(t.getTime());
        setImage(nt);
    }
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 4 with AnimationObject

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

the class TimelineEditor method updatePosition.

public void updatePosition(int x, int y, AnimationObject o, boolean startingPoint) {
    AnimationObjectTableModel dl = (AnimationObjectTableModel) animationObjectList.getModel();
    int index = -1;
    for (int iter = 0; iter < animationObjectList.getModel().getRowCount(); iter++) {
        if (dl.getElementAt(iter) == o) {
            index = iter;
            break;
        }
    }
    Timeline t = (Timeline) TimelineEditor.this.res.getImage(TimelineEditor.this.name);
    AnimationObjectEditor editor = new AnimationObjectEditor(TimelineEditor.this.res, o, t.getDuration());
    if (x > -1) {
        editor.updatePosition(x, y, startingPoint);
    }
    int ok = JOptionPane.showConfirmDialog(TimelineEditor.this, editor, "Edit", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (ok == JOptionPane.OK_OPTION) {
        if (index < 0) {
            return;
        }
        dl.setElementAt(editor.getAnimationObject(), index);
        AnimationObject[] animations = new AnimationObject[t.getAnimationCount()];
        for (int iter = 0; iter < animations.length; iter++) {
            animations[iter] = t.getAnimation(iter);
        }
        animations[index] = editor.getAnimationObject();
        boolean paused = t.isPause();
        int oldTime = t.getTime();
        t = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
        t.setPause(paused);
        t.setTime(oldTime);
        setImage(t);
    }
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 5 with AnimationObject

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

the class TimelineEditor method moveDownActionPerformed.

// GEN-LAST:event_moveUpActionPerformed
private void moveDownActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_moveDownActionPerformed
    int i = animationObjectList.getSelectedRow();
    Timeline t = cloneCurrentTimeline();
    AnimationObject[] animations = new AnimationObject[t.getAnimationCount()];
    for (int iter = 0; iter < animations.length; iter++) {
        animations[iter] = t.getAnimation(iter);
    }
    AnimationObject o = animations[i + 1];
    animations[i + 1] = animations[i];
    animations[i] = o;
    Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    setImage(nt);
    moveDown.setEnabled(i < animations.length - 1);
    moveUp.setEnabled(true);
    animationObjectList.getSelectionModel().setSelectionInterval(i + 1, i + 1);
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Aggregations

AnimationObject (com.codename1.ui.animations.AnimationObject)14 Timeline (com.codename1.ui.animations.Timeline)11 Point (java.awt.Point)8 EncodedImage (com.codename1.ui.EncodedImage)2 Motion (com.codename1.ui.animations.Motion)2 BufferedImage (java.awt.image.BufferedImage)2 Image (com.codename1.ui.Image)1 Dimension (com.codename1.ui.geom.Dimension)1 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 MouseListener (java.awt.event.MouseListener)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ImageReader (javax.imageio.ImageReader)1