Detect object under mouse

 

Hi again


Is there a way to get the object(s) below the mouse cursor (or at a certain position x/y) ? I can't seem to find a function... :/


Thanks! :)

 

You need to do it manually.

Figure out where the mouse is (pick it up from either CHARTEVENT_CLICK or CHARTEVENT_OBJECT_CLICK or CHARTEVENT_MOUSE_MOVE)

Figure out where the object is (ObjectGetInteger).

See if the mouse x/y is within the object's area.

 
honest_knave:

You need to do it manually.

Figure out where the mouse is (pick it up from either CHARTEVENT_CLICK or CHARTEVENT_OBJECT_CLICK or CHARTEVENT_MOUSE_MOVE)

Figure out where the object is (ObjectGetInteger).

See if the mouse x/y is within the object's area.


Ok thanks. But what if it's a line? o_O
 
RichPiano:

Ok thanks. But what if it's a line? o_O

Do you want to know if it has been clicked, or just hovering over the line?
 
honest_knave:

Do you want to know if it has been clicked, or just hovering over the line?

If it has been clicked :X
 
RichPiano:

If it has been clicked :X

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_CLICK && sparam==line_name) // line has been clicked
     {
     
     }
  } 
 
honest_knave:


thank you, but the problem here is that the event is only triggered when the mouse button is released again. but i need it to register when the mouse button is only pressed but not released :/
 
RichPiano:

thank you, but the problem here is that the event is only triggered when the mouse button is released again. but i need it to register when the mouse button is only pressed but not released :/
Then it's not a click.
 
Yep, so you'll need to use CHARTEVENT_MOUSE_MOVE, check the mouse location relative to your line, and check sparam for the mouse button status.
 
honest_knave:
Yep, so you'll need to use CHARTEVENT_MOUSE_MOVE, check the mouse location relative to your line, and check sparam for the mouse button status.

Ok thanks! I guess I'll just use CHARTEVENT_MOUSE_CLICK then as this obviously isn't foreseen in mql4 and such stuff makes me very anxious about bugs. It's also just something cosmetic ;)
Reason: