java.lang.Object
com.dlsc.gemsfx.util.Utils
Some basic utilities which need to be in java (for shifting operations or
other reasons), which are not toolkit dependent.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecalculateBrightness(javafx.scene.paint.Color color) Calculates a perceptual brightness for a color between 0.0 black and 1.0 whilestatic doubleclamp(double min, double value, double max) Simple utility function which clamps the given value to be strictly between the min and max values.static floatclamp(float min, float value, float max) Simple utility function which clamps the given value to be strictly between the min and max values.static intclamp(int min, int value, int max) Simple utility function which clamps the given value to be strictly between the min and max values.static longclamp(long min, long value, long max) Simple utility function which clamps the given value to be strictly between the min and max values.static intclampMax(int value, int max) Simple utility function which clamps the given value to be strictly under the max value.static doubleclampMin(double value, double min) Simple utility function which clamps the given value to be strictly above the min value.static booleanBecause mobile doesn't have string.contains(s) function, this function was written.static javafx.scene.paint.ColorconvertLinearRGBtoSRGB(javafx.scene.paint.Color color) Helper function to convert a color in linear RGB space to SRGB space.static javafx.scene.paint.ColorconvertSRGBtoLinearRGB(javafx.scene.paint.Color color) Helper function to convert a color in sRGB space to linear RGB space.static javafx.scene.paint.ColorderiveColor(javafx.scene.paint.Color c, double brightness) Derives a lighter or darker of a given color.static javafx.stage.ScreenThis function attempts to determine the best screen given the parent object from which we are wanting to position another item relative to.static javafx.stage.ScreengetScreenForPoint(double x, double y) static javafx.stage.ScreengetScreenForRectangle(javafx.geometry.Rectangle2D rect) static booleanhasFullScreenStage(javafx.stage.Screen screen) static double[]HSBtoRGB(double hue, double saturation, double brightness) static booleanstatic javafx.scene.paint.Colorladder(javafx.scene.paint.Color color, javafx.scene.paint.Stop[] stops) Get the color at the givepositionin the ladder of color stopsstatic doublenearest(double less, double value, double more) Utility function which returns eitherlessormoredepending on whichvalueis closer to.static javafx.geometry.Point2DpointRelativeTo(Object parent, double width, double height, double screenX, double screenY, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos) This is the fallthrough function that most other functions fall into.static javafx.geometry.Point2DpointRelativeTo(javafx.scene.Node parent, double anchorWidth, double anchorHeight, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition) static javafx.geometry.Point2DpointRelativeTo(javafx.scene.Node parent, javafx.scene.Node node, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition) static double[]RGBtoHSB(double r, double g, double b) static String[]Because mobile doesn't have string.split(s) function, this function was written.static StringstripQuotes(String str) Helper to remove leading and trailing quotes from a string.static doublesum(double[] values) helper function for calculating the sum of a series of numbers
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
clamp
public static float clamp(float min, float value, float max) Simple utility function which clamps the given value to be strictly between the min and max values. -
clamp
public static int clamp(int min, int value, int max) Simple utility function which clamps the given value to be strictly between the min and max values. -
clamp
public static double clamp(double min, double value, double max) Simple utility function which clamps the given value to be strictly between the min and max values. -
clamp
public static long clamp(long min, long value, long max) Simple utility function which clamps the given value to be strictly between the min and max values. -
clampMin
public static double clampMin(double value, double min) Simple utility function which clamps the given value to be strictly above the min value. -
clampMax
public static int clampMax(int value, int max) Simple utility function which clamps the given value to be strictly under the max value. -
nearest
public static double nearest(double less, double value, double more) Utility function which returns eitherlessormoredepending on whichvalueis closer to. Ifvalueis perfectly between them, then either may be returned. -
stripQuotes
Helper to remove leading and trailing quotes from a string. Works with single or double quotes. -
split
Because mobile doesn't have string.split(s) function, this function was written. -
contains
Because mobile doesn't have string.contains(s) function, this function was written. -
calculateBrightness
public static double calculateBrightness(javafx.scene.paint.Color color) Calculates a perceptual brightness for a color between 0.0 black and 1.0 while -
deriveColor
public static javafx.scene.paint.Color deriveColor(javafx.scene.paint.Color c, double brightness) Derives a lighter or darker of a given color.- Parameters:
c- The color to derive frombrightness- The brightness difference for the new color -1.0 being 100% dark which is always black, 0.0 being no change and 1.0 being 100% lighter which is always white
-
ladder
public static javafx.scene.paint.Color ladder(javafx.scene.paint.Color color, javafx.scene.paint.Stop[] stops) Get the color at the givepositionin the ladder of color stops -
HSBtoRGB
public static double[] HSBtoRGB(double hue, double saturation, double brightness) -
RGBtoHSB
public static double[] RGBtoHSB(double r, double g, double b) -
convertSRGBtoLinearRGB
public static javafx.scene.paint.Color convertSRGBtoLinearRGB(javafx.scene.paint.Color color) Helper function to convert a color in sRGB space to linear RGB space. -
convertLinearRGBtoSRGB
public static javafx.scene.paint.Color convertLinearRGBtoSRGB(javafx.scene.paint.Color color) Helper function to convert a color in linear RGB space to SRGB space. -
sum
public static double sum(double[] values) helper function for calculating the sum of a series of numbers -
pointRelativeTo
public static javafx.geometry.Point2D pointRelativeTo(javafx.scene.Node parent, javafx.scene.Node node, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition) -
pointRelativeTo
public static javafx.geometry.Point2D pointRelativeTo(javafx.scene.Node parent, double anchorWidth, double anchorHeight, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos, double dx, double dy, boolean reposition) -
pointRelativeTo
public static javafx.geometry.Point2D pointRelativeTo(Object parent, double width, double height, double screenX, double screenY, javafx.geometry.HPos hpos, javafx.geometry.VPos vpos) This is the fallthrough function that most other functions fall into. It takes care specifically of the repositioning of the item such that it remains onscreen as best it can, given it's unique qualities.As will all other functions, this one returns a Point2D that represents an x,y location that should safely position the item onscreen as best as possible.
Note that
widthandrefer to the width and height of the node/popup that is needing to be repositioned, not of the parent. Don't use the BASELINE vpos, it doesn't make sense and would produce wrong result.
-
hasFullScreenStage
public static boolean hasFullScreenStage(javafx.stage.Screen screen) -
isQVGAScreen
public static boolean isQVGAScreen() -
getScreen
This function attempts to determine the best screen given the parent object from which we are wanting to position another item relative to. This is particularly important when we want to keep items from going off screen, and for handling multiple monitor support. -
getScreenForRectangle
public static javafx.stage.Screen getScreenForRectangle(javafx.geometry.Rectangle2D rect) -
getScreenForPoint
public static javafx.stage.Screen getScreenForPoint(double x, double y)
-