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 :

-- 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 !

in Engine by (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]
        if(posX > 20 && posX < 990 && posY > 20 && posY < 440):
            if ev.button_index == BUTTON_WHEEL_UP:

But it seems doSth() is called 2 times.

by (41 points)


    if ev.type==InputEvent.MOUSE_BUTTON:


    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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.