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.

153 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. //==============================================================================
  20. static Typeface::Ptr getTypefaceForFontFromLookAndFeel (const Font& font)
  21. {
  22. return LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  23. }
  24. typedef Typeface::Ptr (*GetTypefaceForFont) (const Font&);
  25. extern GetTypefaceForFont juce_getTypefaceForFont;
  26. //==============================================================================
  27. LookAndFeel::LookAndFeel()
  28. : useNativeAlertWindows (false)
  29. {
  30. /* if this fails it means you're trying to create a LookAndFeel object before
  31. the static Colours have been initialised. That ain't gonna work. It probably
  32. means that you're using a static LookAndFeel object and that your compiler has
  33. decided to intialise it before the Colours class.
  34. */
  35. jassert (Colours::white == Colour (0xffffffff));
  36. juce_getTypefaceForFont = getTypefaceForFontFromLookAndFeel;
  37. }
  38. LookAndFeel::~LookAndFeel()
  39. {
  40. masterReference.clear();
  41. }
  42. //==============================================================================
  43. Colour LookAndFeel::findColour (int colourID) const noexcept
  44. {
  45. const ColourSetting c = { colourID, Colour() };
  46. const int index = colours.indexOf (c);
  47. if (index >= 0)
  48. return colours.getReference (index).colour;
  49. jassertfalse;
  50. return Colours::black;
  51. }
  52. void LookAndFeel::setColour (int colourID, Colour newColour) noexcept
  53. {
  54. const ColourSetting c = { colourID, newColour };
  55. const int index = colours.indexOf (c);
  56. if (index >= 0)
  57. colours.getReference (index).colour = newColour;
  58. else
  59. colours.add (c);
  60. }
  61. bool LookAndFeel::isColourSpecified (const int colourID) const noexcept
  62. {
  63. const ColourSetting c = { colourID, Colour() };
  64. return colours.contains (c);
  65. }
  66. //==============================================================================
  67. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() noexcept
  68. {
  69. return Desktop::getInstance().getDefaultLookAndFeel();
  70. }
  71. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) noexcept
  72. {
  73. Desktop::getInstance().setDefaultLookAndFeel (newDefaultLookAndFeel);
  74. }
  75. //==============================================================================
  76. Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  77. {
  78. if (defaultSans.isNotEmpty() && font.getTypefaceName() == Font::getDefaultSansSerifFontName())
  79. {
  80. Font f (font);
  81. f.setTypefaceName (defaultSans);
  82. return Typeface::createSystemTypefaceFor (f);
  83. }
  84. return Font::getDefaultTypefaceForFont (font);
  85. }
  86. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  87. {
  88. if (defaultSans != newName)
  89. {
  90. Typeface::clearTypefaceCache();
  91. defaultSans = newName;
  92. }
  93. }
  94. //==============================================================================
  95. MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  96. {
  97. MouseCursor m (component.getMouseCursor());
  98. Component* parent = component.getParentComponent();
  99. while (parent != nullptr && m == MouseCursor::ParentCursor)
  100. {
  101. m = parent->getMouseCursor();
  102. parent = parent->getParentComponent();
  103. }
  104. return m;
  105. }
  106. LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point<int>& origin,
  107. const RectangleList<int>& initialClip)
  108. {
  109. return new LowLevelGraphicsSoftwareRenderer (imageToRenderOn, origin, initialClip);
  110. }
  111. //==============================================================================
  112. void LookAndFeel::setUsingNativeAlertWindows (bool shouldUseNativeAlerts)
  113. {
  114. useNativeAlertWindows = shouldUseNativeAlerts;
  115. }
  116. bool LookAndFeel::isUsingNativeAlertWindows()
  117. {
  118. #if JUCE_LINUX
  119. return false; // not available currently..
  120. #else
  121. return useNativeAlertWindows;
  122. #endif
  123. }