1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/script/jfx/flyingimage.js Mon Oct 21 13:31:03 2013 +0400 1.3 @@ -0,0 +1,83 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * Testing JavaFX canvas run by Nashorn. 1.29 + * 1.30 + * @test/nocompare 1.31 + * @run 1.32 + * @fork 1.33 + */ 1.34 + 1.35 +TESTNAME = "flyingimage"; 1.36 + 1.37 +var Image = Java.type("javafx.scene.image.Image"); 1.38 +var Color = Java.type("javafx.scene.paint.Color"); 1.39 +var Canvas = Java.type("javafx.scene.canvas.Canvas"); 1.40 +var BorderPane = Java.type("javafx.scene.layout.BorderPane"); 1.41 +var StackPane = Java.type("javafx.scene.layout.StackPane"); 1.42 +var Font = Java.type("javafx.scene.text.Font"); 1.43 +var FontSmoothingType = Java.type("javafx.scene.text.FontSmoothingType"); 1.44 +var Text = Java.type("javafx.scene.text.Text"); 1.45 + 1.46 +var WIDTH = 800; 1.47 +var HEIGHT = 600; 1.48 +var canvas = new Canvas(WIDTH, HEIGHT); 1.49 +function fileToURL(file) { 1.50 + return new File(file).toURI().toURL().toExternalForm(); 1.51 +} 1.52 +var imageUrl = fileToURL(__DIR__ + "flyingimage/flyingimage.png"); 1.53 +var img = new Image(imageUrl); 1.54 +var font = new Font("Arial", 16); 1.55 +var t = 0; 1.56 +var isFrameRendered = false; 1.57 +function renderFrame() { 1.58 + var gc = canvas.graphicsContext2D; 1.59 + gc.setFill(Color.web("#cccccc")); 1.60 + gc.fillRect(0, 0, WIDTH, HEIGHT); 1.61 + gc.setStroke(Color.web("#000000")); 1.62 + gc.setLineWidth(1); 1.63 + gc.strokeRect(5, 5, WIDTH - 10, HEIGHT - 10); 1.64 + var c = 200; 1.65 + var msc= 0.5 * HEIGHT / img.height; 1.66 + var sp0 = 0.003; 1.67 + for (var h = 0; h < c; h++, t++) { 1.68 + gc.setTransform(1, 0, 0, 1, 0, 0); 1.69 + var yh = h / (c - 1); 1.70 + gc.translate((0.5 + Math.sin(t * sp0 + h * 0.1) / 3) * WIDTH, 25 + (HEIGHT * 3 / 4 - 40) * (yh * yh)); 1.71 + var sc = 30 / img.height + msc * yh * yh; 1.72 + gc.rotate(90 * Math.sin(t * sp0 + h * 0.1 + Math.PI)); 1.73 + gc.scale(sc, sc); 1.74 + gc.drawImage(img, -img.width / 2, -img.height / 2); 1.75 + } 1.76 + gc.setTransform(1, 0, 0, 1, 0, 0); 1.77 + isFrameRendered = true; 1.78 +} 1.79 +var stack = new StackPane(); 1.80 +var pane = new BorderPane(); 1.81 + 1.82 +pane.setCenter(canvas); 1.83 +stack.getChildren().add(pane); 1.84 +$STAGE.scene = new Scene(stack); 1.85 +renderFrame(); 1.86 +checkImageAndExit();