0 votes

Hello everybody !

Today, another question about a thing I didn't find anywhere : the VScrollBar interaction with the mouse wheel.

I explain myself:

I've the following architecture :

-Control
-- Panel1
--- Panel2
---- GridContainer
---- VScrollBar

My Grid Container contains some panels/Sprites, and is restricted to the Panel2 zone.
My ScrollBar, by script, display some elements in the GridContainer when his value is changed.
It functions perfectly fine with clicking on the cursor of the scrollbar and moving it by hand, but next come the problem.

The problem is, if I do a mouse wheel up or down on the scrollbar it doesn't work.
So, my question is :

Is there any mean to detect a mouse wheel up or down in a restricted zone of my UI ? (in this case, I want my mouse wheel to be detected when my mouse is in the Panel2 zone, and so in the GridContainer and VScrollBar zone also, as they are in the zone of Panel2).

I currently can detect a mouse wheel (more or less), but it detects it ALWAYS, even if i'm not in the zone I want, and I don't want this ^^'

If you have any idea,

Thank you !

asked Jun 15, 2017 in Engine by mbenoni (41 points)

1 Answer

+1 vote
Best answer

Finally got the solution :

func _input(ev):
    if ev.type==InputEvent.MOUSE_BUTTON:
        var posX = ev.pos[0]
        var posY = ev.pos[1]
               #CHECK WITH COORDINATES OF PANEL
        if(posX > 20 && posX < 990 && posY > 20 && posY < 440):
            if ev.button_index == BUTTON_WHEEL_UP:
                doSth()

But it seems doSth() is called 2 times.

answered Jun 15, 2017 by mbenoni (41 points)

Change

    if ev.type==InputEvent.MOUSE_BUTTON:

into

    if ev.type==InputEvent.MOUSE_BUTTON && ev.is_pressed():

to avoid that it is called 2 times.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.