Experimental middle button mouse scrolling:
Keep the button pressed and the direction and speed of the scrolling will depends to the position of the cursor relatively to the center of the view. It's allow slow and precise short scrolling, but also long fast ones. The speed must be tuned but already use the scroll speed of preferences. (currently top-speed is equal to direction-keys and mouse-at-border) PS: it also replace the old middle-click behavior, since just do a long click has now a similar effect.
This commit is contained in:
parent
76ee766b5a
commit
f81c8a02e7
2 changed files with 21 additions and 11 deletions
|
@ -1021,16 +1021,7 @@ void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool br
|
|||
minimap_scrolling_ = true;
|
||||
last_hex_ = loc;
|
||||
gui_->scroll_to_tile(loc,game_display::WARP,false);
|
||||
} else {
|
||||
const SDL_Rect& rect = gui_->map_area();
|
||||
const int centerx = (rect.x + rect.w)/2;
|
||||
const int centery = (rect.y + rect.h)/2;
|
||||
|
||||
const int xdisp = event.x - centerx;
|
||||
const int ydisp = event.y - centery;
|
||||
|
||||
gui_->scroll(xdisp,ydisp);
|
||||
}
|
||||
}
|
||||
} else if (event.button == SDL_BUTTON_WHEELUP) {
|
||||
scrolly = - preferences::scroll_speed();
|
||||
} else if (event.button == SDL_BUTTON_WHEELDOWN) {
|
||||
|
|
|
@ -699,7 +699,7 @@ void play_controller::play_slice()
|
|||
}
|
||||
|
||||
int mousex, mousey;
|
||||
SDL_GetMouseState(&mousex,&mousey);
|
||||
bool middle_pressed = SDL_GetMouseState(&mousex,&mousey)& SDL_BUTTON(2);
|
||||
tooltips::process(mousex, mousey);
|
||||
|
||||
const int scroll_threshold = (preferences::mouse_scroll_enabled()) ? 5 : 0;
|
||||
|
@ -726,6 +726,25 @@ void play_controller::play_slice()
|
|||
scrolling_ = true;
|
||||
}
|
||||
|
||||
if (middle_pressed) {
|
||||
const SDL_Rect& rect = gui_->map_area();
|
||||
if (point_in_rect(mousex, mousey,rect)) {
|
||||
const double xdisp = ((1.0*mousex / rect.w) - 0.5);
|
||||
const double ydisp = ((1.0*mousey / rect.h) - 0.5);
|
||||
|
||||
// the 2.0 give the normal speed when mouse is at border (xdisp=0.5)
|
||||
// it also guarantee a possible 1-pixel scrolling
|
||||
// when preferences::scroll_speed() is set to minimum (=1)
|
||||
const double scroll_speed = 2.0 * preferences::scroll_speed();
|
||||
|
||||
const int xspeed = round_double(xdisp * scroll_speed);
|
||||
const int yspeed = round_double(ydisp * scroll_speed);
|
||||
|
||||
gui_->scroll(xspeed,yspeed);
|
||||
scrolling_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
gui_->draw();
|
||||
if (!scrolling_) {
|
||||
if (was_scrolling) {
|
||||
|
|
Loading…
Add table
Reference in a new issue