Browse Source

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>.

tags/2021-05-28
jules 11 years ago
parent
commit
6c61dbb68e
30 changed files with 349 additions and 277 deletions
  1. +2
    -2
      extras/Demo/Source/Demos/MultiTouch.cpp
  2. +1
    -1
      modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h
  3. +1
    -1
      modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp
  4. +30
    -11
      modules/juce_gui_basics/components/juce_Component.cpp
  5. +25
    -11
      modules/juce_gui_basics/components/juce_Component.h
  6. +12
    -7
      modules/juce_gui_basics/components/juce_Desktop.cpp
  7. +3
    -1
      modules/juce_gui_basics/components/juce_Desktop.h
  8. +2
    -2
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp
  9. +1
    -1
      modules/juce_gui_basics/mouse/juce_ComponentDragger.cpp
  10. +1
    -1
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp
  11. +22
    -14
      modules/juce_gui_basics/mouse/juce_MouseEvent.cpp
  12. +25
    -9
      modules/juce_gui_basics/mouse/juce_MouseEvent.h
  13. +72
    -74
      modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp
  14. +8
    -8
      modules/juce_gui_basics/mouse/juce_MouseInputSource.h
  15. +11
    -11
      modules/juce_gui_basics/native/juce_android_Windowing.cpp
  16. +10
    -10
      modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm
  17. +2
    -2
      modules/juce_gui_basics/native/juce_ios_Windowing.mm
  18. +10
    -10
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp
  19. +8
    -8
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm
  20. +3
    -3
      modules/juce_gui_basics/native/juce_mac_Windowing.mm
  21. +34
    -31
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp
  22. +29
    -28
      modules/juce_gui_basics/widgets/juce_Slider.cpp
  23. +2
    -2
      modules/juce_gui_basics/widgets/juce_TreeView.cpp
  24. +9
    -9
      modules/juce_gui_basics/windows/juce_ComponentPeer.cpp
  25. +13
    -7
      modules/juce_gui_basics/windows/juce_ComponentPeer.h
  26. +3
    -3
      modules/juce_gui_basics/windows/juce_TooltipWindow.cpp
  27. +1
    -1
      modules/juce_gui_basics/windows/juce_TooltipWindow.h
  28. +6
    -6
      modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp
  29. +1
    -1
      modules/juce_gui_extra/native/juce_win32_ActiveXComponent.cpp
  30. +2
    -2
      modules/juce_gui_extra/native/juce_win32_SystemTrayIcon.cpp

+ 2
- 2
extras/Demo/Source/Demos/MultiTouch.cpp View File

@@ -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();
}


+ 1
- 1
modules/juce_audio_plugin_client/utility/juce_FakeMouseMoveGenerator.h View File

@@ -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());
}
}


+ 1
- 1
modules/juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp View File

@@ -816,7 +816,7 @@ void MidiKeyboardComponent::timerCallback()
const Array<MouseInputSource>& 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());
}
}


