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.

291 lines
12KB

  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. // set up the standard set of colours..
  35. const uint32 textButtonColour = 0xffbbbbff;
  36. const uint32 textHighlightColour = 0x401111ee;
  37. const uint32 standardOutlineColour = 0xb2808080;
  38. static const uint32 standardColours[] =
  39. {
  40. TextButton::buttonColourId, textButtonColour,
  41. TextButton::buttonOnColourId, 0xff4444ff,
  42. TextButton::textColourOnId, 0xff000000,
  43. TextButton::textColourOffId, 0xff000000,
  44. ToggleButton::textColourId, 0xff000000,
  45. TextEditor::backgroundColourId, 0xffffffff,
  46. TextEditor::textColourId, 0xff000000,
  47. TextEditor::highlightColourId, textHighlightColour,
  48. TextEditor::highlightedTextColourId, 0xff000000,
  49. TextEditor::outlineColourId, 0x00000000,
  50. TextEditor::focusedOutlineColourId, textButtonColour,
  51. TextEditor::shadowColourId, 0x38000000,
  52. CaretComponent::caretColourId, 0xff000000,
  53. Label::backgroundColourId, 0x00000000,
  54. Label::textColourId, 0xff000000,
  55. Label::outlineColourId, 0x00000000,
  56. ScrollBar::backgroundColourId, 0x00000000,
  57. ScrollBar::thumbColourId, 0xffffffff,
  58. TreeView::linesColourId, 0x4c000000,
  59. TreeView::backgroundColourId, 0x00000000,
  60. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  61. TreeView::selectedItemBackgroundColourId, 0x00000000,
  62. PopupMenu::backgroundColourId, 0xffffffff,
  63. PopupMenu::textColourId, 0xff000000,
  64. PopupMenu::headerTextColourId, 0xff000000,
  65. PopupMenu::highlightedTextColourId, 0xffffffff,
  66. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  67. ComboBox::buttonColourId, 0xffbbbbff,
  68. ComboBox::outlineColourId, standardOutlineColour,
  69. ComboBox::textColourId, 0xff000000,
  70. ComboBox::backgroundColourId, 0xffffffff,
  71. ComboBox::arrowColourId, 0x99000000,
  72. TextPropertyComponent::backgroundColourId, 0xffffffff,
  73. TextPropertyComponent::textColourId, 0xff000000,
  74. TextPropertyComponent::outlineColourId, standardOutlineColour,
  75. ListBox::backgroundColourId, 0xffffffff,
  76. ListBox::outlineColourId, standardOutlineColour,
  77. ListBox::textColourId, 0xff000000,
  78. Slider::backgroundColourId, 0x00000000,
  79. Slider::thumbColourId, textButtonColour,
  80. Slider::trackColourId, 0x7fffffff,
  81. Slider::rotarySliderFillColourId, 0x7f0000ff,
  82. Slider::rotarySliderOutlineColourId, 0x66000000,
  83. Slider::textBoxTextColourId, 0xff000000,
  84. Slider::textBoxBackgroundColourId, 0xffffffff,
  85. Slider::textBoxHighlightColourId, textHighlightColour,
  86. Slider::textBoxOutlineColourId, standardOutlineColour,
  87. ResizableWindow::backgroundColourId, 0xff777777,
  88. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  89. AlertWindow::backgroundColourId, 0xffededed,
  90. AlertWindow::textColourId, 0xff000000,
  91. AlertWindow::outlineColourId, 0xff666666,
  92. ProgressBar::backgroundColourId, 0xffeeeeee,
  93. ProgressBar::foregroundColourId, 0xffaaaaee,
  94. TooltipWindow::backgroundColourId, 0xffeeeebb,
  95. TooltipWindow::textColourId, 0xff000000,
  96. TooltipWindow::outlineColourId, 0x4c000000,
  97. TabbedComponent::backgroundColourId, 0x00000000,
  98. TabbedComponent::outlineColourId, 0xff777777,
  99. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  100. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  101. Toolbar::backgroundColourId, 0xfff6f8f9,
  102. Toolbar::separatorColourId, 0x4c000000,
  103. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  104. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  105. Toolbar::labelTextColourId, 0xff000000,
  106. Toolbar::editingModeOutlineColourId, 0xffff0000,
  107. DrawableButton::textColourId, 0xff000000,
  108. DrawableButton::textColourOnId, 0xff000000,
  109. DrawableButton::backgroundColourId, 0x00000000,
  110. DrawableButton::backgroundOnColourId, 0xaabbbbff,
  111. HyperlinkButton::textColourId, 0xcc1111ee,
  112. GroupComponent::outlineColourId, 0x66000000,
  113. GroupComponent::textColourId, 0xff000000,
  114. BubbleComponent::backgroundColourId, 0xeeeeeebb,
  115. BubbleComponent::outlineColourId, 0x77000000,
  116. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  117. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  118. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  119. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  120. 0x1005000, /*MidiKeyboardComponent::whiteNoteColourId*/ 0xffffffff,
  121. 0x1005001, /*MidiKeyboardComponent::blackNoteColourId*/ 0xff000000,
  122. 0x1005002, /*MidiKeyboardComponent::keySeparatorLineColourId*/ 0x66000000,
  123. 0x1005003, /*MidiKeyboardComponent::mouseOverKeyOverlayColourId*/ 0x80ffff00,
  124. 0x1005004, /*MidiKeyboardComponent::keyDownOverlayColourId*/ 0xffb6b600,
  125. 0x1005005, /*MidiKeyboardComponent::textLabelColourId*/ 0xff000000,
  126. 0x1005006, /*MidiKeyboardComponent::upDownButtonBackgroundColourId*/ 0xffd3d3d3,
  127. 0x1005007, /*MidiKeyboardComponent::upDownButtonArrowColourId*/ 0xff000000,
  128. 0x1004500, /*CodeEditorComponent::backgroundColourId*/ 0xffffffff,
  129. 0x1004502, /*CodeEditorComponent::highlightColourId*/ textHighlightColour,
  130. 0x1004503, /*CodeEditorComponent::defaultTextColourId*/ 0xff000000,
  131. 0x1004504, /*CodeEditorComponent::lineNumberBackgroundId*/ 0x44999999,
  132. 0x1004505, /*CodeEditorComponent::lineNumberTextId*/ 0x44000000,
  133. 0x1007000, /*ColourSelector::backgroundColourId*/ 0xffe5e5e5,
  134. 0x1007001, /*ColourSelector::labelTextColourId*/ 0xff000000,
  135. 0x100ad00, /*KeyMappingEditorComponent::backgroundColourId*/ 0x00000000,
  136. 0x100ad01, /*KeyMappingEditorComponent::textColourId*/ 0xff000000,
  137. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  138. FileChooserDialogBox::titleTextColourId, 0xff000000,
  139. };
  140. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  141. setColour ((int) standardColours [i], Colour ((uint32) standardColours [i + 1]));
  142. juce_getTypefaceForFont = getTypefaceForFontFromLookAndFeel;
  143. }
  144. LookAndFeel::~LookAndFeel()
  145. {
  146. masterReference.clear();
  147. }
  148. //==============================================================================
  149. Colour LookAndFeel::findColour (int colourID) const noexcept
  150. {
  151. const ColourSetting c = { colourID, Colour() };
  152. const int index = colours.indexOf (c);
  153. if (index >= 0)
  154. return colours.getReference (index).colour;
  155. jassertfalse;
  156. return Colours::black;
  157. }
  158. void LookAndFeel::setColour (int colourID, Colour newColour) noexcept
  159. {
  160. const ColourSetting c = { colourID, newColour };
  161. const int index = colours.indexOf (c);
  162. if (index >= 0)
  163. colours.getReference (index).colour = newColour;
  164. else
  165. colours.add (c);
  166. }
  167. bool LookAndFeel::isColourSpecified (const int colourID) const noexcept
  168. {
  169. const ColourSetting c = { colourID, Colour() };
  170. return colours.contains (c);
  171. }
  172. //==============================================================================
  173. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() noexcept
  174. {
  175. return Desktop::getInstance().getDefaultLookAndFeel();
  176. }
  177. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) noexcept
  178. {
  179. Desktop::getInstance().setDefaultLookAndFeel (newDefaultLookAndFeel);
  180. }
  181. //==============================================================================
  182. Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  183. {
  184. if (defaultSans.isNotEmpty() && font.getTypefaceName() == Font::getDefaultSansSerifFontName())
  185. {
  186. Font f (font);
  187. f.setTypefaceName (defaultSans);
  188. return Typeface::createSystemTypefaceFor (f);
  189. }
  190. return Font::getDefaultTypefaceForFont (font);
  191. }
  192. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  193. {
  194. if (defaultSans != newName)
  195. {
  196. Typeface::clearTypefaceCache();
  197. defaultSans = newName;
  198. }
  199. }
  200. //==============================================================================
  201. MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  202. {
  203. MouseCursor m (component.getMouseCursor());
  204. Component* parent = component.getParentComponent();
  205. while (parent != nullptr && m == MouseCursor::ParentCursor)
  206. {
  207. m = parent->getMouseCursor();
  208. parent = parent->getParentComponent();
  209. }
  210. return m;
  211. }
  212. LowLevelGraphicsContext* LookAndFeel::createGraphicsContext (const Image& imageToRenderOn, const Point<int>& origin,
  213. const RectangleList<int>& initialClip)
  214. {
  215. return new LowLevelGraphicsSoftwareRenderer (imageToRenderOn, origin, initialClip);
  216. }
  217. //==============================================================================
  218. void LookAndFeel::setUsingNativeAlertWindows (bool shouldUseNativeAlerts)
  219. {
  220. useNativeAlertWindows = shouldUseNativeAlerts;
  221. }
  222. bool LookAndFeel::isUsingNativeAlertWindows()
  223. {
  224. #if JUCE_LINUX
  225. return false; // not available currently..
  226. #else
  227. return useNativeAlertWindows;
  228. #endif
  229. }