juce_LookAndFeel.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. //==============================================================================
  18. static Typeface::Ptr getTypefaceForFontFromLookAndFeel (const Font& font)
  19. {
  20. return LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  21. }
  22. typedef Typeface::Ptr (*GetTypefaceForFont) (const Font&);
  23. extern GetTypefaceForFont juce_getTypefaceForFont;
  24. //==============================================================================
  25. LookAndFeel::LookAndFeel()
  26. : useNativeAlertWindows (false)
  27. {
  28. /* if this fails it means you're trying to create a LookAndFeel object before
  29. the static Colours have been initialised. That ain't gonna work. It probably
  30. means that you're using a static LookAndFeel object and that your compiler has
  31. decided to intialise it before the Colours class.
  32. */
  33. jassert (Colours::white == Colour (0xffffffff));
  34. juce_getTypefaceForFont = getTypefaceForFontFromLookAndFeel;
  35. }
  36. LookAndFeel::~LookAndFeel()
  37. {
  38. masterReference.clear();
  39. }
  40. //==============================================================================
  41. Colour LookAndFeel::findColour (int colourID) const noexcept
  42. {
  43. const ColourSetting c = { colourID, Colour() };
  44. const int index = colours.indexOf (c);
  45. if (index >= 0)
  46. return colours.getReference (index).colour;
  47. jassertfalse;
  48. return Colours::black;
  49. }
  50. void LookAndFeel::setColour (int colourID, Colour newColour) noexcept
  51. {
  52. const ColourSetting c = { colourID, newColour };
  53. const int index = colours.indexOf (c);
  54. if (index >= 0)
  55. colours.getReference (index).colour = newColour;
  56. else
  57. colours.add (c);
  58. }
  59. bool LookAndFeel::isColourSpecified (const int colourID) const noexcept
  60. {
  61. const ColourSetting c = { colourID, Colour() };
  62. return colours.contains (c);
  63. }
  64. //==============================================================================
  65. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() noexcept
  66. {
  67. return Desktop::getInstance().getDefaultLookAndFeel();
  68. }
  69. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) noexcept
  70. {
  71. Desktop::getInstance().setDefaultLookAndFeel (newDefaultLookAndFeel);
  72. }
  73. //==============================================================================
  74. Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  75. {
  76. if (defaultSans.isNotEmpty() && font.getTypefaceName() == Font::getDefaultSansSerifFontName())
  77. {
  78. Font f (font);
  79. f.setTypefaceName (defaultSans);
  80. return Typeface::createSystemTypefaceFor (f);
  81. }
  82. return Font::getDefaultTypefaceForFont (font);
  83. }
  84. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  85. {
  86. if (defaultSans != newName)
  87. {
  88. Typeface::clearTypefaceCache();
  89. defaultSans = newName;
  90. }
  91. }
  92. //==============================================================================
  93. MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  94. {
  95. MouseCursor m (component.getMouseCursor());
  96. Component* parent = component.getParentComponent();
  97. while (parent != nullptr && m == MouseCursor::ParentCursor)
  98. {
  99. m = parent->getMouseCursor();
  100. parent = parent->getParentComponent();
  101. }
  102. return m;
  103. }
  104. LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point<int>& origin,
  105. const RectangleList<int>& initialClip)
  106. {
  107. return new LowLevelGraphicsSoftwareRenderer (imageToRenderOn, origin, initialClip);
  108. }
  109. //==============================================================================
  110. void LookAndFeel::setUsingNativeAlertWindows (bool shouldUseNativeAlerts)
  111. {
  112. useNativeAlertWindows = shouldUseNativeAlerts;
  113. }
  114. bool LookAndFeel::isUsingNativeAlertWindows()
  115. {
  116. #if JUCE_LINUX
  117. return false; // not available currently..
  118. #else
  119. return useNativeAlertWindows;
  120. #endif
  121. }