+ 30
- 11
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -239,6 +239,15 @@ struct ScalingHelpers
{
return scaledScreenPosToUnscaled (comp.getDesktopScaleFactor(), pos);
}
static Point<int> addPosition (Point<int> p, const Component& c) noexcept { return p + c.getPosition(); }
static Rectangle<int> addPosition (Rectangle<int> p, const Component& c) noexcept { return p + c.getPosition(); }
static Point<float> addPosition (Point<float> p, const Component& c) noexcept { return p + c.getPosition().toFloat(); }
static Rectangle<float> addPosition (Rectangle<float> p, const Component& c) noexcept { return p + c.getPosition().toFloat(); }
static Point<int> subtractPosition (Point<int> p, const Component& c) noexcept { return p - c.getPosition(); }
static Rectangle<int> subtractPosition (Rectangle<int> p, const Component& c) noexcept { return p - c.getPosition(); }
static Point<float> subtractPosition (Point<float> p, const Component& c) noexcept { return p - c.getPosition().toFloat(); }
static Rectangle<float> subtractPosition (Rectangle<float> 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<int> Component::getLocalPoint (const Component* source, Point<int> point)
return ComponentHelpers::convertCoordinate (this, source, point);
}
Point<float> Component::getLocalPoint (const Component* source, Point<float> point) const
{
return ComponentHelpers::convertCoordinate (this, source, point);
}
Rectangle<int> Component::getLocalArea (const Component* source, const Rectangle<int>& area) const
{
return ComponentHelpers::convertCoordinate (this, source, area);
@@ -1096,6 +1110,11 @@ Point<int> Component::localPointToGlobal (Point<int> point) const
return ComponentHelpers::convertCoordinate (nullptr, this, point);
}
Point<float> Component::localPointToGlobal (Point<float> point) const
{
return ComponentHelpers::convertCoordinate (nullptr, this, point);
}
Rectangle<int> Component::localAreaToGlobal (const Rectangle<int>& area) const
{
return ComponentHelpers::convertCoordinate (nullptr, this, area);
@@ -2386,7 +2405,7 @@ void Component::removeMouseListener (MouseListener* const listenerToRemove)
}
//==============================================================================
void Component::internalMouseEnter (MouseInputSource source, Point<int> relativePos, Time time)
void Component::internalMouseEnter (MouseInputSource source, Point<float> relativePos, Time time)
{
if (isCurrentlyBlockedByAnotherModalComponent())
{
@@ -2412,7 +2431,7 @@ void Component::internalMouseEnter (MouseInputSource source, Point<int> relative
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseEnter, me);
}
void Component::internalMouseExit (MouseInputSource source, Point<int> relativePos, Time time)
void Component::internalMouseExit (MouseInputSource source, Point<float> relativePos, Time time)
{
if (flags.repaintOnMouseActivityFlag)
repaint();
@@ -2432,7 +2451,7 @@ void Component::internalMouseExit (MouseInputSource source, Point<int> relativeP
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseExit, me);
}
void Component::internalMouseDown (MouseInputSource source, Point<int> relativePos, Time time)
void Component::internalMouseDown (MouseInputSource source, Point<float> relativePos, Time time)
{
Desktop& desktop = Desktop::getInstance();
BailOutChecker checker (this);
@@ -2496,7 +2515,7 @@ void Component::internalMouseDown (MouseInputSource source, Point<int> relativeP
MouseListenerList::sendMouseEvent (*this, checker, &MouseListener::mouseDown, me);
}
void Component::internalMouseUp (MouseInputSource source, Point<int> relativePos,
void Component::internalMouseUp (MouseInputSource source, Point<float> relativePos,
Time time, const ModifierKeys oldModifiers)
{
if (flags.mouseDownWasBlocked && isCurrentlyBlockedByAnotherModalComponent())
@@ -2539,7 +2558,7 @@ void Component::internalMouseUp (MouseInputSource source, Point<int> relativePos
}
}
void Component::internalMouseDrag (MouseInputSource source, Point<int> relativePos, Time time)
void Component::internalMouseDrag (MouseInputSource source, Point<float> relativePos, Time time)
{
if (! isCurrentlyBlockedByAnotherModalComponent())
{
@@ -2562,7 +2581,7 @@ void Component::internalMouseDrag (MouseInputSource source, Point<int> relativeP
}
}
void Component::internalMouseMove (MouseInputSource source, Point<int> relativePos, Time time)
void Component::internalMouseMove (MouseInputSource source, Point<float> relativePos, Time time)
{
Desktop& desktop = Desktop::getInstance();
@@ -2588,7 +2607,7 @@ void Component::internalMouseMove (MouseInputSource source, Point<int> relativeP
}
}
void Component::internalMouseWheel (MouseInputSource source, Point<int> relativePos,
void Component::internalMouseWheel (MouseInputSource source, Point<float> relativePos,
Time time, const MouseWheelDetails& wheel)
{
Desktop& desktop = Desktop::getInstance();
@@ -2616,7 +2635,7 @@ void Component::internalMouseWheel (MouseInputSource source, Point<int> relative
}
}
void Component::internalMagnifyGesture (MouseInputSource source, Point<int> relativePos,
void Component::internalMagnifyGesture (MouseInputSource source, Point<float> 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;
}


+ 25
- 11
modules/juce_gui_basics/components/juce_Component.h View File

@@ -355,6 +355,15 @@ public:
Point<int> getLocalPoint (const Component* sourceComponent,
Point<int> 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<float> getLocalPoint (const Component* sourceComponent,
Point<float> 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<int> localPointToGlobal (Point<int> localPoint) const;
/** Converts a point relative to this component's top-left into a screen coordinate.
@see getLocalPoint, localAreaToGlobal
*/
Point<float> localPointToGlobal (Point<float> 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<int>, Time);
void internalMouseExit (MouseInputSource, Point<int>, Time);
void internalMouseDown (MouseInputSource, Point<int>, Time);
void internalMouseUp (MouseInputSource, Point<int>, Time, const ModifierKeys oldModifiers);
void internalMouseDrag (MouseInputSource, Point<int>, Time);
void internalMouseMove (MouseInputSource, Point<int>, Time);
void internalMouseWheel (MouseInputSource, Point<int>, Time, const MouseWheelDetails&);
void internalMagnifyGesture (MouseInputSource, Point<int>, Time, float);
void internalMouseEnter (MouseInputSource, Point<float>, Time);
void internalMouseExit (MouseInputSource, Point<float>, Time);
void internalMouseDown (MouseInputSource, Point<float>, Time);
void internalMouseUp (MouseInputSource, Point<float>, Time, const ModifierKeys oldModifiers);
void internalMouseDrag (MouseInputSource, Point<float>, Time);
void internalMouseMove (MouseInputSource, Point<float>, Time);
void internalMouseWheel (MouseInputSource, Point<float>, Time, const MouseWheelDetails&);
void internalMagnifyGesture (MouseInputSource, Point<float>, Time, float);
void internalBroughtToFront();
void internalFocusGain (const FocusChangeType, const WeakReference<Component>&);
void internalFocusGain (const FocusChangeType);
void internalFocusLoss (const FocusChangeType);
void internalFocusGain (FocusChangeType, const WeakReference<Component>&);
void internalFocusGain (FocusChangeType);
void internalFocusLoss (FocusChangeType);
void internalChildFocusChange (FocusChangeType, const WeakReference<Component>&);
void internalModalInputAttempt();
void internalModifierKeysChanged();


+ 12
- 7
modules/juce_gui_basics/components/juce_Desktop.cpp View File

@@ -148,18 +148,23 @@ void Desktop::componentBroughtToFront (Component* const c)
//==============================================================================
Point<int> Desktop::getMousePosition()
{
return getMousePositionFloat().roundToInt();
}
Point<float> Desktop::getMousePositionFloat()
{
return getInstance().getMainMouseSource().getScreenPosition();
}
void Desktop::setMousePosition (Point<int> newPosition)
{
getInstance().getMainMouseSource().setScreenPosition (newPosition);
getInstance().getMainMouseSource().setScreenPosition (newPosition.toFloat());
}
Point<int> 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<MouseListener>& 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<int> pos (target->getLocalPoint (nullptr, lastFakeMouseMove));
const Point<float> pos (target->getLocalPoint (nullptr, lastFakeMouseMove));
const Time now (Time::getCurrentTime());
const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),


+ 3
- 1
modules/juce_gui_basics/components/juce_Desktop.h View File

@@ -414,7 +414,7 @@ private:
ScopedPointer<Displays> displays;
Point<int> lastFakeMouseMove;
Point<float> lastFakeMouseMove;
void sendMouseMove();
int mouseClickCounter, mouseWheelCounter;
@@ -446,6 +446,8 @@ private:
void triggerFocusCallback();
void handleAsyncUpdate() override;
static Point<float> getMousePositionFloat();
static double getDefaultMasterScale();
Desktop();


+ 2
- 2
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -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;


+ 1
- 1
modules/juce_gui_basics/mouse/juce_ComponentDragger.cpp View File

@@ -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;


+ 1
- 1
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp View File

@@ -353,7 +353,7 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
return;
}
const Point<int> lastMouseDown (draggingSource->getLastMouseDownPosition());
const Point<int> lastMouseDown (draggingSource->getLastMouseDownPosition().roundToInt());
Point<int> imageOffset;
if (dragImage.isNull())


+ 22
- 14
modules/juce_gui_basics/mouse/juce_MouseEvent.cpp View File

@@ -23,17 +23,18 @@
*/
MouseEvent::MouseEvent (MouseInputSource inputSource,
Point<int> position,
Point<float> pos,
ModifierKeys modKeys,
Component* const eventComp,
Component* const originator,
Time time,
Point<int> downPos,
Point<float> 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<int> newPosition) const noexcept
MouseEvent MouseEvent::withNewPosition (Point<float> newPosition) const noexcept
{
return MouseEvent (source, newPosition, mods, eventComponent, originalComponent,
eventTime, mouseDownPos, mouseDownTime,
numberOfClicks, wasMovedSinceMouseDown != 0);
}
MouseEvent MouseEvent::withNewPosition (Point<int> 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<int> MouseEvent::getPosition() const noexcept { return Point<int> (x, y); }
Point<int> MouseEvent::getScreenPosition() const { return eventComponent->localPointToGlobal (getPosition()); }
Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos; }
Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos); }
Point<int> MouseEvent::getMouseDownPosition() const noexcept { return mouseDownPos.roundToInt(); }
Point<int> MouseEvent::getMouseDownScreenPosition() const { return eventComponent->localPointToGlobal (mouseDownPos).roundToInt(); }
Point<int> MouseEvent::getOffsetFromDragStart() const noexcept { return getPosition() - mouseDownPos; }
int MouseEvent::getDistanceFromDragStart() const noexcept { return mouseDownPos.getDistanceFrom (getPosition()); }
Point<int> 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; }


+ 25
- 9
modules/juce_gui_basics/mouse/juce_MouseEvent.h View File

@@ -57,12 +57,12 @@ public:
@param mouseWasDragged whether the mouse has been dragged significantly since the previous mouse-down
*/
MouseEvent (MouseInputSource source,
Point<int> position,
Point<float> position,
ModifierKeys modifiers,
Component* eventComponent,
Component* originator,
Time eventTime,
Point<int> mouseDownPos,
Point<float> 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<float> 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<int> 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<int> 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<float> 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<int> mouseDownPos;
const Point<float> mouseDownPos;
const uint8 numberOfClicks, wasMovedSinceMouseDown;
MouseEvent& operator= (const MouseEvent&);


+ 72
- 74
modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp View File

@@ -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); }
void MouseInputSource::handleEvent (ComponentPeer& peer, Point<int> 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<float> p) { pimpl->setScreenPosition (p); }
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);
}
//==============================================================================


