/* * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package javafx.scene.effect; import javafx.beans.Observable; import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoublePropertyBase; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectPropertyBase; import javafx.scene.Node; import com.sun.javafx.util.Utils; import com.sun.javafx.effect.EffectDirtyBits; import com.sun.javafx.geom.BaseBounds; import com.sun.javafx.geom.transform.BaseTransform; import com.sun.javafx.scene.BoundsAccessor; import com.sun.scenario.effect.PhongLighting; /** * An effect that simulates a light source shining on the given content, * which can be used to give flat objects a more realistic, three-dimensional * appearance. * *
* Example: *
* Light.Distant light = new Light.Distant();
* light.setAzimuth(-135.0);
*
* Lighting lighting = new Lighting();
* lighting.setLight(light);
* lighting.setSurfaceScale(5.0);
*
* Text text = new Text();
* text.setText("JavaFX!");
* text.setFill(Color.STEELBLUE);
* text.setFont(Font.font(null, FontWeight.BOLD, 60));
* text.setX(10.0);
* text.setY(10.0);
* text.setTextOrigin(VPos.TOP);
*
* text.setEffect(lighting);
*
* The code above produces the following:
*
*
*
* Min: 0.0 * Max: 2.0 * Default: 1.0 * Identity: n/a ** @defaultValue 1.0 */ private DoubleProperty diffuseConstant; public final void setDiffuseConstant(double value) { diffuseConstantProperty().set(value); } public final double getDiffuseConstant() { return diffuseConstant == null ? 1 : diffuseConstant.get(); } public final DoubleProperty diffuseConstantProperty() { if (diffuseConstant == null) { diffuseConstant = new DoublePropertyBase(1) { @Override public void invalidated() { markDirty(EffectDirtyBits.EFFECT_DIRTY); } @Override public Object getBean() { return Lighting.this; } @Override public String getName() { return "diffuseConstant"; } }; } return diffuseConstant; } /** * The specular constant. *
* Min: 0.0 * Max: 2.0 * Default: 0.3 * Identity: n/a ** @defaultValue 0.3 */ private DoubleProperty specularConstant; public final void setSpecularConstant(double value) { specularConstantProperty().set(value); } public final double getSpecularConstant() { return specularConstant == null ? 0.3 : specularConstant.get(); } public final DoubleProperty specularConstantProperty() { if (specularConstant == null) { specularConstant = new DoublePropertyBase(0.3) { @Override public void invalidated() { markDirty(EffectDirtyBits.EFFECT_DIRTY); } @Override public Object getBean() { return Lighting.this; } @Override public String getName() { return "specularConstant"; } }; } return specularConstant; } /** * The specular exponent. *
* Min: 0.0 * Max: 40.0 * Default: 20.0 * Identity: n/a ** @defaultValue 20.0 */ private DoubleProperty specularExponent; public final void setSpecularExponent(double value) { specularExponentProperty().set(value); } public final double getSpecularExponent() { return specularExponent == null ? 20 : specularExponent.get(); } public final DoubleProperty specularExponentProperty() { if (specularExponent == null) { specularExponent = new DoublePropertyBase(20) { @Override public void invalidated() { markDirty(EffectDirtyBits.EFFECT_DIRTY); } @Override public Object getBean() { return Lighting.this; } @Override public String getName() { return "specularExponent"; } }; } return specularExponent; } /** * The surface scale factor. *
* Min: 0.0 * Max: 10.0 * Default: 1.5 * Identity: n/a ** @defaultValue 1.5 */ private DoubleProperty surfaceScale; public final void setSurfaceScale(double value) { surfaceScaleProperty().set(value); } public final double getSurfaceScale() { return surfaceScale == null ? 1.5 : surfaceScale.get(); } public final DoubleProperty surfaceScaleProperty() { if (surfaceScale == null) { surfaceScale = new DoublePropertyBase(1.5) { @Override public void invalidated() { markDirty(EffectDirtyBits.EFFECT_DIRTY); } @Override public Object getBean() { return Lighting.this; } @Override public String getName() { return "surfaceScale"; } }; } return surfaceScale; } private Light getLightInternal() { Light localLight = getLight(); return localLight == null ? defaultLight : localLight; } @Override void impl_update() { Effect localBumpInput = getBumpInput(); if (localBumpInput != null) { localBumpInput.impl_sync(); } Effect localContentInput = getContentInput(); if (localContentInput != null) { localContentInput.impl_sync(); } PhongLighting peer = (PhongLighting) impl_getImpl(); peer.setBumpInput(localBumpInput == null ? null : localBumpInput.impl_getImpl()); peer.setContentInput(localContentInput == null ? null : localContentInput.impl_getImpl()); peer.setDiffuseConstant((float)Utils.clamp(0, getDiffuseConstant(), 2)); peer.setSpecularConstant((float)Utils.clamp(0, getSpecularConstant(), 2)); peer.setSpecularExponent((float)Utils.clamp(0, getSpecularExponent(), 40)); peer.setSurfaceScale((float)Utils.clamp(0, getSurfaceScale(), 10)); // we don't need to register on default light in case the light is null // because default light never changes lightChangeListener.register(getLight()); getLightInternal().impl_sync(); peer.setLight(getLightInternal().impl_getImpl()); } /** * @treatAsPrivate implementation detail * @deprecated This is an internal API that is not intended for use and will be removed in the next version */ @Deprecated @Override public BaseBounds impl_getBounds(BaseBounds bounds, BaseTransform tx, Node node, BoundsAccessor boundsAccessor) { return getInputBounds(bounds, tx, node, boundsAccessor, getContentInput()); } }