mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-09 04:30:09 +00:00
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<float> rather than Point<int>.
This commit is contained in:
parent
590cca9776
commit
6c61dbb68e
30 changed files with 348 additions and 276 deletions
|
|
@ -58,7 +58,7 @@ public:
|
|||
return lastPeer;
|
||||
}
|
||||
|
||||
static Point<int> screenPosToLocalPos (Component& comp, Point<int> pos)
|
||||
static Point<float> screenPosToLocalPos (Component& comp, Point<float> pos)
|
||||
{
|
||||
if (ComponentPeer* const peer = comp.getPeer())
|
||||
{
|
||||
|
|
@ -70,23 +70,25 @@ public:
|
|||
return comp.getLocalPoint (nullptr, ScalingHelpers::unscaledScreenPosToScaled (comp, pos));
|
||||
}
|
||||
|
||||
Component* findComponentAt (Point<int> screenPos)
|
||||
Component* findComponentAt (Point<float> screenPos)
|
||||
{
|
||||
if (ComponentPeer* const peer = getPeer())
|
||||
{
|
||||
Point<int> relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos)));
|
||||
Point<float> relativePos (ScalingHelpers::unscaledScreenPosToScaled (peer->getComponent(),
|
||||
peer->globalToLocal (screenPos)));
|
||||
Component& comp = peer->getComponent();
|
||||
|
||||
const Point<int> 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<int> getScreenPosition() const
|
||||
Point<float> 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<int> p)
|
||||
void setScreenPosition (Point<float> p)
|
||||
{
|
||||
MouseInputSource::setRawMousePosition (ScalingHelpers::scaledScreenPosToUnscaled (p));
|
||||
}
|
||||
|
|
@ -109,49 +111,49 @@ public:
|
|||
#define JUCE_MOUSE_EVENT_DBG(desc)
|
||||
#endif
|
||||
|
||||
void sendMouseEnter (Component& comp, Point<int> screenPos, Time time)
|
||||
void sendMouseEnter (Component& comp, Point<float> screenPos, Time time)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("enter")
|
||||
comp.internalMouseEnter (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
|
||||
}
|
||||
|
||||
void sendMouseExit (Component& comp, Point<int> screenPos, Time time)
|
||||
void sendMouseExit (Component& comp, Point<float> screenPos, Time time)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("exit")
|
||||
comp.internalMouseExit (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
|
||||
}
|
||||
|
||||
void sendMouseMove (Component& comp, Point<int> screenPos, Time time)
|
||||
void sendMouseMove (Component& comp, Point<float> screenPos, Time time)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("move")
|
||||
comp.internalMouseMove (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
|
||||
}
|
||||
|
||||
void sendMouseDown (Component& comp, Point<int> screenPos, Time time)
|
||||
void sendMouseDown (Component& comp, Point<float> screenPos, Time time)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("down")
|
||||
comp.internalMouseDown (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
|
||||
}
|
||||
|
||||
void sendMouseDrag (Component& comp, Point<int> screenPos, Time time)
|
||||
void sendMouseDrag (Component& comp, Point<float> screenPos, Time time)
|
||||
{
|
||||
JUCE_MOUSE_EVENT_DBG ("drag")
|
||||
comp.internalMouseDrag (MouseInputSource (this), screenPosToLocalPos (comp, screenPos), time);
|
||||
}
|
||||
|
||||
void sendMouseUp (Component& comp, Point<int> screenPos, Time time, const ModifierKeys oldMods)
|
||||
void sendMouseUp (Component& comp, Point<float> 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<int> screenPos, Time time, const MouseWheelDetails& wheel)
|
||||
void sendMouseWheel (Component& comp, Point<float> 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<int> screenPos, Time time, const float amount)
|
||||
void sendMagnifyGesture (Component& comp, Point<float> 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<int> screenPos, Time time, const ModifierKeys newButtonState)
|
||||
bool setButtons (Point<float> 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<int> screenPos, Time time)
|
||||
void setComponentUnderMouse (Component* const newComponent, Point<float> screenPos, Time time)
|
||||
{
|
||||
Component* current = getComponentUnderMouse();
|
||||
|
||||
|
|
@ -242,7 +244,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void setPeer (ComponentPeer& newPeer, Point<int> screenPos, Time time)
|
||||
void setPeer (ComponentPeer& newPeer, Point<float> screenPos, Time time)
|
||||
{
|
||||
ModifierKeys::updateCurrentModifiers();
|
||||
|
||||
|
|
@ -254,7 +256,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void setScreenPos (Point<int> newScreenPos, Time time, const bool forceUpdate)
|
||||
void setScreenPos (Point<float> newScreenPos, Time time, const bool forceUpdate)
|
||||
{
|
||||
if (! isDragging())
|
||||
setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
|
||||
|
|
@ -285,11 +287,11 @@ public:
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void handleEvent (ComponentPeer& newPeer, Point<int> positionWithinPeer, Time time, const ModifierKeys newMods)
|
||||
void handleEvent (ComponentPeer& newPeer, Point<float> positionWithinPeer, Time time, const ModifierKeys newMods)
|
||||
{
|
||||
lastTime = time;
|
||||
++mouseEventCounter;
|
||||
const Point<int> screenPos (newPeer.localToGlobal (positionWithinPeer));
|
||||
const Point<float> screenPos (newPeer.localToGlobal (positionWithinPeer));
|
||||
|
||||
if (isDragging() && newMods.isAnyMouseButtonDown())
|
||||
{
|
||||
|
|
@ -311,8 +313,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
Component* getTargetForGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
Time time, Point<int>& screenPos)
|
||||
Component* getTargetForGesture (ComponentPeer& peer, Point<float> positionWithinPeer,
|
||||
Time time, Point<float>& screenPos)
|
||||
{
|
||||
lastTime = time;
|
||||
++mouseEventCounter;
|
||||
|
|
@ -325,27 +327,27 @@ public:
|
|||
return isDragging() ? nullptr : getComponentUnderMouse();
|
||||
}
|
||||
|
||||
void handleWheel (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
void handleWheel (ComponentPeer& peer, Point<float> positionWithinPeer,
|
||||
Time time, const MouseWheelDetails& wheel)
|
||||
{
|
||||
Desktop::getInstance().incrementMouseWheelCounter();
|
||||
|
||||
Point<int> screenPos;
|
||||
Point<float> screenPos;
|
||||
if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos))
|
||||
sendMouseWheel (*current, screenPos, time, wheel);
|
||||
}
|
||||
|
||||
void handleMagnifyGesture (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
void handleMagnifyGesture (ComponentPeer& peer, Point<float> positionWithinPeer,
|
||||
Time time, const float scaleFactor)
|
||||
{
|
||||
Point<int> screenPos;
|
||||
Point<float> screenPos;
|
||||
if (Component* current = getTargetForGesture (peer, positionWithinPeer, time, screenPos))
|
||||
sendMagnifyGesture (*current, screenPos, time, scaleFactor);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
Time getLastMouseDownTime() const noexcept { return mouseDowns[0].time; }
|
||||
Point<int> getLastMouseDownPosition() const noexcept { return ScalingHelpers::unscaledScreenPosToScaled (mouseDowns[0].position); }
|
||||
Point<float> 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<int>();
|
||||
unboundedMouseOffset = Point<float>();
|
||||
|
||||
revealCursor (true);
|
||||
}
|
||||
|
|
@ -410,20 +411,20 @@ public:
|
|||
|
||||
void handleUnboundedDrag (Component* current)
|
||||
{
|
||||
const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
|
||||
const Rectangle<float> screenArea (current->getParentMonitorArea().expanded (-2, -2).toFloat());
|
||||
|
||||
if (! screenArea.contains (lastScreenPos))
|
||||
{
|
||||
const Point<int> componentCentre (current->getScreenBounds().getCentre());
|
||||
const Point<float> 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<int>();
|
||||
setScreenPosition (lastScreenPos + unboundedMouseOffset);
|
||||
unboundedMouseOffset = Point<float>();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -461,10 +462,10 @@ public:
|
|||
//==============================================================================
|
||||
const int index;
|
||||
const bool isMouseDevice;
|
||||
Point<int> lastScreenPos;
|
||||
Point<float> lastScreenPos;
|
||||
ModifierKeys buttonState;
|
||||
|
||||
Point<int> unboundedMouseOffset;
|
||||
Point<float> unboundedMouseOffset;
|
||||
bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
|
||||
|
||||
private:
|
||||
|
|
@ -478,7 +479,7 @@ private:
|
|||
{
|
||||
RecentMouseDown() noexcept : peerID (0) {}
|
||||
|
||||
Point<int> position;
|
||||
Point<float> position;
|
||||
Time time;
|
||||
ModifierKeys buttons;
|
||||
uint32 peerID;
|
||||
|
|
@ -497,7 +498,7 @@ private:
|
|||
Time lastTime;
|
||||
bool mouseMovedSignificantlySincePressed;
|
||||
|
||||
void registerMouseDown (Point<int> screenPos, Time time,
|
||||
void registerMouseDown (Point<float> 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<int> screenPos) noexcept
|
||||
void registerMouseDrag (Point<float> 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<int> 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<int> 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<float> 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<float> 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<int> p) { pimpl->setScreenPosition (p); }
|
||||
{ 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<float> p) { pimpl->setScreenPosition (p); }
|
||||
|
||||
void MouseInputSource::handleEvent (ComponentPeer& peer, Point<int> positionWithinPeer,
|
||||
const int64 time, const ModifierKeys mods)
|
||||
void MouseInputSource::handleEvent (ComponentPeer& peer, Point<float> 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<int> positionWithinPeer,
|
||||
const int64 time, const MouseWheelDetails& wheel)
|
||||
void MouseInputSource::handleWheel (ComponentPeer& peer, Point<float> 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<int> positionWithinPeer,
|
||||
const int64 time, const float scaleFactor)
|
||||
void MouseInputSource::handleMagnifyGesture (ComponentPeer& peer, Point<float> pos, int64 time, float scaleFactor)
|
||||
{
|
||||
pimpl->handleMagnifyGesture (peer, positionWithinPeer, Time (time), scaleFactor);
|
||||
pimpl->handleMagnifyGesture (peer, pos, Time (time), scaleFactor);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue