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

Component: Add Point<float> overloads for some common functions

This commit is contained in:
reuk 2021-10-25 18:54:20 +01:00
parent cdbefa3b51
commit eca02270ee
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
3 changed files with 48 additions and 19 deletions

View file

@ -1400,15 +1400,15 @@ void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
bool Component::contains (Point<int> point)
{
return containsInternal (point.toFloat());
return contains (point.toFloat());
}
bool Component::containsInternal (Point<float> point)
bool Component::contains (Point<float> point)
{
if (ComponentHelpers::hitTest (*this, point))
{
if (parentComponent != nullptr)
return parentComponent->containsInternal (ComponentHelpers::convertToParentSpace (*this, point));
return parentComponent->contains (ComponentHelpers::convertToParentSpace (*this, point));
if (flags.hasHeavyweightPeerFlag)
if (auto* peer = getPeer())
@ -1420,26 +1420,26 @@ bool Component::containsInternal (Point<float> point)
bool Component::reallyContains (Point<int> point, bool returnTrueIfWithinAChild)
{
return reallyContainsInternal (point.toFloat(), returnTrueIfWithinAChild);
return reallyContains (point.toFloat(), returnTrueIfWithinAChild);
}
bool Component::reallyContainsInternal (Point<float> point, bool returnTrueIfWithinAChild)
bool Component::reallyContains (Point<float> point, bool returnTrueIfWithinAChild)
{
if (! containsInternal (point))
if (! contains (point))
return false;
auto* top = getTopLevelComponent();
auto* compAtPosition = top->getComponentAtInternal (top->getLocalPoint (this, point));
auto* compAtPosition = top->getComponentAt (top->getLocalPoint (this, point));
return (compAtPosition == this) || (returnTrueIfWithinAChild && isParentOf (compAtPosition));
}
Component* Component::getComponentAt (Point<int> position)
{
return getComponentAtInternal (position.toFloat());
return getComponentAt (position.toFloat());
}
Component* Component::getComponentAtInternal (Point<float> position)
Component* Component::getComponentAt (Point<float> position)
{
if (flags.visibleFlag && ComponentHelpers::hitTest (*this, position))
{
@ -1447,7 +1447,7 @@ Component* Component::getComponentAtInternal (Point<float> position)
{
auto* child = childComponentList.getUnchecked (i);
child = child->getComponentAtInternal (ComponentHelpers::convertFromParentSpace (*child, position));
child = child->getComponentAt (ComponentHelpers::convertFromParentSpace (*child, position));
if (child != nullptr)
return child;
@ -1461,7 +1461,7 @@ Component* Component::getComponentAtInternal (Point<float> position)
Component* Component::getComponentAt (int x, int y)
{
return getComponentAt ({ x, y });
return getComponentAt (Point<int> { x, y });
}
//==============================================================================
@ -3074,7 +3074,7 @@ bool Component::isMouseOver (bool includeChildren) const
if (c != nullptr && (c == this || (includeChildren && isParentOf (c))))
if (ms.isDragging() || ! (ms.isTouch() || ms.isPen()))
if (c->reallyContainsInternal (c->getLocalPoint (nullptr, ms.getScreenPosition()), false))
if (c->reallyContains (c->getLocalPoint (nullptr, ms.getScreenPosition()), false))
return true;
}

View file

@ -936,6 +936,19 @@ public:
*/
bool contains (Point<int> localPoint);
/** Returns true if a given point lies within this component or one of its children.
Never override this method! Use hitTest to create custom hit regions.
@param localPoint the coordinate to test, relative to this component's top-left.
@returns true if the point is within the component's hit-test area, but only if
that part of the component isn't clipped by its parent component. Note
that this won't take into account any overlapping sibling components
which might be in the way - for that, see reallyContains()
@see hitTest, reallyContains, getComponentAt
*/
bool contains (Point<float> localPoint);
/** Returns true if a given point lies in this component, taking any overlapping
siblings into account.
@ -946,6 +959,16 @@ public:
*/
bool reallyContains (Point<int> localPoint, bool returnTrueIfWithinAChild);
/** Returns true if a given point lies in this component, taking any overlapping
siblings into account.
@param localPoint the coordinate to test, relative to this component's top-left.
@param returnTrueIfWithinAChild if the point actually lies within a child of this component,
this determines whether that is counted as a hit.
@see contains, getComponentAt
*/
bool reallyContains (Point<float> localPoint, bool returnTrueIfWithinAChild);
/** Returns the component at a certain point within this one.
@param x the x coordinate to test, relative to this component's left edge.
@ -969,6 +992,17 @@ public:
*/
Component* getComponentAt (Point<int> position);
/** Returns the component at a certain point within this one.
@param position the coordinate to test, relative to this component's top-left.
@returns the component that is at this position - which may be 0, this component,
or one of its children. Note that overlapping siblings that might actually
be in the way are not taken into account by this method - to account for these,
instead call getComponentAt on the top-level parent of this component.
@see hitTest, contains, reallyContains
*/
Component* getComponentAt (Point<float> position);
//==============================================================================
/** Marks the whole component as needing to be redrawn.
@ -2474,7 +2508,6 @@ private:
//==============================================================================
friend class ComponentPeer;
friend class MouseInputSource;
friend class MouseInputSourceInternal;
#ifndef DOXYGEN
@ -2574,10 +2607,6 @@ private:
void sendEnablementChangeMessage();
void sendVisibilityChangeMessage();
bool containsInternal (Point<float>);
bool reallyContainsInternal (Point<float>, bool);
Component* getComponentAtInternal (Point<float>);
struct ComponentHelpers;
friend struct ComponentHelpers;

View file

@ -78,8 +78,8 @@ public:
auto& comp = peer->getComponent();
// (the contains() call is needed to test for overlapping desktop windows)
if (comp.containsInternal (relativePos))
return comp.getComponentAtInternal (relativePos);
if (comp.contains (relativePos))
return comp.getComponentAt (relativePos);
}
return nullptr;