From 6c61dbb68e579abaee797219e78d21de4409413a Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 14 Jun 2014 13:06:53 +0100 Subject: [PATCH] Refactored the internal mouse-handling code to use floating point coords. This shouldn't affect much user code, but a few methods in MouseInputSource have now changed to use Point rather than Point. --- extras/Demo/Source/Demos/MultiTouch.cpp | 4 +- .../utility/juce_FakeMouseMoveGenerator.h | 2 +- .../gui/juce_MidiKeyboardComponent.cpp | 2 +- .../components/juce_Component.cpp | 41 +++-- .../components/juce_Component.h | 36 +++-- .../components/juce_Desktop.cpp | 19 ++- .../juce_gui_basics/components/juce_Desktop.h | 4 +- .../juce_gui_basics/menus/juce_PopupMenu.cpp | 4 +- .../mouse/juce_ComponentDragger.cpp | 2 +- .../mouse/juce_DragAndDropContainer.cpp | 2 +- .../juce_gui_basics/mouse/juce_MouseEvent.cpp | 36 +++-- .../juce_gui_basics/mouse/juce_MouseEvent.h | 34 ++-- .../mouse/juce_MouseInputSource.cpp | 146 +++++++++--------- .../mouse/juce_MouseInputSource.h | 16 +- .../native/juce_android_Windowing.cpp | 22 +-- .../native/juce_ios_UIViewComponentPeer.mm | 20 +-- .../native/juce_ios_Windowing.mm | 4 +- .../native/juce_linux_Windowing.cpp | 20 +-- .../native/juce_mac_NSViewComponentPeer.mm | 16 +- .../native/juce_mac_Windowing.mm | 6 +- .../native/juce_win32_Windowing.cpp | 65 ++++---- .../juce_gui_basics/widgets/juce_Slider.cpp | 57 +++---- .../juce_gui_basics/widgets/juce_TreeView.cpp | 4 +- .../windows/juce_ComponentPeer.cpp | 18 +-- .../windows/juce_ComponentPeer.h | 20 ++- .../windows/juce_TooltipWindow.cpp | 6 +- .../windows/juce_TooltipWindow.h | 2 +- .../native/juce_mac_SystemTrayIcon.cpp | 12 +- .../native/juce_win32_ActiveXComponent.cpp | 2 +- .../native/juce_win32_SystemTrayIcon.cpp | 4 +- 30 files changed, 349 insertions(+), 277 deletions(-) diff --git a/extras/Demo/Source/Demos/MultiTouch.cpp b/extras/Demo/Source/Demos/MultiTouch.cpp index 08dc099709..0273611d85 100644 --- a/extras/Demo/Source/Demos/MultiTouch.cpp +++ b/extras/Demo/Source/Demos/MultiTouch.cpp @@ -55,11 +55,11 @@ public: if (t == nullptr) { t = new Trail (e.source); - t->path.startNewSubPath (e.getPosition().toFloat()); + t->path.startNewSubPath (e.position); trails.add (t); } - t->pushPoint (e.getPosition().toFloat(), e.mods); + t->pushPoint (e.position, e.mods); repaint(); } diff --git a/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h b/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h index 4b374cd6b4..2e342587bc 100644 --- a/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h +++ b/modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h @@ -51,7 +51,7 @@ public: if (Component* const comp = Desktop::getInstance().findComponentAt (screenPos)) if (ComponentPeer* const peer = comp->getPeer()) if (! peer->isFocused()) - peer->handleMouseEvent (0, peer->globalToLocal (screenPos), mods, Time::currentTimeMillis()); + peer->handleMouseEvent (0, peer->globalToLocal (screenPos.toFloat()), mods, Time::currentTimeMillis()); } } diff --git a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp index 2cfe71f860..fae07b732e 100644 --- a/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp +++ b/modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp @@ -816,7 +816,7 @@ void MidiKeyboardComponent::timerCallback() const Array& mouseSources = Desktop::getInstance().getMouseSources(); for (MouseInputSource* mi = mouseSources.begin(), * const e = mouseSources.end(); mi != e; ++mi) - updateNoteUnderMouse (getLocalPoint (nullptr, mi->getScreenPosition()), mi->isDragging(), mi->getIndex()); + updateNoteUnderMouse (getLocalPoint (nullptr, mi->getScreenPosition()).roundToInt(), mi->isDragging(), mi->getIndex()); } } diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index b21211d625..54067ed579 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -239,6 +239,15 @@ struct ScalingHelpers { return scaledScreenPosToUnscaled (comp.getDesktopScaleFactor(), pos); } + + static Point addPosition (Point p, const Component& c) noexcept { return p + c.getPosition(); } + static Rectangle addPosition (Rectangle p, const Component& c) noexcept { return p + c.getPosition(); } + static Point addPosition (Point p, const Component& c) noexcept { return p + c.getPosition().toFloat(); } + static Rectangle addPosition (Rectangle p, const Component& c) noexcept { return p + c.getPosition().toFloat(); } + static Point subtractPosition (Point p, const Component& c) noexcept { return p - c.getPosition(); } + static Rectangle subtractPosition (Rectangle p, const Component& c) noexcept { return p - c.getPosition(); } + static Point subtractPosition (Point p, const Component& c) noexcept { return p - c.getPosition().toFloat(); } + static Rectangle subtractPosition (Rectangle p, const Component& c) noexcept { return p - c.getPosition().toFloat(); } }; //============================================================================== @@ -321,7 +330,7 @@ struct Component::ComponentHelpers } else { - pointInParentSpace -= comp.getPosition(); + pointInParentSpace = ScalingHelpers::subtractPosition (pointInParentSpace, comp); } return pointInParentSpace; @@ -340,7 +349,7 @@ struct Component::ComponentHelpers } else { - pointInLocalSpace += comp.getPosition(); + pointInLocalSpace = ScalingHelpers::addPosition (pointInLocalSpace, comp); } if (comp.affineTransform != nullptr) @@ -1086,6 +1095,11 @@ Point Component::getLocalPoint (const Component* source, Point point) return ComponentHelpers::convertCoordinate (this, source, point); } +Point Component::getLocalPoint (const Component* source, Point point) const +{ + return ComponentHelpers::convertCoordinate (this, source, point); +} + Rectangle Component::getLocalArea (const Component* source, const Rectangle& area) const { return ComponentHelpers::convertCoordinate (this, source, area); @@ -1096,6 +1110,11 @@ Point Component::localPointToGlobal (Point point) const return ComponentHelpers::convertCoordinate (nullptr, this, point); } +Point Component::localPointToGlobal (Point point) const +{ + return ComponentHelpers::convertCoordinate (nullptr, this, point); +} + Rectangle Component::localAreaToGlobal (const Rectangle& area) const { return ComponentHelpers::convertCoordinate (nullptr, this, area); @@ -2386,7 +2405,7 @@ void Component::removeMouseListener (MouseListener* const listenerToRemove) } //============================================================================== -void Component::internalMouseEnter (MouseInputSource source, Point relativePos, Time time) +void Component::internalMouseEnter (MouseInputSource source, Point relativePos, Time time) { if (isCurrentlyBlockedByAnotherModalComponent()) { @@ -2412,7 +2431,7 @@ void Component::internalMouseEnter (MouseInputSource source, Point relative MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseEnter, me); } -void Component::internalMouseExit (MouseInputSource source, Point relativePos, Time time) +void Component::internalMouseExit (MouseInputSource source, Point relativePos, Time time) { if (flags.repaintOnMouseActivityFlag) repaint(); @@ -2432,7 +2451,7 @@ void Component::internalMouseExit (MouseInputSource source, Point relativeP MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseExit, me); } -void Component::internalMouseDown (MouseInputSource source, Point relativePos, Time time) +void Component::internalMouseDown (MouseInputSource source, Point relativePos, Time time) { Desktop& desktop = Desktop::getInstance(); BailOutChecker checker (this); @@ -2496,7 +2515,7 @@ void Component::internalMouseDown (MouseInputSource source, Point relativeP MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseDown, me); } -void Component::internalMouseUp (MouseInputSource source, Point relativePos, +void Component::internalMouseUp (MouseInputSource source, Point relativePos, Time time, const ModifierKeys oldModifiers) { if (flags.mouseDownWasBlocked && isCurrentlyBlockedByAnotherModalComponent()) @@ -2539,7 +2558,7 @@ void Component::internalMouseUp (MouseInputSource source, Point relativePos } } -void Component::internalMouseDrag (MouseInputSource source, Point relativePos, Time time) +void Component::internalMouseDrag (MouseInputSource source, Point relativePos, Time time) { if (! isCurrentlyBlockedByAnotherModalComponent()) { @@ -2562,7 +2581,7 @@ void Component::internalMouseDrag (MouseInputSource source, Point relativeP } } -void Component::internalMouseMove (MouseInputSource source, Point relativePos, Time time) +void Component::internalMouseMove (MouseInputSource source, Point relativePos, Time time) { Desktop& desktop = Desktop::getInstance(); @@ -2588,7 +2607,7 @@ void Component::internalMouseMove (MouseInputSource source, Point relativeP } } -void Component::internalMouseWheel (MouseInputSource source, Point relativePos, +void Component::internalMouseWheel (MouseInputSource source, Point relativePos, Time time, const MouseWheelDetails& wheel) { Desktop& desktop = Desktop::getInstance(); @@ -2616,7 +2635,7 @@ void Component::internalMouseWheel (MouseInputSource source, Point relative } } -void Component::internalMagnifyGesture (MouseInputSource source, Point relativePos, +void Component::internalMagnifyGesture (MouseInputSource source, Point relativePos, Time time, float amount) { if (! isCurrentlyBlockedByAnotherModalComponent()) @@ -2966,7 +2985,7 @@ bool Component::isMouseOver (const bool includeChildren) const Component* const c = mi->getComponentUnderMouse(); if ((c == this || (includeChildren && isParentOf (c))) - && c->reallyContains (c->getLocalPoint (nullptr, mi->getScreenPosition()), false) + && c->reallyContains (c->getLocalPoint (nullptr, mi->getScreenPosition()).roundToInt(), false) && (mi->isMouse() || mi->isDragging())) return true; } diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index 1bc092e0c7..f0d1ba5d38 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -355,6 +355,15 @@ public: Point getLocalPoint (const Component* sourceComponent, Point pointRelativeToSourceComponent) const; + /** Converts a point to be relative to this component's coordinate space. + + This takes a point relative to a different component, and returns its position relative to this + component. If the sourceComponent parameter is null, the source point is assumed to be a global + screen coordinate. + */ + Point getLocalPoint (const Component* sourceComponent, + Point pointRelativeToSourceComponent) const; + /** Converts a rectangle to be relative to this component's coordinate space. This takes a rectangle that is relative to a different component, and returns its position relative @@ -373,6 +382,11 @@ public: */ Point localPointToGlobal (Point localPoint) const; + /** Converts a point relative to this component's top-left into a screen coordinate. + @see getLocalPoint, localAreaToGlobal + */ + Point localPointToGlobal (Point localPoint) const; + /** Converts a rectangle from this component's coordinate space to a screen coordinate. If you've used setTransform() to apply one or more transforms to components, then the source rectangle @@ -2306,18 +2320,18 @@ private: uint8 componentTransparency; //============================================================================== - void internalMouseEnter (MouseInputSource, Point, Time); - void internalMouseExit (MouseInputSource, Point, Time); - void internalMouseDown (MouseInputSource, Point, Time); - void internalMouseUp (MouseInputSource, Point, Time, const ModifierKeys oldModifiers); - void internalMouseDrag (MouseInputSource, Point, Time); - void internalMouseMove (MouseInputSource, Point, Time); - void internalMouseWheel (MouseInputSource, Point, Time, const MouseWheelDetails&); - void internalMagnifyGesture (MouseInputSource, Point, Time, float); + void internalMouseEnter (MouseInputSource, Point, Time); + void internalMouseExit (MouseInputSource, Point, Time); + void internalMouseDown (MouseInputSource, Point, Time); + void internalMouseUp (MouseInputSource, Point, Time, const ModifierKeys oldModifiers); + void internalMouseDrag (MouseInputSource, Point, Time); + void internalMouseMove (MouseInputSource, Point, Time); + void internalMouseWheel (MouseInputSource, Point, Time, const MouseWheelDetails&); + void internalMagnifyGesture (MouseInputSource, Point, Time, float); void internalBroughtToFront(); - void internalFocusGain (const FocusChangeType, const WeakReference&); - void internalFocusGain (const FocusChangeType); - void internalFocusLoss (const FocusChangeType); + void internalFocusGain (FocusChangeType, const WeakReference&); + void internalFocusGain (FocusChangeType); + void internalFocusLoss (FocusChangeType); void internalChildFocusChange (FocusChangeType, const WeakReference&); void internalModalInputAttempt(); void internalModifierKeysChanged(); diff --git a/modules/juce_gui_basics/components/juce_Desktop.cpp b/modules/juce_gui_basics/components/juce_Desktop.cpp index 105dee880e..bb77371eff 100644 --- a/modules/juce_gui_basics/components/juce_Desktop.cpp +++ b/modules/juce_gui_basics/components/juce_Desktop.cpp @@ -148,18 +148,23 @@ void Desktop::componentBroughtToFront (Component* const c) //============================================================================== Point Desktop::getMousePosition() +{ + return getMousePositionFloat().roundToInt(); +} + +Point Desktop::getMousePositionFloat() { return getInstance().getMainMouseSource().getScreenPosition(); } void Desktop::setMousePosition (Point newPosition) { - getInstance().getMainMouseSource().setScreenPosition (newPosition); + getInstance().getMainMouseSource().setScreenPosition (newPosition.toFloat()); } Point Desktop::getLastMouseDownPosition() { - return getInstance().getMainMouseSource().getLastMouseDownPosition(); + return getInstance().getMainMouseSource().getLastMouseDownPosition().roundToInt(); } int Desktop::getMouseButtonClickCounter() const noexcept { return mouseClickCounter; } @@ -197,7 +202,7 @@ void Desktop::resetTimer() else startTimer (100); - lastFakeMouseMove = getMousePosition(); + lastFakeMouseMove = getMousePositionFloat(); } ListenerList& Desktop::getMouseListeners() @@ -222,7 +227,7 @@ void Desktop::removeGlobalMouseListener (MouseListener* const listener) void Desktop::timerCallback() { - if (lastFakeMouseMove != getMousePosition()) + if (lastFakeMouseMove != getMousePositionFloat()) sendMouseMove(); } @@ -232,12 +237,12 @@ void Desktop::sendMouseMove() { startTimer (20); - lastFakeMouseMove = getMousePosition(); + lastFakeMouseMove = getMousePositionFloat(); - if (Component* const target = findComponentAt (lastFakeMouseMove)) + if (Component* const target = findComponentAt (lastFakeMouseMove.roundToInt())) { Component::BailOutChecker checker (target); - const Point pos (target->getLocalPoint (nullptr, lastFakeMouseMove)); + const Point pos (target->getLocalPoint (nullptr, lastFakeMouseMove)); const Time now (Time::getCurrentTime()); const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(), diff --git a/modules/juce_gui_basics/components/juce_Desktop.h b/modules/juce_gui_basics/components/juce_Desktop.h index 3bb3e1a19c..4cc33171c6 100644 --- a/modules/juce_gui_basics/components/juce_Desktop.h +++ b/modules/juce_gui_basics/components/juce_Desktop.h @@ -414,7 +414,7 @@ private: ScopedPointer displays; - Point lastFakeMouseMove; + Point lastFakeMouseMove; void sendMouseMove(); int mouseClickCounter, mouseWheelCounter; @@ -446,6 +446,8 @@ private: void triggerFocusCallback(); void handleAsyncUpdate() override; + static Point getMousePositionFloat(); + static double getDefaultMasterScale(); Desktop(); diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index abfc92201c..963b530f1f 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -980,12 +980,12 @@ public: void timerCallback() override { if (window.windowIsStillValid()) - handleMousePosition (source.getScreenPosition()); + handleMousePosition (source.getScreenPosition().roundToInt()); } bool isOver() const { - return window.reallyContains (window.getLocalPoint (nullptr, source.getScreenPosition()), true); + return window.reallyContains (window.getLocalPoint (nullptr, source.getScreenPosition()).roundToInt(), true); } MenuWindow& window; diff --git a/modules/juce_gui_basics/mouse/juce_ComponentDragger.cpp b/modules/juce_gui_basics/mouse/juce_ComponentDragger.cpp index 3b85495cbd..0259706e3b 100644 --- a/modules/juce_gui_basics/mouse/juce_ComponentDragger.cpp +++ b/modules/juce_gui_basics/mouse/juce_ComponentDragger.cpp @@ -49,7 +49,7 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo // so their coordinates become wrong after the first one moves the window, so in that case, we'll use // the current mouse position instead of the one that the event contains... if (componentToDrag->isOnDesktop()) - bounds += componentToDrag->getLocalPoint (nullptr, e.source.getScreenPosition()) - mouseDownWithinTarget; + bounds += componentToDrag->getLocalPoint (nullptr, e.source.getScreenPosition()).roundToInt() - mouseDownWithinTarget; else bounds += e.getEventRelativeTo (componentToDrag).getPosition() - mouseDownWithinTarget; diff --git a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp index aa09107967..e4ff98ddd1 100644 --- a/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp +++ b/modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp @@ -353,7 +353,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription, return; } - const Point lastMouseDown (draggingSource->getLastMouseDownPosition()); + const Point lastMouseDown (draggingSource->getLastMouseDownPosition().roundToInt()); Point imageOffset; if (dragImage.isNull()) diff --git a/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp b/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp index db1ad12951..df94ae31a9 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseEvent.cpp @@ -23,17 +23,18 @@ */ MouseEvent::MouseEvent (MouseInputSource inputSource, - Point position, + Point pos, ModifierKeys modKeys, Component* const eventComp, Component* const originator, Time time, - Point downPos, + Point downPos, Time downTime, const int numClicks, const bool mouseWasDragged) noexcept - : x (position.x), - y (position.y), + : position (pos), + x (roundToInt (pos.x)), + y (roundToInt (pos.y)), mods (modKeys), eventComponent (eventComp), originalComponent (originator), @@ -55,19 +56,26 @@ MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) cons { jassert (otherComponent != nullptr); - return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, getPosition()), + return MouseEvent (source, otherComponent->getLocalPoint (eventComponent, position), mods, otherComponent, originalComponent, eventTime, otherComponent->getLocalPoint (eventComponent, mouseDownPos), mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0); } -MouseEvent MouseEvent::withNewPosition (Point newPosition) const noexcept +MouseEvent MouseEvent::withNewPosition (Point newPosition) const noexcept { return MouseEvent (source, newPosition, mods, eventComponent, originalComponent, eventTime, mouseDownPos, mouseDownTime, numberOfClicks, wasMovedSinceMouseDown != 0); } +MouseEvent MouseEvent::withNewPosition (Point newPosition) const noexcept +{ + return MouseEvent (source, newPosition.toFloat(), mods, eventComponent, originalComponent, + eventTime, mouseDownPos, mouseDownTime, + numberOfClicks, wasMovedSinceMouseDown != 0); +} + //============================================================================== bool MouseEvent::mouseWasClicked() const noexcept { @@ -86,17 +94,17 @@ int MouseEvent::getLengthOfMousePress() const noexcept Point MouseEvent::getPosition() const noexcept { return Point (x, y); } Point MouseEvent::getScreenPosition() const { return eventComponent->localPointToGlobal (getPosition()); } -Point MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos; } -Point MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos); } +Point MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos.roundToInt(); } +Point MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos).roundToInt(); } -Point MouseEvent::getOffsetFromDragStart() const noexcept { return getPosition() - mouseDownPos; } -int MouseEvent::getDistanceFromDragStart() const noexcept { return mouseDownPos.getDistanceFrom (getPosition()); } +Point MouseEvent::getOffsetFromDragStart() const noexcept { return (position - mouseDownPos).roundToInt(); } +int MouseEvent::getDistanceFromDragStart() const noexcept { return roundToInt (mouseDownPos.getDistanceFrom (position)); } -int MouseEvent::getMouseDownX() const noexcept { return mouseDownPos.x; } -int MouseEvent::getMouseDownY() const noexcept { return mouseDownPos.y; } +int MouseEvent::getMouseDownX() const noexcept { return roundToInt (mouseDownPos.x); } +int MouseEvent::getMouseDownY() const noexcept { return roundToInt (mouseDownPos.y); } -int MouseEvent::getDistanceFromDragStartX() const noexcept { return x - mouseDownPos.x; } -int MouseEvent::getDistanceFromDragStartY() const noexcept { return y - mouseDownPos.y; } +int MouseEvent::getDistanceFromDragStartX() const noexcept { return getOffsetFromDragStart().x; } +int MouseEvent::getDistanceFromDragStartY() const noexcept { return getOffsetFromDragStart().y; } int MouseEvent::getScreenX() const { return getScreenPosition().x; } int MouseEvent::getScreenY() const { return getScreenPosition().y; } diff --git a/modules/juce_gui_basics/mouse/juce_MouseEvent.h b/modules/juce_gui_basics/mouse/juce_MouseEvent.h index 87328b1c18..92ac754ed0 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseEvent.h +++ b/modules/juce_gui_basics/mouse/juce_MouseEvent.h @@ -57,12 +57,12 @@ public: @param mouseWasDragged whether the mouse has been dragged significantly since the previous mouse-down */ MouseEvent (MouseInputSource source, - Point position, + Point position, ModifierKeys modifiers, Component* eventComponent, Component* originator, Time eventTime, - Point mouseDownPos, + Point mouseDownPos, Time mouseDownTime, int numberOfClicks, bool mouseWasDragged) noexcept; @@ -71,10 +71,22 @@ public: ~MouseEvent() noexcept; //============================================================================== + /** The position of the mouse when the event occurred. + + This value is relative to the top-left of the component to which the + event applies (as indicated by the MouseEvent::eventComponent field). + + This is a more accurate floating-point version of the position returned by + getPosition() and the integer x and y member variables. + */ + const Point position; + /** The x-position of the mouse when the event occurred. This value is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field). + + For a floating-point coordinate, see MouseEvent::position */ const int x; @@ -82,6 +94,8 @@ public: This value is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field). + + For a floating-point coordinate, see MouseEvent::position */ const int y; @@ -130,25 +144,19 @@ public: //============================================================================== /** Returns the x coordinate of the last place that a mouse was pressed. - The coordinate is relative to the component specified in MouseEvent::component. - @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked */ int getMouseDownX() const noexcept; /** Returns the y coordinate of the last place that a mouse was pressed. - The coordinate is relative to the component specified in MouseEvent::component. - @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked */ int getMouseDownY() const noexcept; /** Returns the coordinates of the last place that a mouse was pressed. - The coordinates are relative to the component specified in MouseEvent::component. - @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked */ Point getMouseDownPosition() const noexcept; @@ -221,6 +229,8 @@ public: This position is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field). + + For a floating-point position, see MouseEvent::position */ Point getPosition() const noexcept; @@ -269,6 +279,12 @@ public: */ MouseEvent getEventRelativeTo (Component* newComponent) const noexcept; + /** Creates a copy of this event with a different position. + All other members of the event object are the same, but the x and y are + replaced with these new values. + */ + MouseEvent withNewPosition (Point newPosition) const noexcept; + /** Creates a copy of this event with a different position. All other members of the event object are the same, but the x and y are replaced with these new values. @@ -297,7 +313,7 @@ public: private: //============================================================================== - const Point mouseDownPos; + const Point mouseDownPos; const uint8 numberOfClicks, wasMovedSinceMouseDown; MouseEvent& operator= (const MouseEvent&); diff --git a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp index 42df454310..46698bd709 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp @@ -58,7 +58,7 @@ public: return lastPeer; } - static Point screenPosToLocalPos (Component& comp, Point pos) + static Point screenPosToLocalPos (Component& comp, Point pos) { if (ComponentPeer* const peer = comp.getPeer()) { @@ -70,23 +70,25 @@ public: return comp.getLocalPoint (nullptr, ScalingHelpers::unscaledScreenPosToScaled (comp, pos)); } - Component* findComponentAt (Point screenPos) + Component* findComponentAt (Point screenPos) { if (ComponentPeer* const peer = getPeer()) { - Point relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(), - peer->globalToLocal (screenPos))); + Point relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(), + peer->globalToLocal (screenPos))); Component& comp = peer->getComponent(); + const Point pos (relativePos.roundToInt()); + // (the contains() call is needed to test for overlapping desktop windows) - if (comp.contains (relativePos)) - return comp.getComponentAt (relativePos); + if (comp.contains (pos)) + return comp.getComponentAt (pos); } return nullptr; } - Point getScreenPosition() const + Point getScreenPosition() const { // This needs to return the live position if possible, but it mustn't update the lastScreenPos // value, because that can cause continuity problems. @@ -95,7 +97,7 @@ public: : lastScreenPos)); } - void setScreenPosition (Point p) + void setScreenPosition (Point p) { MouseInputSource::setRawMousePosition (ScalingHelpers::scaledScreenPosToUnscaled (p)); } @@ -109,49 +111,49 @@ public: #define JUCE_MOUSE_EVENT_DBG(desc) #endif - void sendMouseEnter (Component& comp, Point screenPos, Time time) + void sendMouseEnter (Component& comp, Point screenPos, Time time) { JUCE_MOUSE_EVENT_DBG ("enter") comp.internalMouseEnter (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); } - void sendMouseExit (Component& comp, Point screenPos, Time time) + void sendMouseExit (Component& comp, Point screenPos, Time time) { JUCE_MOUSE_EVENT_DBG ("exit") comp.internalMouseExit (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); } - void sendMouseMove (Component& comp, Point screenPos, Time time) + void sendMouseMove (Component& comp, Point screenPos, Time time) { JUCE_MOUSE_EVENT_DBG ("move") comp.internalMouseMove (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); } - void sendMouseDown (Component& comp, Point screenPos, Time time) + void sendMouseDown (Component& comp, Point screenPos, Time time) { JUCE_MOUSE_EVENT_DBG ("down") comp.internalMouseDown (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); } - void sendMouseDrag (Component& comp, Point screenPos, Time time) + void sendMouseDrag (Component& comp, Point screenPos, Time time) { JUCE_MOUSE_EVENT_DBG ("drag") comp.internalMouseDrag (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time); } - void sendMouseUp (Component& comp, Point screenPos, Time time, const ModifierKeys oldMods) + void sendMouseUp (Component& comp, Point screenPos, Time time, const ModifierKeys oldMods) { JUCE_MOUSE_EVENT_DBG ("up") comp.internalMouseUp (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, oldMods); } - void sendMouseWheel (Component& comp, Point screenPos, Time time, const MouseWheelDetails& wheel) + void sendMouseWheel (Component& comp, Point screenPos, Time time, const MouseWheelDetails& wheel) { JUCE_MOUSE_EVENT_DBG ("wheel") comp.internalMouseWheel (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, wheel); } - void sendMagnifyGesture (Component& comp, Point screenPos, Time time, const float amount) + void sendMagnifyGesture (Component& comp, Point screenPos, Time time, const float amount) { JUCE_MOUSE_EVENT_DBG ("magnify") comp.internalMagnifyGesture (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time, amount); @@ -159,7 +161,7 @@ public: //============================================================================== // (returns true if the button change caused a modal event loop) - bool setButtons (Point screenPos, Time time, const ModifierKeys newButtonState) + bool setButtons (Point screenPos, Time time, const ModifierKeys newButtonState) { if (buttonState == newButtonState) return false; @@ -209,7 +211,7 @@ public: return lastCounter != mouseEventCounter; } - void setComponentUnderMouse (Component* const newComponent, Point screenPos, Time time) + void setComponentUnderMouse (Component* const newComponent, Point screenPos, Time time) { Component* current = getComponentUnderMouse(); @@ -242,7 +244,7 @@ public: } } - void setPeer (ComponentPeer& newPeer, Point screenPos, Time time) + void setPeer (ComponentPeer& newPeer, Point screenPos, Time time) { ModifierKeys::updateCurrentModifiers(); @@ -254,7 +256,7 @@ public: } } - void setScreenPos (Point newScreenPos, Time time, const bool forceUpdate) + void setScreenPos (Point newScreenPos, Time time, const bool forceUpdate) { if (! isDragging()) setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time); @@ -285,11 +287,11 @@ public: } //============================================================================== - void handleEvent (ComponentPeer& newPeer, Point positionWithinPeer, Time time, const ModifierKeys newMods) + void handleEvent (ComponentPeer& newPeer, Point positionWithinPeer, Time time, const ModifierKeys newMods) { lastTime = time; ++mouseEventCounter; - const Point screenPos (newPeer.localToGlobal (positionWithinPeer)); + const Point screenPos (newPeer.localToGlobal (positionWithinPeer)); if (isDragging() && newMods.isAnyMouseButtonDown()) { @@ -311,8 +313,8 @@ public: } } - Component* getTargetForGesture (ComponentPeer& peer, Point positionWithinPeer, - Time time, Point& screenPos) + Component* getTargetForGesture (ComponentPeer& peer, Point positionWithinPeer, + Time time, Point& screenPos) { lastTime = time; ++mouseEventCounter; @@ -325,27 +327,27 @@ public: return isDragging() ? nullptr : getComponentUnderMouse(); } - void handleWheel (ComponentPeer& peer, Point positionWithinPeer, + void handleWheel (ComponentPeer& peer, Point positionWithinPeer, Time time, const MouseWheelDetails& wheel) { Desktop::getInstance().incrementMouseWheelCounter(); - Point screenPos; + Point screenPos; if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos)) sendMouseWheel (*current, screenPos, time, wheel); } - void handleMagnifyGesture (ComponentPeer& peer, Point positionWithinPeer, + void handleMagnifyGesture (ComponentPeer& peer, Point positionWithinPeer, Time time, const float scaleFactor) { - Point screenPos; + Point screenPos; if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos)) sendMagnifyGesture (*current, screenPos, time, scaleFactor); } //============================================================================== Time getLastMouseDownTime() const noexcept { return mouseDowns[0].time; } - Point getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); } + Point getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); } int getNumberOfMultipleClicks() const noexcept { @@ -397,12 +399,11 @@ public: { // when released, return the mouse to within the component's bounds if (Component* current = getComponentUnderMouse()) - Desktop::setMousePosition (current->getScreenBounds() - .getConstrainedPoint (lastScreenPos)); + setScreenPosition (current->getScreenBounds().toFloat().getConstrainedPoint (lastScreenPos)); } isUnboundedMouseModeOn = enable; - unboundedMouseOffset = Point(); + unboundedMouseOffset = Point(); revealCursor (true); } @@ -410,20 +411,20 @@ public: void handleUnboundedDrag (Component* current) { - const Rectangle screenArea (current->getParentMonitorArea().expanded (-2, -2)); + const Rectangle screenArea (current->getParentMonitorArea().expanded (-2, -2).toFloat()); if (! screenArea.contains (lastScreenPos)) { - const Point componentCentre (current->getScreenBounds().getCentre()); + const Point componentCentre (current->getScreenBounds().toFloat().getCentre()); unboundedMouseOffset += (lastScreenPos - componentCentre); - Desktop::setMousePosition (componentCentre); + setScreenPosition (componentCentre); } else if (isCursorVisibleUntilOffscreen && (! unboundedMouseOffset.isOrigin()) && screenArea.contains (lastScreenPos + unboundedMouseOffset)) { - Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset); - unboundedMouseOffset = Point(); + setScreenPosition (lastScreenPos + unboundedMouseOffset); + unboundedMouseOffset = Point(); } } @@ -461,10 +462,10 @@ public: //============================================================================== const int index; const bool isMouseDevice; - Point lastScreenPos; + Point lastScreenPos; ModifierKeys buttonState; - Point unboundedMouseOffset; + Point unboundedMouseOffset; bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen; private: @@ -478,7 +479,7 @@ private: { RecentMouseDown() noexcept : peerID (0) {} - Point position; + Point position; Time time; ModifierKeys buttons; uint32 peerID; @@ -497,7 +498,7 @@ private: Time lastTime; bool mouseMovedSignificantlySincePressed; - void registerMouseDown (Point screenPos, Time time, + void registerMouseDown (Point screenPos, Time time, Component& component, const ModifierKeys modifiers) noexcept { for (int i = numElementsInArray (mouseDowns); --i > 0;) @@ -515,7 +516,7 @@ private: mouseMovedSignificantlySincePressed = false; } - void registerMouseDrag (Point screenPos) noexcept + void registerMouseDrag (Point screenPos) noexcept { mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4; @@ -535,47 +536,44 @@ MouseInputSource& MouseInputSource::operator= (const MouseInputSource& other) no return *this; } -bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; } -bool MouseInputSource::isTouch() const { return ! isMouse(); } -bool MouseInputSource::canHover() const { return isMouse(); } -bool MouseInputSource::hasMouseWheel() const { return isMouse(); } -int MouseInputSource::getIndex() const { return pimpl->index; } -bool MouseInputSource::isDragging() const { return pimpl->isDragging(); } -Point MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); } -ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); } -Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); } -void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); } -int MouseInputSource::getNumberOfMultipleClicks() const noexcept { return pimpl->getNumberOfMultipleClicks(); } -Time MouseInputSource::getLastMouseDownTime() const noexcept { return pimpl->getLastMouseDownTime(); } -Point MouseInputSource::getLastMouseDownPosition() const noexcept { return pimpl->getLastMouseDownPosition(); } +bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; } +bool MouseInputSource::isTouch() const { return ! isMouse(); } +bool MouseInputSource::canHover() const { return isMouse(); } +bool MouseInputSource::hasMouseWheel() const { return isMouse(); } +int MouseInputSource::getIndex() const { return pimpl->index; } +bool MouseInputSource::isDragging() const { return pimpl->isDragging(); } +Point MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); } +ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); } +Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); } +void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); } +int MouseInputSource::getNumberOfMultipleClicks() const noexcept { return pimpl->getNumberOfMultipleClicks(); } +Time MouseInputSource::getLastMouseDownTime() const noexcept { return pimpl->getLastMouseDownTime(); } +Point MouseInputSource::getLastMouseDownPosition() const noexcept { return pimpl->getLastMouseDownPosition(); } bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const noexcept { return pimpl->hasMouseMovedSignificantlySincePressed(); } -bool MouseInputSource::canDoUnboundedMovement() const noexcept { return isMouse(); } +bool MouseInputSource::canDoUnboundedMovement() const noexcept { return isMouse(); } void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) const - { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); } -bool MouseInputSource::isUnboundedMouseMovementEnabled() const { return pimpl->isUnboundedMouseModeOn; } -bool MouseInputSource::hasMouseCursor() const noexcept { return isMouse(); } -void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); } -void MouseInputSource::hideCursor() { pimpl->hideCursor(); } -void MouseInputSource::revealCursor() { pimpl->revealCursor (false); } -void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); } -void MouseInputSource::setScreenPosition (Point p) { pimpl->setScreenPosition (p); } - -void MouseInputSource::handleEvent (ComponentPeer& peer, Point positionWithinPeer, - const int64 time, const ModifierKeys mods) + { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); } +bool MouseInputSource::isUnboundedMouseMovementEnabled() const { return pimpl->isUnboundedMouseModeOn; } +bool MouseInputSource::hasMouseCursor() const noexcept { return isMouse(); } +void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); } +void MouseInputSource::hideCursor() { pimpl->hideCursor(); } +void MouseInputSource::revealCursor() { pimpl->revealCursor (false); } +void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); } +void MouseInputSource::setScreenPosition (Point p) { pimpl->setScreenPosition (p); } + +void MouseInputSource::handleEvent (ComponentPeer& peer, Point pos, int64 time, ModifierKeys mods) { - pimpl->handleEvent (peer, positionWithinPeer, Time (time), mods.withOnlyMouseButtons()); + pimpl->handleEvent (peer, pos, Time (time), mods.withOnlyMouseButtons()); } -void MouseInputSource::handleWheel (ComponentPeer& peer, Point positionWithinPeer, - const int64 time, const MouseWheelDetails& wheel) +void MouseInputSource::handleWheel (ComponentPeer& peer, Point pos, int64 time, const MouseWheelDetails& wheel) { - pimpl->handleWheel (peer, positionWithinPeer, Time (time), wheel); + pimpl->handleWheel (peer, pos, Time (time), wheel); } -void MouseInputSource::handleMagnifyGesture (ComponentPeer& peer, Point positionWithinPeer, - const int64 time, const float scaleFactor) +void MouseInputSource::handleMagnifyGesture (ComponentPeer& peer, Point pos, int64 time, float scaleFactor) { - pimpl->handleMagnifyGesture (peer, positionWithinPeer, Time (time), scaleFactor); + pimpl->handleMagnifyGesture (peer, pos, Time (time), scaleFactor); } //============================================================================== diff --git a/modules/juce_gui_basics/mouse/juce_MouseInputSource.h b/modules/juce_gui_basics/mouse/juce_MouseInputSource.h index c8ab0dffda..e257363119 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseInputSource.h +++ b/modules/juce_gui_basics/mouse/juce_MouseInputSource.h @@ -88,7 +88,7 @@ public: bool isDragging() const; /** Returns the last-known screen position of this source. */ - Point getScreenPosition() const; + Point getScreenPosition() const; /** Returns a set of modifiers that indicate which buttons are currently held down on this device. @@ -114,7 +114,7 @@ public: Time getLastMouseDownTime() const noexcept; /** Returns the screen position at which the last mouse-down occurred. */ - Point getLastMouseDownPosition() const noexcept; + Point getLastMouseDownPosition() const noexcept; /** Returns true if this mouse is currently down, and if it has been dragged more than a couple of pixels from the place it was pressed. @@ -162,7 +162,7 @@ public: bool isUnboundedMouseMovementEnabled() const; /** Attempts to set this mouse pointer's screen position. */ - void setScreenPosition (Point newPosition); + void setScreenPosition (Point newPosition); private: //============================================================================== @@ -174,12 +174,12 @@ private: struct SourceList; explicit MouseInputSource (MouseInputSourceInternal*) noexcept; - void handleEvent (ComponentPeer&, Point, int64 time, const ModifierKeys); - void handleWheel (ComponentPeer&, Point, int64 time, const MouseWheelDetails&); - void handleMagnifyGesture (ComponentPeer&, Point, int64 time, float scaleFactor); + void handleEvent (ComponentPeer&, Point, int64 time, ModifierKeys); + void handleWheel (ComponentPeer&, Point, int64 time, const MouseWheelDetails&); + void handleMagnifyGesture (ComponentPeer&, Point, int64 time, float scaleFactor); - static Point getCurrentRawMousePosition(); - static void setRawMousePosition (Point); + static Point getCurrentRawMousePosition(); + static void setRawMousePosition (Point); JUCE_LEAK_DETECTOR (MouseInputSource) }; diff --git a/modules/juce_gui_basics/native/juce_android_Windowing.cpp b/modules/juce_gui_basics/native/juce_android_Windowing.cpp index 02353be730..b2d1ee7772 100644 --- a/modules/juce_gui_basics/native/juce_android_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_android_Windowing.cpp @@ -234,14 +234,14 @@ public: view.callIntMethod (ComponentPeerView.getTop)); } - Point localToGlobal (Point relativePosition) override + Point localToGlobal (Point relativePosition) override { - return relativePosition + getScreenPosition(); + return relativePosition + getScreenPosition().toFloat(); } - Point globalToLocal (Point screenPosition) override + Point globalToLocal (Point screenPosition) override { - return screenPosition - getScreenPosition(); + return screenPosition - getScreenPosition().toFloat(); } void setMinimised (bool shouldBeMinimised) override @@ -320,7 +320,7 @@ public: lastMousePos = pos; // this forces a mouse-enter/up event, in case for some reason we didn't get a mouse-up before. - handleMouseEvent (index, pos.toInt(), currentModifiers.withoutMouseButtons(), time); + handleMouseEvent (index, pos, currentModifiers.withoutMouseButtons(), time); if (isValidPeer (this)) handleMouseDragCallback (index, pos, time); @@ -333,8 +333,8 @@ public: jassert (index < 64); touchesDown = (touchesDown | (1 << (index & 63))); currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier); - handleMouseEvent (index, pos.toInt(), currentModifiers.withoutMouseButtons() - .withFlags (ModifierKeys::leftButtonModifier), time); + handleMouseEvent (index, pos, currentModifiers.withoutMouseButtons() + .withFlags (ModifierKeys::leftButtonModifier), time); } void handleMouseUpCallback (int index, Point pos, int64 time) @@ -347,7 +347,7 @@ public: if (touchesDown == 0) currentModifiers = currentModifiers.withoutMouseButtons(); - handleMouseEvent (index, pos.toInt(), currentModifiers.withoutMouseButtons(), time); + handleMouseEvent (index, pos, currentModifiers.withoutMouseButtons(), time); } void handleKeyDownCallback (int k, int kc) @@ -611,12 +611,12 @@ bool MouseInputSource::SourceList::addSource() return true; } -Point MouseInputSource::getCurrentRawMousePosition() +Point MouseInputSource::getCurrentRawMousePosition() { - return AndroidComponentPeer::lastMousePos.toInt(); + return AndroidComponentPeer::lastMousePos; } -void MouseInputSource::setRawMousePosition (Point) +void MouseInputSource::setRawMousePosition (Point) { // not needed } diff --git a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm index 791958645a..3d973d3e41 100644 --- a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm @@ -145,8 +145,8 @@ public: Rectangle getBounds() const override { return getBounds (! isSharedWindow); } Rectangle getBounds (bool global) const; - Point localToGlobal (Point relativePosition) override; - Point globalToLocal (Point screenPosition) override; + Point localToGlobal (Point relativePosition) override; + Point globalToLocal (Point screenPosition) override; void setAlpha (float newAlpha) override; void setMinimised (bool) override {} bool isMinimised() const override { return false; } @@ -477,7 +477,7 @@ void ModifierKeys::updateCurrentModifiers() noexcept currentModifiers = UIViewComponentPeer::currentModifiers; } -Point juce_lastMousePos; +Point juce_lastMousePos; //============================================================================== UIViewComponentPeer::UIViewComponentPeer (Component& comp, const int windowStyleFlags, UIView* viewToAttachTo) @@ -603,14 +603,14 @@ Rectangle UIViewComponentPeer::getBounds (const bool global) const return convertToRectInt (r); } -Point UIViewComponentPeer::localToGlobal (Point relativePosition) +Point UIViewComponentPeer::localToGlobal (Point relativePosition) { - return relativePosition + getBounds (true).getPosition(); + return relativePosition + getBounds (true).getPosition().toFloat(); } -Point UIViewComponentPeer::globalToLocal (Point screenPosition) +Point UIViewComponentPeer::globalToLocal (Point screenPosition) { - return screenPosition - getBounds (true).getPosition(); + return screenPosition - getBounds (true).getPosition().toFloat(); } void UIViewComponentPeer::setAlpha (float newAlpha) @@ -737,8 +737,8 @@ void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, cons continue; CGPoint p = [touch locationInView: view]; - const Point pos ((int) p.x, (int) p.y); - juce_lastMousePos = pos + getBounds (true).getPosition(); + const Point pos (p.x, p.y); + juce_lastMousePos = pos + getBounds (true).getPosition().toFloat(); const int64 time = getMouseTime (event); const int touchIndex = currentTouches.getIndexOfTouch (touch); @@ -782,7 +782,7 @@ void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, cons if (isUp || isCancel) { - handleMouseEvent (touchIndex, Point (-1, -1), modsToSend, time); + handleMouseEvent (touchIndex, Point (-1.0f, -1.0f), modsToSend, time); if (! isValidPeer (this)) return; } diff --git a/modules/juce_gui_basics/native/juce_ios_Windowing.mm b/modules/juce_gui_basics/native/juce_ios_Windowing.mm index 6b9031fb74..6df6db061e 100644 --- a/modules/juce_gui_basics/native/juce_ios_Windowing.mm +++ b/modules/juce_gui_basics/native/juce_ios_Windowing.mm @@ -312,12 +312,12 @@ bool Desktop::canUseSemiTransparentWindows() noexcept return true; } -Point MouseInputSource::getCurrentRawMousePosition() +Point MouseInputSource::getCurrentRawMousePosition() { return juce_lastMousePos; } -void MouseInputSource::setRawMousePosition (Point) +void MouseInputSource::setRawMousePosition (Point) { } diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index 91746d2b18..4cbb70709e 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -971,14 +971,14 @@ public: Rectangle getBounds() const override { return bounds; } - Point localToGlobal (Point relativePosition) override + Point localToGlobal (Point relativePosition) override { - return relativePosition + bounds.getPosition(); + return relativePosition + bounds.getPosition().toFloat(); } - Point globalToLocal (Point screenPosition) override + Point globalToLocal (Point screenPosition) override { - return screenPosition - bounds.getPosition(); + return screenPosition - bounds.getPosition().toFloat(); } void setAlpha (float /* newAlpha */) override @@ -1491,9 +1491,9 @@ public: } template - static Point getMousePos (const EventType& e) noexcept + static Point getMousePos (const EventType& e) noexcept { - return Point (e.x, e.y); + return Point ((float) e.x, (float) e.y); } void handleWheelEvent (const XButtonPressedEvent& buttonPressEvent, const float amount) @@ -3123,7 +3123,7 @@ bool Desktop::canUseSemiTransparentWindows() noexcept && (matchedDepth == desiredDepth); } -Point MouseInputSource::getCurrentRawMousePosition() +Point MouseInputSource::getCurrentRawMousePosition() { Window root, child; int x, y, winx, winy; @@ -3140,14 +3140,14 @@ Point MouseInputSource::getCurrentRawMousePosition() x = y = -1; } - return Point (x, y); + return Point ((float) x, (float) y); } -void MouseInputSource::setRawMousePosition (Point newPosition) +void MouseInputSource::setRawMousePosition (Point newPosition) { ScopedXLock xlock; Window root = RootWindow (display, DefaultScreen (display)); - XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY()); + XWarpPointer (display, None, root, 0, 0, 0, 0, roundToInt (newPosition.getX()), roundToInt (newPosition.getY())); } double Desktop::getDefaultMasterScale() diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index aebf2e7d65..66fad3888e 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -295,14 +295,14 @@ public: return getBounds (! isSharedWindow); } - Point localToGlobal (Point relativePosition) override + Point localToGlobal (Point relativePosition) override { - return relativePosition + getBounds (true).getPosition(); + return relativePosition + getBounds (true).getPosition().toFloat(); } - Point globalToLocal (Point screenPosition) override + Point globalToLocal (Point screenPosition) override { - return screenPosition - getBounds (true).getPosition(); + return screenPosition - getBounds (true).getPosition().toFloat(); } void setAlpha (float newAlpha) override @@ -559,7 +559,7 @@ public: belowWindowWithWindowNumber: 0] != [window windowNumber]) { // moved into another window which overlaps this one, so trigger an exit - handleMouseEvent (0, Point (-1, -1), currentModifiers, getMouseTime (ev)); + handleMouseEvent (0, Point (-1.0f, -1.0f), currentModifiers, getMouseTime (ev)); } else #endif @@ -936,7 +936,7 @@ public: MouseInputSource mouse = desktop.getMainMouseSource(); if (mouse.getComponentUnderMouse() == nullptr - && desktop.findComponentAt (mouse.getScreenPosition()) == nullptr) + && desktop.findComponentAt (mouse.getScreenPosition().roundToInt()) == nullptr) { [[NSCursor arrowCursor] set]; } @@ -1010,10 +1010,10 @@ public: + (int64) ([e timestamp] * 1000.0); } - static Point getMousePos (NSEvent* e, NSView* view) + static Point getMousePos (NSEvent* e, NSView* view) { NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil]; - return Point ((int) p.x, (int) ([view frame].size.height - p.y)); + return Point (p.x, [view frame].size.height - p.y); } static int getModifierForButtonNumber (const NSInteger num) diff --git a/modules/juce_gui_basics/native/juce_mac_Windowing.mm b/modules/juce_gui_basics/native/juce_mac_Windowing.mm index dd85fe3b33..9dfde47ccd 100644 --- a/modules/juce_gui_basics/native/juce_mac_Windowing.mm +++ b/modules/juce_gui_basics/native/juce_mac_Windowing.mm @@ -209,16 +209,16 @@ bool Desktop::canUseSemiTransparentWindows() noexcept return true; } -Point MouseInputSource::getCurrentRawMousePosition() +Point MouseInputSource::getCurrentRawMousePosition() { JUCE_AUTORELEASEPOOL { const NSPoint p ([NSEvent mouseLocation]); - return Point (roundToInt (p.x), roundToInt (getMainScreenHeight() - p.y)); + return Point (p.x, getMainScreenHeight() - p.y); } } -void MouseInputSource::setRawMousePosition (Point newPosition) +void MouseInputSource::setRawMousePosition (Point newPosition) { // this rubbish needs to be done around the warp call, to avoid causing a // bizarre glitch.. diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 94878cf46f..4f2afe12ef 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -704,8 +704,8 @@ public: r.top + windowBorder.getTop()); } - Point localToGlobal (Point relativePosition) override { return relativePosition + getScreenPosition(); } - Point globalToLocal (Point screenPosition) override { return screenPosition - getScreenPosition(); } + Point localToGlobal (Point relativePosition) override { return relativePosition + getScreenPosition().toFloat(); } + Point globalToLocal (Point screenPosition) override { return screenPosition - getScreenPosition().toFloat(); } void setAlpha (float newAlpha) override { @@ -993,7 +993,7 @@ public: if (ownerInfo == nullptr) return S_FALSE; - ownerInfo->dragInfo.position = ownerInfo->getMousePos (mousePos); + ownerInfo->dragInfo.position = ownerInfo->getMousePos (mousePos).roundToInt(); const bool wasWanted = ownerInfo->owner.handleDragMove (ownerInfo->dragInfo); *pdwEffect = wasWanted ? (DWORD) DROPEFFECT_COPY : (DWORD) DROPEFFECT_NONE; return S_OK; @@ -1004,7 +1004,7 @@ public: HRESULT hr = updateFileList (pDataObject); if (SUCCEEDED (hr)) { - ownerInfo->dragInfo.position = ownerInfo->getMousePos (mousePos); + ownerInfo->dragInfo.position = ownerInfo->getMousePos (mousePos).roundToInt(); const bool wasWanted = ownerInfo->owner.handleDragDrop (ownerInfo->dragInfo); *pdwEffect = wasWanted ? (DWORD) DROPEFFECT_COPY : (DWORD) DROPEFFECT_NONE; hr = S_OK; @@ -1018,9 +1018,10 @@ public: { OwnerInfo (HWNDComponentPeer& p) : owner (p) {} - Point getMousePos (const POINTL& mousePos) const + Point getMousePos (const POINTL& mousePos) const { - return owner.globalToLocal (Point (mousePos.x, mousePos.y)); + return owner.globalToLocal (Point (static_cast (mousePos.x), + static_cast (mousePos.y))); } template @@ -1648,7 +1649,7 @@ private: } //============================================================================== - void doMouseEvent (Point position) + void doMouseEvent (Point position) { handleMouseEvent (0, position, currentModifiers, getMouseEventTime()); } @@ -1699,7 +1700,7 @@ private: return 1000 / 60; // Throttling the incoming mouse-events seems to still be needed in XP.. } - void doMouseMove (Point position) + void doMouseMove (Point position) { if (! isMouseOver) { @@ -1720,7 +1721,7 @@ private: } else if (! isDragging) { - if (! contains (position, false)) + if (! contains (position.roundToInt(), false)) return; } @@ -1735,7 +1736,7 @@ private: } } - void doMouseDown (Point position, const WPARAM wParam) + void doMouseDown (Point position, const WPARAM wParam) { if (GetCapture() != hwnd) SetCapture (hwnd); @@ -1748,7 +1749,7 @@ private: doMouseEvent (position); } - void doMouseUp (Point position, const WPARAM wParam) + void doMouseUp (Point position, const WPARAM wParam) { updateModifiersFromWParam (wParam); const bool wasDragging = isDragging; @@ -1784,9 +1785,9 @@ private: doMouseEvent (getCurrentMousePos()); } - ComponentPeer* findPeerUnderMouse (Point& localPos) + ComponentPeer* findPeerUnderMouse (Point& localPos) { - const Point globalPos (getCurrentMousePosGlobal()); + const Point globalPos (getCurrentMousePosGlobal().roundToInt()); // Because Windows stupidly sends all wheel events to the window with the keyboard // focus, we have to redirect them here according to the mouse pos.. @@ -1796,7 +1797,7 @@ private: if (peer == nullptr) peer = this; - localPos = peer->globalToLocal (globalPos); + localPos = peer->globalToLocal (globalPos.toFloat()); return peer; } @@ -1811,7 +1812,7 @@ private: wheel.isReversed = false; wheel.isSmooth = false; - Point localPos; + Point localPos; if (ComponentPeer* const peer = findPeerUnderMouse (localPos)) peer->handleMouseWheel (0, localPos, getMouseEventTime(), wheel); } @@ -1825,7 +1826,7 @@ private: if (getGestureInfo != nullptr && getGestureInfo ((HGESTUREINFO) lParam, &gi)) { updateKeyModifiers(); - Point localPos; + Point localPos; if (ComponentPeer* const peer = findPeerUnderMouse (localPos)) { @@ -1883,8 +1884,8 @@ private: bool isCancel = false; const int touchIndex = currentTouches.getIndexOfTouch (touch.dwID); const int64 time = getMouseEventTime(); - const Point pos (globalToLocal (Point ((int) TOUCH_COORD_TO_PIXEL (touch.x), - (int) TOUCH_COORD_TO_PIXEL (touch.y)))); + const Point pos (globalToLocal (Point (static_cast (TOUCH_COORD_TO_PIXEL (touch.x)), + static_cast (TOUCH_COORD_TO_PIXEL (touch.y))))); ModifierKeys modsToSend (currentModifiers); if (isDown) @@ -1895,7 +1896,7 @@ private: if (! isPrimary) { // this forces a mouse-enter/up event, in case for some reason we didn't get a mouse-up before. - handleMouseEvent (touchIndex, pos, modsToSend.withoutMouseButtons(), time); + handleMouseEvent (touchIndex, pos.toFloat(), modsToSend.withoutMouseButtons(), time); if (! isValidPeer (this)) // (in case this component was deleted by the event) return false; } @@ -1921,14 +1922,14 @@ private: if (! isPrimary) { - handleMouseEvent (touchIndex, pos, modsToSend, time); + handleMouseEvent (touchIndex, pos.toFloat(), modsToSend, time); if (! isValidPeer (this)) // (in case this component was deleted by the event) return false; } if ((isUp || isCancel) && ! isPrimary) { - handleMouseEvent (touchIndex, Point (-10, -10), currentModifiers, time); + handleMouseEvent (touchIndex, Point (-10.0f, -10.0f), currentModifiers, time); if (! isValidPeer (this)) return false; } @@ -2326,17 +2327,18 @@ private: return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData); } - static Point getPointFromLParam (LPARAM lParam) noexcept + static Point getPointFromLParam (LPARAM lParam) noexcept { - return Point (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); + return Point (static_cast (GET_X_LPARAM (lParam)), + static_cast (GET_Y_LPARAM (lParam))); } - static Point getCurrentMousePosGlobal() noexcept + static Point getCurrentMousePosGlobal() noexcept { return getPointFromLParam (GetMessagePos()); } - Point getCurrentMousePos() noexcept + Point getCurrentMousePos() noexcept { return globalToLocal (getCurrentMousePosGlobal()); } @@ -2417,8 +2419,8 @@ private: case WM_WINDOWPOSCHANGED: { - const Point pos (getCurrentMousePos()); - if (contains (pos, false)) + const Point pos (getCurrentMousePos()); + if (contains (pos.roundToInt(), false)) doMouseEvent (pos); } @@ -3131,16 +3133,17 @@ bool MouseInputSource::SourceList::addSource() return false; } -Point MouseInputSource::getCurrentRawMousePosition() +Point MouseInputSource::getCurrentRawMousePosition() { POINT mousePos; GetCursorPos (&mousePos); - return Point (mousePos.x, mousePos.y); + return Point ((float) mousePos.x, (float) mousePos.y); } -void MouseInputSource::setRawMousePosition (Point newPosition) +void MouseInputSource::setRawMousePosition (Point newPosition) { - SetCursorPos (newPosition.x, newPosition.y); + SetCursorPos (roundToInt (newPosition.x), + roundToInt (newPosition.y)); } //============================================================================== diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp index c519a784e9..13e267d509 100644 --- a/modules/juce_gui_basics/widgets/juce_Slider.cpp +++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp @@ -745,12 +745,12 @@ public: || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar || style == LinearBarVertical) && ! snapsToMousePos)) { - const int mouseDiff = (style == RotaryHorizontalDrag - || style == LinearHorizontal - || style == LinearBar - || (style == IncDecButtons && incDecDragDirectionIsHorizontal())) - ? e.x - mouseDragStartPos.x - : mouseDragStartPos.y - e.y; + const float mouseDiff = (style == RotaryHorizontalDrag + || style == LinearHorizontal + || style == LinearBar + || (style == IncDecButtons && incDecDragDirectionIsHorizontal())) + ? e.position.x - mouseDragStartPos.x + : mouseDragStartPos.y - e.position.y; newPos = owner.valueToProportionOfLength (valueOnMouseDown) + mouseDiff * (1.0 / pixelsForFullDragExtent); @@ -763,7 +763,8 @@ public: } else if (style == RotaryHorizontalVerticalDrag) { - const int mouseDiff = (e.x - mouseDragStartPos.x) + (mouseDragStartPos.y - e.y); + const float mouseDiff = (e.position.x - mouseDragStartPos.x) + + (mouseDragStartPos.y - e.position.y); newPos = owner.valueToProportionOfLength (valueOnMouseDown) + mouseDiff * (1.0 / pixelsForFullDragExtent); @@ -779,13 +780,13 @@ public: void handleVelocityDrag (const MouseEvent& e) { - const int mouseDiff = style == RotaryHorizontalVerticalDrag - ? (e.x - mousePosWhenLastDragged.x) + (mousePosWhenLastDragged.y - e.y) - : (isHorizontal() - || style == RotaryHorizontalDrag - || (style == IncDecButtons && incDecDragDirectionIsHorizontal())) - ? e.x - mousePosWhenLastDragged.x - : e.y - mousePosWhenLastDragged.y; + const float mouseDiff = style == RotaryHorizontalVerticalDrag + ? (e.x - mousePosWhenLastDragged.x) + (mousePosWhenLastDragged.y - e.y) + : (isHorizontal() + || style == RotaryHorizontalDrag + || (style == IncDecButtons && incDecDragDirectionIsHorizontal())) + ? e.position.x - mousePosWhenLastDragged.x + : e.position.y - mousePosWhenLastDragged.y; const double maxSpeed = jmax (200, sliderRegionSize); double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff)); @@ -816,7 +817,7 @@ public: { incDecDragged = false; useDragEvents = false; - mouseDragStartPos = mousePosWhenLastDragged = e.getPosition(); + mouseDragStartPos = mousePosWhenLastDragged = e.position; currentDrag = nullptr; if (owner.isEnabled()) @@ -887,7 +888,7 @@ public: return; incDecDragged = true; - mouseDragStartPos = e.getPosition(); + mouseDragStartPos = e.position; } if (isAbsoluteDragMode (e.mods) || (maximum - minimum) / sliderRegionSize < interval) @@ -930,7 +931,7 @@ public: minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue(); } - mousePosWhenLastDragged = e.getPosition(); + mousePosWhenLastDragged = e.position; } } @@ -1036,29 +1037,29 @@ public: const double pos = sliderBeingDragged == 2 ? getMaxValue() : (sliderBeingDragged == 1 ? getMinValue() : (double) currentValue.getValue()); - Point mousePos; + Point mousePos; if (isRotary()) { mousePos = mi->getLastMouseDownPosition(); - const int delta = roundToInt (pixelsForFullDragExtent * (owner.valueToProportionOfLength (valueOnMouseDown) - - owner.valueToProportionOfLength (pos))); + const float delta = (float) (pixelsForFullDragExtent * (owner.valueToProportionOfLength (valueOnMouseDown) + - owner.valueToProportionOfLength (pos))); - if (style == RotaryHorizontalDrag) mousePos += Point (-delta, 0); - else if (style == RotaryVerticalDrag) mousePos += Point (0, delta); - else mousePos += Point (delta / -2, delta / 2); + if (style == RotaryHorizontalDrag) mousePos += Point (-delta, 0.0f); + else if (style == RotaryVerticalDrag) mousePos += Point (0.0f, delta); + else mousePos += Point (delta / -2.0f, delta / 2.0f); - mousePos = owner.getScreenBounds().reduced (4).getConstrainedPoint (mousePos); + mousePos = owner.getScreenBounds().reduced (4).toFloat().getConstrainedPoint (mousePos); mouseDragStartPos = mousePosWhenLastDragged = owner.getLocalPoint (nullptr, mousePos); valueOnMouseDown = valueWhenLastDragged; } else { - const int pixelPos = (int) getLinearSliderPos (pos); + const float pixelPos = (float) getLinearSliderPos (pos); - mousePos = owner.localPointToGlobal (Point (isHorizontal() ? pixelPos : (owner.getWidth() / 2), - isVertical() ? pixelPos : (owner.getHeight() / 2))); + mousePos = owner.localPointToGlobal (Point (isHorizontal() ? pixelPos : (owner.getWidth() / 2.0f), + isVertical() ? pixelPos : (owner.getHeight() / 2.0f))); } mi->setScreenPosition (mousePos); @@ -1231,7 +1232,7 @@ public: double velocityModeSensitivity, velocityModeOffset, minMaxDiff; int velocityModeThreshold; float rotaryStart, rotaryEnd; - Point mouseDragStartPos, mousePosWhenLastDragged; + Point mouseDragStartPos, mousePosWhenLastDragged; int sliderRegionStart, sliderRegionSize; int sliderBeingDragged; int pixelsForFullDragExtent; diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.cpp b/modules/juce_gui_basics/widgets/juce_TreeView.cpp index b31bc49152..c7bb76e6e2 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.cpp +++ b/modules/juce_gui_basics/widgets/juce_TreeView.cpp @@ -67,7 +67,7 @@ public: selectBasedOnModifiers (item, e.mods); if (e.x >= pos.getX()) - item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition())); + item->itemClicked (e.withNewPosition (e.position - pos.getPosition().toFloat())); } } } @@ -92,7 +92,7 @@ public: Rectangle pos; if (TreeViewItem* const item = findItemAt (e.y, pos)) if (e.x >= pos.getX() || ! owner.openCloseButtonsVisible) - item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition())); + item->itemDoubleClicked (e.withNewPosition (e.position - pos.getPosition().toFloat())); } } diff --git a/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp b/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp index 976c5a4282..ad95469732 100644 --- a/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp +++ b/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp @@ -85,25 +85,22 @@ bool ComponentPeer::isKioskMode() const } //============================================================================== -void ComponentPeer::handleMouseEvent (const int touchIndex, const Point positionWithinPeer, - const ModifierKeys newMods, const int64 time) +void ComponentPeer::handleMouseEvent (int touchIndex, Point pos, ModifierKeys newMods, int64 time) { if (MouseInputSource* mouse = Desktop::getInstance().mouseSources->getOrCreateMouseInputSource (touchIndex)) - MouseInputSource (*mouse).handleEvent (*this, positionWithinPeer, time, newMods); + MouseInputSource (*mouse).handleEvent (*this, pos, time, newMods); } -void ComponentPeer::handleMouseWheel (const int touchIndex, const Point positionWithinPeer, - const int64 time, const MouseWheelDetails& wheel) +void ComponentPeer::handleMouseWheel (int touchIndex, Point pos, int64 time, const MouseWheelDetails& wheel) { if (MouseInputSource* mouse = Desktop::getInstance().mouseSources->getOrCreateMouseInputSource (touchIndex)) - MouseInputSource (*mouse).handleWheel (*this, positionWithinPeer, time, wheel); + MouseInputSource (*mouse).handleWheel (*this, pos, time, wheel); } -void ComponentPeer::handleMagnifyGesture (const int touchIndex, const Point positionWithinPeer, - const int64 time, const float scaleFactor) +void ComponentPeer::handleMagnifyGesture (int touchIndex, Point pos, int64 time, float scaleFactor) { if (MouseInputSource* mouse = Desktop::getInstance().mouseSources->getOrCreateMouseInputSource (touchIndex)) - MouseInputSource (*mouse).handleMagnifyGesture (*this, positionWithinPeer, time, scaleFactor); + MouseInputSource (*mouse).handleMagnifyGesture (*this, pos, time, scaleFactor); } //============================================================================== @@ -402,6 +399,9 @@ const Rectangle& ComponentPeer::getNonFullScreenBounds() const noexcept return lastNonFullscreenBounds; } +Point ComponentPeer::localToGlobal (Point p) { return localToGlobal (p.toFloat()).roundToInt(); } +Point ComponentPeer::globalToLocal (Point p) { return globalToLocal (p.toFloat()).roundToInt(); } + Rectangle ComponentPeer::localToGlobal (const Rectangle& relativePosition) { return relativePosition.withPosition (localToGlobal (relativePosition.getPosition())); diff --git a/modules/juce_gui_basics/windows/juce_ComponentPeer.h b/modules/juce_gui_basics/windows/juce_ComponentPeer.h index 4ffb7b0da7..930653d165 100644 --- a/modules/juce_gui_basics/windows/juce_ComponentPeer.h +++ b/modules/juce_gui_basics/windows/juce_ComponentPeer.h @@ -148,13 +148,19 @@ public: virtual Rectangle getBounds() const = 0; /** Converts a position relative to the top-left of this component to screen coordinates. */ - virtual Point localToGlobal (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 (Point screenPosition) = 0; + + /** Converts a position relative to the top-left of this component to screen coordinates. */ + Point localToGlobal (Point relativePosition); /** Converts a screen coordinate to a position relative to the top-left of this component. */ - virtual Point globalToLocal (Point screenPosition) = 0; + Point globalToLocal (Point screenPosition); + + /** Converts a rectangle relative to the top-left of this component to screen coordinates. */ + virtual Rectangle localToGlobal (const Rectangle& relativePosition); /** Converts a screen area to a position relative to the top-left of this component. */ virtual Rectangle globalToLocal (const Rectangle& screenPosition); @@ -300,9 +306,9 @@ public: virtual void setAlpha (float newAlpha) = 0; //============================================================================== - void handleMouseEvent (int touchIndex, const Point positionWithinPeer, const ModifierKeys newMods, int64 time); - void handleMouseWheel (int touchIndex, const Point positionWithinPeer, int64 time, const MouseWheelDetails&); - void handleMagnifyGesture (int touchIndex, const Point positionWithinPeer, int64 time, float scaleFactor); + void handleMouseEvent (int touchIndex, Point positionWithinPeer, ModifierKeys newMods, int64 time); + void handleMouseWheel (int touchIndex, Point positionWithinPeer, int64 time, const MouseWheelDetails&); + void handleMagnifyGesture (int touchIndex, Point positionWithinPeer, int64 time, float scaleFactor); void handleUserClosingWindow(); diff --git a/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp b/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp index cc1ff7aa84..fbd0686074 100644 --- a/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_TooltipWindow.cpp @@ -138,7 +138,7 @@ void TooltipWindow::timerCallback() mouseClicks = clickCount; mouseWheelMoves = wheelCount; - const Point mousePos (mouseSource.getScreenPosition()); + const Point mousePos (mouseSource.getScreenPosition()); const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12; lastMousePos = mousePos; @@ -159,7 +159,7 @@ void TooltipWindow::timerCallback() } else if (tipChanged) { - displayTip (mousePos, newTip); + displayTip (mousePos.roundToInt(), newTip); } } else @@ -170,7 +170,7 @@ void TooltipWindow::timerCallback() && newTip != tipShowing && now > lastCompChangeTime + (unsigned int) millisecondsBeforeTipAppears) { - displayTip (mousePos, newTip); + displayTip (mousePos.roundToInt(), newTip); } } } diff --git a/modules/juce_gui_basics/windows/juce_TooltipWindow.h b/modules/juce_gui_basics/windows/juce_TooltipWindow.h index e6515ee2f3..d32d997743 100644 --- a/modules/juce_gui_basics/windows/juce_TooltipWindow.h +++ b/modules/juce_gui_basics/windows/juce_TooltipWindow.h @@ -111,7 +111,7 @@ public: private: //============================================================================== int millisecondsBeforeTipAppears; - Point lastMousePos; + Point lastMousePos; int mouseClicks, mouseWheelMoves; unsigned int lastCompChangeTime, lastHideTime; Component* lastComponentUnderMouse; diff --git a/modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp b/modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp index 99c91777ef..fcf53a2264 100644 --- a/modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp +++ b/modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp @@ -99,21 +99,21 @@ public: if (isLeft || isRight) // Only mouse up is sent by the OS, so simulate a down/up { - owner.mouseDown (MouseEvent (mouseSource, Point(), + owner.mouseDown (MouseEvent (mouseSource, Point(), eventMods.withFlags (isLeft ? ModifierKeys::leftButtonModifier : ModifierKeys::rightButtonModifier), &owner, &owner, now, - Point(), now, 1, false)); + Point(), now, 1, false)); - owner.mouseUp (MouseEvent (mouseSource, Point(), eventMods.withoutMouseButtons(), + owner.mouseUp (MouseEvent (mouseSource, Point(), eventMods.withoutMouseButtons(), &owner, &owner, now, - Point(), now, 1, false)); + Point(), now, 1, false)); } else if (type == NSMouseMoved) { - owner.mouseMove (MouseEvent (mouseSource, Point(), eventMods, + owner.mouseMove (MouseEvent (mouseSource, Point(), eventMods, &owner, &owner, now, - Point(), now, 1, false)); + Point(), now, 1, false)); } } } diff --git a/modules/juce_gui_extra/native/juce_win32_ActiveXComponent.cpp b/modules/juce_gui_extra/native/juce_win32_ActiveXComponent.cpp index 4465b3b7b2..ffcd181279 100644 --- a/modules/juce_gui_extra/native/juce_win32_ActiveXComponent.cpp +++ b/modules/juce_gui_extra/native/juce_win32_ActiveXComponent.cpp @@ -187,7 +187,7 @@ namespace ActiveXHelpers case WM_MBUTTONUP: case WM_RBUTTONUP: peer->handleMouseEvent (0, Point (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left, - GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top), + GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top).toFloat(), ModifierKeys::getCurrentModifiersRealtime(), getMouseEventTime()); break; diff --git a/modules/juce_gui_extra/native/juce_win32_SystemTrayIcon.cpp b/modules/juce_gui_extra/native/juce_win32_SystemTrayIcon.cpp index 823bb0476f..1eef9d8054 100644 --- a/modules/juce_gui_extra/native/juce_win32_SystemTrayIcon.cpp +++ b/modules/juce_gui_extra/native/juce_win32_SystemTrayIcon.cpp @@ -111,8 +111,8 @@ public: const Time eventTime (getMouseEventTime()); const MouseEvent e (Desktop::getInstance().getMainMouseSource(), - Point(), eventMods, &owner, &owner, eventTime, - Point(), eventTime, 1, false); + Point(), eventMods, &owner, &owner, eventTime, + Point(), eventTime, 1, false); if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN) {