Browse Source

Fix for win32 scaled component mouse positioning.

tags/2021-05-28
jules 12 years ago
parent
commit
16b9bbe212
7 changed files with 61 additions and 76 deletions
  1. +1
    -1
      modules/juce_gui_basics/components/juce_Component.cpp
  2. +6
    -6
      modules/juce_gui_basics/native/juce_android_Windowing.cpp
  3. +8
    -8
      modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm
  4. +7
    -6
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp
  5. +7
    -7
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm
  6. +26
    -42
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp
  7. +6
    -6
      modules/juce_gui_basics/windows/juce_ComponentPeer.h

+ 1
- 1
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -1328,7 +1328,7 @@ bool Component::contains (Point<int> 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;


+ 6
- 6
modules/juce_gui_basics/native/juce_android_Windowing.cpp View File

@@ -234,12 +234,12 @@ public:
view.callIntMethod (ComponentPeerView.getTop));
}
Point<int> localToGlobal (const Point<int>& relativePosition) override
Point<int> localToGlobal (Point<int> relativePosition) override
{
return relativePosition + getScreenPosition();
}
Point<int> globalToLocal (const Point<int>& screenPosition) override
Point<int> globalToLocal (Point<int> screenPosition) override
{
return screenPosition - getScreenPosition();
}
@@ -279,12 +279,12 @@ public:
// n/a
}
bool contains (const Point<int>& position, bool trueIfInAChildWindow) const override
bool contains (Point<int> 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<int> getFrameSize() const override


+ 8
- 8
modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm View File

@@ -137,14 +137,14 @@ public:
Rectangle<int> getBounds() const override;
Rectangle<int> getBounds (bool global) const;
Point<int> localToGlobal (const Point<int>& relativePosition) override;
Point<int> globalToLocal (const Point<int>& screenPosition) override;
Point<int> localToGlobal (Point<int> relativePosition) override;
Point<int> globalToLocal (Point<int> 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<int>& position, bool trueIfInAChildWindow) const override;
bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override;
BorderSize<int> getFrameSize() const override;
bool setAlwaysOnTop (bool alwaysOnTop) override;
void toFront (bool makeActiveWindow) override;
@@ -569,12 +569,12 @@ Rectangle<int> UIViewComponentPeer::getBounds() const
return getBounds (! isSharedWindow);
}
Point<int> UIViewComponentPeer::localToGlobal (const Point<int>& relativePosition)
Point<int> UIViewComponentPeer::localToGlobal (Point<int> relativePosition)
{
return relativePosition + getBounds (true).getPosition();
}
Point<int> UIViewComponentPeer::globalToLocal (const Point<int>& screenPosition)
Point<int> UIViewComponentPeer::globalToLocal (Point<int> screenPosition)
{
return screenPosition - getBounds (true).getPosition();
}
@@ -679,12 +679,12 @@ void UIViewComponentPeer::updateTransformAndScreenBounds()
[view setNeedsDisplay];
}
bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
bool UIViewComponentPeer::contains (Point<int> 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)


+ 7
- 6
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -967,12 +967,12 @@ public:
Rectangle<int> getBounds() const override { return bounds; }
Point<int> localToGlobal (const Point<int>& relativePosition) override
Point<int> localToGlobal (Point<int> relativePosition) override
{
return relativePosition + bounds.getPosition();
}
Point<int> globalToLocal (const Point<int>& screenPosition) override
Point<int> globalToLocal (Point<int> screenPosition) override
{
return screenPosition - bounds.getPosition();
}
@@ -1088,9 +1088,9 @@ public:
return result;
}
bool contains (const Point<int>& position, bool trueIfInAChildWindow) const override
bool contains (Point<int> 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;
}


+ 7
- 7
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -278,12 +278,12 @@ public:
return getBounds (! isSharedWindow);
}
Point<int> localToGlobal (const Point<int>& relativePosition) override
Point<int> localToGlobal (Point<int> relativePosition) override
{
return relativePosition + getBounds (true).getPosition();
}
Point<int> globalToLocal (const Point<int>& screenPosition) override
Point<int> globalToLocal (Point<int> screenPosition) override
{
return screenPosition - getBounds (true).getPosition();
}
@@ -363,16 +363,16 @@ public:
return fullScreen;
}
bool contains (const Point<int>& position, bool trueIfInAChildWindow) const override
bool contains (Point<int> 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);


+ 26
- 42
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -146,6 +146,13 @@ static void setWindowPos (HWND hwnd, Rectangle<int> 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<int> (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<int> getBounds() const override
{
RECT r;
GetWindowRect (hwnd, &r);
Rectangle<int> bounds (rectangleFromRECT (r));
Rectangle<int> 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<int> getScreenPosition() const
{
RECT r;
GetWindowRect (hwnd, &r);
RECT r = getWindowRect (hwnd);
return Point<int> (r.left + windowBorder.getLeft(),
r.top + windowBorder.getTop());
r.top + windowBorder.getTop());
}
Point<int> localToGlobal (const Point<int>& relativePosition) override
{
return relativePosition + getScreenPosition();
}
Point<int> globalToLocal (const Point<int>& screenPosition) override
{
return screenPosition - getScreenPosition();
}
Point<int> localToGlobal (Point<int> relativePosition) override { return relativePosition + getScreenPosition(); }
Point<int> globalToLocal (Point<int> screenPosition) override { return screenPosition - getScreenPosition(); }
void setAlpha (float newAlpha) override
{
@@ -754,10 +748,13 @@ public:
return wp.showCmd == SW_SHOWMAXIMIZED;
}
bool isWindowAtPoint (const Point<int>& localPos, bool trueIfInAChildWindow) const
bool contains (Point<int> 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<int>& position, bool trueIfInAChildWindow) const override
{
return isPositiveAndBelow (position.x, component.getWidth())
&& isPositiveAndBelow (position.y, component.getHeight())
&& isWindowAtPoint (position, trueIfInAChildWindow);
}
BorderSize<int> 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<int> 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);


+ 6
- 6
modules/juce_gui_basics/windows/juce_ComponentPeer.h View File

@@ -154,13 +154,13 @@ public:
virtual Rectangle<int> getBounds() const = 0;
/** Converts a position relative to the top-left of this component to screen coordinates. */
virtual Point<int> localToGlobal (const Point<int>& relativePosition) = 0;
virtual Point<int> localToGlobal (Point<int> relativePosition) = 0;
/** Converts a rectangle relative to the top-left of this component to screen coordinates. */
virtual Rectangle<int> localToGlobal (const Rectangle<int>& relativePosition);
/** Converts a screen coordinate to a position relative to the top-left of this component. */
virtual Point<int> globalToLocal (const Point<int>& screenPosition) = 0;
virtual Point<int> globalToLocal (Point<int> screenPosition) = 0;
/** Converts a screen area to a position relative to the top-left of this component. */
virtual Rectangle<int> globalToLocal (const Rectangle<int>& 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<int>& position, bool trueIfInAChildWindow) const = 0;
virtual bool contains (Point<int> 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


Loading…
Cancel
Save