/*
 * MainScreen.fx
 *
 * Created on Mar 23, 2010, 1:01:59 PM
 */
package vismobile;

import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.control.Slider;
import javafx.scene.transform.Scale;
import javafx.scene.input.MouseEvent;

/**
 * @author Student
 */
public class MainScreen extends Scene {

    var myRect: Rectangle;
    var mySlide: Slider;
    override var content = [
                Group {
                    translateY: bind 0 - mySlide.value * 30
                    content: [
                        VBox {
                            spacing: 0
                            content: [
                                Apps {
                                    id: "CarContextCourse"
                                    index: 1
                                    image: "course_lg"
                                    desc: "Course Context"
                                }
                                Apps {
                                    id: "CarContextFine"
                                    index: 2
                                    image: "fine_lg"
                                    desc: "Fine Context"
                                }
                                Apps {
                                    id: "Pedestrian"
                                    index: 3
                                    image: "pedestrian_lg"
                                    desc: "Pedestrian App"
                                }
                                Apps {
                                    id: "Gov"
                                    index: 4
                                    image: "gov20_lg"
                                    desc: "Gov 2.0"
                                }
                                Apps {
                                    id: "AdvisoryAlert"
                                    index: 5
                                    image: "alert_lg"
                                    desc: "Advisory Alert"
                                }
                                 Apps {
                                    id: "VMS"
                                    index: 6
                                    image: "vms_lg"
                                    desc: "VMS"
                                }
                                Apps {
                                    id: "Weather"
                                    index: 7
                                    image: "weather_lg"
                                    desc: "Weather"
                                }
                                Apps {
                                    id: "Config"
                                    index: 8
                                    image: "config_lg"
                                    desc: "Configuration"
                                }
                                 Apps {
                                    id: "ConstructionZone"
                                    index: 9
                                    image: "construction_lg"
                                    desc: "Costruction Zone"
                                }
                                Apps {
                                    id: "PoliceCar"
                                    index: 10
                                    image: "police_lg"
                                    desc: "Police Car"
                                }
                                Apps {
                                    id: "Ambulance"
                                    index: 11
                                    image: "ambulance_lg"
                                    desc: "Ambulance"
                                }
                                Apps {
                                    id: "FireTruck"
                                    index: 12
                                    image: "fire_lg"
                                    desc: "Fire Truck"
                                }
                                Apps {
                                    id: "TowTruck"
                                    index: 13
                                    image: "tow_lg"
                                    desc: "Tow Truck"
                                }
                                Apps {
                                    id: "Fuel"
                                    index: 14
                                    image: "fuel_lg"
                                    desc: "Gas Prices"
                                }
                            ]
                        }
                    ]
                }
                mySlide = Slider {
                    height: (Main.stage.height) / 2 - 8
                    translateX: (Main.stage.width / 5) * 4
                    translateY: 8
                    transforms: [
                        Scale { x: 2 y: 2 }
                    ]
                    blockIncrement: 60
                    clickToPosition: true
                    min: 0
                    max: 10
                    vertical: true
                }
            ]
}

class Apps extends CustomNode {

    var image: String;
    var desc: String = "";
    var index: Integer;

    public override function create(): Node {
        Group {
            var rect: Rectangle;
            var txt: Text;
            var imgView: ImageView;
            blocksMouse: true
            onMousePressed: function (e: MouseEvent): Void {

                Main.scene = Main.scenelist[index];
                Main.activeScene = this.id;

                //(Main.scenelist[index] as AdvisoryAlert).Reset();

            };
            content: [
                rect = Rectangle {
                    width: (Main.stage.width / 4) * 3
                    height: (Main.stage.height / 8)
                    arcWidth: ((Main.stage.width / 4) * 3) / 10
                    arcHeight: (Main.stage.height / 8) / 5
                    fill: null
                    stroke: Color.MEDIUMBLUE
                    strokeWidth: 4
                },
                Rectangle {
                    width: (Main.stage.width / 4) * 3
                    height: (Main.stage.height / 8)
                    arcWidth: ((Main.stage.width / 4) * 3) / 10
                    arcHeight: (Main.stage.height / 8) / 5
                    fill: RadialGradient {
                        centerX: 0.5
                        centerY: 0.5
                        stops: [
                            Stop { offset: 0.0 color: Color.DARKBLUE },
                            Stop { offset: 0.8 color: Color.BLACK }
                        ]
                    }
                },
                //Displays the image
                imgView = ImageView {
                    image: CommonFunctionsFX.getImage(image)
                    fitWidth: (rect.height / 3) * 2
                    translateY: (rect.height / 2) - (rect.height / 3)
                    preserveRatio: true
                    smooth: true
                    cache: true
                }
                txt = Text {
                    font: Font {
                        size: 16
                    }
                    translateX: imgView.boundsInParent.maxX + 10
                    translateY: (rect.height / 2) - (txt.boundsInLocal.height) / 2 + 5;
                    fill: Color.WHITE
                    content: desc
                }
            ]
        }
    }

}
