All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.palexdev.mfxeffects.MFXElevationManager Maven / Gradle / Ivy

There is a newer version: 11.26.0
Show newest version
/*
 * Copyright (C) 2022 Parisi Alessandro - [email protected]
 * This file is part of MaterialFX (https://github.com/palexdev/MaterialFX)
 *
 * MaterialFX is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3 of the License,
 * or (at your option) any later version.
 *
 * MaterialFX is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with MaterialFX. If not, see .
 */

package io.github.palexdev.mfxeffects;

import io.github.palexdev.mfxeffects.enums.ElevationLevel;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.paint.Color;

/**
 * Utility class which manages a preset number of {@code DropShadow} effects ordered by {@code DepthLevel}, but
 * it also allows to create custom {@code DropShadow} effects with {@link #shadowOf(Color, double, double, double, double)}.
 * 

* {@link ElevationLevel} */ public class MFXElevationManager { /** * Returns a new instance of {@code DropShadow} with the specified characteristics. * * @return The desired custom {@code DropShadow} effect * @see DropShadow */ public static DropShadow shadowOf(Color color, double radius, double spread, double offsetX, double offsetY) { return new DropShadow( BlurType.GAUSSIAN, color, radius, spread, offsetX, offsetY ); } /** * Retrieves the {@code DropShadow} associated with the specified {@code DepthLevel}. * * @param level The desired {@code DepthLevel} between 1 and 5 * @return The desired {@code DropShadow} effect */ public static DropShadow shadowOf(ElevationLevel level) { return new DropShadow( BlurType.GAUSSIAN, level.getColor(), level.getRadius(), level.getSpread(), level.getOffsetX(), level.getOffsetY() ); } /** * Retrieves the {@code DropShadow} associated with the specified {@code DepthLevel} added to delta. *

* Example 1: for a depth level equal to 3 and a delta equal to 2, the returned {@code DropShadow} effect is * the effected associated to a depth level of 5. *

* Example 2: for a depth level equal to 5 and a delta equal to whatever integer, the returned {@code DropShadow} effect is * the effected associated to a depth level of 5. * * @param level The desired {@code DepthLevel} between 1 and 5 * @param delta The number of levels to shift * @return The final {@code DropShadow} effect} *

* {@link #nextLevel(ElevationLevel)} */ public static DropShadow shadowOf(ElevationLevel level, int delta) { ElevationLevel endLevel = level; for (int i = 0; i < delta; i++) { endLevel = nextLevel(endLevel); } return shadowOf(endLevel); } /** * From a starting {@code DepthLevel} retrieves the {@code DropShadow} effect associated to the next {@code DepthLevel}. * * @param startLevel The starting {@code DepthLevel} * @return The {@code DropShadow} effect associated to the next {@code DepthLevel} * @see ElevationLevel */ private static ElevationLevel nextLevel(ElevationLevel startLevel) { return !(startLevel.equals(ElevationLevel.LEVEL5)) ? startLevel.next() : ElevationLevel.LEVEL5; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy