Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene; 027 028import javafx.application.ConditionalFeature; 029import javafx.application.Platform; 030import javafx.geometry.Rectangle2D; 031import javafx.scene.paint.Paint; 032import javafx.scene.transform.Transform; 033import sun.util.logging.PlatformLogger; 034 035/** 036 * Parameters used to specify the rendering attributes for Node snapshot. 037 * @since 2.2 038 */ 039public class SnapshotParameters { 040 041 private boolean depthBuffer; 042 private Camera camera; 043 private Transform transform; 044 private Paint fill; 045 private Rectangle2D viewport; 046 047 /** 048 * Constructs a new SnapshotParameters object with default values for 049 * all rendering attributes. 050 */ 051 public SnapshotParameters() { 052 } 053 054 /** 055 * Gets the current depthBuffer flag. 056 * 057 * @return the depthBuffer flag 058 */ 059 public boolean isDepthBuffer() { 060 return depthBuffer; 061 } 062 063 boolean isDepthBufferInternal() { 064 if(!Platform.isSupported(ConditionalFeature.SCENE3D)) { 065 return false; 066 } 067 return depthBuffer; 068 } 069 070 /** 071 * Sets the depthBuffer flag to the specified value. 072 * The default value is false. 073 * 074 * Note that this is a conditional feature. See 075 * {@link javafx.application.ConditionalFeature#SCENE3D ConditionalFeature.SCENE3D} 076 * 077 * @param depthBuffer the depthBuffer to set 078 */ 079 public void setDepthBuffer(boolean depthBuffer) { 080 if (depthBuffer && !Platform.isSupported(ConditionalFeature.SCENE3D)) { 081 String logname = SnapshotParameters.class.getName(); 082 PlatformLogger.getLogger(logname).warning("System can't support " 083 + "ConditionalFeature.SCENE3D"); 084 } 085 this.depthBuffer = depthBuffer; 086 } 087 088 /** 089 * Gets the current camera. 090 * 091 * @return the camera 092 */ 093 public Camera getCamera() { 094 return camera; 095 } 096 097 Camera defaultCamera; 098 099 Camera getEffectiveCamera() { 100 if (camera instanceof PerspectiveCamera 101 && !Platform.isSupported(ConditionalFeature.SCENE3D)) { 102 if (defaultCamera == null) { 103 // According to Scene.doSnapshot, temporarily, it adjusts camera 104 // viewport to the snapshot size. So, its viewport doesn't matter. 105 defaultCamera = new ParallelCamera(); 106 } 107 return defaultCamera; 108 } 109 return camera; 110 } 111 112 /** 113 * Sets the camera to the specified value. 114 * The default value is null, which means a ParallelCamera will be used. 115 * 116 * @param camera the camera to set 117 */ 118 public void setCamera(Camera camera) { 119 if (camera instanceof PerspectiveCamera 120 && !Platform.isSupported(ConditionalFeature.SCENE3D)) { 121 String logname = SnapshotParameters.class.getName(); 122 PlatformLogger.getLogger(logname).warning("System can't support " 123 + "ConditionalFeature.SCENE3D"); 124 } 125 this.camera = camera; 126 } 127 128 /** 129 * Gets the current transform. 130 * 131 * @return the transform 132 */ 133 public Transform getTransform() { 134 return transform; 135 } 136 137 /** 138 * Sets the transform to the specified value. This transform is applied to 139 * the node being rendered before any local transforms are applied. 140 * A value of null indicates that the identity transform should be used. 141 * The default value is null. 142 * 143 * @param transform the transform to set 144 */ 145 public void setTransform(Transform transform) { 146 this.transform = transform; 147 } 148 149 /** 150 * Gets the current fill. 151 * 152 * @return the fill 153 */ 154 public Paint getFill() { 155 return fill; 156 } 157 158 /** 159 * Sets the fill to the specified value. This is used to fill the entire 160 * image being rendered prior to rendering the node. A value of null 161 * indicates that the color white should be used for the fill. 162 * The default value is null. 163 * 164 * @param fill the fill to set 165 */ 166 public void setFill(Paint fill) { 167 this.fill = fill; 168 } 169 170 /** 171 * Gets the current viewport 172 * 173 * @return the viewport 174 */ 175 public Rectangle2D getViewport() { 176 return viewport; 177 } 178 179 /** 180 * Sets the viewport used for rendering. 181 * The viewport is specified in the parent coordinate system of the 182 * node being rendered. It is not transformed by the transform 183 * of this SnapshotParameters. 184 * If this viewport is non-null it is used instead of the bounds of the 185 * node being rendered and specifies the source rectangle that will be 186 * rendered into the image. 187 * In this case, the upper-left pixel of the viewport will map to 188 * the upper-left pixel (0,0) 189 * in the rendered image. 190 * If the viewport is null, then the entire area of the node defined 191 * by its boundsInParent, after first applying the 192 * transform of this SnapshotParameters, will be rendered. 193 * The default value is null. 194 * 195 * @param viewport the viewport to set 196 */ 197 public void setViewport(Rectangle2D viewport) { 198 this.viewport = viewport; 199 } 200 201 /** 202 * Returns a deep clone of this SnapshotParameters 203 * 204 * @return a clone 205 */ 206 SnapshotParameters copy() { 207 SnapshotParameters params = new SnapshotParameters(); 208 params.camera = camera == null ? null : camera.copy(); 209 params.depthBuffer = depthBuffer; 210 params.fill = fill; 211 params.viewport = viewport; 212 params.transform = transform == null ? null : transform.clone(); 213 return params; 214 } 215}