diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 5eaeade806..52bd47a4cc 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1328,7 +1328,7 @@ bool Component::contains (Point point) if (flags.hasHeavyweightPeerFlag) if (const ComponentPeer* const peer = getPeer()) - return peer->contains (point, true); + return peer->contains (ComponentHelpers::localPositionToRawPeerPos (*this, point), true); } return false; diff --git a/modules/juce_gui_basics/native/juce_android_Windowing.cpp b/modules/juce_gui_basics/native/juce_android_Windowing.cpp index c0e406a303..6625d48fd5 100644 --- a/modules/juce_gui_basics/native/juce_android_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_android_Windowing.cpp @@ -234,12 +234,12 @@ public: view.callIntMethod (ComponentPeerView.getTop)); } - Point localToGlobal (const Point& relativePosition) override + Point localToGlobal (Point relativePosition) override { return relativePosition + getScreenPosition(); } - Point globalToLocal (const Point& screenPosition) override + Point globalToLocal (Point screenPosition) override { return screenPosition - getScreenPosition(); } @@ -279,12 +279,12 @@ public: // n/a } - bool contains (const Point& position, bool trueIfInAChildWindow) const override + bool contains (Point localPos, bool trueIfInAChildWindow) const override { - return isPositiveAndBelow (position.x, component.getWidth()) - && isPositiveAndBelow (position.y, component.getHeight()) + return isPositiveAndBelow (localPos.x, component.getWidth()) + && isPositiveAndBelow (localPos.y, component.getHeight()) && ((! trueIfInAChildWindow) || view.callBooleanMethod (ComponentPeerView.containsPoint, - position.x, position.y)); + localPos.x, localPos.y)); } BorderSize getFrameSize() const override diff --git a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm index c98790380d..88eef5a884 100644 --- a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm @@ -137,14 +137,14 @@ public: Rectangle getBounds() const override; Rectangle getBounds (bool global) const; - Point localToGlobal (const Point& relativePosition) override; - Point globalToLocal (const Point& screenPosition) override; + Point localToGlobal (Point relativePosition) override; + Point globalToLocal (Point screenPosition) override; void setAlpha (float newAlpha) override; void setMinimised (bool shouldBeMinimised) override; bool isMinimised() const override; void setFullScreen (bool shouldBeFullScreen) override; bool isFullScreen() const override; - bool contains (const Point& position, bool trueIfInAChildWindow) const override; + bool contains (Point localPos, bool trueIfInAChildWindow) const override; BorderSize getFrameSize() const override; bool setAlwaysOnTop (bool alwaysOnTop) override; void toFront (bool makeActiveWindow) override; @@ -569,12 +569,12 @@ Rectangle UIViewComponentPeer::getBounds() const return getBounds (! isSharedWindow); } -Point UIViewComponentPeer::localToGlobal (const Point& relativePosition) +Point UIViewComponentPeer::localToGlobal (Point relativePosition) { return relativePosition + getBounds (true).getPosition(); } -Point UIViewComponentPeer::globalToLocal (const Point& screenPosition) +Point UIViewComponentPeer::globalToLocal (Point screenPosition) { return screenPosition - getBounds (true).getPosition(); } @@ -679,12 +679,12 @@ void UIViewComponentPeer::updateTransformAndScreenBounds() [view setNeedsDisplay]; } -bool UIViewComponentPeer::contains (const Point& position, bool trueIfInAChildWindow) const +bool UIViewComponentPeer::contains (Point localPos, bool trueIfInAChildWindow) const { - if (! component.getLocalBounds().contains (position)) + if (! component.getLocalBounds().contains (localPos)) return false; - UIView* v = [view hitTest: convertToCGPoint (position) + UIView* v = [view hitTest: convertToCGPoint (localPos) withEvent: nil]; if (trueIfInAChildWindow) diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index a818131fd0..604fc0ce19 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -967,12 +967,12 @@ public: Rectangle getBounds() const override { return bounds; } - Point localToGlobal (const Point& relativePosition) override + Point localToGlobal (Point relativePosition) override { return relativePosition + bounds.getPosition(); } - Point globalToLocal (const Point& screenPosition) override + Point globalToLocal (Point screenPosition) override { return screenPosition - bounds.getPosition(); } @@ -1088,9 +1088,9 @@ public: return result; } - bool contains (const Point& position, bool trueIfInAChildWindow) const override + bool contains (Point localPos, bool trueIfInAChildWindow) const override { - if (! bounds.withZeroOrigin().contains (position)) + if (! bounds.withZeroOrigin().contains (localPos)) return false; for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) @@ -1100,7 +1100,8 @@ public: if (c == &component) break; - if (c->contains (position + bounds.getPosition() - c->getScreenPosition())) + // TODO: needs scaling correctly + if (c->contains (localPos + bounds.getPosition() - c->getScreenPosition())) return false; } @@ -1114,7 +1115,7 @@ public: ScopedXLock xlock; return XGetGeometry (display, (::Drawable) windowH, &root, &wx, &wy, &ww, &wh, &bw, &depth) - && XTranslateCoordinates (display, windowH, windowH, position.getX(), position.getY(), &wx, &wy, &child) + && XTranslateCoordinates (display, windowH, windowH, localPos.getX(), localPos.getY(), &wx, &wy, &child) && child == None; } diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 4b0ea731b0..4e8741e912 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -278,12 +278,12 @@ public: return getBounds (! isSharedWindow); } - Point localToGlobal (const Point& relativePosition) override + Point localToGlobal (Point relativePosition) override { return relativePosition + getBounds (true).getPosition(); } - Point globalToLocal (const Point& screenPosition) override + Point globalToLocal (Point screenPosition) override { return screenPosition - getBounds (true).getPosition(); } @@ -363,16 +363,16 @@ public: return fullScreen; } - bool contains (const Point& position, bool trueIfInAChildWindow) const override + bool contains (Point localPos, bool trueIfInAChildWindow) const override { - if (! (isPositiveAndBelow (position.getX(), component.getWidth()) - && isPositiveAndBelow (position.getY(), component.getHeight()))) + if (! (isPositiveAndBelow (localPos.getX(), component.getWidth()) + && isPositiveAndBelow (localPos.getY(), component.getHeight()))) return false; NSRect frameRect = [view frame]; - NSView* v = [view hitTest: NSMakePoint (frameRect.origin.x + position.getX(), - frameRect.origin.y + frameRect.size.height - position.getY())]; + NSView* v = [view hitTest: NSMakePoint (frameRect.origin.x + localPos.getX(), + frameRect.origin.y + frameRect.size.height - localPos.getY())]; return trueIfInAChildWindow ? (v != nil) : (v == view); diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index be8055a792..5c6c1b1992 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -146,6 +146,13 @@ static void setWindowPos (HWND hwnd, Rectangle bounds, UINT flags) SetWindowPos (hwnd, 0, bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), flags); } +static RECT getWindowRect (HWND hwnd) +{ + RECT r; + GetWindowRect (hwnd, &r); + return r; +} + static void setWindowZOrder (HWND hwnd, HWND insertAfter) { SetWindowPos (hwnd, insertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING); @@ -350,8 +357,7 @@ public: if (transparent) { - RECT windowBounds; - GetWindowRect (hwnd, &windowBounds); + RECT windowBounds = getWindowRect (hwnd); POINT p = { -x, -y }; POINT pos = { windowBounds.left, windowBounds.top }; @@ -591,12 +597,10 @@ public: info.cbSize = sizeof (info); if (GetWindowInfo (hwnd, &info)) - { windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top, info.rcClient.left - info.rcWindow.left, info.rcWindow.bottom - info.rcClient.bottom, info.rcWindow.right - info.rcClient.right); - } #if JUCE_DIRECT2D if (direct2DContext != nullptr) @@ -614,8 +618,7 @@ public: { if (HWND parentHwnd = GetParent (hwnd)) { - RECT parentRect; - GetWindowRect (parentHwnd, &parentRect); + RECT parentRect = getWindowRect (parentHwnd); newBounds.translate (parentRect.left, parentRect.top); } } @@ -640,13 +643,11 @@ public: Rectangle getBounds() const override { - RECT r; - GetWindowRect (hwnd, &r); - Rectangle bounds (rectangleFromRECT (r)); + Rectangle bounds (rectangleFromRECT (getWindowRect (hwnd))); if (HWND parentH = GetParent (hwnd)) { - GetWindowRect (parentH, &r); + RECT r = getWindowRect (parentH); bounds.translate (-r.left, -r.top); } @@ -655,21 +656,14 @@ public: Point getScreenPosition() const { - RECT r; - GetWindowRect (hwnd, &r); + RECT r = getWindowRect (hwnd); + return Point (r.left + windowBorder.getLeft(), - r.top + windowBorder.getTop()); + r.top + windowBorder.getTop()); } - Point localToGlobal (const Point& relativePosition) override - { - return relativePosition + getScreenPosition(); - } - - Point globalToLocal (const Point& screenPosition) override - { - return screenPosition - getScreenPosition(); - } + Point localToGlobal (Point relativePosition) override { return relativePosition + getScreenPosition(); } + Point globalToLocal (Point screenPosition) override { return screenPosition - getScreenPosition(); } void setAlpha (float newAlpha) override { @@ -754,10 +748,13 @@ public: return wp.showCmd == SW_SHOWMAXIMIZED; } - bool isWindowAtPoint (const Point& localPos, bool trueIfInAChildWindow) const + bool contains (Point localPos, bool trueIfInAChildWindow) const override { - RECT r; - GetWindowRect (hwnd, &r); + RECT r = getWindowRect (hwnd); + + if (! (isPositiveAndBelow (localPos.x, (int) (r.right - r.left)) + && isPositiveAndBelow (localPos.y, (int) (r.bottom - r.top)))) + return false; POINT p = { localPos.x + r.left + windowBorder.getLeft(), localPos.y + r.top + windowBorder.getTop() }; @@ -766,13 +763,6 @@ public: return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0)); } - bool contains (const Point& position, bool trueIfInAChildWindow) const override - { - return isPositiveAndBelow (position.x, component.getWidth()) - && isPositiveAndBelow (position.y, component.getHeight()) - && isWindowAtPoint (position, trueIfInAChildWindow); - } - BorderSize getFrameSize() const override { return windowBorder; @@ -1422,8 +1412,7 @@ private: if (parent == ((EnumWindowsInfo*) context)->peer->hwnd) { - RECT r; - GetWindowRect (hwnd, &r); + RECT r = getWindowRect (hwnd); POINT pos = { r.left, r.top }; ScreenToClient (GetParent (hwnd), &pos); @@ -1495,8 +1484,7 @@ private: // it's not possible to have a transparent window with a title bar at the moment! jassert (! hasTitleBar()); - RECT r; - GetWindowRect (hwnd, &r); + RECT r = getWindowRect (hwnd); x = y = 0; w = r.right - r.left; h = r.bottom - r.top; @@ -2348,7 +2336,7 @@ private: case WM_WINDOWPOSCHANGED: { const Point pos (getCurrentMousePos()); - if (isWindowAtPoint (pos, false)) + if (contains (pos, false)) doMouseEvent (pos); } @@ -3207,11 +3195,7 @@ void Desktop::Displays::findDisplays (float masterScale) monitors.swap (i, 0); if (monitors.size() == 0) - { - RECT r; - GetWindowRect (GetDesktopWindow(), &r); - monitors.add (rectangleFromRECT (r)); - } + monitors.add (rectangleFromRECT (getWindowRect (GetDesktopWindow()))); RECT workArea; SystemParametersInfo (SPI_GETWORKAREA, 0, &workArea, 0); diff --git a/modules/juce_gui_basics/windows/juce_ComponentPeer.h b/modules/juce_gui_basics/windows/juce_ComponentPeer.h index 118892cd06..ca73b55cb7 100644 --- a/modules/juce_gui_basics/windows/juce_ComponentPeer.h +++ b/modules/juce_gui_basics/windows/juce_ComponentPeer.h @@ -154,13 +154,13 @@ public: virtual Rectangle getBounds() const = 0; /** Converts a position relative to the top-left of this component to screen coordinates. */ - virtual Point localToGlobal (const Point& relativePosition) = 0; + virtual Point localToGlobal (Point relativePosition) = 0; /** Converts a rectangle relative to the top-left of this component to screen coordinates. */ virtual Rectangle localToGlobal (const Rectangle& relativePosition); /** Converts a screen coordinate to a position relative to the top-left of this component. */ - virtual Point globalToLocal (const Point& screenPosition) = 0; + virtual Point globalToLocal (Point screenPosition) = 0; /** Converts a screen area to a position relative to the top-left of this component. */ virtual Rectangle globalToLocal (const Rectangle& screenPosition); @@ -201,11 +201,11 @@ public: /** Checks if a point is in the window. - Coordinates are relative to the top-left of this window. If trueIfInAChildWindow - is false, then this returns false if the point is actually inside a child of this - window. + The position is relative to the top-left of this window, in unscaled peer coordinates. + If trueIfInAChildWindow is false, then this returns false if the point is actually + inside a child of this window. */ - virtual bool contains (const Point& position, bool trueIfInAChildWindow) const = 0; + virtual bool contains (Point localPos, bool trueIfInAChildWindow) const = 0; /** Returns the size of the window frame that's around this window. Whether or not the window has a normal window frame depends on the flags