OnMouse Over Container

Just starting out? Need help? Post your questions and find answers here.
Johanson
User
User
Posts: 40
Joined: Sat Aug 01, 2020 9:53 am

OnMouse Over Container

Post by Johanson »

I need the function 'OnMouseOver Container'
- reaction to moving the mouse over the yellow container, similar to 'GadgetToolTip (...)'.

Unfortunately, after hovering over the checkbox, the tooltip from the container stops working
https://drive.google.com/file/d/10JPIof ... sp=sharing

I want to be able to, for example, highlight the selected country contour on the map after MouseOver a given container.

Code: Select all

LoadImage(0, "PureBasic.bmp")
OpenWindow(#PB_Any, 0, 0, 600,600, "OnMouseOver Container", #PB_Window_SystemMenu)

 Container_A0 = ContainerGadget(#PB_Any, 50,30, 480,260)
   SetGadgetColor(Container_A0, #PB_Gadget_BackColor, #Green)
 
   t_A=TextGadget(#PB_Any, 50,5, 300,20, "Group A")
   SetGadgetColor(t_A, #PB_Gadget_BackColor, #Green)
   Container_A1 = ContainerGadget(#PB_Any, 10,30, 460,45)
     SetGadgetColor(Container_A1, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A1, "Container_A1")
     ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A1 ...")
   CloseGadgetList()
   
   Container_A2 = ContainerGadget(#PB_Any, 10,80, 460,45)
     SetGadgetColor(Container_A2, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A2, "Container_A2")
     ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A2 ...")
   CloseGadgetList()
     
   Container_A3 = ContainerGadget(#PB_Any, 10,130, 460,45)
     SetGadgetColor(Container_A3, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A3, "Container_A3")
     ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A3 ...")
   CloseGadgetList()
   
   t_A_=TextGadget(#PB_Any, 50,180, 300,20, ". . . ")
   SetGadgetColor(t_A_, #PB_Gadget_BackColor, #Green)
   
   Container_A99 = ContainerGadget(#PB_Any, 10,205, 460,45)
     SetGadgetColor(Container_A99, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A99, "Container_A99")
     ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A99 ...")
   CloseGadgetList()
 CloseGadgetList()
 
 Container_B0 = ContainerGadget(#PB_Any, 50,320, 480,260)
   SetGadgetColor(Container_B0, #PB_Gadget_BackColor, #Green)
 
   t_B=TextGadget(#PB_Any, 50,5, 300,20, "Group B")
   SetGadgetColor(t_B, #PB_Gadget_BackColor, #Green)
   Container_B1 = ContainerGadget(#PB_Any, 10,30, 460,45)
     SetGadgetColor(Container_B1, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B1, "Container_B1")
     ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B1 ...")
   CloseGadgetList()
   
   Container_B2 = ContainerGadget(#PB_Any, 10,80, 460,45)
     SetGadgetColor(Container_B2, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B2, "Container_B2")
     Im_B2=ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     Ch_B2=CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B2 ...")
   CloseGadgetList()
     
   Container_B3 = ContainerGadget(#PB_Any, 10,130, 460,45)
     SetGadgetColor(Container_B3, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B3, "Container_B3")
     ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B3 ...")
   CloseGadgetList()
   
   t_A_=TextGadget(#PB_Any, 50,180, 300,20, ". . . ")
   SetGadgetColor(t_A_, #PB_Gadget_BackColor, #Green)
   
   Container_B99 = ContainerGadget(#PB_Any, 10,205, 460,45)
     SetGadgetColor(Container_B99, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B99, "Container_B99")
     ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B99 ...")
   CloseGadgetList()
 CloseGadgetList()
 
Repeat 
  Event = WindowEvent()
Until Event = #PB_Event_CloseWindow
Last edited by Johanson on Fri May 28, 2021 1:38 pm, edited 3 times in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5032
Joined: Sun Apr 12, 2009 6:27 am

Re: OnMouse Over Container

Post by RASHAD »

Hi
Post a small working snippet so the forum members can help you
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5032
Joined: Sun Apr 12, 2009 6:27 am

Re: OnMouse Over Container

Post by RASHAD »

Hi
You can add GadgetToolTip = the Container GadgetToolTip to each CheckBox to get the same tooltip all around

Code: Select all

LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")
OpenWindow(#PB_Any, 0, 0, 600,600, "OnMouseOver Container", #PB_Window_SystemMenu)

Container_A0 = ContainerGadget(#PB_Any, 50,30, 480,260)
SetGadgetColor(Container_A0, #PB_Gadget_BackColor, #Green)
 
   t_A=TextGadget(#PB_Any, 50,5, 300,20, "Group A")
   SetGadgetColor(t_A, #PB_Gadget_BackColor, #Green)
   Container_A1 = ContainerGadget(#PB_Any, 10,30, 460,45)
     SetGadgetColor(Container_A1, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A1, "Container_A1")
     img_a1 = ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(img_a1,1)
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A1 ...")
   CloseGadgetList()
   
   Container_A2 = ContainerGadget(#PB_Any, 10,80, 460,45)
     SetGadgetColor(Container_A2, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A2, "Container_A2")
     img_a2 = ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(img_a2,1)
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A2 ...")
   CloseGadgetList()
     
   Container_A3 = ContainerGadget(#PB_Any, 10,130, 460,45)
     SetGadgetColor(Container_A3, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A3, "Container_A3")
     img_a3 = ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(img_a3,1)
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A3 ...")
   CloseGadgetList()
   
   t_A_=TextGadget(#PB_Any, 50,180, 300,20, ". . . ")
   SetGadgetColor(t_A_, #PB_Gadget_BackColor, #Green)
   
   Container_A99 = ContainerGadget(#PB_Any, 10,205, 460,45)
     SetGadgetColor(Container_A99, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_A99, "Container_A99")
     img_a99 = ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(img_a99,1)
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox A99 ...")
   CloseGadgetList()
 CloseGadgetList()
 
 Container_B0 = ContainerGadget(#PB_Any, 50,320, 480,260)
   SetGadgetColor(Container_B0, #PB_Gadget_BackColor, #Green)
 
   t_B=TextGadget(#PB_Any, 50,5, 300,20, "Group B")
   SetGadgetColor(t_B, #PB_Gadget_BackColor, #Green)
   Container_B1 = ContainerGadget(#PB_Any, 10,30, 460,45)
     SetGadgetColor(Container_B1, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B1, "Container_B1")
     img_b1 = ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(img_b1,1)
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B1 ...")
   CloseGadgetList()
   
   Container_B2 = ContainerGadget(#PB_Any, 10,80, 460,45)
     SetGadgetColor(Container_B2, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B2, "Container_B2")
     Im_B2=ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(Im_B2,1)
     Ch_B2=CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B2 ...")
   CloseGadgetList()
     
   Container_B3 = ContainerGadget(#PB_Any, 10,130, 460,45)
     SetGadgetColor(Container_B3, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B3, "Container_B3")
     im_b3 = ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(Im_B3,1)
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B3 ...")
   CloseGadgetList()
   
   t_A_=TextGadget(#PB_Any, 50,180, 300,20, ". . . ")
   SetGadgetColor(t_A_, #PB_Gadget_BackColor, #Green)
   
   Container_B99 = ContainerGadget(#PB_Any, 10,205, 460,45)
     SetGadgetColor(Container_B99, #PB_Gadget_BackColor, #Yellow)
     GadgetToolTip(Container_B99, "Container_B99")
     im_b99 = ImageGadget(#PB_Any, 5,5, 100, 30, ImageID(0))
     DisableGadget(Im_b99,1)
     CheckBoxGadget(#PB_Any, 185,10, 265,25, "CheckBox B99 ...")
   CloseGadgetList()
 CloseGadgetList()
 
Repeat 
  Event = WindowEvent()
Until Event = #PB_Event_CloseWindow
Egypt my love
Johanson
User
User
Posts: 40
Joined: Sat Aug 01, 2020 9:53 am

Re: OnMouse Over Container

Post by Johanson »

I like the idea of using 'DisableGadget ()'
--- SUPER !!!! --- I didn't know about it,

but I do NOT mean a tooltip, rather the OnMouseOver function, thanks to which you will be able to run appropriate procedures depending on the element over which the mouse is located
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: OnMouse Over Container

Post by netmaestro »

#PB_Canvas_Container will let you use a canvas for your container, giving you the full spectrum of events including all the mouse ones. You can use individual canvas containers for your items and they'll all report mouse events, identifiable with PB_Event_Gadget().
BERESHEIT
Johanson
User
User
Posts: 40
Joined: Sat Aug 01, 2020 9:53 am

Re: OnMouse Over Container

Post by Johanson »

Yes - this is it
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: OnMouse Over Container

Post by davido »

@Johanson,
Thank you for bring this up.

@netmaestro,
I didn't know this, Thank you, I'll find it very useful. :D
DE AA EB
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: OnMouse Over Container

Post by netmaestro »

If you're going to place gadgets in the canvas that require input or that must respond to clicks there is a bit more you need to do. The gadget must be subclassed to pass on messages to the canvas as the canvas won't get mouse messages while the user is hovering over its contained gadget. This is not difficult, and the code I provide here can be used as boilerplate, you just have to change window# and gadget# to suit your implementation. Windows only, that's all I know.

Code: Select all

;/////////////// BOILERPLATE ///////////////
Procedure ButtonProc(hWnd, Msg, wParam, lParam)
  oldproc = GetProp_(hWnd, "oldproc")
  Select Msg
    Case #WM_NCDESTROY
      RemoveProp_(hWnd, "oldproc")
      
    Case #WM_MOUSEMOVE
      TrackMouseEvent_(@tme)
      PostEvent(#PB_Event_Gadget,0,0,#PB_EventType_MouseEnter)
       
    Case #WM_MOUSEHOVER   
       TrackMouseEvent_(@tme)

     Case #WM_MOUSELEAVE
       PostEvent(#PB_Event_Gadget,0,0,#PB_EventType_MouseLeave)
  EndSelect
  ProcedureReturn CallWindowProc_(oldproc, hWnd, Msg, wParam, lParam)
EndProcedure
;/////////////// END BOILERPLATE ///////////////

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(0,10,10,120,20,#PB_Canvas_Container)
ButtonGadget(1,0,0,120,20,"out of button")
CloseGadgetList()

;/////////////// BOILERPLATE ///////////////
SetProp_(GadgetID(1),"oldproc",SetWindowLongPtr_(GadgetID(1),#GWL_WNDPROC,@ButtonProc()))

With tme.TRACKMOUSEEVENT
  \cbSize=SizeOf(TRACKMOUSEEVENT)
  \dwFlags = #TME_LEAVE|#TME_HOVER 
  \hwndTrack = GadgetID(1)
EndWith
;/////////////// END BOILERPLATE ///////////////

Repeat
  EventID=WaitWindowEvent()
  Select EventID
    Case #PB_Event_Gadget
      If EventGadget()=0
        Select EventType()
          Case #PB_EventType_MouseEnter
            SetGadgetText(1,"in button")
          Case #PB_EventType_MouseLeave
            SetGadgetText(1,"out of button")
          Case #PB_EventType_MouseMove
            
        EndSelect
      EndIf
  EndSelect
      
Until EventID=#PB_Event_CloseWindow
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5032
Joined: Sun Apr 12, 2009 6:27 am

Re: OnMouse Over Container

Post by RASHAD »

Using native commands
Tested with Windows OS (Should be OK with other OS)

Code: Select all

Global x,y

Procedure ismouse(gad)
  If x >= GadgetX(gad) And x <= (GadgetX(gad)+GadgetWidth(gad)) And y >= GadgetY(gad) And y <= (GadgetY(gad)+GadgetHeight(gad))
    result = 1
  Else
    result = 0
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,320,500,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
cont1 = ContainerGadget(#PB_Any,10,10,300,220,#PB_Container_Single)
  SetGadgetColor(cont1,#PB_Gadget_BackColor,$929292)
  ContainerGadget(0,10,10,278,198,#PB_Container_Single)
  ButtonGadget(1,10,10,120,20,"#1")
  GadgetToolTip(1,"Gadget #1")
  ButtonGadget(2,10,40,120,20,"#2")
  GadgetToolTip(2,"Gadget #2")
  CloseGadgetList()
CloseGadgetList()

cont2 = ContainerGadget(#PB_Any,10,240,300,220,#PB_Container_Single)
  SetGadgetColor(cont2,#PB_Gadget_BackColor,$929292)
  ContainerGadget(3,10,10,278,198,#PB_Container_Single)
  ButtonGadget(4,10,10,120,20,"#4")
  GadgetToolTip(4,"Gadget #4")
  ButtonGadget(5,10,40,120,20,"#5")
  GadgetToolTip(5,"Gadget #5")
  CloseGadgetList()
CloseGadgetList()

AddWindowTimer(0,125,100)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Timer
      x = WindowMouseX(0)
      y = WindowMouseY(0)
      If ismouse(cont1)
        SetGadgetColor(cont1,#PB_Gadget_BackColor,$2527FE)
      Else
        SetGadgetColor(cont1,#PB_Gadget_BackColor,$929292)
      EndIf
      
      If ismouse(cont2)
        SetGadgetColor(cont2,#PB_Gadget_BackColor,$2527FE)
      Else
        SetGadgetColor(cont2,#PB_Gadget_BackColor,$929292)
      EndIf

     Case #PB_Event_Gadget
       Select EventGadget()         
        Case 1,2,4,5
          Debug Str(EventGadget())
      EndSelect
        
  EndSelect
      
Until Quit = 1

Egypt my love
Post Reply