From f4cbb721a5118e516248a05cb77032a96882527f Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 2 Jan 2012 10:57:11 +0000 Subject: [PATCH] Minor update to ResizableWindow positioning, and slider tooltips. --- .../juce_graphics/geometry/juce_Rectangle.h | 28 ++++++++----------- .../juce_gui_basics/widgets/juce_Slider.cpp | 4 +-- .../windows/juce_ResizableWindow.cpp | 21 +++++++++----- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index 444b2527e6..ba5fe06b49 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -490,19 +490,17 @@ public: } /** Clips a rectangle so that it lies only within this one. - This is a non-static version of intersectRectangles(). - Returns false if the two regions didn't overlap. */ bool intersectRectangle (ValueType& otherX, ValueType& otherY, ValueType& otherW, ValueType& otherH) const noexcept { - const int maxX = jmax (otherX, pos.x); + const ValueType maxX (jmax (otherX, pos.x)); otherW = jmin (otherX + otherW, pos.x + w) - maxX; if (otherW > ValueType()) { - const int maxY = jmax (otherY, pos.y); + const ValueType maxY (jmax (otherY, pos.y)); otherH = jmin (otherY + otherH, pos.y + h) - maxY; if (otherH > ValueType()) @@ -570,13 +568,13 @@ public: bool reduceIfPartlyContainedIn (const Rectangle& other) noexcept { int inside = 0; - const int otherR = other.getRight(); + const ValueType otherR (other.getRight()); if (pos.x >= other.pos.x && pos.x < otherR) inside = 1; - const int otherB = other.getBottom(); + const ValueType otherB (other.getBottom()); if (pos.y >= other.pos.y && pos.y < otherB) inside |= 2; - const int r = pos.x + w; + const ValueType r (pos.x + w); if (r >= other.pos.x && r < otherR) inside |= 4; - const int b = pos.y + h; + const ValueType b (pos.y + h); if (b >= other.pos.y && b < otherB) inside |= 8; switch (inside) @@ -619,10 +617,10 @@ public: */ Rectangle getSmallestIntegerContainer() const noexcept { - const int x1 = (int) std::floor (static_cast (pos.x)); - const int y1 = (int) std::floor (static_cast (pos.y)); - const int x2 = (int) std::ceil (static_cast (pos.x + w)); - const int y2 = (int) std::ceil (static_cast (pos.y + h)); + const int x1 = static_cast (std::floor (static_cast (pos.x))); + const int y1 = static_cast (std::floor (static_cast (pos.y))); + const int x2 = static_cast (std::ceil (static_cast (pos.x + w))); + const int y2 = static_cast (std::ceil (static_cast (pos.y + h))); return Rectangle (x1, y1, x2 - x1, y2 - y1); } @@ -661,20 +659,18 @@ public: //============================================================================== /** Static utility to intersect two sets of rectangular co-ordinates. - Returns false if the two regions didn't overlap. - @see intersectRectangle */ static bool intersectRectangles (ValueType& x1, ValueType& y1, ValueType& w1, ValueType& h1, const ValueType x2, const ValueType y2, const ValueType w2, const ValueType h2) noexcept { - const ValueType x = jmax (x1, x2); + const ValueType x (jmax (x1, x2)); w1 = jmin (x1 + w1, x2 + w2) - x; if (w1 > ValueType()) { - const ValueType y = jmax (y1, y2); + const ValueType y (jmax (y1, y2)); h1 = jmin (y1 + h1, y2 + h2) - y; if (h1 > ValueType()) diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp index 7d9f26209c..ab160b6587 100644 --- a/modules/juce_gui_basics/widgets/juce_Slider.cpp +++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp @@ -335,8 +335,8 @@ void Slider::lookAndFeelChanged() if (style == LinearBar) valueBox->addMouseListener (this, false); - - valueBox->setTooltip (getTooltip()); + else + valueBox->setTooltip (getTooltip()); } else { diff --git a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp index eb945acee4..c01f57f216 100644 --- a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp @@ -535,19 +535,26 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) if (newPos.isEmpty()) return false; - const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre())); - ComponentPeer* const peer = isOnDesktop() ? getPeer() : nullptr; if (peer != nullptr) peer->getFrameSize().addTo (newPos); - if (! screen.contains (newPos)) { - newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()), - jmin (newPos.getHeight(), screen.getHeight())); + Desktop& desktop = Desktop::getInstance(); + RectangleList allMonitors (desktop.getAllMonitorDisplayAreas()); + allMonitors.clipTo (newPos); + const Rectangle onScreenArea (allMonitors.getBounds()); - newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()), - jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY())); + if (onScreenArea.getWidth() * onScreenArea.getHeight() < 32 * 32) + { + const Rectangle screen (desktop.getMonitorAreaContaining (newPos.getCentre())); + + newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()), + jmin (newPos.getHeight(), screen.getHeight())); + + newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()), + jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY())); + } } if (peer != nullptr)