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.

juce_LookAndFeel.cpp 4.7KB

7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. {
  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. }
  41. //==============================================================================
  42. Colour LookAndFeel::findColour (int colourID) const noexcept
  43. {
  44. const ColourSetting c = { colourID, Colour() };
  45. const int index = colours.indexOf (c);
  46. if (index >= 0)
  47. return colours.getReference (index).colour;
  48. jassertfalse;
  49. return Colours::black;
  50. }
  51. void LookAndFeel::setColour (int colourID, Colour newColour) noexcept
  52. {
  53. const ColourSetting c = { colourID, newColour };
  54. const int index = colours.indexOf (c);
  55. if (index >= 0)
  56. colours.getReference (index).colour = newColour;
  57. else
  58. colours.add (c);
  59. }
  60. bool LookAndFeel::isColourSpecified (const int colourID) const noexcept
  61. {
  62. const ColourSetting c = { colourID, Colour() };
  63. return colours.contains (c);
  64. }
  65. //==============================================================================
  66. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() noexcept
  67. {
  68. return Desktop::getInstance().getDefaultLookAndFeel();
  69. }
  70. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) noexcept
  71. {
  72. Desktop::getInstance().setDefaultLookAndFeel (newDefaultLookAndFeel);
  73. }
  74. //==============================================================================
  75. Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  76. {
  77. if (defaultSans.isNotEmpty() && font.getTypefaceName() == Font::getDefaultSansSerifFontName())
  78. {
  79. Font f (font);
  80. f.setTypefaceName (defaultSans);
  81. return Typeface::createSystemTypefaceFor (f);
  82. }
  83. return Font::getDefaultTypefaceForFont (font);
  84. }
  85. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  86. {
  87. if (defaultSans != newName)
  88. {
  89. Typeface::clearTypefaceCache();
  90. defaultSans = newName;
  91. }
  92. }
  93. //==============================================================================
  94. MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  95. {
  96. MouseCursor m (component.getMouseCursor());
  97. Component* parent = component.getParentComponent();
  98. while (parent != nullptr && m == MouseCursor::ParentCursor)
  99. {
  100. m = parent->getMouseCursor();
  101. parent = parent->getParentComponent();
  102. }
  103. return m;
  104. }
  105. LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point<int>& origin,
  106. const RectangleList<int>& initialClip)
  107. {
  108. return new LowLevelGraphicsSoftwareRenderer (imageToRenderOn, origin, initialClip);
  109. }
  110. //==============================================================================
  111. void LookAndFeel::setUsingNativeAlertWindows (bool shouldUseNativeAlerts)
  112. {
  113. useNativeAlertWindows = shouldUseNativeAlerts;
  114. }
  115. bool LookAndFeel::isUsingNativeAlertWindows()
  116. {
  117. #if JUCE_LINUX
  118. return false; // not available currently..
  119. #else
  120. return useNativeAlertWindows;
  121. #endif
  122. }
  123. } // namespace juce