use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class ResourceEditorView method isInUse.
/**
* Returns true if the given image is used by a theme or timeline animation,
* false otherwise.
*/
private boolean isInUse(String imageName) {
Object multi = loadedResources.getResourceObject(imageName);
if (multi instanceof EditableResources.MultiImage) {
EditableResources.MultiImage m = (EditableResources.MultiImage) multi;
for (com.codename1.ui.Image i : m.getInternalImages()) {
if (isInUse(i)) {
return true;
}
}
return false;
}
com.codename1.ui.Image resourceValue = loadedResources.getImage(imageName);
return isInUse(resourceValue);
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class PulsateEditor method updateTimeline.
private void updateTimeline() {
AnimationObject[] anim = new AnimationObject[get(frames) * 2 - 1];
internalImages = new EncodedImage[get(frames)];
int small = Math.min(get(smallSize), get(largeSize));
int large = Math.max(get(smallSize), get(largeSize));
int dur = get(duration);
int segment = dur / anim.length;
Motion calculator = Motion.createSplineMotion(small, large, dur / 2);
float ratioOfLargest = ((float) large) / 100.0f;
int timelineWidth = (int) (ratioOfLargest * ((float) sourceImage.getWidth()));
int timelineHeight = (int) (ratioOfLargest * ((float) sourceImage.getHeight()));
for (int iter = 0; iter < internalImages.length; iter++) {
calculator.setCurrentMotionTime(segment * iter);
int percentAtTime = calculator.getValue();
float ratioAtTime = ((float) percentAtTime) / 100.0f;
int currentWidth = (int) (sourceImage.getWidth() * ratioAtTime);
int currentHeight = (int) (sourceImage.getHeight() * ratioAtTime);
internalImages[iter] = EncodedImage.create(scale(sourceImage, currentWidth, currentHeight));
anim[iter] = AnimationObject.createAnimationImage(internalImages[iter], (timelineWidth - currentWidth) / 2, (timelineHeight - currentHeight) / 2);
anim[iter].setStartTime(segment * iter);
anim[iter].setEndTime(segment * iter + segment);
// peek at the next frame to calculate the diff
calculator.setCurrentMotionTime(segment * iter + segment);
int percentAtNextFrame = calculator.getValue();
float ratioAtNextFrame = ((float) percentAtNextFrame) / 100.0f;
int nextWidth = (int) (sourceImage.getWidth() * ratioAtNextFrame);
int nextHeight = (int) (sourceImage.getHeight() * ratioAtNextFrame);
anim[iter].defineHeight(AnimationObject.MOTION_TYPE_SPLINE, segment * iter, segment, currentHeight, nextHeight);
anim[iter].defineWidth(AnimationObject.MOTION_TYPE_SPLINE, segment * iter, segment, currentWidth, nextWidth);
anim[iter].defineMotionX(AnimationObject.MOTION_TYPE_SPLINE, segment * iter, segment, (timelineWidth - currentWidth) / 2, (timelineWidth - nextWidth) / 2);
anim[iter].defineMotionY(AnimationObject.MOTION_TYPE_SPLINE, segment * iter, segment, (timelineHeight - currentHeight) / 2, (timelineHeight - nextHeight) / 2);
// create the "inverse" shrinking animation object
if (iter > 0) {
int nextOffset = anim.length - iter;
anim[nextOffset] = AnimationObject.createAnimationImage(internalImages[iter], (timelineWidth - currentWidth) / 2, (timelineHeight - currentHeight) / 2);
anim[nextOffset].setStartTime(segment * nextOffset);
if (iter == 1) {
// this resolves any rounding errors that might have occured in the creation of the frames
anim[nextOffset].setEndTime(dur);
} else {
anim[nextOffset].setEndTime(segment * nextOffset + segment);
}
// peek at the previous frame to calculate the diff
calculator.setCurrentMotionTime(segment * iter - segment);
int percentAtPreviousFrame = calculator.getValue();
float ratioAtPreviousFrame = ((float) percentAtPreviousFrame) / 100.0f;
int previousWidth = (int) (sourceImage.getWidth() * ratioAtPreviousFrame);
int previousHeight = (int) (sourceImage.getHeight() * ratioAtPreviousFrame);
anim[nextOffset].defineHeight(AnimationObject.MOTION_TYPE_SPLINE, segment * nextOffset, segment, currentHeight, previousHeight);
anim[nextOffset].defineWidth(AnimationObject.MOTION_TYPE_SPLINE, segment * nextOffset, segment, currentWidth, previousWidth);
anim[nextOffset].defineMotionX(AnimationObject.MOTION_TYPE_SPLINE, segment * nextOffset, segment, (timelineWidth - currentWidth) / 2, (timelineWidth - previousWidth) / 2);
anim[nextOffset].defineMotionY(AnimationObject.MOTION_TYPE_SPLINE, segment * nextOffset, segment, (timelineHeight - currentHeight) / 2, (timelineHeight - previousHeight) / 2);
}
}
currentImage = Timeline.createTimeline(dur, anim, new com.codename1.ui.geom.Dimension(timelineWidth, timelineHeight));
previewLabel.setIcon(currentImage);
previewLabel.repaint();
preview.repaint();
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class InfiniteProgress method initComponent.
/**
* {@inheritDoc}
*/
protected void initComponent() {
super.initComponent();
if (animation == null) {
animation = UIManager.getInstance().getThemeImageConstant("infiniteImage");
}
Form f = getComponentForm();
if (f != null) {
f.registerAnimated(this);
}
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class InfiniteProgress method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
if (this.getComponentForm() != null && Display.getInstance().getCurrent() != this.getComponentForm()) {
return;
}
super.paint(g);
if (animation == null) {
return;
}
int v = angle % 360;
Style s = getStyle();
/*if(g.isAffineSupported()) {
g.rotate(((float)v) / 57.2957795f, getAbsoluteX() + s.getPadding(LEFT) + getWidth() / 2, getAbsoluteY() + s.getPadding(TOP) + getHeight() / 2);
g.drawImage(getAnimation(), getX() + s.getPadding(LEFT), getY() + s.getPadding(TOP));
g.resetAffine();
} else {*/
Image rotated;
if (animation instanceof FontImage) {
rotated = animation.rotate(v);
} else {
Integer angle = new Integer(v);
rotated = cache.get(angle);
if (rotated == null) {
rotated = animation.rotate(v);
cache.put(v, rotated);
}
}
g.drawImage(rotated, getX() + s.getPaddingLeftNoRTL(), getY() + s.getPaddingTop());
// }
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class InteractionDialog method disposeToTheLeft.
/**
* Removes the interaction dialog from view with an animation to the left
*/
public void disposeToTheLeft() {
disposed = true;
final Container p = getParent();
if (p != null) {
final Form f = p.getComponentForm();
if (f != null) {
setX(-getWidth());
if (animateShow) {
p.animateUnlayout(400, 255, new Runnable() {
public void run() {
if (p.getParent() != null) {
Container pp = getLayeredPane(f);
remove();
p.remove();
pp.removeAll();
pp.revalidate();
cleanupLayer(f);
}
}
});
} else {
p.revalidate();
Container pp = getLayeredPane(f);
remove();
p.remove();
pp.removeAll();
pp.revalidate();
}
} else {
remove();
}
}
}
Aggregations