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.

260 lines
12KB

  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. //==============================================================================
  22. /**
  23. The latest JUCE look-and-feel style, as introduced in 2017.
  24. @see LookAndFeel, LookAndFeel_V1, LookAndFeel_V2, LookAndFeel_V3
  25. @tags{GUI}
  26. */
  27. class JUCE_API LookAndFeel_V4 : public LookAndFeel_V3
  28. {
  29. public:
  30. /**
  31. A struct containing the set of colours to apply to the GUI
  32. */
  33. class ColourScheme
  34. {
  35. public:
  36. /** The standard set of colours to use. */
  37. enum UIColour
  38. {
  39. windowBackground = 0,
  40. widgetBackground,
  41. menuBackground,
  42. outline,
  43. defaultText,
  44. defaultFill,
  45. highlightedText,
  46. highlightedFill,
  47. menuText,
  48. numColours
  49. };
  50. template <typename... ItemColours>
  51. ColourScheme (ItemColours... coloursToUse)
  52. {
  53. static_assert (sizeof... (coloursToUse) == numColours, "Must supply one colour for each UIColour item");
  54. const Colour c[] = { Colour (coloursToUse)... };
  55. for (int i = 0; i < numColours; ++i)
  56. palette[i] = c[i];
  57. }
  58. ColourScheme (const ColourScheme&) = default;
  59. ColourScheme& operator= (const ColourScheme&) = default;
  60. /** Returns a colour from the scheme */
  61. Colour getUIColour (UIColour colourToGet) const noexcept;
  62. /** Sets a scheme colour. */
  63. void setUIColour (UIColour colourToSet, Colour newColour) noexcept;
  64. /** Returns true if two ColourPalette objects contain the same colours. */
  65. bool operator== (const ColourScheme&) const noexcept;
  66. /** Returns false if two ColourPalette objects contain the same colours. */
  67. bool operator!= (const ColourScheme&) const noexcept;
  68. private:
  69. Colour palette[numColours];
  70. };
  71. //==============================================================================
  72. /** Creates a LookAndFeel_V4 object with a default colour scheme. */
  73. LookAndFeel_V4();
  74. /** Creates a LookAndFeel_V4 object with a given colour scheme. */
  75. LookAndFeel_V4 (ColourScheme);
  76. /** Destructor. */
  77. ~LookAndFeel_V4() override;
  78. //==============================================================================
  79. void setColourScheme (ColourScheme);
  80. ColourScheme& getCurrentColourScheme() noexcept { return currentColourScheme; }
  81. static ColourScheme getDarkColourScheme();
  82. static ColourScheme getMidnightColourScheme();
  83. static ColourScheme getGreyColourScheme();
  84. static ColourScheme getLightColourScheme();
  85. //==============================================================================
  86. Button* createDocumentWindowButton (int) override;
  87. void positionDocumentWindowButtons (DocumentWindow&, int, int, int, int, Button*, Button*, Button*, bool) override;
  88. void drawDocumentWindowTitleBar (DocumentWindow&, Graphics&, int, int, int, int, const Image*, bool) override;
  89. //==============================================================================
  90. Font getTextButtonFont (TextButton&, int buttonHeight) override;
  91. void drawButtonBackground (Graphics&, Button&, const Colour& backgroundColour,
  92. bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
  93. void drawToggleButton (Graphics&, ToggleButton&,
  94. bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
  95. void drawTickBox (Graphics&, Component&,
  96. float x, float y, float w, float h,
  97. bool ticked, bool isEnabled,
  98. bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
  99. void changeToggleButtonWidthToFitText (ToggleButton&) override;
  100. //==============================================================================
  101. AlertWindow* createAlertWindow (const String& title, const String& message,
  102. const String& button1,
  103. const String& button2,
  104. const String& button3,
  105. AlertWindow::AlertIconType iconType,
  106. int numButtons, Component* associatedComponent) override;
  107. void drawAlertBox (Graphics&, AlertWindow&, const Rectangle<int>& textArea, TextLayout&) override;
  108. int getAlertWindowButtonHeight() override;
  109. Font getAlertWindowTitleFont() override;
  110. Font getAlertWindowMessageFont() override;
  111. Font getAlertWindowFont() override;
  112. //==============================================================================
  113. void drawProgressBar (Graphics&, ProgressBar&, int width, int height, double progress, const String& textToShow) override;
  114. bool isProgressBarOpaque (ProgressBar&) override { return false; }
  115. //==============================================================================
  116. int getDefaultScrollbarWidth() override;
  117. void drawScrollbar (Graphics&, ScrollBar&, int x, int y, int width, int height, bool isScrollbarVertical,
  118. int thumbStartPosition, int thumbSize, bool isMouseOver, bool isMouseDown) override;
  119. //==============================================================================
  120. Path getTickShape (float height) override;
  121. Path getCrossShape (float height) override;
  122. //==============================================================================
  123. void fillTextEditorBackground (Graphics&, int width, int height, TextEditor&) override;
  124. void drawTextEditorOutline (Graphics&, int width, int height, TextEditor&) override;
  125. //==============================================================================
  126. Button* createFileBrowserGoUpButton() override;
  127. void layoutFileBrowserComponent (FileBrowserComponent&,
  128. DirectoryContentsDisplayComponent*,
  129. FilePreviewComponent*,
  130. ComboBox* currentPathBox,
  131. TextEditor* filenameBox,
  132. Button* goUpButton) override;
  133. void drawFileBrowserRow (Graphics&, int width, int height,
  134. const File& file, const String& filename, Image* icon,
  135. const String& fileSizeDescription, const String& fileTimeDescription,
  136. bool isDirectory, bool isItemSelected, int itemIndex,
  137. DirectoryContentsDisplayComponent&) override;
  138. //==============================================================================
  139. void drawPopupMenuItem (Graphics&, const Rectangle<int>& area,
  140. bool isSeparator, bool isActive, bool isHighlighted, bool isTicked, bool hasSubMenu,
  141. const String& text, const String& shortcutKeyText,
  142. const Drawable* icon, const Colour* textColour) override;
  143. void getIdealPopupMenuItemSize (const String& text, bool isSeparator, int standardMenuItemHeight,
  144. int& idealWidth, int& idealHeight) override;
  145. void drawMenuBarBackground (Graphics&, int width, int height, bool isMouseOverBar, MenuBarComponent&) override;
  146. void drawMenuBarItem (Graphics&, int width, int height,
  147. int itemIndex, const String& itemText,
  148. bool isMouseOverItem, bool isMenuOpen, bool isMouseOverBar,
  149. MenuBarComponent&) override;
  150. //==============================================================================
  151. void drawComboBox (Graphics&, int width, int height, bool isButtonDown,
  152. int buttonX, int buttonY, int buttonW, int buttonH,
  153. ComboBox&) override;
  154. Font getComboBoxFont (ComboBox&) override;
  155. void positionComboBoxText (ComboBox&, Label&) override;
  156. //==============================================================================
  157. int getSliderThumbRadius (Slider&) override;
  158. void drawLinearSlider (Graphics&, int x, int y, int width, int height,
  159. float sliderPos, float minSliderPos, float maxSliderPos,
  160. const Slider::SliderStyle, Slider&) override;
  161. void drawRotarySlider (Graphics&, int x, int y, int width, int height,
  162. float sliderPosProportional, float rotaryStartAngle,
  163. float rotaryEndAngle, Slider&) override;
  164. void drawPointer (Graphics&, float x, float y, float diameter,
  165. const Colour&, int direction) noexcept;
  166. Label* createSliderTextBox (Slider&) override;
  167. //==============================================================================
  168. void drawTooltip (Graphics&, const String& text, int width, int height) override;
  169. //==============================================================================
  170. void drawConcertinaPanelHeader (Graphics&, const Rectangle<int>& area,
  171. bool isMouseOver, bool isMouseDown,
  172. ConcertinaPanel&, Component& panel) override;
  173. //==============================================================================
  174. void drawLevelMeter (Graphics&, int, int, float) override;
  175. //==============================================================================
  176. void paintToolbarBackground (Graphics&, int width, int height, Toolbar&) override;
  177. void paintToolbarButtonLabel (Graphics&, int x, int y, int width, int height,
  178. const String& text, ToolbarItemComponent&) override;
  179. //==============================================================================
  180. void drawPropertyPanelSectionHeader (Graphics&, const String& name, bool isOpen, int width, int height) override;
  181. void drawPropertyComponentBackground (Graphics&, int width, int height, PropertyComponent&) override;
  182. void drawPropertyComponentLabel (Graphics&, int width, int height, PropertyComponent&) override;
  183. Rectangle<int> getPropertyComponentContentPosition (PropertyComponent&) override;
  184. //==============================================================================
  185. void drawCallOutBoxBackground (CallOutBox&, Graphics&, const Path&, Image&) override;
  186. //==============================================================================
  187. void drawStretchableLayoutResizerBar (Graphics&, int, int, bool, bool, bool) override;
  188. private:
  189. //==============================================================================
  190. void drawLinearProgressBar (Graphics&, ProgressBar&, int width, int height, double progress, const String&);
  191. void drawCircularProgressBar (Graphics&, ProgressBar&, const String&);
  192. int getPropertyComponentIndent (PropertyComponent&);
  193. //==============================================================================
  194. void initialiseColours();
  195. ColourScheme currentColourScheme;
  196. //==============================================================================
  197. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeel_V4)
  198. };
  199. } // namespace juce