From 6fe9e2db73b5ed9508b5fd2a71538eae097ff4da Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 10 Jul 2012 11:50:17 +0100 Subject: [PATCH] Minor clean-ups. --- .../Source/Project/jucer_Project.cpp | 2 +- .../Source/Utility/jucer_MiscUtilities.h | 6 + .../layout/juce_TabbedButtonBar.cpp | 26 +-- .../layout/juce_TabbedButtonBar.h | 1 - .../lookandfeel/juce_LookAndFeel.cpp | 175 ++++++------------ .../lookandfeel/juce_LookAndFeel.h | 2 +- .../properties/juce_PropertyComponent.cpp | 21 +-- .../windows/juce_CallOutBox.cpp | 3 +- 8 files changed, 90 insertions(+), 146 deletions(-) diff --git a/extras/Introjucer/Source/Project/jucer_Project.cpp b/extras/Introjucer/Source/Project/jucer_Project.cpp index 6c140cd5fb..31db5ebf54 100644 --- a/extras/Introjucer/Source/Project/jucer_Project.cpp +++ b/extras/Introjucer/Source/Project/jucer_Project.cpp @@ -780,7 +780,7 @@ Icon Project::Item::getIcon() const if (isImageFile()) return Icon (icons.imageDoc, Colours::blue); - return Icon (icons.document, Colours::yellow.darker (1.0f)); + return Icon (icons.document, Colours::yellow); } else if (isMainGroup()) { diff --git a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h index b1465f0a12..e85aeef4f6 100644 --- a/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h +++ b/extras/Introjucer/Source/Utility/jucer_MiscUtilities.h @@ -62,6 +62,7 @@ struct Icon { Icon() : path (nullptr) {} Icon (const Path& p, const Colour& c) : path (&p), colour (c) {} + Icon (const Path* p, const Colour& c) : path (p), colour (c) {} void draw (Graphics& g, const Rectangle& area) const { @@ -74,6 +75,11 @@ struct Icon } } + Icon withContrastingColourTo (const Colour& background) const + { + return Icon (path, background.contrasting (colour, 0.6f)); + } + const Path* path; Colour colour; }; diff --git a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp index 066632df2f..b7ff56ba60 100644 --- a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp +++ b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp @@ -49,13 +49,12 @@ void TabBarButton::paintButton (Graphics& g, const Rectangle area (getActiveArea()); g.setOrigin (area.getX(), area.getY()); - getLookAndFeel() - .drawTabButton (g, area.getWidth(), area.getHeight(), - owner.getTabBackgroundColour (getIndex()), - getIndex(), getButtonText(), *this, - owner.getOrientation(), - isMouseOverButton, isButtonDown, - getToggleState()); + getLookAndFeel().drawTabButton (g, area.getWidth(), area.getHeight(), + owner.getTabBackgroundColour (getIndex()), + getIndex(), getButtonText(), *this, + owner.getOrientation(), + isMouseOverButton, isButtonDown, + getToggleState()); } void TabBarButton::clicked (const ModifierKeys& mods) @@ -86,9 +85,9 @@ bool TabBarButton::hitTest (int mx, int my) } Path p; - getLookAndFeel() - .createTabButtonShape (p, area.getWidth(), area.getHeight(), getIndex(), getButtonText(), *this, - owner.getOrientation(), false, false, getToggleState()); + getLookAndFeel().createTabButtonShape (p, area.getWidth(), area.getHeight(), + getIndex(), getButtonText(), *this, + owner.getOrientation(), false, false, getToggleState()); return p.contains ((float) (mx - area.getX()), (float) (my - area.getY())); @@ -325,14 +324,15 @@ void TabbedButtonBar::lookAndFeelChanged() void TabbedButtonBar::resized() { + LookAndFeel& lf = getLookAndFeel(); + int depth = getWidth(); int length = getHeight(); if (orientation == TabsAtTop || orientation == TabsAtBottom) std::swap (depth, length); - const int overlap = getLookAndFeel().getTabButtonOverlap (depth) - + getLookAndFeel().getTabButtonSpaceAroundImage() * 2; + const int overlap = lf.getTabButtonOverlap (depth) + lf.getTabButtonSpaceAroundImage() * 2; int i, totalLength = overlap; int numVisibleButtons = tabs.size(); @@ -357,7 +357,7 @@ void TabbedButtonBar::resized() { if (extraTabsButton == nullptr) { - addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton()); + addAndMakeVisible (extraTabsButton = lf.createTabBarExtrasButton()); extraTabsButton->addListener (behindFrontTab); extraTabsButton->setAlwaysOnTop (true); extraTabsButton->setTriggeredOnMouseDown (true); diff --git a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h index 555fd27192..ecc3e4cf2d 100644 --- a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h +++ b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h @@ -81,7 +81,6 @@ protected: int getIndex() const; private: - //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabBarButton); }; diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp index 1c0b27de59..96c21b8642 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp @@ -2079,15 +2079,9 @@ int LookAndFeel::getTabButtonSpaceAroundImage() return 4; } -void LookAndFeel::createTabButtonShape (Path& p, - int width, int height, - int /*tabIndex*/, - const String& /*text*/, - Button& /*button*/, - TabbedButtonBar::Orientation orientation, - const bool /*isMouseOver*/, - const bool /*isMouseDown*/, - const bool /*isFrontTab*/) +void LookAndFeel::createTabButtonShape (Path& p, int width, int height, int /*tabIndex*/, + const String& /*text*/, Button& /*button*/, TabbedButtonBar::Orientation orientation, + const bool /*isMouseOver*/, const bool /*isMouseDown*/, const bool /*isFrontTab*/) { const float w = (float) width; const float h = (float) height; @@ -2146,16 +2140,10 @@ void LookAndFeel::createTabButtonShape (Path& p, p = p.createPathWithRoundedCorners (3.0f); } -void LookAndFeel::fillTabButtonShape (Graphics& g, - const Path& path, - const Colour& preferredColour, - int /*tabIndex*/, - const String& /*text*/, - Button& button, - TabbedButtonBar::Orientation /*orientation*/, - const bool /*isMouseOver*/, - const bool /*isMouseDown*/, - const bool isFrontTab) +void LookAndFeel::fillTabButtonShape (Graphics& g, const Path& path, const Colour& preferredColour, + int /*tabIndex*/, const String& /*text*/, Button& button, + TabbedButtonBar::Orientation /*orientation*/, const bool /*isMouseOver*/, + const bool /*isMouseDown*/, const bool isFrontTab) { g.setColour (isFrontTab ? preferredColour : preferredColour.withMultipliedAlpha (0.9f)); @@ -2169,16 +2157,10 @@ void LookAndFeel::fillTabButtonShape (Graphics& g, g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f)); } -void LookAndFeel::drawTabButtonText (Graphics& g, - int x, int y, int w, int h, - const Colour& preferredBackgroundColour, - int /*tabIndex*/, - const String& text, - Button& button, - TabbedButtonBar::Orientation orientation, - const bool isMouseOver, - const bool isMouseDown, - const bool isFrontTab) +void LookAndFeel::drawTabButtonText (Graphics& g, int x, int y, int w, int h, + const Colour& preferredBackgroundColour, int /*tabIndex*/, + const String& text, Button& button, TabbedButtonBar::Orientation orientation, + const bool isMouseOver, const bool isMouseDown, const bool isFrontTab) { int length = w; int depth = h; @@ -2198,21 +2180,13 @@ void LookAndFeel::drawTabButtonText (Graphics& g, Justification::centred, jmax (1, depth / 12)); - AffineTransform transform; + AffineTransform t; - if (orientation == TabbedButtonBar::TabsAtLeft) + switch (orientation) { - transform = transform.rotated (float_Pi * -0.5f) - .translated ((float) x, (float) (y + h)); - } - else if (orientation == TabbedButtonBar::TabsAtRight) - { - transform = transform.rotated (float_Pi * 0.5f) - .translated ((float) (x + w), (float) y); - } - else - { - transform = transform.translated ((float) x, (float) y); + case TabbedButtonBar::TabsAtLeft: t = t.rotated (float_Pi * -0.5f).translated ((float) x, (float) (y + h)); break; + case TabbedButtonBar::TabsAtRight: t = t.rotated (float_Pi * 0.5f).translated ((float) (x + w), (float) y); break; + default: t = t.translated ((float) x, (float) y); } if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId))) @@ -2228,53 +2202,32 @@ void LookAndFeel::drawTabButtonText (Graphics& g, if (! button.isEnabled()) g.setOpacity (0.3f); - textLayout.draw (g, transform); + textLayout.draw (g, t); } -int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/, - const String& text, - int tabDepth, - Button&) +int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/, const String& text, int tabDepth, Button&) { Font f (tabDepth * 0.6f); return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2; } -void LookAndFeel::drawTabButton (Graphics& g, - int w, int h, - const Colour& preferredColour, - int tabIndex, - const String& text, - Button& button, - TabbedButtonBar::Orientation orientation, - const bool isMouseOver, - const bool isMouseDown, - const bool isFrontTab) +void LookAndFeel::drawTabButton (Graphics& g, int w, int h, const Colour& preferredColour, + int tabIndex, const String& text, Button& button, TabbedButtonBar::Orientation orientation, + const bool isMouseOver, const bool isMouseDown, const bool isFrontTab) { - int length = w; - int depth = h; - - if (orientation == TabbedButtonBar::TabsAtLeft - || orientation == TabbedButtonBar::TabsAtRight) - { - std::swap (length, depth); - } - Path tabShape; - - createTabButtonShape (tabShape, w, h, - tabIndex, text, button, orientation, + createTabButtonShape (tabShape, w, h, tabIndex, text, button, orientation, isMouseOver, isMouseDown, isFrontTab); fillTabButtonShape (g, tabShape, preferredColour, tabIndex, text, button, orientation, isMouseOver, isMouseDown, isFrontTab); + const int depth = (orientation == TabbedButtonBar::TabsAtLeft || orientation == TabbedButtonBar::TabsAtRight) ? w : h; const int indent = getTabButtonOverlap (depth); int x = 0, y = 0; - if (orientation == TabbedButtonBar::TabsAtLeft - || orientation == TabbedButtonBar::TabsAtRight) + if (orientation == TabbedButtonBar::TabsAtLeft || orientation == TabbedButtonBar::TabsAtRight) { y += indent; h -= indent * 2; @@ -2290,63 +2243,51 @@ void LookAndFeel::drawTabButton (Graphics& g, isMouseOver, isMouseDown, isFrontTab); } -void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g, - int w, int h, - TabbedButtonBar& tabBar, +void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g, int w, int h, TabbedButtonBar& tabBar, TabbedButtonBar::Orientation orientation) { const float shadowSize = 0.2f; - float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f; - Rectangle shadowRect; + float x1 = 0, y1 = 0, x2 = 0, y2 = 0; + Rectangle shadowRect, line; - if (orientation == TabbedButtonBar::TabsAtLeft) + switch (orientation) { - x1 = (float) w; - x2 = w * (1.0f - shadowSize); - shadowRect.setBounds ((int) x2, 0, w - (int) x2, h); - } - else if (orientation == TabbedButtonBar::TabsAtRight) - { - x2 = w * shadowSize; - shadowRect.setBounds (0, 0, (int) x2, h); - } - else if (orientation == TabbedButtonBar::TabsAtBottom) - { - y2 = h * shadowSize; - shadowRect.setBounds (0, 0, w, (int) y2); - } - else - { - y1 = (float) h; - y2 = h * (1.0f - shadowSize); - shadowRect.setBounds (0, (int) y2, w, h - (int) y2); + case TabbedButtonBar::TabsAtLeft: + x1 = (float) w; + x2 = w * (1.0f - shadowSize); + shadowRect.setBounds ((int) x2, 0, w - (int) x2, h); + line.setBounds (w - 1, 0, 1, h); + break; + + case TabbedButtonBar::TabsAtRight: + x2 = w * shadowSize; + shadowRect.setBounds (0, 0, (int) x2, h); + line.setBounds (0, 0, 1, h); + break; + + case TabbedButtonBar::TabsAtTop: + y1 = (float) h; + y2 = h * (1.0f - shadowSize); + shadowRect.setBounds (0, (int) y2, w, h - (int) y2); + line.setBounds (0, h - 1, w, 1); + break; + + case TabbedButtonBar::TabsAtBottom: + y2 = h * shadowSize; + shadowRect.setBounds (0, 0, w, (int) y2); + line.setBounds (0, 0, w, 1); + break; + + default: break; } g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1, Colours::transparentBlack, x2, y2, false)); - - shadowRect.expand (2, 2); - g.fillRect (shadowRect); + g.fillRect (shadowRect.expanded (2, 2)); g.setColour (Colour (0x80000000)); - - if (orientation == TabbedButtonBar::TabsAtLeft) - { - g.fillRect (w - 1, 0, 1, h); - } - else if (orientation == TabbedButtonBar::TabsAtRight) - { - g.fillRect (0, 0, 1, h); - } - else if (orientation == TabbedButtonBar::TabsAtBottom) - { - g.fillRect (0, 0, w, 1); - } - else - { - g.fillRect (0, h - 1, w, 1); - } + g.fillRect (line); } Button* LookAndFeel::createTabBarExtrasButton() @@ -2526,7 +2467,7 @@ void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height, Justification::centredLeft, 2); } -const Rectangle LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component) +Rectangle LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component) { const int textW = jmin (200, component.getWidth() / 3); return Rectangle (textW, 1, component.getWidth() - textW - 1, component.getHeight() - 3); diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h index e95e038459..ace3831161 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h @@ -608,7 +608,7 @@ public: virtual void drawPropertyComponentLabel (Graphics& g, int width, int height, PropertyComponent& component); - virtual const Rectangle getPropertyComponentContentPosition (PropertyComponent& component); + virtual Rectangle getPropertyComponentContentPosition (PropertyComponent& component); //============================================================================== virtual void drawCallOutBoxBackground (CallOutBox& box, Graphics& g, const Path& path, Image& cachedImage); diff --git a/modules/juce_gui_basics/properties/juce_PropertyComponent.cpp b/modules/juce_gui_basics/properties/juce_PropertyComponent.cpp index c9f59321f9..1640499c8a 100644 --- a/modules/juce_gui_basics/properties/juce_PropertyComponent.cpp +++ b/modules/juce_gui_basics/properties/juce_PropertyComponent.cpp @@ -23,29 +23,28 @@ ============================================================================== */ -PropertyComponent::PropertyComponent (const String& name, - const int preferredHeight_) - : Component (name), - preferredHeight (preferredHeight_) +PropertyComponent::PropertyComponent (const String& name, const int preferredHeight_) + : Component (name), preferredHeight (preferredHeight_) { jassert (name.isNotEmpty()); } -PropertyComponent::~PropertyComponent() -{ -} +PropertyComponent::~PropertyComponent() {} //============================================================================== void PropertyComponent::paint (Graphics& g) { - getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this); - getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this); + LookAndFeel& lf = getLookAndFeel(); + + lf.drawPropertyComponentBackground (g, getWidth(), getHeight(), *this); + lf.drawPropertyComponentLabel (g, getWidth(), getHeight(), *this); } void PropertyComponent::resized() { - if (getNumChildComponents() > 0) - getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this)); + Component* const c = getChildComponent(0); + if (c != nullptr) + c->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this)); } void PropertyComponent::enablementChanged() diff --git a/modules/juce_gui_basics/windows/juce_CallOutBox.cpp b/modules/juce_gui_basics/windows/juce_CallOutBox.cpp index ee941f2984..c97f6ef026 100644 --- a/modules/juce_gui_basics/windows/juce_CallOutBox.cpp +++ b/modules/juce_gui_basics/windows/juce_CallOutBox.cpp @@ -136,8 +136,7 @@ void CallOutBox::updatePosition (const Rectangle& newAreaToPointTo, const R targetArea = newAreaToPointTo; availableArea = newAreaToFitIn; - Rectangle newBounds (0, 0, - content.getWidth() + borderSpace * 2, + Rectangle newBounds (content.getWidth() + borderSpace * 2, content.getHeight() + borderSpace * 2); const int hw = newBounds.getWidth() / 2;