1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-15 00:24:19 +00:00

Added a parameter includeChildren to Component::isMouseButtonDown

This commit is contained in:
jules 2018-05-08 11:55:20 +01:00
parent 49ddaddbae
commit 7909af4ecb
2 changed files with 23 additions and 18 deletions

View file

@ -325,7 +325,7 @@ struct Component::ComponentHelpers
} }
template <typename PointOrRect> template <typename PointOrRect>
static PointOrRect convertFromDistantParentSpace (const Component* parent, const Component& target, const PointOrRect& coordInParent) static PointOrRect convertFromDistantParentSpace (const Component* parent, const Component& target, PointOrRect coordInParent)
{ {
auto* directParent = target.getParentComponent(); auto* directParent = target.getParentComponent();
jassert (directParent != nullptr); jassert (directParent != nullptr);
@ -2495,9 +2495,9 @@ void Component::internalMagnifyGesture (MouseInputSource source, Point<float> re
BailOutChecker checker (this); BailOutChecker checker (this);
const MouseEvent me (source, relativePos, source.getCurrentModifiers(), MouseInputSource::invalidPressure, const MouseEvent me (source, relativePos, source.getCurrentModifiers(), MouseInputSource::invalidPressure,
MouseInputSource::invalidOrientation, MouseInputSource::invalidRotation, MouseInputSource::invalidOrientation, MouseInputSource::invalidRotation,
MouseInputSource::invalidTiltX, MouseInputSource::invalidTiltY, MouseInputSource::invalidTiltX, MouseInputSource::invalidTiltY,
this, this, time, relativePos, time, 0, false); this, this, time, relativePos, time, 0, false);
if (isCurrentlyBlockedByAnotherModalComponent()) if (isCurrentlyBlockedByAnotherModalComponent())
{ {
@ -2520,7 +2520,7 @@ void Component::internalMagnifyGesture (MouseInputSource source, Point<float> re
void Component::sendFakeMouseMove() const void Component::sendFakeMouseMove() const
{ {
MouseInputSource mainMouse = Desktop::getInstance().getMainMouseSource(); auto mainMouse = Desktop::getInstance().getMainMouseSource();
if (! mainMouse.isDragging()) if (! mainMouse.isDragging())
mainMouse.triggerFakeMove(); mainMouse.triggerFakeMove();
@ -2862,20 +2862,25 @@ bool Component::isMouseOver (bool includeChildren) const
{ {
auto* c = ms.getComponentUnderMouse(); auto* c = ms.getComponentUnderMouse();
if ((c == this || (includeChildren && isParentOf (c))) if (c == this || (includeChildren && isParentOf (c)))
&& c->reallyContains (c->getLocalPoint (nullptr, ms.getScreenPosition().roundToInt()), false) if (ms.isDragging() || ! ms.isTouch())
&& ((! ms.isTouch()) || ms.isDragging())) if (c->reallyContains (c->getLocalPoint (nullptr, ms.getScreenPosition()).roundToInt(), false))
return true; return true;
} }
return false; return false;
} }
bool Component::isMouseButtonDown() const bool Component::isMouseButtonDown (bool includeChildren) const
{ {
for (auto& ms : Desktop::getInstance().getMouseSources()) for (auto& ms : Desktop::getInstance().getMouseSources())
if (ms.isDragging() && ms.getComponentUnderMouse() == this) {
return true; auto* c = ms.getComponentUnderMouse();
if (c == this || (includeChildren && isParentOf (c)))
if (ms.isDragging())
return true;
}
return false; return false;
} }
@ -2886,9 +2891,9 @@ bool Component::isMouseOverOrDragging (bool includeChildren) const
{ {
auto* c = ms.getComponentUnderMouse(); auto* c = ms.getComponentUnderMouse();
if ((c == this || (includeChildren && isParentOf (c))) if (c == this || (includeChildren && isParentOf (c)))
&& ((! ms.isTouch()) || ms.isDragging())) if (ms.isDragging() || ! ms.isTouch())
return true; return true;
} }
return false; return false;
@ -2919,8 +2924,8 @@ void Component::removeKeyListener (KeyListener* listenerToRemove)
keyListeners->removeFirstMatchingValue (listenerToRemove); keyListeners->removeFirstMatchingValue (listenerToRemove);
} }
bool Component::keyPressed (const KeyPress&) { return false; } bool Component::keyPressed (const KeyPress&) { return false; }
bool Component::keyStateChanged (const bool /*isKeyDown*/) { return false; } bool Component::keyStateChanged (bool /*isKeyDown*/) { return false; }
void Component::modifierKeysChanged (const ModifierKeys& modifiers) void Component::modifierKeysChanged (const ModifierKeys& modifiers)
{ {

View file

@ -1791,7 +1791,7 @@ public:
@see isMouseButtonDownAnywhere, isMouseOver, isMouseOverOrDragging @see isMouseButtonDownAnywhere, isMouseOver, isMouseOverOrDragging
*/ */
bool isMouseButtonDown() const; bool isMouseButtonDown (bool includeChildren = false) const;
/** True if the mouse is over this component, or if it's being dragged in this component. /** True if the mouse is over this component, or if it's being dragged in this component.
This is a handy equivalent to (isMouseOver() || isMouseButtonDown()). This is a handy equivalent to (isMouseOver() || isMouseButtonDown()).