SuperTux / supertux

SuperTux source code
https://supertux.org
GNU General Public License v3.0
2.49k stars 470 forks source link

Add slider menu item, configuring on-screen controls size #3021

Open Vankata453 opened 1 month ago

Vankata453 commented 1 month ago

Adds the ItemSlider menu item. It allows selecting an integer value between a minimum and a maximum value. It can be used with the left mouse button, left/right arrow keys or scroll wheel. The slider step (interval between values when using the arrow keys or scroll wheel) is configurable from "Options" -> "Advanced".

The sound volume, music volume and flash intensity options now utilize a slider. The on-screen controls scale option was added back in "Options" -> "Controls" and utilizes a slider as well.

https://github.com/user-attachments/assets/63888af9-24da-43a2-a44c-52e24aa057f7

Additionally:

Closes #3010. Closes #3033.

Vankata453 commented 1 month ago

Just make sure there's a way to specify the step.

What step?

MatusGuy commented 1 month ago

The step is the interval between values. For example, if the step is 5, each time you press the right key, instead of increasing by 1 it increases by 5. And when using a cursor it snaps to the right place.

Vankata453 commented 1 month ago

Sure, will make an option for it.

tobbi commented 1 month ago

I haven't tested it yet but... Many of the sliders in UI Frameworks have the option of increasing / decreasing when the user hovers over the slider and uses the mouse wheel. Any plans on implementing that?

Vankata453 commented 1 month ago

Will do, I forgot they had that.

Vankata453 commented 1 month ago

Added customizable slider steps and scroll wheel support.

Thatstinkyguy commented 1 month ago

@Vankata453 Awesome work! Will these features be added to the Android version?

Vankata453 commented 1 month ago

Will these features be added to the Android version?

After this is merged, they will.

tobbi commented 1 month ago
/home/runner/work/supertux/supertux/src/gui/item_slider.cpp:90:96: error: implicit conversion from 'int' to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        *m_value = static_cast<int>(((mouse_pos.x - m_slider_x) / SLIDER_WIDTH) * (m_max_value - m_min_value)) + m_min_value;
                                                                                ~  ~~~~~~~~~~~~^~~~~~~~~~~~~
/home/runner/work/supertux/supertux/src/gui/item_slider.cpp:114:96: error: implicit conversion from 'int' to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        *m_value = static_cast<int>(((mouse_pos.x - m_slider_x) / SLIDER_WIDTH) * (m_max_value - m_min_value)) + m_min_value;
                                                                                ~  ~~~~~~~~~~~~^~~~~~~~~~~~~
2 errors generated.