From 9ed6f088e3927e4da44a17faf16907da8c9234da Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 9 Jan 2013 12:43:43 +0000 Subject: [PATCH] Improved Path::addBubble. --- .../Source/Project/jucer_Project.cpp | 2 +- modules/juce_graphics/geometry/juce_Path.cpp | 47 ++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/extras/Introjucer/Source/Project/jucer_Project.cpp b/extras/Introjucer/Source/Project/jucer_Project.cpp index 7b380343ae..9f9eafe7ce 100644 --- a/extras/Introjucer/Source/Project/jucer_Project.cpp +++ b/extras/Introjucer/Source/Project/jucer_Project.cpp @@ -346,7 +346,7 @@ void Project::createPropertyEditors (PropertyListBuilder& props) "The name of the project."); props.add (new TextPropertyComponent (getVersionValue(), "Project Version", 16, false), - "The project's version number, This should be in the format major.minor.point"); + "The project's version number, This should be in the format major.minor.point[.point]"); props.add (new TextPropertyComponent (getCompanyName(), "Company Name", 256, false), "Your company name, which will be added to the properties of the binary where possible"); diff --git a/modules/juce_graphics/geometry/juce_Path.cpp b/modules/juce_graphics/geometry/juce_Path.cpp index 1180554bb2..a04108464f 100644 --- a/modules/juce_graphics/geometry/juce_Path.cpp +++ b/modules/juce_graphics/geometry/juce_Path.cpp @@ -732,58 +732,61 @@ void Path::addBubble (const Rectangle& bodyArea, const float cornerSize, const float arrowBaseWidth) { - const float cornerSize2 = 2.0f * cornerSize; + const float halfW = bodyArea.getWidth() / 2.0f; + const float halfH = bodyArea.getHeight() / 2.0f; + const float cornerSizeW = jmin (cornerSize, halfW); + const float cornerSizeH = jmin (cornerSize, halfH); + const float cornerSizeW2 = 2.0f * cornerSizeW; + const float cornerSizeH2 = 2.0f * cornerSizeH; - startNewSubPath (bodyArea.getX() + cornerSize, bodyArea.getY()); + startNewSubPath (bodyArea.getX() + cornerSizeW, bodyArea.getY()); - const float targetLimitX = bodyArea.getX() + cornerSize + arrowBaseWidth; - const float targetLimitW = bodyArea.getWidth() - cornerSize2 - arrowBaseWidth * 2.0f; + const Rectangle targetLimit (bodyArea.reduced (jmin (halfW - 1.0f, cornerSizeW + arrowBaseWidth), + jmin (halfH - 1.0f, cornerSizeH + arrowBaseWidth))); - const float targetLimitY = bodyArea.getY() + cornerSize + arrowBaseWidth; - const float targetLimitH = bodyArea.getHeight() - cornerSize2 - arrowBaseWidth * 2.0f; - - if (Rectangle (targetLimitX, maximumArea.getY(), - targetLimitW, bodyArea.getY() - maximumArea.getY()).contains (arrowTip)) + if (Rectangle (targetLimit.getX(), maximumArea.getY(), + targetLimit.getWidth(), bodyArea.getY() - maximumArea.getY()).contains (arrowTip)) { lineTo (arrowTip.x - arrowBaseWidth, bodyArea.getY()); lineTo (arrowTip.x, arrowTip.y); lineTo (arrowTip.x + arrowBaseWidth, bodyArea.getY()); } - lineTo (bodyArea.getRight() - cornerSize, bodyArea.getY()); - addArc (bodyArea.getRight() - cornerSize2, bodyArea.getY(), cornerSize2, cornerSize2, 0, float_Pi * 0.5f); + lineTo (bodyArea.getRight() - cornerSizeW, bodyArea.getY()); + addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getY(), cornerSizeW2, cornerSizeH2, 0, float_Pi * 0.5f); - if (Rectangle (bodyArea.getRight(), targetLimitY, - maximumArea.getRight() - bodyArea.getRight(), targetLimitH).contains (arrowTip)) + if (Rectangle (bodyArea.getRight(), targetLimit.getY(), + maximumArea.getRight() - bodyArea.getRight(), targetLimit.getHeight()).contains (arrowTip)) { lineTo (bodyArea.getRight(), arrowTip.y - arrowBaseWidth); lineTo (arrowTip.x, arrowTip.y); lineTo (bodyArea.getRight(), arrowTip.y + arrowBaseWidth); } - lineTo (bodyArea.getRight(), bodyArea.getBottom() - cornerSize); - addArc (bodyArea.getRight() - cornerSize2, bodyArea.getBottom() - cornerSize2, cornerSize2, cornerSize2, float_Pi * 0.5f, float_Pi); + lineTo (bodyArea.getRight(), bodyArea.getBottom() - cornerSizeH); + addArc (bodyArea.getRight() - cornerSizeW2, bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, float_Pi * 0.5f, float_Pi); - if (Rectangle (targetLimitX, bodyArea.getBottom(), - targetLimitW, maximumArea.getBottom() - bodyArea.getBottom()).contains (arrowTip)) + if (Rectangle (targetLimit.getX(), bodyArea.getBottom(), + targetLimit.getWidth(), maximumArea.getBottom() - bodyArea.getBottom()).contains (arrowTip)) { lineTo (arrowTip.x + arrowBaseWidth, bodyArea.getBottom()); lineTo (arrowTip.x, arrowTip.y); lineTo (arrowTip.x - arrowBaseWidth, bodyArea.getBottom()); } - lineTo (bodyArea.getX() + cornerSize, bodyArea.getBottom()); - addArc (bodyArea.getX(), bodyArea.getBottom() - cornerSize2, cornerSize2, cornerSize2, float_Pi, float_Pi * 1.5f); + lineTo (bodyArea.getX() + cornerSizeW, bodyArea.getBottom()); + addArc (bodyArea.getX(), bodyArea.getBottom() - cornerSizeH2, cornerSizeW2, cornerSizeH2, float_Pi, float_Pi * 1.5f); - if (Rectangle (maximumArea.getX(), targetLimitY, bodyArea.getX() - maximumArea.getX(), targetLimitH).contains (arrowTip)) + if (Rectangle (maximumArea.getX(), targetLimit.getY(), + bodyArea.getX() - maximumArea.getX(), targetLimit.getHeight()).contains (arrowTip)) { lineTo (bodyArea.getX(), arrowTip.y + arrowBaseWidth); lineTo (arrowTip.x, arrowTip.y); lineTo (bodyArea.getX(), arrowTip.y - arrowBaseWidth); } - lineTo (bodyArea.getX(), bodyArea.getY() + cornerSize); - addArc (bodyArea.getX(), bodyArea.getY(), cornerSize2, cornerSize2, float_Pi * 1.5f, float_Pi * 2.0f - 0.05f); + lineTo (bodyArea.getX(), bodyArea.getY() + cornerSizeH); + addArc (bodyArea.getX(), bodyArea.getY(), cornerSizeW2, cornerSizeH2, float_Pi * 1.5f, float_Pi * 2.0f - 0.05f); closeSubPath(); }