/*
* 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 effectsplaygroundmobile;
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.image.*;
import javafx.scene.paint.*;
import javafx.scene.input.*;
import javafx.scene.layout.*;
import javafx.scene.text.*;
import javafx.util.Sequences;
public class Core {
public var scaleFactor = 1.0 on replace {
title = Text {
fill: Color.WHITE
content: bind selectedButton.title
font: Font {size: 12*scaleFactor}
}
}
public def photoView = PhotoView {
scaleFactor: bind scaleFactor
image: Image { url: "{__DIR__}images/main_image.png" }
cropActive: bind selectedButton.id == "Crop"
funActive: bind selectedButton.title == "Fun Stuff"
}
public var controls1:HBox = HBox {
opacity: 1.0
blocksMouse: true
spacing: bind 5*scaleFactor
content: [
Button {
title: "Flip"
fill: Color.GREEN core: this text: "Flip"
scaleFactor: bind scaleFactor
imageURL: "{__DIR__}images/button-flip.png"
subControls : HBox {
spacing: bind 10*scaleFactor
content: [
ImageButton {
scaleFactor: bind scaleFactor
url: "icon-flip_horiz"
action: photoView.flipHorz
hasHighlightImage: true
},
ImageButton {
scaleFactor: bind scaleFactor
url: "icon-flip_vert"
action: photoView.flipVert
hasHighlightImage: true
},
]
}
restoreAction: photoView.resetFlip;
},
Button {
title: "Rotate"
fill: Color.LIGHTBLUE core: this text: "Rot"
scaleFactor: bind scaleFactor
imageURL: "{__DIR__}images/button-rotate.png"
subControls : HBox {
spacing: bind 10*scaleFactor
content: [
ImageButton {
scaleFactor: bind scaleFactor
url: "icon-rotate_left"
action: photoView.rotateCCW
hasHighlightImage: true
},
ImageButton {
scaleFactor: bind scaleFactor
url: "icon-rotate_right"
action: photoView.rotateCW
hasHighlightImage: true
},
]
}
restoreAction: photoView.resetRotate;
},
Button {
title: "Lighten Effect"
fill: Color.RED core: this text: "Light"
imageURL: "{__DIR__}images/button-lighten.png"
scaleFactor: bind scaleFactor
subControls: ImageSlider {
scaleFactor: bind scaleFactor
minimum: 0.0 maximum: 100.0
value: bind photoView.lightness with inverse
}
restoreAction: function():Void {
photoView.lightness = 0.0;
}
},
Button {
title: "Darken Effect"
fill: Color.YELLOW core: this text: "Dark"
scaleFactor: bind scaleFactor
imageURL: "{__DIR__}images/button-darken.png"
subControls: ImageSlider {
scaleFactor: bind scaleFactor
minimum: 0.0 maximum: 100.0
value: bind photoView.darkness with inverse
}
restoreAction: function():Void {
photoView.darkness = 0.0;
}
},
VBox {
content: [
ImageButton {
scaleFactor: bind scaleFactor
url: "arrow-up"
enabled: false
hasHighlightImage: true
},
ImageButton {
scaleFactor: bind scaleFactor
url: "arrow-down"
enabled: true
hasHighlightImage: true
hasActiveImage: true
action: function():Void {
controls1.opacity = 0.001;
controls1.blocksMouse = false;
controls2.opacity = 1.0;
controls2.blocksMouse = true;
}
},
]
}
]
};
public var controls2:HBox = HBox {
opacity: 0.001
blocksMouse: false
spacing: bind 5*scaleFactor
content: [
Button {
title: "Sepia Effect"
fill: Color.PURPLE core: this text: "Sepi"
scaleFactor: bind scaleFactor
imageURL: "{__DIR__}images/button-sepia.png"
subControls: ImageSlider {
scaleFactor: bind scaleFactor
minimum: 0.0 maximum: 100.0
value: bind photoView.sepia with inverse
}
restoreAction: function():Void {
photoView.sepia = 0.0;
}
},
Button {
title: "Frames"
fill: Color.PINK core: this text: "Fram"
scaleFactor: bind scaleFactor
imageURL: "{__DIR__}images/button-frames.png"
subControls: HBox {
spacing: bind 5*scaleFactor
content: [
ImageButton {
scaleFactor: bind scaleFactor
url: "button-frame-blue"
action: function():Void {
photoView.frameImage = Image { url: "{__DIR__}images/frame-blue.png" }
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "button-frame-gold"
action: function():Void {
photoView.frameImage = Image { url: "{__DIR__}images/frame-gold.png" }
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "button-frame-red"
action: function():Void {
photoView.frameImage = Image { url: "{__DIR__}images/frame-red.png" }
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "button-frame-yellow"
action: function():Void {
photoView.frameImage = Image { url: "{__DIR__}images/frame-yellow.png" }
}
},
]
}
restoreAction: function():Void {
photoView.frameImage = null;
}
},
Button {
title: "Fun Stuff"
fill: Color.CADETBLUE core: this text: "Fun"
scaleFactor: bind scaleFactor
imageURL: "{__DIR__}images/button-fun.png"
subControls: HBox {
spacing: bind 5*scaleFactor
content: [
ImageButton {
scaleFactor: bind scaleFactor
url: "button-fun-ants"
action: function():Void {
photoView.funImage = Image { url: "{__DIR__}images/fun-ants.png" }
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "button-fun-face"
action: function():Void {
photoView.funImage = Image { url: "{__DIR__}images/fun-face.png" }
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "button-fun-hat"
action: function():Void {
photoView.funImage = Image { url: "{__DIR__}images/fun-hat.png" }
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "button-fun-hearts"
action: function():Void {
photoView.funImage = Image { url: "{__DIR__}images/fun-hearts.png" }
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "button-fun-stars"
action: function():Void {
photoView.funImage = Image { url: "{__DIR__}images/fun-stars.png" }
}
},
]
}
restoreAction: function():Void {
photoView.funImage = null;
}
},
Button {
id: "Crop"
title: "Scale and Crop"
fill: Color.ORANGE
core: this
text: "Scale and Crop"
scaleFactor: bind scaleFactor
imageURL: "{__DIR__}images/button-crop.png"
subControls: HBox {
spacing: bind 10*scaleFactor
content:[
ImageSlider {
scaleFactor: bind scaleFactor
minimum: 0.1 maximum: 200.0
value: bind photoView.zoomValue with inverse
},
ImageButton {
scaleFactor: bind scaleFactor
url: "icon-crop"
action: photoView.crop
hasHighlightImage: true
},
]
}
restoreAction: function():Void {
photoView.resetCrop();
photoView.resetZoom();
}
},
VBox {
content:[
ImageButton {
scaleFactor: bind scaleFactor
url: "arrow-up"
enabled: true
hasActiveImage: true
hasHighlightImage: true
action: function():Void {
controls1.opacity = 1.0;
controls1.blocksMouse = true;
controls2.opacity = 0.001;
controls2.blocksMouse = false;
}
},
ImageButton {
scaleFactor: bind scaleFactor
url: "arrow-down"
enabled: false
hasHighlightImage: true
},
]
}
]
}
var restoreActions: (function(): Void)[];
public function restore(): Void {
for(restoreAction in restoreActions) {
restoreAction();
}
restoreActions = [selectedButton.restoreAction];
}
public var selectedButton:Button on replace {
if (selectedButton != null and Sequences.indexByIdentity(restoreActions, selectedButton.restoreAction) < 0) {
insert selectedButton.restoreAction into restoreActions;
}
};
public var title: Text;
}