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.

145 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. /** Represents a connected display device. */
  31. struct Display
  32. {
  33. /** This will be true if this is the user's main display device. */
  34. bool isMain;
  35. /** The total area of this display in logical pixels including any OS-dependent objects
  36. like the taskbar, menu bar, etc. */
  37. Rectangle<int> totalArea;
  38. /** The total area of this display in logical pixels which isn't covered by OS-dependent
  39. objects like the taskbar, menu bar, etc.
  40. */
  41. Rectangle<int> userArea;
  42. /** The top-left of this display in physical coordinates. */
  43. Point<int> topLeftPhysical;
  44. /** The scale factor of this display.
  45. For higher-resolution displays, or displays with a user-defined scale factor set,
  46. this may be a value other than 1.0.
  47. This value is used to convert between physical and logical pixels. For example, a Component
  48. with size 10x10 will use 20x20 physical pixels on a display with a scale factor of 2.0.
  49. */
  50. double scale;
  51. /** The DPI of the display.
  52. This is the number of physical pixels per inch. To get the number of logical
  53. pixels per inch, divide this by the Display::scale value.
  54. */
  55. double dpi;
  56. };
  57. /** Converts a Rectangle from physical to logical pixels.
  58. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  59. regardless of the display that the Rectangle to be converted is on.
  60. */
  61. Rectangle<int> physicalToLogical (Rectangle<int>, const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  62. /** Converts a Rectangle from logical to physical pixels.
  63. If useScaleFactorOfDisplay is not null then its scale factor will be used for the conversion
  64. regardless of the display that the Rectangle to be converted is on.
  65. */
  66. Rectangle<int> logicalToPhysical (Rectangle<int>, const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  67. /** Converts a Point from physical to logical pixels. */
  68. template <typename ValueType>
  69. Point<ValueType> physicalToLogical (Point<ValueType>, const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  70. /** Converts a Point from logical to physical pixels. */
  71. template <typename ValueType>
  72. Point<ValueType> logicalToPhysical (Point<ValueType>, const Display* useScaleFactorOfDisplay = nullptr) const noexcept;
  73. /** Returns the Display object representing the display containing a given Rectangle (either
  74. in logical or physical pixels).
  75. If the Rectangle lies outside all the displays then the nearest one will be returned.
  76. */
  77. const Display& findDisplayForRect (Rectangle<int>, bool isPhysical = false) const noexcept;
  78. /** Returns the Display object representing the display containing a given Point (either
  79. in logical or physical pixels).
  80. If the Point lies outside all the displays then the nearest one will be returned.
  81. */
  82. const Display& findDisplayForPoint (Point<int>, bool isPhysical = false) const noexcept;
  83. /** Returns the Display object representing the display acting as the user's main screen. */
  84. const Display& getMainDisplay() const noexcept;
  85. /** Returns a RectangleList made up of all the displays in LOGICAL pixels. */
  86. RectangleList<int> getRectangleList (bool userAreasOnly) const;
  87. /** Returns the smallest bounding box which contains all the displays in LOGICAL pixels. */
  88. Rectangle<int> getTotalBounds (bool userAreasOnly) const;
  89. /** An Array containing the Display objects for all of the connected displays. */
  90. Array<Display> displays;
  91. #ifndef DOXYGEN
  92. /** @internal */
  93. void refresh();
  94. /** @internal */
  95. ~Displays() = default;
  96. // This method has been deprecated - use the findDisplayForPoint() or findDisplayForRect() methods instead
  97. // as they can deal with converting between logical and physical pixels
  98. JUCE_DEPRECATED (const Display& getDisplayContaining (Point<int> position) const noexcept);
  99. #endif
  100. private:
  101. friend class Desktop;
  102. void init (Desktop&);
  103. void findDisplays (float masterScale);
  104. void updateToLogical();
  105. };
  106. } // namespace juce