+ 8
- 8
modules/juce_gui_basics/mouse/juce_MouseInputSource.h View File

@@ -88,7 +88,7 @@ public:
bool isDragging() const;
/** Returns the last-known screen position of this source. */
Point<int> getScreenPosition() const;
Point<float> 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<int> getLastMouseDownPosition() const noexcept;
Point<float> 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<int> newPosition);
void setScreenPosition (Point<float> newPosition);
private:
//==============================================================================
@@ -174,12 +174,12 @@ private:
struct SourceList;
explicit MouseInputSource (MouseInputSourceInternal*) noexcept;
void handleEvent (ComponentPeer&, Point<int>, int64 time, const ModifierKeys);
void handleWheel (ComponentPeer&, Point<int>, int64 time, const MouseWheelDetails&);
void handleMagnifyGesture (ComponentPeer&, Point<int>, int64 time, float scaleFactor);
void handleEvent (ComponentPeer&, Point<float>, int64 time, ModifierKeys);
void handleWheel (ComponentPeer&, Point<float>, int64 time, const MouseWheelDetails&);
void handleMagnifyGesture (ComponentPeer&, Point<float>, int64 time, float scaleFactor);
static Point<int> getCurrentRawMousePosition();
static void setRawMousePosition (Point<int>);
static Point<float> getCurrentRawMousePosition();
static void setRawMousePosition (Point<float>);
JUCE_LEAK_DETECTOR (MouseInputSource)
};


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

