Make middle click scrolling based on movement distance not screen centre.

This commit is contained in:
David Mikos 2013-12-21 22:28:59 +10:30
parent a1e6eb821a
commit 36b6b60beb
6 changed files with 25 additions and 11 deletions

View file

@ -82,6 +82,8 @@ Version 1.11.7+dev:
* Hide eras menu in MP Create for campaigns which have
"allow_era_choice=no".
* 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.
* 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

@ -55,6 +55,8 @@ Version 1.11.7+dev:
will need to do so again.
* Added possibility to hide eras menu for campaigns in MP Create.
* 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.
Version 1.11.7:

View file

@ -20,6 +20,8 @@
#include "game_preferences.hpp"
#include "log.hpp"
#include "mouse_handler_base.hpp"
#include "resources.hpp"
#include "play_controller.hpp"
#include <boost/foreach.hpp>
@ -171,18 +173,15 @@ bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse
dx += scroll_speed;
}
if ((mouse_flags & SDL_BUTTON_MMASK) != 0 && preferences::middle_click_scrolls()) {
map_location original_loc = resources::controller->get_mouse_handler_base().get_scroll_start();
const SDL_Rect& rect = get_display().map_outside_area();
if (point_in_rect(mousex, mousey,rect)) {
// relative distance from the center to the border
// NOTE: the view is a rectangle, so can be more sensible in one direction
// but seems intuitive to use and it's useful since you must
// more often scroll in the direction where the view is shorter
const double xdisp = ((1.0*mousex / rect.w) - 0.5);
const double ydisp = ((1.0*mousey / rect.h) - 0.5);
// 4.0 give twice the normal speed when mouse is at border (xdisp=0.5)
int speed = 4 * scroll_speed;
dx += round_double(xdisp * speed);
dy += round_double(ydisp * speed);
// Scroll speed is proportional from the distance from the first
// middle click and scrolling speed preference.
double speed = 0.02 * scroll_speed;
dx += speed * (mousex - original_loc.x);
dy += speed * (mousey - original_loc.y);
}
}

View file

@ -115,7 +115,6 @@ protected:
bool browse_;
bool scrolling_;
joystick_manager joystick_manager_;
};

View file

@ -157,6 +157,8 @@ void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bo
}
} else if (is_middle_click(event)) {
if (event.state == SDL_PRESSED) {
set_scroll_start(event.x, event.y);
map_location loc = gui().minimap_location_on(event.x,event.y);
minimap_scrolling_ = false;
if(loc.valid()) {

View file

@ -134,6 +134,12 @@ public:
*/
virtual void right_mouse_up(int x, int y, const bool browse);
/**
* Called when the middle click scrolling
*/
void set_scroll_start (int x, int y) { scroll_start_x_ = x; scroll_start_y_ = y; }
const map_location get_scroll_start () { return map_location(scroll_start_x_, scroll_start_y_); }
protected:
void cancel_dragging();
void clear_dragging(const SDL_MouseButtonEvent& event, bool browse);
@ -161,6 +167,10 @@ protected:
/** Show context menu flag */
bool show_menu_;
/** Relative to middle click scrolling */
int scroll_start_x_;
int scroll_start_y_;
};
} // end namespace events