/*
 * BlendMode.fx
 *
 * Created on 11 Mar, 2009, 10:03:47 PM
 */

package blendmode;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.effect.BlendMode;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextOrigin;
import javafx.stage.Stage;

/**
 @author Rakesh Menon
 */

var blendMode: BlendMode[] [
    BlendMode.ADD,
    BlendMode.BLUE,
    BlendMode.COLOR_BURN,
    BlendMode.COLOR_DODGE,
    BlendMode.DARKEN,
    BlendMode.DIFFERENCE,
    BlendMode.EXCLUSION,
    BlendMode.GREEN,
    BlendMode.HARD_LIGHT,
    BlendMode.LIGHTEN,
    BlendMode.MULTIPLY,
    BlendMode.OVERLAY,
    BlendMode.RED,
    BlendMode.SOFT_LIGHT,
    BlendMode.SRC_ATOP,
    BlendMode.SRC_IN,
    BlendMode.SRC_OUT,
    BlendMode.SRC_OVER
];

var index = 0;
var timeline: Timeline = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
        KeyFrame {
            time: 5s
            action: function() {
                if(index < ((sizeof blendMode1)) {
                    index++;
                else {
                    index = 0;
                }
            }
        }
    ]
};
timeline.play();

var blendGroup = Group {
    
    // Specify BlendMode
    blendMode: bind blendMode[index]
    
    content: [
        ImageView {
            image: Image {
                url: "{__DIR__}images/sky.jpg"
            }
        },
        ImageView {
            image: Image {
                url: "{__DIR__}images/baloon.jpg"
            }
        },
    ]
    
    translateX: 5
    translateY: 5
};

var blendText: Text = Text {
    content: bind "{blendMode[index]}"
    font: Font {
        name: "Bitstream Vera Sans Bold"
        size: 20
    }
    textOrigin: TextOrigin.TOP
    fill: Color.WHITE
    translateY: 425
    translateX: bind (266 - blendText.boundsInLocal.width2.0
};

Stage {
    scene: Scene {
        content: blendGroup, blendText ]
        width: 276
        height: 460
        fill: Color.BLACK
    }
    title: "Blend Mode"
    resizable: false
}