/*
* 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 carousel;
import javafx.util.Math;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.lang.Duration;
import javafx.lang.FX;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.*;
import javafx.scene.paint.*;
import javafx.scene.Scene;
import javafx.scene.shape.*;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.layout.LayoutInfo;
import carousel.Carousel;
var carousel:Carousel[];
var im:String[] = [
"{__DIR__}im1.PNG",
"{__DIR__}im2.PNG",
"{__DIR__}im3.PNG",
"{__DIR__}im4.PNG",
"{__DIR__}im5.PNG",
"{__DIR__}im6.PNG"
];
var s_left:Image = Image {
url: "{__DIR__}leftlight.png"
};
var s_leftglow:Image = Image {
url: "{__DIR__}left.png"
};
var s_right:Image = Image {
url: "{__DIR__}rightlight.png"
};
var s_rightglow:Image = Image {
url: "{__DIR__}right.png"
};
var s_right_d = s_right;
var s_left_d = s_left;
var dur:Duration = 15ms;
var width:Number = bind scene.width;
var height:Number = bind scene.height;
def _arcDim = 5;
def _navigator = 30;
def _repeatCount = 21;
def _imgXPadding = 70;
def rectLayoutHgt = 25;
def imgXDimension = 40;
for(i in [0..5]) {
insert Carousel {
X: Math.cos(Carousel.angle + i * Carousel.image_gap +
Carousel.shift) * Carousel.radius_x + Carousel.xcenter;
Y: -Math .sin(Carousel.angle + i * Carousel.image_gap +
Carousel.shift) * Carousel.radius_y + Carousel.ycenter
Z: Math.sin(Carousel.angle + i * Carousel.image_gap +
Carousel.shift) * Carousel.radius + Carousel.zcenter
local_opacity: Carousel.fl / (Carousel.fl + Math.sin(Carousel.angle +
i * Carousel.image_gap + Carousel.shift) * Carousel.radius
+ Carousel.zcenter)
scale: Carousel.fl / (Carousel.fl + Math.sin(Carousel.angle +
i * Carousel.image_gap + Carousel.shift) * Carousel.radius
+ Carousel.zcenter)
image: bind Image {
url: im[i]
}
} into carousel
}
var timeline = Timeline {
repeatCount: _repeatCount
keyFrames: [
KeyFrame {
time: dur
action: function() {
Carousel.angle_rad = Carousel.angle_rad + Math.PI / 60;
for(i in [0..5]) {
carousel[i].update(i,Carousel.angle_rad);
}
}
}
]
}timeline.play();
var timeline_rev = Timeline {
repeatCount: _repeatCount
keyFrames: [
KeyFrame {
time: dur
action: function() {
Carousel.angle_rad = Carousel.angle_rad - Math.PI / 60;
for(i in [0..5]) {
carousel[i].update(i,Carousel.angle_rad);
}
}
}
]
}
var gp = Group {
onKeyPressed:function(e:KeyEvent):Void {
if (__PROFILE__ != "tv") {
if((e.code == KeyCode.VK_LEFT) or (e.code == KeyCode.VK_TRACK_PREV)) {
timeline_rev.play();
}
if((e.code == KeyCode.VK_RIGHT) or (e.code == KeyCode.VK_TRACK_NEXT)) {
timeline.play();
}
if((e.code == KeyCode.VK_Q) or (e.code == KeyCode.VK_POWER)) {
FX.exit();
}
} else {
if(e.code == KeyCode.VK_LEFT) {
timeline_rev.play();
}
if(e.code == KeyCode.VK_RIGHT) {
timeline.play();
}
if(e.code == KeyCode.VK_Q) {
FX.exit();
}
}
}
layoutX: bind (width - 240) * 0.5;
layoutY: bind (height - 320) * 0.25;
content: [
carousel,
]
};
var scene:Scene = Scene {
fill: Color.BLACK
content: [
Rectangle {
x: 0
y: bind height - _navigator
layoutInfo:LayoutInfo{
width: bind width
height: rectLayoutHgt
}
arcHeight:_arcDim
arcWidth:_arcDim
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
proportional: true
stops: [
Stop {
offset: 0.0
color: Color.GRAY },
Stop {
offset: 0.5
color: Color.BLACK },
Stop {
offset: 1.0
color: Color.GRAY }
]
}
opacity:0.5
},
ImageView {
x: imgXDimension
y: bind height - _navigator
image: bind s_left
cursor: Cursor.HAND
onMouseClicked: function( e: MouseEvent ):Void {
s_left = s_leftglow;
timeline_rev.play();
}
onMouseMoved: function( e: MouseEvent ):Void {
s_left = s_leftglow;
}
onMouseExited: function( e: MouseEvent ):Void {
s_left = s_left_d;
}
},
ImageView {
x: bind width - _imgXPadding
y: bind height - _navigator
image: bind s_right
cursor: Cursor.HAND
onMouseClicked: function( e: MouseEvent ):Void {
s_right = s_rightglow;
timeline.play();
}
onMouseMoved: function( e: MouseEvent ):Void {
s_right = s_rightglow;
}
onMouseExited: function( e: MouseEvent ):Void {
s_right = s_right_d;
}
}
]
};
insert gp into scene.content;
var stage = Stage{
title: "Carousel Application"
width: if (__PROFILE__ != "tv") then 240 else 1280
height: if (__PROFILE__ != "tv") then 320 else 720
style: StageStyle.TRANSPARENT
scene: scene
}
gp.requestFocus();
stage;