/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
* Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Oracle Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package whiteout;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.animation.transition.*;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.scene.paint.Color;
public class Splash extends CustomNode {
public-init var env: Env;
def textWhite = Text {
content: "White"
visible: false
translateY: env.screenHeight / 3
font: env.bigFont
fill: Color.WHITE
};
def textOut = Text {
content: "Out"
visible: false
translateY: env.screenHeight / 3
font: env.bigFont
fill: Color.WHITE
};
var buttonY = env.screenHeight + 5;
def startButton: BlueButton = BlueButton {
env: env
text: "Start"
visible: true
translateX: bind (env.screenWidth - startButton.layoutBounds.width) / 2
translateY: bind buttonY
onMouseReleased : function(e: MouseEvent) {
def canvas = Canvas {env: env, opacity: 0.0};
insert canvas into Main.myStage.scene.content;
def fadeToCanvas = Timeline {
keyFrames: [
at (0s) {opacity => 1.0},
at (.4s) {opacity => 0.0},
at (0s) {canvas.opacity => 0.0},
at (1s) {canvas.opacity => 1.0},
KeyFrame {
time: 1s
action: function () {
delete this from Main.myStage.scene.content;
}
}
]
}
fadeToCanvas.play();
}
};
public function transitionIn(){
def spring = SpringInterpolator { bounce: false};
def finalWhiteX = (env.screenWidth - textWhite.layoutBounds.width - textOut.layoutBounds.width - 2) / 2;
def finalOutX = finalWhiteX + textWhite.layoutBounds.width;
def finalButtonY = (.5 * (env.screenHeight +
(textOut.translateY + textOut.layoutBounds.maxY) -
startButton.layoutBounds.height)) as Integer;
textWhite.translateX = -(textWhite.layoutBounds.width + 1);
textWhite.visible = true;
textOut.translateX = env.screenWidth + 1;
textOut.visible = true;
opacity = 0.0;
def opa = Timeline {
keyFrames: [
at (.5s) {opacity => 1.0 tween Interpolator.LINEAR},
at (.8s) {textWhite.translateX => finalWhiteX tween Interpolator.LINEAR},
at (.8s) {textOut.translateX => finalOutX tween Interpolator.LINEAR},
KeyFrame {
time: 1.5s
values: buttonY => finalButtonY tween spring
}
]
}
opa.play();
}
override public function create() : Node {
return Group {
content: [
Rectangle{
fill: env.slateGrad
width: env.screenWidth
height: env.screenHeight
},
textWhite,
textOut,
startButton
]
}
}
}