LuciadCPillar 2023.1.04
luciad::ScreenDistance Class Referencefinal

This class is used to represent distances between screen locations. More...

#include <luciad/input/ScreenDistance.h>

Public Member Functions

constexpr ScreenDistance (double distance, ScreenDistanceUnit unit)
 Explicit constructor taking a distance value and a unit. More...
 
constexpr double asMillimeters (double dpi, double displayScale) const
 Converting value method which returns the distance value as a double, expressed in millimeters. More...
 
constexpr double asPixels (double dpi, double displayScale) const
 Converting value method which returns the distance value as a double, expressed in device independent pixels. More...
 
constexpr ScreenDistanceUnit getUnit () const
 
constexpr double getValue () const
 

Static Public Member Functions

static constexpr ScreenDistance millimeters (double millimeters)
 Utility factory method for constructing a ScreenDistance expressed in millimeters. More...
 
static constexpr ScreenDistance pixels (double pixels)
 Utility factory method for constructing a ScreenDistance expressed in device independent pixels. More...
 

Detailed Description

This class is used to represent distances between screen locations.

It consists of a unit (expressed as a ScreenDistanceUnit) and the distance value.

This class contains utility methods for converting distance values from millimeters to pixels or vice-versa, by taking DPI and display scale into account (see ScreenDistance#asPixels and ScreenDistance#asMillimeters).

Related article: Support high-resolution (HiDPI) displays.

Since
2022.0

Constructor & Destructor Documentation

◆ ScreenDistance()

constexpr luciad::ScreenDistance::ScreenDistance ( double  distance,
ScreenDistanceUnit  unit 
)
inlineconstexpr

Explicit constructor taking a distance value and a unit.

Parameters
distancethe distance, expressed in the chosen unit.
uniteither ScreenDistanceUnit::Pixels or ScreenDistanceUnit::Millimeters.

Member Function Documentation

◆ asMillimeters()

constexpr double luciad::ScreenDistance::asMillimeters ( double  dpi,
double  displayScale 
) const
inlineconstexpr

Converting value method which returns the distance value as a double, expressed in millimeters.

In order to make any possible conversion from device independent pixels to millimeters, the display DPI and display scale must be provided. If the stored unit is ScreenDistanceUnit::Millimeters, the currently stored value is returned.

Parameters
dpithe display density in dots per inch
displayScalethe display scale
Returns
the screen distance in millimeters, as a double.

◆ asPixels()

constexpr double luciad::ScreenDistance::asPixels ( double  dpi,
double  displayScale 
) const
inlineconstexpr

Converting value method which returns the distance value as a double, expressed in device independent pixels.

In order to make any possible conversion from millimeters to pixels, the display DPI and display scale must be provided. If the stored unit is ScreenDistanceUnit::Pixels, the currently stored value is returned.

Parameters
dpithe display density in dots per inch
displayScalethe display scale
Returns
the screen distance in device independent pixels, as a double.

◆ getUnit()

constexpr ScreenDistanceUnit luciad::ScreenDistance::getUnit ( ) const
inlineconstexpr
Returns
the screen distance unit.

◆ getValue()

constexpr double luciad::ScreenDistance::getValue ( ) const
inlineconstexpr
Returns
the screen distance value, as a double.

◆ millimeters()

static constexpr ScreenDistance luciad::ScreenDistance::millimeters ( double  millimeters)
inlinestaticconstexpr

Utility factory method for constructing a ScreenDistance expressed in millimeters.

Parameters
millimetersthe distance in millimeters.
Returns
a ScreenDistance instance taking the passed value and expressed in millimeters.

◆ pixels()

static constexpr ScreenDistance luciad::ScreenDistance::pixels ( double  pixels)
inlinestaticconstexpr

Utility factory method for constructing a ScreenDistance expressed in device independent pixels.

Parameters
pixelsthe distance in device independent pixels.
Returns
a ScreenDistance instance taking the passed value and expressed in device independent pixels.