Support for SDL2's mouse wheel event in the GUI1 slider.

This commit is contained in:
Boldizsár Lipka 2014-03-14 22:19:44 +01:00
parent 2d54ec7aca
commit ec2af1d30d
2 changed files with 41 additions and 0 deletions

View File

@ -253,6 +253,38 @@ void slider::mouse_down(const SDL_MouseButtonEvent& event)
}
}
#if SDL_VERSION_ATLEAST(2,0,0)
void slider::mouse_wheel(const SDL_MouseWheelEvent& event) {
bool prev_change = value_change_;
int x, y;
SDL_GetMouseState(&x, &y);
if (!point_in_rect(x, y, location()))
return;
if (event.y > 0 || event.x > 0) {
value_change_ = false;
set_focus(true);
set_value(value_ + increment_);
if(value_change_) {
sound::play_UI_sound(game_config::sounds::slider_adjust);
} else {
value_change_ = prev_change;
}
}
if (event.y < 0 || event.x < 0) {
value_change_ = false;
set_focus(true);
set_value(value_ - increment_);
if(value_change_) {
sound::play_UI_sound(game_config::sounds::slider_adjust);
} else {
value_change_ = prev_change;
}
}
}
#endif
bool slider::requires_event_focus(const SDL_Event* event) const
{
if(!focus_ || !enabled() || hidden()) {
@ -313,6 +345,12 @@ void slider::handle_event(const SDL_Event& event)
// }
// }
// break;
#if SDL_VERSION_ATLEAST(2,0,0)
case SDL_MOUSEWHEEL:
if (!mouse_locked())
mouse_wheel(event.wheel);
break;
#endif
default:
return;
}

View File

@ -55,6 +55,9 @@ protected:
private:
void mouse_motion(const SDL_MouseMotionEvent& event);
void mouse_down(const SDL_MouseButtonEvent& event);
#if SDL_VERSION_ATLEAST(2,0,0)
void mouse_wheel(const SDL_MouseWheelEvent& event);
#endif
void set_slider_position(int x);
SDL_Rect slider_area() const;
surface image_, pressedImage_, activeImage_, disabledImage_;