@@ -234,14 +234,14 @@ public:
view.callIntMethod (ComponentPeerView.getTop));
}
Point<int> localToGlobal (Point<int> relativePosition) override
Point<float> localToGlobal (Point<float> relativePosition) override
{
return relativePosition + getScreenPosition();
return relativePosition + getScreenPosition().toFloat();
}
Point<int> globalToLocal (Point<int> screenPosition) override
Point<float> globalToLocal (Point<float> 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<float> 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<int> MouseInputSource::getCurrentRawMousePosition()
Point<float> MouseInputSource::getCurrentRawMousePosition()
{
return AndroidComponentPeer::lastMousePos.toInt();
return AndroidComponentPeer::lastMousePos;
}
void MouseInputSource::setRawMousePosition (Point<int>)
void MouseInputSource::setRawMousePosition (Point<float>)
{
// not needed
}


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

@@ -145,8 +145,8 @@ public:
Rectangle<int> getBounds() const override { return getBounds (! isSharedWindow); }
Rectangle<int> getBounds (bool global) const;
Point<int> localToGlobal (Point<int> relativePosition) override;
Point<int> globalToLocal (Point<int> screenPosition) override;
Point<float> localToGlobal (Point<float> relativePosition) override;
Point<float> globalToLocal (Point<float> 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<int> juce_lastMousePos;
Point<float> juce_lastMousePos;
//==============================================================================
UIViewComponentPeer::UIViewComponentPeer (Component& comp, const int windowStyleFlags, UIView* viewToAttachTo)
@@ -603,14 +603,14 @@ Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
return convertToRectInt (r);
}
Point<int> UIViewComponentPeer::localToGlobal (Point<int> relativePosition)
Point<float> UIViewComponentPeer::localToGlobal (Point<float> relativePosition)
{
return relativePosition + getBounds (true).getPosition();
return relativePosition + getBounds (true).getPosition().toFloat();
}
Point<int> UIViewComponentPeer::globalToLocal (Point<int> screenPosition)
Point<float> UIViewComponentPeer::globalToLocal (Point<float> 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<int> pos ((int) p.x, (int) p.y);
juce_lastMousePos = pos + getBounds (true).getPosition();
const Point<float> 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<int> (-1, -1), modsToSend, time);
handleMouseEvent (touchIndex, Point<float> (-1.0f, -1.0f), modsToSend, time);
if (! isValidPeer (this))
return;
}


