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.

157 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. namespace juce
  20. {
  21. static Typeface::Ptr getTypefaceForFontFromLookAndFeel (const Font& font)
  22. {
  23. return LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  24. }
  25. typedef Typeface::Ptr (*GetTypefaceForFont) (const Font&);
  26. extern GetTypefaceForFont juce_getTypefaceForFont;
  27. //==============================================================================
  28. LookAndFeel::LookAndFeel()
  29. : useNativeAlertWindows (false)
  30. {
  31. /* if this fails it means you're trying to create a LookAndFeel object before
  32. the static Colours have been initialised. That ain't gonna work. It probably
  33. means that you're using a static LookAndFeel object and that your compiler has
  34. decided to intialise it before the Colours class.
  35. */
  36. jassert (Colours::white == Colour (0xffffffff));
  37. juce_getTypefaceForFont = getTypefaceForFontFromLookAndFeel;
  38. }
  39. LookAndFeel::~LookAndFeel()
  40. {
  41. masterReference.clear();
  42. }
  43. //==============================================================================
  44. Colour LookAndFeel::findColour (int colourID) const noexcept
  45. {
  46. const ColourSetting c = { colourID, Colour() };
  47. const int index = colours.indexOf (c);
  48. if (index >= 0)
  49. return colours.getReference (index).colour;
  50. jassertfalse;
  51. return Colours::black;
  52. }
  53. void LookAndFeel::setColour (int colourID, Colour newColour) noexcept
  54. {
  55. const ColourSetting c = { colourID, newColour };
  56. const int index = colours.indexOf (c);
  57. if (index >= 0)
  58. colours.getReference (index).colour = newColour;
  59. else
  60. colours.add (c);
  61. }
  62. bool LookAndFeel::isColourSpecified (const int colourID) const noexcept
  63. {
  64. const ColourSetting c = { colourID, Colour() };
  65. return colours.contains (c);
  66. }
  67. //==============================================================================
  68. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() noexcept
  69. {
  70. return Desktop::getInstance().getDefaultLookAndFeel();
  71. }
  72. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) noexcept
  73. {
  74. Desktop::getInstance().setDefaultLookAndFeel (newDefaultLookAndFeel);
  75. }
  76. //==============================================================================
  77. Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  78. {
  79. if (defaultSans.isNotEmpty() && font.getTypefaceName() == Font::getDefaultSansSerifFontName())
  80. {
  81. Font f (font);
  82. f.setTypefaceName (defaultSans);
  83. return Typeface::createSystemTypefaceFor (f);
  84. }
  85. return Font::getDefaultTypefaceForFont (font);
  86. }
  87. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  88. {
  89. if (defaultSans != newName)
  90. {
  91. Typeface::clearTypefaceCache();
  92. defaultSans = newName;
  93. }
  94. }
  95. //==============================================================================
  96. MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  97. {
  98. MouseCursor m (component.getMouseCursor());
  99. Component* parent = component.getParentComponent();
  100. while (parent != nullptr && m == MouseCursor::ParentCursor)
  101. {
  102. m = parent->getMouseCursor();
  103. parent = parent->getParentComponent();
  104. }
  105. return m;
  106. }
  107. LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point<int>& origin,
  108. const RectangleList<int>& initialClip)
  109. {
  110. return new LowLevelGraphicsSoftwareRenderer (imageToRenderOn, origin, initialClip);
  111. }
  112. //==============================================================================
  113. void LookAndFeel::setUsingNativeAlertWindows (bool shouldUseNativeAlerts)
  114. {
  115. useNativeAlertWindows = shouldUseNativeAlerts;
  116. }
  117. bool LookAndFeel::isUsingNativeAlertWindows()
  118. {
  119. #if JUCE_LINUX
  120. return false; // not available currently..
  121. #else
  122. return useNativeAlertWindows;
  123. #endif
  124. }
  125. } // namespace juce