You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/07/01 14:24:27 UTC
svn commit: r790138 -
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java
Author: tvolkert
Date: Wed Jul 1 12:24:27 2009
New Revision: 790138
URL: http://svn.apache.org/viewvc?rev=790138&view=rev
Log:
PIVOT-152 :: Move flip transition into CardPaneSkin
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java?rev=790138&r1=790137&r2=790138&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/CardPaneSkin.java Wed Jul 1 12:24:27 2009
@@ -24,6 +24,7 @@
import org.apache.pivot.wtk.Container;
import org.apache.pivot.wtk.Dimensions;
import org.apache.pivot.wtk.effects.FadeDecorator;
+import org.apache.pivot.wtk.effects.ScaleDecorator;
import org.apache.pivot.wtk.effects.Transition;
import org.apache.pivot.wtk.effects.TransitionListener;
import org.apache.pivot.wtk.effects.easing.Easing;
@@ -44,7 +45,8 @@
public enum SelectionChangeEffect {
CROSSFADE,
HORIZONTAL_SLIDE,
- VERTICAL_SLIDE
+ VERTICAL_SLIDE,
+ FLIP;
}
/**
@@ -57,7 +59,11 @@
public final Component toCard;
public SelectionChangeTransition(int from, int to) {
- super(SELECTION_CHANGE_DURATION, SELECTION_CHANGE_RATE, false);
+ this(from, to, SELECTION_CHANGE_DURATION);
+ }
+
+ public SelectionChangeTransition(int from, int to, int duration) {
+ super(duration, SELECTION_CHANGE_RATE, false);
CardPane cardPane = (CardPane)getComponent();
fromCard = (from == -1) ? null : cardPane.get(from);
@@ -70,7 +76,7 @@
*
* @author gbrown
*/
- public class CrossfadeTransition extends SelectionChangeTransition {
+ public final class CrossfadeTransition extends SelectionChangeTransition {
private FadeDecorator fadeOutDecorator = new FadeDecorator();
private FadeDecorator fadeInDecorator = new FadeDecorator();
@@ -126,7 +132,7 @@
*
* @author gbrown
*/
- public class SlideTransition extends SelectionChangeTransition {
+ public final class SlideTransition extends SelectionChangeTransition {
private int direction;
private Easing slideEasing = new Quartic();
@@ -170,6 +176,52 @@
}
}
+ /**
+ * Class that performs flip selection change transitions.
+ *
+ * @author tvolkert
+ */
+ public final class FlipTransition extends SelectionChangeTransition {
+ private double theta;
+ private ScaleDecorator scaleDecorator = new ScaleDecorator();
+
+ public FlipTransition(int from, int to) {
+ super(from, to, 350);
+ }
+
+ @Override
+ public void start(TransitionListener transitionListener) {
+ theta = 0;
+ getComponent().getDecorators().add(scaleDecorator);
+
+ super.start(transitionListener);
+ }
+
+ @Override
+ public void stop() {
+ getComponent().getDecorators().remove(scaleDecorator);
+
+ super.stop();
+ }
+
+ @Override
+ protected void update() {
+ float percentComplete = getPercentComplete();
+
+ if (percentComplete < 1f) {
+ theta = Math.PI * percentComplete;
+
+ float scaleY = (float)Math.abs(Math.cos(theta));
+ scaleDecorator.setScaleY(Math.max(scaleY, 0.01f));
+
+ fromCard.setVisible(theta < Math.PI / 2);
+ toCard.setVisible(theta >= Math.PI / 2);
+
+ repaintComponent();
+ }
+ }
+ }
+
private boolean sizeToSelection = false;
private SelectionChangeEffect selectionChangeEffect = null;
@@ -376,7 +428,7 @@
&& selectionChangeTransition == null) {
int previousSelectedIndex = cardPane.getSelectedIndex();
- switch(selectionChangeEffect) {
+ switch (selectionChangeEffect) {
case CROSSFADE: {
selectionChangeTransition = new CrossfadeTransition(previousSelectedIndex, selectedIndex);
break;
@@ -390,6 +442,14 @@
}
break;
}
+
+ case FLIP: {
+ if (previousSelectedIndex != -1
+ && selectedIndex != -1) {
+ selectionChangeTransition = new FlipTransition(previousSelectedIndex, selectedIndex);
+ }
+ break;
+ }
}
if (selectionChangeTransition != null) {