+ 2
- 2
modules/juce_gui_basics/native/juce_ios_Windowing.mm View File

@@ -312,12 +312,12 @@ bool Desktop::canUseSemiTransparentWindows() noexcept
return true;
}
Point<int> MouseInputSource::getCurrentRawMousePosition()
Point<float> MouseInputSource::getCurrentRawMousePosition()
{
return juce_lastMousePos;
}
void MouseInputSource::setRawMousePosition (Point<int>)
void MouseInputSource::setRawMousePosition (Point<float>)
{
}


+ 10
- 10
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -971,14 +971,14 @@ public:
Rectangle<int> getBounds() const override { return bounds; }
Point<int> localToGlobal (Point<int> relativePosition) override
Point<float> localToGlobal (Point<float> relativePosition) override
{
return relativePosition + bounds.getPosition();
return relativePosition + bounds.getPosition().toFloat();
}
Point<int> globalToLocal (Point<int> screenPosition) override
Point<float> globalToLocal (Point<float> screenPosition) override
{
return screenPosition - bounds.getPosition();
return screenPosition - bounds.getPosition().toFloat();
}
void setAlpha (float /* newAlpha */) override
@@ -1491,9 +1491,9 @@ public:
}
template <typename EventType>
static Point<int> getMousePos (const EventType& e) noexcept
static Point<float> getMousePos (const EventType& e) noexcept
{
return Point<int> (e.x, e.y);
return Point<float> ((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<int> MouseInputSource::getCurrentRawMousePosition()
Point<float> MouseInputSource::getCurrentRawMousePosition()
{
Window root, child;
int x, y, winx, winy;
@@ -3140,14 +3140,14 @@ Point<int> MouseInputSource::getCurrentRawMousePosition()
x = y = -1;
}
return Point<int> (x, y);
return Point<float> ((float) x, (float) y);
}
void MouseInputSource::setRawMousePosition (Point<int> newPosition)
void MouseInputSource::setRawMousePosition (Point<float> 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()


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

@@ -295,14 +295,14 @@ public:
return getBounds (! isSharedWindow);
}
Point<int> localToGlobal (Point<int> relativePosition) override
Point<float> localToGlobal (Point<float> relativePosition) override
{
return relativePosition + getBounds (true).getPosition();
return relativePosition + getBounds (true).getPosition().toFloat();
}
Point<int> globalToLocal (Point<int> screenPosition) override
Point<float> globalToLocal (Point<float> 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<int> (-1, -1), currentModifiers, getMouseTime (ev));
handleMouseEvent (0, Point<float> (-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<int> getMousePos (NSEvent* e, NSView* view)
static Point<float> getMousePos (NSEvent* e, NSView* view)
{
NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
return Point<int> ((int) p.x, (int) ([view frame].size.height - p.y));
return Point<float> (p.x, [view frame].size.height - p.y);
}
static int getModifierForButtonNumber (const NSInteger num)


+ 3
- 3
modules/juce_gui_basics/native/juce_mac_Windowing.mm View File

@@ -209,16 +209,16 @@ bool Desktop::canUseSemiTransparentWindows() noexcept
return true;
}
Point<int> MouseInputSource::getCurrentRawMousePosition()
Point<float> MouseInputSource::getCurrentRawMousePosition()
{
JUCE_AUTORELEASEPOOL
{
const NSPoint p ([NSEvent mouseLocation]);
return Point<int> (roundToInt (p.x), roundToInt (getMainScreenHeight() - p.y));
return Point<float> (p.x, getMainScreenHeight() - p.y);
}
}
void MouseInputSource::setRawMousePosition (Point<int> newPosition)
void MouseInputSource::setRawMousePosition (Point<float> newPosition)
{
// this rubbish needs to be done around the warp call, to avoid causing a
// bizarre glitch..


+ 34
- 31
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -704,8 +704,8 @@ public:
r.top + windowBorder.getTop());
}
Point<int> localToGlobal (Point<int> relativePosition) override { return relativePosition + getScreenPosition(); }
Point<int> globalToLocal (Point<int> screenPosition) override { return screenPosition - getScreenPosition(); }
Point<float> localToGlobal (Point<float> relativePosition) override { return relativePosition + getScreenPosition().toFloat(); }
Point<float> globalToLocal (Point<float> 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<int> getMousePos (const POINTL& mousePos) const
Point<float> getMousePos (const POINTL& mousePos) const
{
return owner.globalToLocal (Point<int> (mousePos.x, mousePos.y));
return owner.globalToLocal (Point<float> (static_cast<float> (mousePos.x),
static_cast<float> (mousePos.y)));
}
template <typename CharType>
@@ -1648,7 +1649,7 @@ private:
}
//==============================================================================
void doMouseEvent (Point<int> position)
void doMouseEvent (Point<float> 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<int> position)
void doMouseMove (Point<float> 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<int> position, const WPARAM wParam)
void doMouseDown (Point<float> position, const WPARAM wParam)
{
if (GetCapture() != hwnd)
SetCapture (hwnd);
@@ -1748,7 +1749,7 @@ private:
doMouseEvent (position);
}
void doMouseUp (Point<int> position, const WPARAM wParam)
void doMouseUp (Point<float> position, const WPARAM wParam)
{
updateModifiersFromWParam (wParam);
const bool wasDragging = isDragging;
@@ -1784,9 +1785,9 @@ private:
doMouseEvent (getCurrentMousePos());
}
ComponentPeer* findPeerUnderMouse (Point<int>& localPos)
ComponentPeer* findPeerUnderMouse (Point<float>& localPos)
{
const Point<int> globalPos (getCurrentMousePosGlobal());
const Point<int> 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<int> localPos;
Point<float> 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<int> localPos;
Point<float> 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<int> pos (globalToLocal (Point<int> ((int) TOUCH_COORD_TO_PIXEL (touch.x),
(int) TOUCH_COORD_TO_PIXEL (touch.y))));
const Point<float> pos (globalToLocal (Point<float> (static_cast<float> (TOUCH_COORD_TO_PIXEL (touch.x)),
static_cast<float> (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<int> (-10, -10), currentModifiers, time);
handleMouseEvent (touchIndex, Point<float> (-10.0f, -10.0f), currentModifiers, time);
if (! isValidPeer (this))
return false;
}
@@ -2326,17 +2327,18 @@ private:
return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
}
static Point<int> getPointFromLParam (LPARAM lParam) noexcept
static Point<float> getPointFromLParam (LPARAM lParam) noexcept
{
return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
return Point<float> (static_cast<float> (GET_X_LPARAM (lParam)),
static_cast<float> (GET_Y_LPARAM (lParam)));
}
static Point<int> getCurrentMousePosGlobal() noexcept
static Point<float> getCurrentMousePosGlobal() noexcept
{
return getPointFromLParam (GetMessagePos());
}
Point<int> getCurrentMousePos() noexcept
Point<float> getCurrentMousePos() noexcept
{
return globalToLocal (getCurrentMousePosGlobal());
}
@@ -2417,8 +2419,8 @@ private:
case WM_WINDOWPOSCHANGED:
{
const Point<int> pos (getCurrentMousePos());
if (contains (pos, false))
const Point<float> pos (getCurrentMousePos());
if (contains (pos.roundToInt(), false))
doMouseEvent (pos);
}
@@ -3131,16 +3133,17 @@ bool MouseInputSource::SourceList::addSource()
return false;
}
Point<int> MouseInputSource::getCurrentRawMousePosition()
Point<float> MouseInputSource::getCurrentRawMousePosition()
{
POINT mousePos;
GetCursorPos (&mousePos);
return Point<int> (mousePos.x, mousePos.y);
return Point<float> ((float) mousePos.x, (float) mousePos.y);
}
void MouseInputSource::setRawMousePosition (Point<int> newPosition)
void MouseInputSource::setRawMousePosition (Point<float> newPosition)
{
SetCursorPos (newPosition.x, newPosition.y);
SetCursorPos (roundToInt (newPosition.x),
roundToInt (newPosition.y));
}
//==============================================================================


+ 29
- 28
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -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<int> mousePos;
Point<float> 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<int> (-delta, 0);
else if (style == RotaryVerticalDrag) mousePos += Point<int> (0, delta);
else mousePos += Point<int> (delta / -2, delta / 2);
if (style == RotaryHorizontalDrag) mousePos += Point<float> (-delta, 0.0f);
else if (style == RotaryVerticalDrag) mousePos += Point<float> (0.0f, delta);
else mousePos += Point<float> (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<int> (isHorizontal() ? pixelPos : (owner.getWidth() / 2),
isVertical() ? pixelPos : (owner.getHeight() / 2)));
mousePos = owner.localPointToGlobal (Point<float> (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<int> mouseDragStartPos, mousePosWhenLastDragged;
Point<float> mouseDragStartPos, mousePosWhenLastDragged;
int sliderRegionStart, sliderRegionSize;
int sliderBeingDragged;
int pixelsForFullDragExtent;


+ 2
- 2
modules/juce_gui_basics/widgets/juce_TreeView.cpp View File

@@ -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<int> 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()));
}
}


+ 9
- 9
modules/juce_gui_basics/windows/juce_ComponentPeer.cpp View File

@@ -85,25 +85,22 @@ bool ComponentPeer::isKioskMode() const
}
//==============================================================================
void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int> positionWithinPeer,
const ModifierKeys newMods, const int64 time)
void ComponentPeer::handleMouseEvent (int touchIndex, Point<float> 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<int> positionWithinPeer,
const int64 time, const MouseWheelDetails& wheel)
void ComponentPeer::handleMouseWheel (int touchIndex, Point<float> 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<int> positionWithinPeer,
const int64 time, const float scaleFactor)
void ComponentPeer::handleMagnifyGesture (int touchIndex, Point<float> 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<int>& ComponentPeer::getNonFullScreenBounds() const noexcept
return lastNonFullscreenBounds;
}
Point<int> ComponentPeer::localToGlobal (Point<int> p) { return localToGlobal (p.toFloat()).roundToInt(); }
Point<int> ComponentPeer::globalToLocal (Point<int> p) { return globalToLocal (p.toFloat()).roundToInt(); }
Rectangle<int> ComponentPeer::localToGlobal (const Rectangle<int>& relativePosition)
{
return relativePosition.withPosition (localToGlobal (relativePosition.getPosition()));


+ 13
- 7
modules/juce_gui_basics/windows/juce_ComponentPeer.h View File

@@ -148,13 +148,19 @@ public:
virtual Rectangle<int> getBounds() const = 0;
/** Converts a position relative to the top-left of this component to screen coordinates. */
virtual Point<int> localToGlobal (Point<int> relativePosition) = 0;
virtual Point<float> localToGlobal (Point<float> relativePosition) = 0;
/** Converts a rectangle relative to the top-left of this component to screen coordinates. */
virtual Rectangle<int> localToGlobal (const Rectangle<int>& relativePosition);
/** Converts a screen coordinate to a position relative to the top-left of this component. */
virtual Point<float> globalToLocal (Point<float> screenPosition) = 0;
/** Converts a position relative to the top-left of this component to screen coordinates. */
Point<int> localToGlobal (Point<int> relativePosition);
/** Converts a screen coordinate to a position relative to the top-left of this component. */
virtual Point<int> globalToLocal (Point<int> screenPosition) = 0;
Point<int> globalToLocal (Point<int> screenPosition);
/** Converts a rectangle relative to the top-left of this component to screen coordinates. */
virtual Rectangle<int> localToGlobal (const Rectangle<int>& relativePosition);
/** Converts a screen area to a position relative to the top-left of this component. */
virtual Rectangle<int> globalToLocal (const Rectangle<int>& screenPosition);
@@ -300,9 +306,9 @@ public:
virtual void setAlpha (float newAlpha) = 0;
//==============================================================================
void handleMouseEvent (int touchIndex, const Point<int> positionWithinPeer, const ModifierKeys newMods, int64 time);
void handleMouseWheel (int touchIndex, const Point<int> positionWithinPeer, int64 time, const MouseWheelDetails&);
void handleMagnifyGesture (int touchIndex, const Point<int> positionWithinPeer, int64 time, float scaleFactor);
void handleMouseEvent (int touchIndex, Point<float> positionWithinPeer, ModifierKeys newMods, int64 time);
void handleMouseWheel (int touchIndex, Point<float> positionWithinPeer, int64 time, const MouseWheelDetails&);
void handleMagnifyGesture (int touchIndex, Point<float> positionWithinPeer, int64 time, float scaleFactor);
void handleUserClosingWindow();


+ 3
- 3
modules/juce_gui_basics/windows/juce_TooltipWindow.cpp View File

@@ -138,7 +138,7 @@ void TooltipWindow::timerCallback()
mouseClicks = clickCount;
mouseWheelMoves = wheelCount;
const Point<int> mousePos (mouseSource.getScreenPosition());
const Point<float> 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);
}
}
}

