📄 transitionanimation.java
字号:
/* * Fire (Flexible Interface Rendering Engine) is a set of graphics widgets for creating GUIs for j2me applications. * Copyright (C) 2006-2008 Bluevibe (www.bluevibe.net) * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * *//** * */package gr.fire.ui;import gr.fire.core.Animation;import gr.fire.core.Component;import gr.fire.core.FireScreen;import javax.microedition.lcdui.Graphics;/** * @author padeler * */public class TransitionAnimation extends Animation{ public static final int TRANSITION_NONE = 0x00000000; public static final int TRANSITION_LEFT = 0x00000001; public static final int TRANSITION_RIGHT = 0x00000002; public static final int TRANSITION_CARD = 0x00000100; public static final int TRANSITION_SCROLL= 0x00000200; public static final int TRANSITION_FLIP= 0x00000400; public static final long MILISECONDS_PER_FRAME=40; public static final int FRAMES = 6; // number of frames in this animation. private Component owner; private Component trigger; private int properties; private int frameCount=0; private long lastFrame; private int width, height,diff; private int animationX,animationY; public void paint(Graphics dest) { int transition = properties&0x0000FF00; switch(transition) { case TRANSITION_CARD: { Graphics g = dest; g.translate(-g.getTranslateX()+animationX,-g.getTranslateY()+animationY); g.setClip(0,0,width,height); owner.paint(g); g.setColor(0x00000000); g.translate(-g.getTranslateX()+animationX,-g.getTranslateY()+animationY); g.setClip(0,0,width,height); g.drawRect(0,0,width-1,height-1); break; } case TRANSITION_FLIP: break; case TRANSITION_SCROLL: { Graphics g = dest; if((properties&0x000000FF)==TRANSITION_RIGHT) { g.translate(-g.getTranslateX()+animationX,-g.getTranslateY()); g.setClip(0,0,width,height); owner.paint(g); // paint the component that is comming g.translate(-g.getTranslateX()+width+animationX,-g.getTranslateY()); g.setClip(0,0,width,height); trigger.paint(g); // paint the component that is leaving. } else { g.translate(-g.getTranslateX()+animationX,-g.getTranslateY()); g.setClip(0,0,width,height); owner.paint(g); // paint the component that is comming g.translate(-g.getTranslateX()-width+animationX,-g.getTranslateY()); g.setClip(0,0,width,height); trigger.paint(g); // paint the component that is leaving. } break; } } } public Component getOwner() { return owner; } public Object getProperties() { return new Integer(properties); } public Component getTrigger() { return trigger; } public boolean isRunning() { return (frameCount<FRAMES); } public void setup(Component owner, Component trigger, Object prop) { if(owner==null || trigger==null || prop==null || (prop instanceof Integer)==false) throw new IllegalArgumentException("Owner and trigger components cannot be null, properties is an Integer"); this.owner = owner; this.trigger= trigger; this.properties = ((Integer)prop).intValue(); FireScreen screen = FireScreen.getScreen(); width = screen.getWidth(); height = screen.getHeight(); diff = width/FRAMES; int direction = properties & 0x000000FF; if(direction==TRANSITION_LEFT) { animationX = width; } else if(direction==TRANSITION_RIGHT) { animationX=-width; } animationY = 0; lastFrame = System.currentTimeMillis(); } public boolean step() { long now = System.currentTimeMillis(); if(now-lastFrame>=MILISECONDS_PER_FRAME) { lastFrame=now; frameCount++; int direction = properties & 0x000000FF; switch (direction) { case TRANSITION_LEFT: animationX -= diff; break; case TRANSITION_RIGHT: animationX += diff; break; } return true; } return false; } /* (non-Javadoc) * @see gr.fire.core.Animation#stop() */ public void stop() { frameCount = FRAMES; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -