Recent

Author Topic: Disable "hit test" on components?  (Read 3929 times)

laggyluk

  • Jr. Member
  • **
  • Posts: 69
Disable "hit test" on components?
« on: June 08, 2017, 04:04:32 pm »
Is there a way to stop components from intercepting mouse clicks which I want to be processed by their parent?
For example I have a panel with background image and on it there are some visual 'nodes'. Everyting can be panned around with middle mouse btn but it doesn't work when starting click over node because it intercepts the event.

tl;dr
no, you have to implement event handlers for child objects and forward them to parents like that:
Code: Pascal  [Select][+][-]
  1. procedure TTreeNode.OnLineMouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. begin
  4.   tpanel(parent).OnMouseDown(sender,button,shift,left+x,top+y);
  5. end;
« Last Edit: June 08, 2017, 05:47:27 pm by laggyluk »

sky_khan

  • Guest
Re: Disable "hit test" on components?
« Reply #1 on: June 08, 2017, 04:31:37 pm »
Are you talking about background image? Which control intercepts mouse events? If it is background image, you can avoid this by painting background on panel's canvas manually in panel's onpaint event.

laggyluk

  • Jr. Member
  • **
  • Posts: 69
Re: Disable "hit test" on components?
« Reply #2 on: June 08, 2017, 04:42:17 pm »
It's more complicated. I have a scrollbox hosting TjanTiledPanel (panel with tiled bg image). On that panel there are bunch of 'nodes' made of TBCPanel and some labels (from BGRA components). Nodes are connected with each other with TShapeLine forming sort of a tree structure.

Lines block my scrollbox interaction (panning with MMB). Labels block Node interaction (dragging with LMB). Simplest solution would be disabling mouse events on those child components and leave it to their parents to handle.

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Disable "hit test" on components?
« Reply #3 on: June 08, 2017, 04:46:54 pm »
Can you show us some screenshots?

sky_khan

  • Guest
Re: Disable "hit test" on components?
« Reply #4 on: June 08, 2017, 04:49:37 pm »
You can stop mouse event handling with csNoStdEvents in ControlStyle but I dont know an easy way about how child controls to transfer mouse events to their parents without modifying their source.

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Disable "hit test" on components?
« Reply #5 on: June 08, 2017, 05:01:56 pm »
Maybe:

if (Parent is TControl) then
  (Parent as TControl).OnClick;

laggyluk

  • Jr. Member
  • **
  • Posts: 69
Re: Disable "hit test" on components?
« Reply #6 on: June 08, 2017, 05:07:31 pm »
yeah but then I'd have to implement useless event handlers for each component

http://i.imgur.com/ICdIfjF.png

left side is design time, you can see how line component covers half of area and this is blocking the clicks on bg. On the right form during runtime.


taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Disable "hit test" on components?
« Reply #7 on: June 08, 2017, 05:16:05 pm »
yeah but then I'd have to implement useless event handlers for each component

http://i.imgur.com/ICdIfjF.png

left side is design time, you can see how line component covers half of area and this is blocking the clicks on bg. On the right form during runtime.
as far as I remember all mouse and keyboard events have the same signature. You only need to double click the events on the OI for the parent control to create the handlers once and link all the child controls to the same event handlers. No need to write delegation code to call the parents event at all.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: Disable "hit test" on components?
« Reply #8 on: June 08, 2017, 05:19:48 pm »
Yep, what taazz said is true. I usually create once and use it for several other same-type controls.

laggyluk, you may want to test the code from Mr.Madguy. A while ago he provided a good example that similar to your case. Not sure if it helps, but you should check:

http://forum.lazarus.freepascal.org/index.php/topic,36871
« Last Edit: June 08, 2017, 05:24:17 pm by Handoko »

 

TinyPortal © 2005-2018