+ 1
- 1
modules/juce_gui_basics/windows/juce_TooltipWindow.h View File

@@ -111,7 +111,7 @@ public:
private:
//==============================================================================
int millisecondsBeforeTipAppears;
Point<int> lastMousePos;
Point<float> lastMousePos;
int mouseClicks, mouseWheelMoves;
unsigned int lastCompChangeTime, lastHideTime;
Component* lastComponentUnderMouse;


+ 6
- 6
modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp View File

@@ -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<int>(),
owner.mouseDown (MouseEvent (mouseSource, Point<float>(),
eventMods.withFlags (isLeft ? ModifierKeys::leftButtonModifier
: ModifierKeys::rightButtonModifier),
&owner, &owner, now,
Point<int>(), now, 1, false));
Point<float>(), now, 1, false));
owner.mouseUp (MouseEvent (mouseSource, Point<int>(), eventMods.withoutMouseButtons(),
owner.mouseUp (MouseEvent (mouseSource, Point<float>(), eventMods.withoutMouseButtons(),
&owner, &owner, now,
Point<int>(), now, 1, false));
Point<float>(), now, 1, false));
}
else if (type == NSMouseMoved)
{
owner.mouseMove (MouseEvent (mouseSource, Point<int>(), eventMods,
owner.mouseMove (MouseEvent (mouseSource, Point<float>(), eventMods,
&owner, &owner, now,
Point<int>(), now, 1, false));
Point<float>(), now, 1, false));
}
}
}


+ 1
- 1
modules/juce_gui_extra/native/juce_win32_ActiveXComponent.cpp View File

@@ -187,7 +187,7 @@ namespace ActiveXHelpers
case WM_MBUTTONUP:
case WM_RBUTTONUP:
peer->handleMouseEvent (0, Point<int> (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;


+ 2
- 2
modules/juce_gui_extra/native/juce_win32_SystemTrayIcon.cpp View File

@@ -111,8 +111,8 @@ public:
const Time eventTime (getMouseEventTime());
const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
Point<int>(), eventMods, &owner, &owner, eventTime,
Point<int>(), eventTime, 1, false);
Point<float>(), eventMods, &owner, &owner, eventTime,
Point<float>(), eventTime, 1, false);
if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
{


Loading…
Cancel
Save