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.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /** This class is used to hold a few look and feel base classes which are associated
  22. with classes that may not be present because they're from modules other than
  23. juce_gui_basics.
  24. @tags{GUI}
  25. */
  26. struct JUCE_API ExtraLookAndFeelBaseClasses
  27. {
  28. //==============================================================================
  29. /** This abstract base class is implemented by LookAndFeel classes. */
  30. struct JUCE_API LassoComponentMethods
  31. {
  32. virtual ~LassoComponentMethods() = default;
  33. virtual void drawLasso (Graphics&, Component& lassoComp) = 0;
  34. };
  35. //==============================================================================
  36. /** This abstract base class is implemented by LookAndFeel classes. */
  37. struct JUCE_API KeyMappingEditorComponentMethods
  38. {
  39. virtual ~KeyMappingEditorComponentMethods() = default;
  40. virtual void drawKeymapChangeButton (Graphics&, int width, int height, Button&, const String& keyDescription) = 0;
  41. };
  42. //==============================================================================
  43. /** This abstract base class is implemented by LookAndFeel classes. */
  44. struct JUCE_API AudioDeviceSelectorComponentMethods
  45. {
  46. virtual ~AudioDeviceSelectorComponentMethods() = default;
  47. virtual void drawLevelMeter (Graphics&, int width, int height, float level) = 0;
  48. };
  49. };
  50. //==============================================================================
  51. /**
  52. LookAndFeel objects define the appearance of all the JUCE widgets, and subclasses
  53. can be used to apply different 'skins' to the application.
  54. This class is an abstract base-class - for actual look-and-feels that you can
  55. instantiate, see LookAndFeel_V1, LookAndFeel_V2 and LookAndFeel_V3.
  56. @see LookAndFeel_V1, LookAndFeel_V2, LookAndFeel_V3
  57. @tags{GUI}
  58. */
  59. class JUCE_API LookAndFeel : public ScrollBar::LookAndFeelMethods,
  60. public Button::LookAndFeelMethods,
  61. public ImageButton::LookAndFeelMethods,
  62. public TextEditor::LookAndFeelMethods,
  63. public FileBrowserComponent::LookAndFeelMethods,
  64. public TreeView::LookAndFeelMethods,
  65. public BubbleComponent::LookAndFeelMethods,
  66. public AlertWindow::LookAndFeelMethods,
  67. public PopupMenu::LookAndFeelMethods,
  68. public ComboBox::LookAndFeelMethods,
  69. public Label::LookAndFeelMethods,
  70. public Slider::LookAndFeelMethods,
  71. public ResizableWindow::LookAndFeelMethods,
  72. public DocumentWindow::LookAndFeelMethods,
  73. public TooltipWindow::LookAndFeelMethods,
  74. public TabbedButtonBar::LookAndFeelMethods,
  75. public PropertyComponent::LookAndFeelMethods,
  76. public FilenameComponent::LookAndFeelMethods,
  77. public GroupComponent::LookAndFeelMethods,
  78. public TableHeaderComponent::LookAndFeelMethods,
  79. public CallOutBox::LookAndFeelMethods,
  80. public Toolbar::LookAndFeelMethods,
  81. public ConcertinaPanel::LookAndFeelMethods,
  82. public ProgressBar::LookAndFeelMethods,
  83. public StretchableLayoutResizerBar::LookAndFeelMethods,
  84. public ExtraLookAndFeelBaseClasses::KeyMappingEditorComponentMethods,
  85. public ExtraLookAndFeelBaseClasses::AudioDeviceSelectorComponentMethods,
  86. public ExtraLookAndFeelBaseClasses::LassoComponentMethods,
  87. public SidePanel::LookAndFeelMethods
  88. {
  89. public:
  90. //==============================================================================
  91. /** Creates the default JUCE look and feel. */
  92. LookAndFeel();
  93. /** Destructor. */
  94. ~LookAndFeel() override;
  95. //==============================================================================
  96. /** Returns the current default look-and-feel for a component to use when it
  97. hasn't got one explicitly set.
  98. @see setDefaultLookAndFeel
  99. */
  100. static LookAndFeel& getDefaultLookAndFeel() noexcept;
  101. /** Changes the default look-and-feel.
  102. @param newDefaultLookAndFeel the new look-and-feel object to use - if this is
  103. set to null, it will revert to using the default one. The
  104. object passed-in must be deleted by the caller when
  105. it's no longer needed.
  106. @see getDefaultLookAndFeel
  107. */
  108. static void setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) noexcept;
  109. //==============================================================================
  110. /** Looks for a colour that has been registered with the given colour ID number.
  111. If a colour has been set for this ID number using setColour(), then it is
  112. returned. If none has been set, it will just return Colours::black.
  113. The colour IDs for various purposes are stored as enums in the components that
  114. they are relevant to - for an example, see Slider::ColourIds,
  115. Label::ColourIds, TextEditor::ColourIds, TreeView::ColourIds, etc.
  116. If you're looking up a colour for use in drawing a component, it's usually
  117. best not to call this directly, but to use the Component::findColour() method
  118. instead. That will first check whether a suitable colour has been registered
  119. directly with the component, and will fall-back on calling the component's
  120. LookAndFeel's findColour() method if none is found.
  121. @see setColour, Component::findColour, Component::setColour
  122. */
  123. Colour findColour (int colourId) const noexcept;
  124. /** Registers a colour to be used for a particular purpose.
  125. For more details, see the comments for findColour().
  126. @see findColour, Component::findColour, Component::setColour
  127. */
  128. void setColour (int colourId, Colour colour) noexcept;
  129. /** Returns true if the specified colour ID has been explicitly set using the
  130. setColour() method.
  131. */
  132. bool isColourSpecified (int colourId) const noexcept;
  133. //==============================================================================
  134. /** Returns the typeface that should be used for a given font.
  135. The default implementation just does what you'd expect it to, but you can override
  136. this if you want to intercept fonts and use your own custom typeface object.
  137. @see setDefaultTypeface
  138. */
  139. virtual Typeface::Ptr getTypefaceForFont (const Font&);
  140. /** Allows you to supply a default typeface that will be returned as the default
  141. sans-serif font.
  142. Instead of a typeface object, you can specify a typeface by name using the
  143. setDefaultSansSerifTypefaceName() method.
  144. You can perform more complex typeface substitutions by overloading
  145. getTypefaceForFont() but this lets you easily set a global typeface.
  146. */
  147. void setDefaultSansSerifTypeface (Typeface::Ptr newDefaultTypeface);
  148. /** Allows you to change the default sans-serif font.
  149. If you need to supply your own Typeface object for any of the default fonts, rather
  150. than just supplying the name (e.g. if you want to use an embedded font), then
  151. you can instead call setDefaultSansSerifTypeface() with an object to use.
  152. */
  153. void setDefaultSansSerifTypefaceName (const String& newName);
  154. //==============================================================================
  155. /** Sets whether native alert windows (if available) or standard JUCE AlertWindows
  156. drawn with AlertWindow::LookAndFeelMethods will be used.
  157. @see isUsingNativeAlertWindows
  158. */
  159. void setUsingNativeAlertWindows (bool shouldUseNativeAlerts);
  160. /** Returns true if native alert windows will be used (if available).
  161. The default setting for this is false.
  162. @see setUsingNativeAlertWindows
  163. */
  164. bool isUsingNativeAlertWindows();
  165. //==============================================================================
  166. /** Draws a small image that spins to indicate that something's happening.
  167. This method should use the current time to animate itself, so just keep
  168. repainting it every so often.
  169. */
  170. virtual void drawSpinningWaitAnimation (Graphics&, const Colour& colour,
  171. int x, int y, int w, int h) = 0;
  172. /** Returns a tick shape for use in yes/no boxes, etc. */
  173. virtual Path getTickShape (float height) = 0;
  174. /** Returns a cross shape for use in yes/no boxes, etc. */
  175. virtual Path getCrossShape (float height) = 0;
  176. /** Creates a drop-shadower for a given component, if required.
  177. @see DropShadower
  178. */
  179. virtual std::unique_ptr<DropShadower> createDropShadowerForComponent (Component&) = 0;
  180. /** Creates a focus outline for a given component, if required.
  181. @see FocusOutline
  182. */
  183. virtual std::unique_ptr<FocusOutline> createFocusOutlineForComponent (Component&) = 0;
  184. //==============================================================================
  185. /** Override this to get the chance to swap a component's mouse cursor for a
  186. customised one.
  187. @see MouseCursor
  188. */
  189. virtual MouseCursor getMouseCursorFor (Component&);
  190. /** Creates a new graphics context object. */
  191. virtual std::unique_ptr<LowLevelGraphicsContext> createGraphicsContext (const Image& imageToRenderOn,
  192. Point<int> origin,
  193. const RectangleList<int>& initialClip);
  194. /** Plays the system's default 'beep' noise, to alert the user about something
  195. very important. This is only supported on some platforms.
  196. */
  197. virtual void playAlertSound();
  198. private:
  199. //==============================================================================
  200. struct ColourSetting
  201. {
  202. int colourID;
  203. Colour colour;
  204. bool operator< (const ColourSetting& other) const noexcept { return colourID < other.colourID; }
  205. bool operator== (const ColourSetting& other) const noexcept { return colourID == other.colourID; }
  206. };
  207. SortedSet<ColourSetting> colours;
  208. String defaultSans, defaultSerif, defaultFixed;
  209. Typeface::Ptr defaultTypeface;
  210. bool useNativeAlertWindows = false;
  211. JUCE_DECLARE_WEAK_REFERENCEABLE (LookAndFeel)
  212. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeel)
  213. };
  214. } // namespace juce