Very confused, why is there no "isPointInsideRect" function?


#1

Where is the "isMouseInsideRect or “isMouseInsideComponent” or “doesRectOverlapRect”?

Trying not to post simple questions on the forum, but when I look at: https://juce.com/doc/classPoint

And I don’t see an obvious function that would be useful… I’m trying to learn how to use JUCE, but this is so discouraging.

Do I need to code everything myself? That’s fine if I do, but I don’t want to reinvent the wheel if I don’t have to. So teach me how to find answers. This is about learning to learn.


#2

The Rectangle class would be more useful to look into for that stuff. That has contains() method with overloads that take a Point or another Rectangle etc.


#3

Contains… there it is. Xenakios, fancy meeting you here.


#4

Component also has isMouseOver.


#5

if mouse is over a child component, is mouse also over the parent component?


#6
bool 	isMouseOver (bool includeChildren=false) const

#7

wtffffffffffff how would I have found that on my own? :confounded:

oh it’s in the function parameter


#8

You just have to read through all the Component documentation, it’s long as hell but worth it…


#9

ok soooo, is this the correct way to do this? IT’S WARKEENG!

virtual void mouseEnter(const MouseEvent& event) override
{
	if (Component::isMouseOver(true))
	{
		sliderBrightness->setVisible(true);
		sliderAfterglow->setVisible(true);
	}
}

virtual void mouseExit(const MouseEvent& event) override
{
	if (!Component::isMouseOver(true))
	{
		sliderBrightness->setVisible(false);
		sliderAfterglow->setVisible(false);
	}
}

edit: wait, i think the mouse drag out has an issue. I need to check if mouse is outside of component on mouse up maybe.


#10

Hmm, don’t mouseEnter and mouseExit get called only when the mouse is inside the component anyway? So why do the explicit mouse over check?


#11

ok, also, mouseUp event looks like it’s not triggered if mouse is not inside component, so I think I’ll have to implement this mouse handling in the parent.

without the checks, this happens:

ok it looks like I don’t need the check for mouseEnter, but I do need it for mouseExit.


#14

Ah, of course. I haven’t looked much into overlapping components. Stuff is hard enough without considering those kinds of things! :smiley:


#15

hmm, can’t figure out the mouse drag issue. mouseUp is not triggered for parent component if mouseDown was inside a child component. How should I deal with this?


#16

To implement this, I’d follow a different approach:

Implement a MouseListener that, in its mouseMove() method, updates the visibility of those Components depending on whether the mouse is inside any of them.

Then add said MouseListener as a global listener with addGlobalMouseListener() in Desktop

No need to keep track of entered and exited states.


#17

TBH when you start connecting components together by intercepting mouse events, you should treat that as a warning that you probably need to abstract the problem.

e.g. perhaps that child component should be responding to its own mouseUp by calling some kind of meaningful method on its parent to tell it what has happened?


#18

ok, I already solved my problems actually ( mouseUp is not triggered for parent component if mouseDown was inside a child component ), but thanks for the tips! I’ll undoubtedly run into this kind of thing again.