Make it so that sliders can be mouse wheel scrolled.

This commit is contained in:
David Mikos 2013-12-22 00:16:27 +10:30
parent 36b6b60beb
commit cd8c83532b
7 changed files with 110 additions and 2 deletions

View file

@ -84,6 +84,7 @@ Version 1.11.7+dev:
* Introduced side's name in MP Connect.
* Middle click scrolling is now based on distance from initial click instead
of the centre of the screen.
* Make sliders able to be scrolled with the mouse wheel
* WML engine:
* WML variable turn_number is set correctly (to 1) in prestart and start
events. Previously, it retained its last value from the previous scenario

View file

@ -57,6 +57,7 @@ Version 1.11.7+dev:
* Introduced side's name in MP Connect.
* Middle click scrolling is now based on distance from initial click instead
of the centre of the screen.
* Make sliders able to be scrolled with the mouse wheel
Version 1.11.7:

View file

@ -459,6 +459,38 @@ void mouse_handler::left_mouse_up(int /*x*/, int /*y*/, const bool /*browse*/)
resources::controller->set_button_state(*gui_);
}
void mouse_handler::mouse_wheel_up(int /*x*/, int /*y*/, const bool /*browse*/)
{
gui::slider* s = gui_->find_slider("map-zoom-slider");
if (s && s->value_change())
if (gui_->set_zoom(s->value(), true))
resources::controller->set_button_state(*gui_);
}
void mouse_handler::mouse_wheel_down(int /*x*/, int /*y*/, const bool /*browse*/)
{
gui::slider* s = gui_->find_slider("map-zoom-slider");
if (s && s->value_change())
if (gui_->set_zoom(s->value(), true))
resources::controller->set_button_state(*gui_);
}
void mouse_handler::mouse_wheel_left(int /*x*/, int /*y*/, const bool /*browse*/)
{
gui::slider* s = gui_->find_slider("map-zoom-slider");
if (s && s->value_change())
if (gui_->set_zoom(s->value(), true))
resources::controller->set_button_state(*gui_);
}
void mouse_handler::mouse_wheel_right(int /*x*/, int /*y*/, const bool /*browse*/)
{
gui::slider* s = gui_->find_slider("map-zoom-slider");
if (s && s->value_change())
if (gui_->set_zoom(s->value(), true))
resources::controller->set_button_state(*gui_);
}
void mouse_handler::select_or_action()
{
if (!resources::game_map->on_board(last_hex_))

View file

@ -78,6 +78,10 @@ public:
void select_or_action();
void left_mouse_up(int x, int y, const bool /*browse*/);
void mouse_wheel_up(int x, int y, const bool /*browse*/);
void mouse_wheel_down(int x, int y, const bool /*browse*/);
void mouse_wheel_left(int x, int y, const bool /*browse*/);
void mouse_wheel_right(int x, int y, const bool /*browse*/);
protected:
/**

View file

@ -181,12 +181,21 @@ void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bo
} else if (allow_mouse_wheel_scroll(event.x, event.y)) {
if (event.button == SDL_BUTTON_WHEELUP) {
scrolly = - preferences::scroll_speed();
mouse_wheel_up(event.x, event.y, browse);
} else if (event.button == SDL_BUTTON_WHEELDOWN) {
scrolly = preferences::scroll_speed();
mouse_wheel_down(event.x, event.y, browse);
} else if (event.button == SDL_BUTTON_WHEELLEFT) {
scrollx = - preferences::scroll_speed();
mouse_wheel_left(event.x, event.y, browse);
} else if (event.button == SDL_BUTTON_WHEELRIGHT) {
scrollx = preferences::scroll_speed();
mouse_wheel_right(event.x, event.y, browse);
}
// Don't scroll map and map zoom slider at same time
gui::slider* s = gui().find_slider("map-zoom-slider");
if (point_in_rect(event.x, event.y, s->location())) {
scrollx = 0; scrolly = 0;
}
}
@ -260,6 +269,22 @@ void mouse_handler_base::left_mouse_up(int /*x*/, int /*y*/, const bool /*browse
{
}
void mouse_handler_base::mouse_wheel_up(int /*x*/, int /*y*/, const bool /*browse*/)
{
}
void mouse_handler_base::mouse_wheel_down(int /*x*/, int /*y*/, const bool /*browse*/)
{
}
void mouse_handler_base::mouse_wheel_left(int /*x*/, int /*y*/, const bool /*browse*/)
{
}
void mouse_handler_base::mouse_wheel_right(int /*x*/, int /*y*/, const bool /*browse*/)
{
}
bool mouse_handler_base::right_click(int x, int y, const bool browse)
{
if (right_click_show_menu(x, y, browse)) {

View file

@ -134,6 +134,26 @@ public:
*/
virtual void right_mouse_up(int x, int y, const bool browse);
/**
* Called when the mouse wheel is scrolled up
*/
virtual void mouse_wheel_up(int x, int y, const bool browse);
/**
* Called when the mouse wheel is scrolled down
*/
virtual void mouse_wheel_down(int x, int y, const bool browse);
/**
* Called when the mouse wheel is scrolled left
*/
virtual void mouse_wheel_left(int x, int y, const bool browse);
/**
* Called when the mouse wheel is scrolled right
*/
virtual void mouse_wheel_right(int x, int y, const bool browse);
/**
* Called when the middle click scrolling
*/

View file

@ -209,14 +209,39 @@ void slider::mouse_motion(const SDL_MouseMotionEvent& event)
void slider::mouse_down(const SDL_MouseButtonEvent& event)
{
if (event.button != SDL_BUTTON_LEFT || !point_in_rect(event.x, event.y, location()))
bool prev_change = value_change_;
if (!point_in_rect(event.x, event.y, location()))
return;
if (event.button == SDL_BUTTON_WHEELUP || event.button == SDL_BUTTON_WHEELRIGHT) {
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.button == SDL_BUTTON_WHEELDOWN || event.button == SDL_BUTTON_WHEELLEFT) {
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.button != SDL_BUTTON_LEFT)
return;
state_ = CLICKED;
if (point_in_rect(event.x, event.y, slider_area())) {
sound::play_UI_sound(game_config::sounds::button_press);
} else {
bool prev_change = value_change_;
value_change_ = false;
set_focus(true);
set_slider_position(event.x);