The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
8.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Manages details about connected display devices.
  23. @tags{GUI}
  24. */
  25. class JUCE_API Displays
  26. {
  27. private:
  28. Displays (Desktop&);
  29. public:
  30. //==============================================================================
  31. /** Represents a connected display device. */
  32. struct JUCE_API Display
  33. {
  34. /** This will be true if this is the user's main display device. */
  35. bool isMain;
  36. /** The total area of this display in logical pixels including any OS-dependent objects
  37. like the taskbar, menu bar, etc.
  38. */
  39. Rectangle<int> totalArea;
  40. /** The total area of this display in logical pixels which isn't covered by OS-dependent
  41. objects like the taskbar, menu bar, etc.
  42. */
  43. Rectangle<int> userArea;
  44. /** Represents the area of this display in logical pixels that is not functional for
  45. displaying content.
  46. On mobile devices this may be the area covered by display cutouts and notches, where
  47. you still want to draw a background but should not position important content.
  48. */
  49. BorderSize<int> safeAreaInsets;
  50. /** Represents the area of this display in logical pixels that is obscured by an
  51. onscreen keyboard.
  52. This is currently only supported on iOS, and on Android 11+.
  53. This will only return the bounds of the keyboard when it is in 'docked' mode.
  54. If the keyboard is floating (e.g. on an iPad using the split keyboard mode),
  55. no insets will be reported.
  56. */
  57. BorderSize<int> keyboardInsets;
  58. /** The top-left of this display in physical coordinates. */
  59. Point<int> topLeftPhysical;
  60. /** The scale factor of this display.
  61. For higher-resolution displays, or displays with a user-defined scale factor set,
  62. this may be a value other than 1.0.
  63. This value is used to convert between physical and logical pixels. For example, a Component
  64. with size 10x10 will use 20x20 physical pixels on a display with a scale factor of 2.0.
  65. */
  66. double scale;
  67. /** The DPI of the display.
  68. This is the number of physical pixels per inch. To get the number of logical
  69. pixels per inch, divide this by the Display::scale value.
  70. */
  71. double dpi;
  72. };
  73. //==============================================================================
  74. /** Converts an integer Rectangle from physical to logical pixels.
  75. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  76. regardless of the display that the Rectangle to be converted is on.
  77. */
  78. Rectangle<int> physicalToLogical (Rectangle<int> physicalRect,
  79. const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  80. /** Converts a floating-point Rectangle from physical to logical pixels.
  81. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  82. regardless of the display that the Rectangle to be converted is on.
  83. */
  84. Rectangle<float> physicalToLogical (Rectangle<float> physicalRect,
  85. const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  86. /** Converts an integer Rectangle from logical to physical pixels.
  87. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  88. regardless of the display that the Rectangle to be converted is on.
  89. */
  90. Rectangle<int> logicalToPhysical (Rectangle<int> logicalRect,
  91. const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  92. /** Converts a floating-point Rectangle from logical to physical pixels.
  93. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  94. regardless of the display that the Rectangle to be converted is on.
  95. */
  96. Rectangle<float> logicalToPhysical (Rectangle<float> logicalRect,
  97. const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  98. /** Converts a Point from physical to logical pixels.
  99. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  100. regardless of the display that the Point to be converted is on.
  101. */
  102. template <typename ValueType>
  103. Point<ValueType> physicalToLogical (Point<ValueType> physicalPoint,
  104. const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  105. /** Converts a Point from logical to physical pixels.
  106. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  107. regardless of the display that the Point to be converted is on.
  108. */
  109. template <typename ValueType>
  110. Point<ValueType> logicalToPhysical (Point<ValueType> logicalPoint,
  111. const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  112. /** Returns the Display object representing the display containing a given Rectangle (either
  113. in logical or physical pixels), or nullptr if there are no connected displays.
  114. If the Rectangle lies outside all the displays then the nearest one will be returned.
  115. */
  116. const Display* getDisplayForRect (Rectangle<int> rect, bool isPhysical = false) const noexcept;
  117. /** Returns the Display object representing the display containing a given Point (either
  118. in logical or physical pixels), or nullptr if there are no connected displays.
  119. If the Point lies outside all the displays then the nearest one will be returned.
  120. */
  121. const Display* getDisplayForPoint (Point<int> point, bool isPhysical = false) const noexcept;
  122. /** Returns the Display object representing the display acting as the user's main screen, or nullptr
  123. if there are no connected displays.
  124. */
  125. const Display* getPrimaryDisplay() const noexcept;
  126. /** Returns a RectangleList made up of all the displays in LOGICAL pixels. */
  127. RectangleList<int> getRectangleList (bool userAreasOnly) const;
  128. /** Returns the smallest bounding box which contains all the displays in LOGICAL pixels. */
  129. Rectangle<int> getTotalBounds (bool userAreasOnly) const;
  130. /** An Array containing the Display objects for all of the connected displays. */
  131. Array<Display> displays;
  132. #ifndef DOXYGEN
  133. /** @internal */
  134. void refresh();
  135. [[deprecated ("Use the getDisplayForPoint or getDisplayForRect methods instead "
  136. "as they can deal with converting between logical and physical pixels.")]]
  137. const Display& getDisplayContaining (Point<int> position) const noexcept;
  138. // These methods have been deprecated - use the methods which return a Display* instead as they will return
  139. // nullptr on headless systems with no connected displays
  140. [[deprecated]] const Display& findDisplayForRect (Rectangle<int>, bool isPhysical = false) const noexcept;
  141. [[deprecated]] const Display& findDisplayForPoint (Point<int>, bool isPhysical = false) const noexcept;
  142. [[deprecated]] const Display& getMainDisplay() const noexcept;
  143. #endif
  144. private:
  145. friend class Desktop;
  146. void init (Desktop&);
  147. void findDisplays (float masterScale);
  148. void updateToLogical();
  149. Display emptyDisplay;
  150. };
  151. } // namespace juce