1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2020 - Raw Material Software Limited
6 
7    JUCE is an open source library subject to commercial or open-source
8    licensing.
9 
10    By using JUCE, you agree to the terms of both the JUCE 6 End-User License
11    Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
12 
13    End User License Agreement: www.juce.com/juce-6-licence
14    Privacy Policy: www.juce.com/juce-privacy-policy
15 
16    Or: You may also use this code under the terms of the GPL v3 (see
17    www.gnu.org/licenses).
18 
19    JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20    EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21    DISCLAIMED.
22 
23   ==============================================================================
24 */
25 
26 namespace juce
27 {
28 
29 //==============================================================================
30 /**
31     The latest JUCE look-and-feel style, as introduced in 2017.
32     @see LookAndFeel, LookAndFeel_V1, LookAndFeel_V2, LookAndFeel_V3
33 
34     @tags{GUI}
35 */
36 class JUCE_API  LookAndFeel_V4   : public LookAndFeel_V3
37 {
38 public:
39     /**
40          A struct containing the set of colours to apply to the GUI
41     */
42     class ColourScheme
43     {
44     public:
45         /** The standard set of colours to use. */
46         enum UIColour
47         {
48             windowBackground = 0,
49             widgetBackground,
50             menuBackground,
51             outline,
52             defaultText,
53             defaultFill,
54             highlightedText,
55             highlightedFill,
56             menuText,
57 
58             numColours
59         };
60 
61         template <typename... ItemColours>
ColourScheme(ItemColours...coloursToUse)62         ColourScheme (ItemColours... coloursToUse)
63         {
64             static_assert (sizeof... (coloursToUse) == numColours, "Must supply one colour for each UIColour item");
65             const Colour c[] = { Colour (coloursToUse)... };
66 
67             for (int i = 0; i < numColours; ++i)
68                 palette[i] = c[i];
69         }
70 
71         ColourScheme (const ColourScheme&) = default;
72         ColourScheme& operator= (const ColourScheme&) = default;
73 
74         /** Returns a colour from the scheme */
75         Colour getUIColour (UIColour colourToGet) const noexcept;
76 
77         /** Sets a scheme colour. */
78         void setUIColour (UIColour colourToSet, Colour newColour) noexcept;
79 
80         /** Returns true if two ColourPalette objects contain the same colours. */
81         bool operator== (const ColourScheme&) const noexcept;
82         /** Returns false if two ColourPalette objects contain the same colours. */
83         bool operator!= (const ColourScheme&) const noexcept;
84 
85     private:
86         Colour palette[numColours];
87     };
88 
89     //==============================================================================
90     /** Creates a LookAndFeel_V4 object with a default colour scheme. */
91     LookAndFeel_V4();
92 
93     /** Creates a LookAndFeel_V4 object with a given colour scheme. */
94     LookAndFeel_V4 (ColourScheme);
95 
96     /** Destructor. */
97     ~LookAndFeel_V4() override;
98 
99     //==============================================================================
100     void setColourScheme (ColourScheme);
getCurrentColourScheme()101     ColourScheme& getCurrentColourScheme() noexcept       { return currentColourScheme; }
102 
103     static ColourScheme getDarkColourScheme();
104     static ColourScheme getMidnightColourScheme();
105     static ColourScheme getGreyColourScheme();
106     static ColourScheme getLightColourScheme();
107 
108     //==============================================================================
109     Button* createDocumentWindowButton (int) override;
110     void positionDocumentWindowButtons (DocumentWindow&, int, int, int, int, Button*, Button*, Button*, bool) override;
111     void drawDocumentWindowTitleBar (DocumentWindow&, Graphics&, int, int, int, int, const Image*, bool) override;
112 
113     //==============================================================================
114     Font getTextButtonFont (TextButton&, int buttonHeight) override;
115 
116     void drawButtonBackground (Graphics&, Button&, const Colour& backgroundColour,
117                                bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
118 
119     void drawToggleButton (Graphics&, ToggleButton&,
120                            bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
121     void drawTickBox (Graphics&, Component&,
122                       float x, float y, float w, float h,
123                       bool ticked, bool isEnabled,
124                       bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
125 
126     void changeToggleButtonWidthToFitText (ToggleButton&) override;
127 
128     //==============================================================================
129     AlertWindow* createAlertWindow (const String& title, const String& message,
130                                     const String& button1,
131                                     const String& button2,
132                                     const String& button3,
133                                     AlertWindow::AlertIconType iconType,
134                                     int numButtons, Component* associatedComponent) override;
135     void drawAlertBox (Graphics&, AlertWindow&, const Rectangle<int>& textArea, TextLayout&) override;
136 
137     int getAlertWindowButtonHeight() override;
138     Font getAlertWindowTitleFont() override;
139     Font getAlertWindowMessageFont() override;
140     Font getAlertWindowFont() override;
141 
142     //==============================================================================
143     void drawProgressBar (Graphics&, ProgressBar&, int width, int height, double progress, const String& textToShow) override;
isProgressBarOpaque(ProgressBar &)144     bool isProgressBarOpaque (ProgressBar&) override    { return false; }
145 
146     //==============================================================================
147     int getDefaultScrollbarWidth() override;
148     void drawScrollbar (Graphics&, ScrollBar&, int x, int y, int width, int height, bool isScrollbarVertical,
149                         int thumbStartPosition, int thumbSize, bool isMouseOver, bool isMouseDown) override;
150 
151     //==============================================================================
152     Path getTickShape (float height) override;
153     Path getCrossShape (float height) override;
154 
155     //==============================================================================
156     void fillTextEditorBackground (Graphics&, int width, int height, TextEditor&) override;
157     void drawTextEditorOutline (Graphics&, int width, int height, TextEditor&) override;
158 
159     //==============================================================================
160     Button* createFileBrowserGoUpButton() override;
161 
162     void layoutFileBrowserComponent (FileBrowserComponent&,
163                                      DirectoryContentsDisplayComponent*,
164                                      FilePreviewComponent*,
165                                      ComboBox* currentPathBox,
166                                      TextEditor* filenameBox,
167                                      Button* goUpButton) override;
168 
169     void drawFileBrowserRow (Graphics&, int width, int height,
170                              const File& file, const String& filename, Image* icon,
171                              const String& fileSizeDescription, const String& fileTimeDescription,
172                              bool isDirectory, bool isItemSelected, int itemIndex,
173                              DirectoryContentsDisplayComponent&) override;
174 
175     //==============================================================================
176     void drawPopupMenuItem (Graphics&, const Rectangle<int>& area,
177                             bool isSeparator, bool isActive, bool isHighlighted, bool isTicked, bool hasSubMenu,
178                             const String& text, const String& shortcutKeyText,
179                             const Drawable* icon, const Colour* textColour) override;
180 
181     void getIdealPopupMenuItemSize (const String& text, bool isSeparator, int standardMenuItemHeight,
182                                     int& idealWidth, int& idealHeight) override;
183 
184     void drawMenuBarBackground (Graphics&, int width, int height, bool isMouseOverBar, MenuBarComponent&) override;
185 
186     void drawMenuBarItem (Graphics&, int width, int height,
187                           int itemIndex, const String& itemText,
188                           bool isMouseOverItem, bool isMenuOpen, bool isMouseOverBar,
189                           MenuBarComponent&) override;
190 
191     //==============================================================================
192     void drawComboBox (Graphics&, int width, int height, bool isButtonDown,
193                        int buttonX, int buttonY, int buttonW, int buttonH,
194                        ComboBox&) override;
195     Font getComboBoxFont (ComboBox&) override;
196     void positionComboBoxText (ComboBox&, Label&) override;
197 
198     //==============================================================================
199     int getSliderThumbRadius (Slider&) override;
200 
201     void drawLinearSlider (Graphics&, int x, int y, int width, int height,
202                            float sliderPos, float minSliderPos, float maxSliderPos,
203                            const Slider::SliderStyle, Slider&) override;
204 
205     void drawRotarySlider (Graphics&, int x, int y, int width, int height,
206                            float sliderPosProportional, float rotaryStartAngle,
207                            float rotaryEndAngle, Slider&) override;
208 
209     void drawPointer (Graphics&, float x, float y, float diameter,
210                       const Colour&, int direction) noexcept;
211 
212     Label* createSliderTextBox (Slider&) override;
213 
214     //==============================================================================
215     void drawTooltip (Graphics&, const String& text, int width, int height) override;
216 
217     //==============================================================================
218     void drawConcertinaPanelHeader (Graphics&, const Rectangle<int>& area,
219                                     bool isMouseOver, bool isMouseDown,
220                                     ConcertinaPanel&, Component& panel) override;
221 
222     //==============================================================================
223     void drawLevelMeter (Graphics&, int, int, float) override;
224 
225     //==============================================================================
226     void paintToolbarBackground (Graphics&, int width, int height, Toolbar&) override;
227 
228     void paintToolbarButtonLabel (Graphics&, int x, int y, int width, int height,
229                                   const String& text, ToolbarItemComponent&) override;
230 
231     //==============================================================================
232     void drawPropertyPanelSectionHeader (Graphics&, const String& name, bool isOpen, int width, int height) override;
233     void drawPropertyComponentBackground (Graphics&, int width, int height, PropertyComponent&) override;
234     void drawPropertyComponentLabel (Graphics&, int width, int height, PropertyComponent&) override;
235     Rectangle<int> getPropertyComponentContentPosition (PropertyComponent&) override;
236 
237     //==============================================================================
238     void drawCallOutBoxBackground (CallOutBox&, Graphics&, const Path&, Image&) override;
239 
240     //==============================================================================
241     void drawStretchableLayoutResizerBar (Graphics&, int, int, bool, bool, bool) override;
242 
243 private:
244     //==============================================================================
245     void drawLinearProgressBar (Graphics&, ProgressBar&, int width, int height, double progress, const String&);
246     void drawCircularProgressBar (Graphics&, ProgressBar&, const String&);
247 
248     int getPropertyComponentIndent (PropertyComponent&);
249 
250     //==============================================================================
251     void initialiseColours();
252     ColourScheme currentColourScheme;
253 
254     //==============================================================================
255     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeel_V4)
256 };
257 
258 } // namespace juce
259