Audio plugin host https://kx.studio/carla
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.

186 lines
7.7KB

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