29LookAndFeel_V1::LookAndFeel_V1()
45 scrollbarShadow.
setShadowProperties (DropShadow (Colours::black.withAlpha (0.5f), 2, Point<int>()));
48LookAndFeel_V1::~LookAndFeel_V1()
53void LookAndFeel_V1::drawButtonBackground (Graphics& g, Button& button,
const Colour& backgroundColour,
54 bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown)
56 const int width = button.getWidth();
57 const int height = button.getHeight();
59 const float indent = 2.0f;
64 p.addRoundedRectangle (indent, indent,
65 (
float) width - indent * 2.0f,
66 (
float) height - indent * 2.0f,
69 Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
71 if (shouldDrawButtonAsHighlighted)
73 if (shouldDrawButtonAsDown)
75 else if (bc.getBrightness() > 0.5f)
76 bc = bc.darker (0.1f);
78 bc = bc.brighter (0.1f);
84 g.setColour (bc.contrasting().withAlpha ((shouldDrawButtonAsHighlighted) ? 0.6f : 0.4f));
85 g.strokePath (p, PathStrokeType ((shouldDrawButtonAsHighlighted) ? 2.0f : 1.4f));
88void LookAndFeel_V1::drawTickBox (Graphics& g, Component& ,
89 float x,
float y,
float w,
float h,
93 const bool shouldDrawButtonAsDown)
96 box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
98 g.setColour (isEnabled ? Colours::blue.withAlpha (shouldDrawButtonAsDown ? 0.3f : 0.1f)
99 : Colours::lightgrey.withAlpha (0.1f));
103 g.fillPath (box, trans);
105 g.setColour (Colours::black.withAlpha (0.6f));
106 g.strokePath (box, PathStrokeType (0.9f), trans);
111 tick.startNewSubPath (1.5f, 3.0f);
112 tick.lineTo (3.0f, 6.0f);
113 tick.lineTo (6.0f, 0.0f);
115 g.setColour (isEnabled ? Colours::black : Colours::grey);
116 g.strokePath (tick, PathStrokeType (2.5f), trans);
122 if (button.hasKeyboardFocus (
true))
125 g.
drawRect (0, 0, button.getWidth(), button.getHeight());
128 const int tickWidth =
jmin (20, button.getHeight() - 4);
130 drawTickBox (g, button, 4.0f, (
float) (button.getHeight() - tickWidth) * 0.5f,
131 (
float) tickWidth, (
float) tickWidth,
132 button.getToggleState(),
134 shouldDrawButtonAsHighlighted,
135 shouldDrawButtonAsDown);
138 g.
setFont (
jmin (15.0f, (
float) button.getHeight() * 0.6f));
140 if (! button.isEnabled())
143 const int textX = tickWidth + 5;
147 button.getWidth() - textX - 2, button.getHeight() - 8,
152 int width,
int height,
153 double progress,
const String& textToShow)
155 if (progress < 0 || progress >= 1.0)
174 g.
setFont ((
float) height * 0.6f);
182 int width,
int height,
int buttonDirection,
183 bool isScrollbarVertical,
184 bool shouldDrawButtonAsHighlighted,
185 bool shouldDrawButtonAsDown)
187 if (isScrollbarVertical)
194 const auto w = (
float) width;
195 const auto h = (
float) height;
197 if (buttonDirection == 0)
201 else if (buttonDirection == 1)
205 else if (buttonDirection == 2)
209 else if (buttonDirection == 3)
214 if (shouldDrawButtonAsDown)
216 else if (shouldDrawButtonAsHighlighted)
217 g.
setColour (Colours::white.withAlpha (0.7f));
223 g.
setColour (Colours::black.withAlpha (0.5f));
228 int x,
int y,
int width,
int height,
229 bool isScrollbarVertical,
int thumbStartPosition,
int thumbSize,
230 bool isMouseOver,
bool isMouseDown)
235 .
withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
237 if ((
float) thumbSize > 0.0f)
241 if (isScrollbarVertical)
247 thumb.
setBounds (x + 1, thumbStartPosition,
248 width - 2, thumbSize);
256 thumb.
setBounds (thumbStartPosition, y + 1,
257 thumbSize, height - 2);
261 .
withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
265 g.
setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
270 for (
int i = 3; --i >= 0;)
272 const float linePos = (
float) thumbStartPosition + (
float) thumbSize * 0.5f + (
float) (i - 1) * 4.0f;
273 g.
setColour (Colours::black.withAlpha (0.15f));
275 if (isScrollbarVertical)
277 g.
drawLine ((
float) x + (
float) width * 0.2f, linePos, (
float) width * 0.8f, linePos);
278 g.
setColour (Colours::white.withAlpha (0.15f));
279 g.
drawLine ((
float) width * 0.2f, linePos - 1.0f, (
float) width * 0.8f, linePos - 1.0f);
283 g.
drawLine (linePos, (
float) height * 0.2f, linePos, (
float) height * 0.8f);
284 g.
setColour (Colours::white.withAlpha (0.15f));
285 g.
drawLine (linePos - 1.0f, (
float) height * 0.2f, linePos - 1.0f, (
float) height * 0.8f);
294 return &scrollbarShadow;
303 g.
setColour (Colours::black.withAlpha (0.6f));
314void LookAndFeel_V1::drawTextEditorOutline (Graphics& g,
int width,
int height, TextEditor& textEditor)
316 if (textEditor.isEnabled())
319 g.drawRect (0, 0, width, height);
324void LookAndFeel_V1::drawComboBox (Graphics& g,
int width,
int height,
325 const bool isButtonDown,
326 int buttonX,
int buttonY,
int buttonW,
int buttonH,
332 : ComboBox::backgroundColourId));
333 g.fillRect (buttonX, buttonY, buttonW, buttonH);
336 g.drawRect (0, 0, width, height);
338 const float arrowX = 0.2f;
339 const float arrowH = 0.3f;
341 const auto x = (
float) buttonX;
342 const auto y = (
float) buttonY;
343 const auto w = (
float) buttonW;
344 const auto h = (
float) buttonH;
349 p.addTriangle (x + w * 0.5f, y + h * (0.45f - arrowH),
350 x + w * (1.0f - arrowX), y + h * 0.45f,
351 x + w * arrowX, y + h * 0.45f);
353 p.addTriangle (x + w * 0.5f, y + h * (0.55f + arrowH),
354 x + w * (1.0f - arrowX), y + h * 0.55f,
355 x + w * arrowX, y + h * 0.55f);
363Font LookAndFeel_V1::getComboBoxFont (ComboBox& box)
365 Font f (
jmin (15.0f, (
float) box.getHeight() * 0.85f));
366 f.setHorizontalScale (0.9f);
371static void drawTriangle (Graphics& g,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3, Colour fill, Colour outline)
374 p.addTriangle (x1, y1, x2, y2, x3, y3);
378 g.setColour (outline);
379 g.strokePath (p, PathStrokeType (0.3f));
382void LookAndFeel_V1::drawLinearSlider (Graphics& g,
383 int x,
int y,
int w,
int h,
384 float sliderPos,
float minSliderPos,
float maxSliderPos,
393 g.fillRect (x, y, (
int) sliderPos - x, h);
396 g.drawRect (x, y, (
int) sliderPos - x, h);
401 .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
403 if (slider.isHorizontal())
405 g.fillRect (x, y +
roundToInt ((
float) h * 0.6f),
410 g.fillRect (x +
roundToInt ((
float) w * 0.5f -
jmin (3.0f, (
float) w * 0.1f)), y,
416 if (slider.isEnabled())
417 alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
420 const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
425 (
float) x + (
float) w * 0.5f +
jmin (4.0f, (
float) w * 0.3f), minSliderPos,
426 (
float) x + (
float) w * 0.5f -
jmin (8.0f, (
float) w * 0.4f), minSliderPos - 7.0f,
427 (
float) x + (
float) w * 0.5f -
jmin (8.0f, (
float) w * 0.4f), minSliderPos,
431 (
float) x + (
float) w * 0.5f +
jmin (4.0f, (
float) w * 0.3f), maxSliderPos,
432 (
float) x + (
float) w * 0.5f -
jmin (8.0f, (
float) w * 0.4f), maxSliderPos,
433 (
float) x + (
float) w * 0.5f -
jmin (8.0f, (
float) w * 0.4f), maxSliderPos + 7.0f,
439 minSliderPos, (
float) y + (
float) h * 0.6f -
jmin (4.0f, (
float) h * 0.3f),
440 minSliderPos - 7.0f, (
float) y + (
float) h * 0.9f,
441 minSliderPos, (
float) y + (
float) h * 0.9f,
445 maxSliderPos, (
float) y + (
float) h * 0.6f -
jmin (4.0f, (
float) h * 0.3f),
446 maxSliderPos, (
float) y + (
float) h * 0.9f,
447 maxSliderPos + 7.0f, (
float) y + (
float) h * 0.9f,
454 sliderPos, (
float) y + (
float) h * 0.9f,
455 sliderPos - 7.0f, (
float) y + (
float) h * 0.2f,
456 sliderPos + 7.0f, (
float) y + (
float) h * 0.2f,
462 (
float) x + (
float) w * 0.5f -
jmin (4.0f, (
float) w * 0.3f), sliderPos,
463 (
float) x + (
float) w * 0.5f +
jmin (8.0f, (
float) w * 0.4f), sliderPos - 7.0f,
464 (
float) x + (
float) w * 0.5f +
jmin (8.0f, (
float) w * 0.4f), sliderPos + 7.0f,
470 drawLinearSliderOutline (g, x, y, w, h, style, slider);
473Button* LookAndFeel_V1::createSliderButton (Slider&,
const bool isIncrement)
476 return new ArrowButton (
"u", 0.75f, Colours::white.withAlpha (0.8f));
478 return new ArrowButton (
"d", 0.25f, Colours::white.withAlpha (0.8f));
481ImageEffectFilter* LookAndFeel_V1::getSliderEffect (Slider&)
483 return &scrollbarShadow;
486int LookAndFeel_V1::getSliderThumbRadius (Slider&)
492void LookAndFeel_V1::drawCornerResizer (Graphics& g,
int w,
int h,
bool isMouseOver,
bool isMouseDragging)
494 g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
495 : Colours::darkgrey);
497 const float lineThickness = (
float)
jmin (w, h) * 0.1f;
499 for (
float i = 0.0f; i < 1.0f; i += 0.3f)
501 g.drawLine ((
float) w * i,
510Button* LookAndFeel_V1::createDocumentWindowButton (
int buttonType)
514 if (buttonType == DocumentWindow::closeButton)
516 shape.addLineSegment (Line<float> (0.0f, 0.0f, 1.0f, 1.0f), 0.35f);
517 shape.addLineSegment (Line<float> (1.0f, 0.0f, 0.0f, 1.0f), 0.35f);
519 ShapeButton*
const b =
new ShapeButton (
"close",
522 Colour (0xf7ff3333));
524 b->setShape (shape,
true,
true,
true);
527 else if (buttonType == DocumentWindow::minimiseButton)
529 shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), 0.25f);
534 dp.setFill (Colours::black.withAlpha (0.3f));
538 else if (buttonType == DocumentWindow::maximiseButton)
540 shape.addLineSegment (Line<float> (0.5f, 0.0f, 0.5f, 1.0f), 0.25f);
541 shape.addLineSegment (Line<float> (0.0f, 0.5f, 1.0f, 0.5f), 0.25f);
546 dp.setFill (Colours::black.withAlpha (0.3f));
555void LookAndFeel_V1::positionDocumentWindowButtons (DocumentWindow&,
556 int titleBarX,
int titleBarY,
int titleBarW,
int titleBarH,
557 Button* minimiseButton,
558 Button* maximiseButton,
560 bool positionTitleBarButtonsOnLeft)
562 titleBarY += titleBarH / 8;
563 titleBarH -= titleBarH / 4;
565 const int buttonW = titleBarH;
567 int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
568 : titleBarX + titleBarW - buttonW - 4;
570 if (closeButton !=
nullptr)
572 closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
573 x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
574 : -(buttonW + buttonW / 5);
577 if (positionTitleBarButtonsOnLeft)
578 std::swap (minimiseButton, maximiseButton);
580 if (maximiseButton !=
nullptr)
582 maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
583 x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
586 if (minimiseButton !=
nullptr)
587 minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
Represents a colour, also including a transparency value.
Colour withAlpha(uint8 newAlpha) const noexcept
Returns a colour that's the same colour as this one, but with a new alpha value.
Colour contrasting(float amount=1.0f) const noexcept
Returns a colour that will be clearly visible against this colour.
@ outlineColourId
The colour for an outline around the box.
@ buttonColourId
The base colour for the button (a LookAndFeel class will probably use variations on this).
@ backgroundColourId
The background colour to fill the box with.
Colour findColour(int colourID, bool inheritFromParent=false) const
Looks for a colour that has been registered with the given colour ID number.
void setShadowProperties(const DropShadow &newShadow)
Sets up parameters affecting the shadow's appearance.
A graphics context, used for drawing a component or image.
void setOpacity(float newOpacity)
Changes the opacity to use with the current colour.
void drawText(const String &text, int x, int y, int width, int height, Justification justificationType, bool useEllipsesIfTooBig=true) const
Draws a line of text within a specified rectangle.
void drawFittedText(const String &text, int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
Tries to draw a text string inside a given space.
void setFont(const Font &newFont)
Changes the font to use for subsequent text-drawing functions.
void drawRect(int x, int y, int width, int height, int lineThickness=1) const
Draws a rectangular outline, using the current colour or brush.
void fillRect(Rectangle< int > rectangle) const
Fills a rectangle with the current colour or brush.
void fillPath(const Path &path) const
Fills a path using the currently selected colour or brush.
void setColour(Colour newColour)
Changes the current drawing colour.
void drawLine(float startX, float startY, float endX, float endY) const
Draws a line between two points.
void strokePath(const Path &path, const PathStrokeType &strokeType, const AffineTransform &transform={}) const
Draws a path's outline using the currently selected colour or brush.
void fillAll() const
Fills the context's entire clip region with the current colour or brush.
A graphical effect filter that can be applied to components.
@ centred
Indicates that the item should be centred vertically and horizontally.
@ centredLeft
Indicates that the item should be centred vertically but placed on the left hand side.
@ outlineColourId
An optional colour to use to draw a border around the list.
void drawPopupMenuBackground(Graphics &, int width, int height) override
Fills the background of a popup menu component.
void drawToggleButton(Graphics &, ToggleButton &, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
Draws the contents of a standard ToggleButton.
void drawScrollbarButton(Graphics &, ScrollBar &, int width, int height, int buttonDirection, bool isScrollbarVertical, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
Draws one of the buttons on a scrollbar.
void drawProgressBar(Graphics &, ProgressBar &, int width, int height, double progress, const String &textToShow) override
Draws a progress bar.
void drawScrollbar(Graphics &, ScrollBar &, int x, int y, int width, int height, bool isScrollbarVertical, int thumbStartPosition, int thumbSize, bool isMouseOver, bool isMouseDown) override
Draws the thumb area of a scrollbar.
ImageEffectFilter * getScrollbarEffect() override
Returns the component effect to use for a scrollbar.
void drawProgressBar(Graphics &, ProgressBar &, int width, int height, double progress, const String &textToShow) override
Draws a progress bar.
void setColour(int colourId, Colour colour) noexcept
Registers a colour to be used for a particular purpose.
Colour findColour(int colourId) const noexcept
Looks for a colour that has been registered with the given colour ID number.
Describes a type of stroke used to render a solid outline along a path.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3)
Adds a triangle to the path.
A progress bar component.
@ backgroundColourId
The background colour, behind the bar.
@ foregroundColourId
The colour to use to draw the bar itself.
Manages a rectangle and allows geometric operations to be performed on it.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
void setBounds(ValueType newX, ValueType newY, ValueType newWidth, ValueType newHeight) noexcept
Changes all the rectangle's coordinates.
SliderStyle
The types of slider available.
@ ThreeValueHorizontal
A horizontal slider that has three thumbs instead of one, so it can show a minimum and maximum value,...
@ TwoValueHorizontal
A horizontal slider that has two thumbs instead of one, so it can show a minimum and maximum value.
@ LinearBar
A horizontal bar slider with the text label drawn on top of it.
@ LinearHorizontal
A traditional horizontal slider.
@ LinearVertical
A traditional vertical slider.
@ ThreeValueVertical
A vertical slider that has three thumbs instead of one, so it can show a minimum and maximum value,...
@ TwoValueVertical
A vertical slider that has two thumbs instead of one, so it can show a minimum and maximum value.
@ textBoxTextColourId
The colour for the text in the text-editor box used for editing the value.
@ textBoxOutlineColourId
The colour to use for a border around the text-editor box.
@ trackColourId
The colour to draw the groove that the thumb moves along.
@ backgroundColourId
A colour to use to fill the slider's background.
@ thumbColourId
The colour to draw the thumb with.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
@ buttonColourId
The colour used to fill the button shape (when the button is toggled 'off').
@ outlineColourId
If this is non-transparent, it will be used to draw a box around the edge of the component.
@ focusedOutlineColourId
If this is non-transparent, it will be used to draw a box around the edge of the component when it ha...
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.