mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added new version of Path::addRoundedRectangle(). Introjucer: new button look and feel.
This commit is contained in:
parent
2791f878e7
commit
745e2ae8b9
7 changed files with 153 additions and 99 deletions
|
|
@ -358,8 +358,8 @@ struct AppearanceEditor
|
|||
rebuildProperties();
|
||||
addAndMakeVisible (&panel);
|
||||
|
||||
loadButton.setColour (TextButton::buttonColourId, Colours::darkgrey.withAlpha (0.5f));
|
||||
saveButton.setColour (TextButton::buttonColourId, Colours::darkgrey.withAlpha (0.5f));
|
||||
loadButton.setColour (TextButton::buttonColourId, Colours::lightgrey.withAlpha (0.5f));
|
||||
saveButton.setColour (TextButton::buttonColourId, Colours::lightgrey.withAlpha (0.5f));
|
||||
loadButton.setColour (TextButton::textColourOffId, Colours::white);
|
||||
saveButton.setColour (TextButton::textColourOffId, Colours::white);
|
||||
|
||||
|
|
@ -533,6 +533,7 @@ IntrojucerLookAndFeel::IntrojucerLookAndFeel()
|
|||
{
|
||||
setColour (mainBackgroundColourId, Colour::greyLevel (0.8f));
|
||||
setColour (treeviewHighlightColourId, Colour (0x401111ee));
|
||||
setColour (TextButton::buttonColourId, Colour (0xffeeeeff));
|
||||
}
|
||||
|
||||
Rectangle<int> IntrojucerLookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
|
||||
|
|
@ -713,3 +714,52 @@ void IntrojucerLookAndFeel::drawConcertinaPanelHeader (Graphics& g, const Rectan
|
|||
g.setFont (Font (area.getHeight() * 0.6f).boldened());
|
||||
g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
|
||||
}
|
||||
|
||||
void IntrojucerLookAndFeel::drawButtonBackground (Graphics& g,
|
||||
Button& button,
|
||||
const Colour& backgroundColour,
|
||||
bool isMouseOverButton,
|
||||
bool isButtonDown)
|
||||
{
|
||||
const bool flatOnLeft = button.isConnectedOnLeft();
|
||||
const bool flatOnRight = button.isConnectedOnRight();
|
||||
const bool flatOnTop = button.isConnectedOnTop();
|
||||
const bool flatOnBottom = button.isConnectedOnBottom();
|
||||
|
||||
const float width = button.getWidth();
|
||||
const float height = button.getHeight();
|
||||
|
||||
const float x = 0.5f;
|
||||
const float y = 0.5f;
|
||||
const float w = width - 1.0f;
|
||||
const float h = height - 1.0f;
|
||||
const float cornerSize = 4.0f;
|
||||
|
||||
Colour baseColour (backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true)
|
||||
? 1.3f : 0.9f)
|
||||
.withMultipliedAlpha (button.isEnabled() ? 0.9f : 0.5f));
|
||||
|
||||
if (isButtonDown) baseColour = baseColour.contrasting (0.2f);
|
||||
else if (isMouseOverButton) baseColour = baseColour.contrasting (0.1f);
|
||||
|
||||
const float mainBrightness = baseColour.getBrightness();
|
||||
const float mainAlpha = baseColour.getFloatAlpha();
|
||||
|
||||
Path outline;
|
||||
outline.addRoundedRectangle (x, y, w, h, cornerSize, cornerSize,
|
||||
! (flatOnLeft || flatOnTop),
|
||||
! (flatOnRight || flatOnTop),
|
||||
! (flatOnLeft || flatOnBottom),
|
||||
! (flatOnRight || flatOnBottom));
|
||||
|
||||
g.setGradientFill (ColourGradient (baseColour.brighter (0.2f), 0.0f, 0.0f,
|
||||
baseColour.darker (0.25f), 0.0f, height, false));
|
||||
g.fillPath (outline);
|
||||
|
||||
g.setColour (Colours::white.withAlpha (0.4f * mainAlpha * mainBrightness * mainBrightness));
|
||||
g.strokePath (outline, PathStrokeType (1.0f), AffineTransform::translation (0.0f, 1.0f)
|
||||
.scaled (1.0f, (h - 1.6f) / h));
|
||||
|
||||
g.setColour (Colours::black.withAlpha (0.4f * mainAlpha));
|
||||
g.strokePath (outline, PathStrokeType (1.0f));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,6 +109,10 @@ public:
|
|||
void drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area,
|
||||
bool isMouseOver, bool isMouseDown,
|
||||
ConcertinaPanel& concertina, Component& panel);
|
||||
|
||||
void drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour,
|
||||
bool isMouseOverButton, bool isButtonDown);
|
||||
|
||||
private:
|
||||
Image backgroundTexture;
|
||||
Colour backgroundTextureBaseColour;
|
||||
|
|
|
|||
|
|
@ -114,15 +114,21 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
void systemRequestedQuit()
|
||||
{
|
||||
if ((! triggerAsyncQuitIfModalCompsActive())
|
||||
&& mainWindowList.askAllWindowsToClose())
|
||||
quit();
|
||||
}
|
||||
|
||||
bool triggerAsyncQuitIfModalCompsActive()
|
||||
{
|
||||
if (cancelAnyModalComponents())
|
||||
{
|
||||
new AsyncQuitRetrier();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mainWindowList.askAllWindowsToClose())
|
||||
quit();
|
||||
return false;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -76,10 +76,10 @@ public:
|
|||
r.removeFromBottom (6);
|
||||
|
||||
if (saveAndOpenButton.isVisible())
|
||||
saveAndOpenButton.setBounds (r.removeFromBottom (28).reduced (20, 3));
|
||||
saveAndOpenButton.setBounds (r.removeFromBottom (30).reduced (16, 4));
|
||||
|
||||
if (openProjectButton.isVisible())
|
||||
openProjectButton.setBounds (r.removeFromBottom (28).reduced (20, 3));
|
||||
openProjectButton.setBounds (r.removeFromBottom (30).reduced (16, 4));
|
||||
|
||||
tree.setBounds (r);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -434,8 +434,15 @@ void Path::addRectangle (const float x, const float y,
|
|||
|
||||
void Path::addRoundedRectangle (const float x, const float y,
|
||||
const float w, const float h,
|
||||
float csx,
|
||||
float csy)
|
||||
float csx, float csy)
|
||||
{
|
||||
addRoundedRectangle (x, y, w, h, csx, csy, true, true, true, true);
|
||||
}
|
||||
|
||||
void Path::addRoundedRectangle (const float x, const float y, const float w, const float h,
|
||||
float csx, float csy,
|
||||
const bool curveTopLeft, const bool curveTopRight,
|
||||
const bool curveBottomLeft, const bool curveBottomRight)
|
||||
{
|
||||
csx = jmin (csx, w * 0.5f);
|
||||
csy = jmin (csy, h * 0.5f);
|
||||
|
|
@ -444,15 +451,46 @@ void Path::addRoundedRectangle (const float x, const float y,
|
|||
const float x2 = x + w;
|
||||
const float y2 = y + h;
|
||||
|
||||
startNewSubPath (x + csx, y);
|
||||
lineTo (x2 - csx, y);
|
||||
cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
|
||||
lineTo (x2, y2 - csy);
|
||||
cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
|
||||
lineTo (x + csx, y2);
|
||||
cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
|
||||
lineTo (x, y + csy);
|
||||
cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
|
||||
if (curveTopLeft)
|
||||
{
|
||||
startNewSubPath (x, y + csy);
|
||||
cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
startNewSubPath (x, y);
|
||||
}
|
||||
|
||||
if (curveTopRight)
|
||||
{
|
||||
lineTo (x2 - csx, y);
|
||||
cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
|
||||
}
|
||||
else
|
||||
{
|
||||
lineTo (x2, y);
|
||||
}
|
||||
|
||||
if (curveBottomRight)
|
||||
{
|
||||
lineTo (x2, y2 - csy);
|
||||
cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
|
||||
}
|
||||
else
|
||||
{
|
||||
lineTo (x2, y2);
|
||||
}
|
||||
|
||||
if (curveBottomLeft)
|
||||
{
|
||||
lineTo (x + csx, y2);
|
||||
cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
|
||||
}
|
||||
else
|
||||
{
|
||||
lineTo (x, y2);
|
||||
}
|
||||
|
||||
closeSubPath();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -343,6 +343,15 @@ public:
|
|||
float cornerSizeX,
|
||||
float cornerSizeY);
|
||||
|
||||
/** Adds a rectangle with rounded corners to the path.
|
||||
The rectangle is added as a new sub-path. (Any currently open paths will be left open).
|
||||
@see addRectangle, addTriangle
|
||||
*/
|
||||
void addRoundedRectangle (float x, float y, float width, float height,
|
||||
float cornerSizeX, float cornerSizeY,
|
||||
bool curveTopLeft, bool curveTopRight,
|
||||
bool curveBottomLeft, bool curveBottomRight);
|
||||
|
||||
/** Adds a rectangle with rounded corners to the path.
|
||||
The rectangle is added as a new sub-path. (Any currently open paths will be left open).
|
||||
@see addRectangle, addTriangle
|
||||
|
|
|
|||
|
|
@ -25,58 +25,6 @@
|
|||
|
||||
namespace LookAndFeelHelpers
|
||||
{
|
||||
static void createRoundedPath (Path& p,
|
||||
const float x, const float y,
|
||||
const float w, const float h,
|
||||
const float cs,
|
||||
const bool curveTopLeft, const bool curveTopRight,
|
||||
const bool curveBottomLeft, const bool curveBottomRight) noexcept
|
||||
{
|
||||
const float cs2 = 2.0f * cs;
|
||||
|
||||
if (curveTopLeft)
|
||||
{
|
||||
p.startNewSubPath (x, y + cs);
|
||||
p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.startNewSubPath (x, y);
|
||||
}
|
||||
|
||||
if (curveTopRight)
|
||||
{
|
||||
p.lineTo (x + w - cs, y);
|
||||
p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.lineTo (x + w, y);
|
||||
}
|
||||
|
||||
if (curveBottomRight)
|
||||
{
|
||||
p.lineTo (x + w, y + h - cs);
|
||||
p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.lineTo (x + w, y + h);
|
||||
}
|
||||
|
||||
if (curveBottomLeft)
|
||||
{
|
||||
p.lineTo (x + cs, y + h);
|
||||
p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.lineTo (x, y + h);
|
||||
}
|
||||
|
||||
p.closeSubPath();
|
||||
}
|
||||
|
||||
static Colour createBaseColour (const Colour& buttonColour,
|
||||
const bool hasKeyboardFocus,
|
||||
const bool isMouseOverButton,
|
||||
|
|
@ -85,10 +33,8 @@ namespace LookAndFeelHelpers
|
|||
const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
|
||||
const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
|
||||
|
||||
if (isButtonDown)
|
||||
return baseColour.contrasting (0.2f);
|
||||
else if (isMouseOverButton)
|
||||
return baseColour.contrasting (0.1f);
|
||||
if (isButtonDown) return baseColour.contrasting (0.2f);
|
||||
if (isMouseOverButton) return baseColour.contrasting (0.1f);
|
||||
|
||||
return baseColour;
|
||||
}
|
||||
|
|
@ -106,17 +52,17 @@ namespace LookAndFeelHelpers
|
|||
tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth);
|
||||
return tl;
|
||||
}
|
||||
|
||||
static Typeface::Ptr getTypefaceForFontFromLookAndFeel (const Font& font)
|
||||
{
|
||||
return LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
typedef Typeface::Ptr (*GetTypefaceForFont) (const Font&);
|
||||
extern GetTypefaceForFont juce_getTypefaceForFont;
|
||||
|
||||
static Typeface::Ptr getTypefaceForFontFromLookAndFeel (const Font& font)
|
||||
{
|
||||
return LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
LookAndFeel::LookAndFeel()
|
||||
: useNativeAlertWindows (false)
|
||||
|
|
@ -267,7 +213,7 @@ LookAndFeel::LookAndFeel()
|
|||
for (int i = 0; i < numElementsInArray (standardColours); i += 2)
|
||||
setColour (standardColours [i], Colour ((uint32) standardColours [i + 1]));
|
||||
|
||||
juce_getTypefaceForFont = getTypefaceForFontFromLookAndFeel;
|
||||
juce_getTypefaceForFont = LookAndFeelHelpers::getTypefaceForFontFromLookAndFeel;
|
||||
}
|
||||
|
||||
LookAndFeel::~LookAndFeel()
|
||||
|
|
@ -2865,11 +2811,11 @@ void LookAndFeel::drawShinyButtonShape (Graphics& g,
|
|||
const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
|
||||
|
||||
Path outline;
|
||||
LookAndFeelHelpers::createRoundedPath (outline, x, y, w, h, cs,
|
||||
! (flatOnLeft || flatOnTop),
|
||||
! (flatOnRight || flatOnTop),
|
||||
! (flatOnLeft || flatOnBottom),
|
||||
! (flatOnRight || flatOnBottom));
|
||||
outline.addRoundedRectangle (x, y, w, h, cs, cs,
|
||||
! (flatOnLeft || flatOnTop),
|
||||
! (flatOnRight || flatOnTop),
|
||||
! (flatOnLeft || flatOnBottom),
|
||||
! (flatOnRight || flatOnBottom));
|
||||
|
||||
ColourGradient cg (baseColour, 0.0f, y,
|
||||
baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
|
||||
|
|
@ -2997,11 +2943,11 @@ void LookAndFeel::drawGlassLozenge (Graphics& g,
|
|||
const int intEdge = (int) edgeBlurRadius;
|
||||
|
||||
Path outline;
|
||||
LookAndFeelHelpers::createRoundedPath (outline, x, y, width, height, cs,
|
||||
! (flatOnLeft || flatOnTop),
|
||||
! (flatOnRight || flatOnTop),
|
||||
! (flatOnLeft || flatOnBottom),
|
||||
! (flatOnRight || flatOnBottom));
|
||||
outline.addRoundedRectangle (x, y, width, height, cs, cs,
|
||||
! (flatOnLeft || flatOnTop),
|
||||
! (flatOnRight || flatOnTop),
|
||||
! (flatOnLeft || flatOnBottom),
|
||||
! (flatOnRight || flatOnBottom));
|
||||
|
||||
{
|
||||
ColourGradient cg (colour.darker (0.2f), 0, y,
|
||||
|
|
@ -3047,15 +2993,16 @@ void LookAndFeel::drawGlassLozenge (Graphics& g,
|
|||
const float rightIndent = flatOnTop || flatOnRight ? 0.0f : cs * 0.4f;
|
||||
|
||||
Path highlight;
|
||||
LookAndFeelHelpers::createRoundedPath (highlight,
|
||||
x + leftIndent,
|
||||
y + cs * 0.1f,
|
||||
width - (leftIndent + rightIndent),
|
||||
height * 0.4f, cs * 0.4f,
|
||||
! (flatOnLeft || flatOnTop),
|
||||
! (flatOnRight || flatOnTop),
|
||||
! (flatOnLeft || flatOnBottom),
|
||||
! (flatOnRight || flatOnBottom));
|
||||
highlight.addRoundedRectangle (x + leftIndent,
|
||||
y + cs * 0.1f,
|
||||
width - (leftIndent + rightIndent),
|
||||
height * 0.4f,
|
||||
cs * 0.4f,
|
||||
cs * 0.4f,
|
||||
! (flatOnLeft || flatOnTop),
|
||||
! (flatOnRight || flatOnTop),
|
||||
! (flatOnLeft || flatOnBottom),
|
||||
! (flatOnRight || flatOnBottom));
|
||||
|
||||
g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
|
||||
Colours::transparentWhite, 0, y + height * 0.4f, false));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue