void app_mouse_button( SDL_MouseButtonEvent * _event ) { // we index mouse starting at 0 int button = _event->button - 1; // pass down mouse events for menu processing // note: wheel events are sent above in app_mouse_wheel for sdl2 if( _event->type == SDL_MOUSEBUTTONDOWN ) input_buffer_send( button + LEFT_MOUSE ); switch( _event->button ) { #if !SDL_VERSION_ATLEAST(2,0,0) // mouse wheel button down/up are sent at same time // so if we react to the up event then we undo the down event ! // so we must ignore up events and reset it further bellow manually // since a wheel event can never be held down this is ok... case SDL_BUTTON_WHEELUP: if( _event->type == SDL_MOUSEBUTTONDOWN ) mouse_wheel_up(); break; case SDL_BUTTON_WHEELDOWN: if( _event->type == SDL_MOUSEBUTTONDOWN ) mouse_wheel_down(); break; #endif // // Every other mouse button works like normal // default: // save the button state mouse_state.buttons[ button ] = ( _event->type == SDL_MOUSEBUTTONDOWN ); //DebugPrintf("sdl mouse button %d %s\n",_event->button, // (mouse_state.buttons[ button ]?"pressed":"released")); break; } }
void mouse_handler_base::mouse_wheel(int scrollx, int scrolly, bool browse) { int x, y; SDL_GetMouseState(&x, &y); int movex = scrollx * preferences::scroll_speed(); int movey = scrolly * preferences::scroll_speed(); // Don't scroll map and map zoom slider at same time gui::slider* s = gui().find_slider("map-zoom-slider"); if (s && point_in_rect(x, y, s->location())) { movex = 0; movey = 0; } if (movex != 0 || movey != 0) { CKey pressed; // Alt + mousewheel do an 90° rotation on the scroll direction if (pressed[SDLK_LALT] || pressed[SDLK_RALT]) { gui().scroll(movey,movex); } else { gui().scroll(movex,-movey); } } if (scrollx < 0) { mouse_wheel_left(x, y, browse); } else if (scrollx > 0) { mouse_wheel_right(x, y, browse); } if (scrolly < 0) { mouse_wheel_down(x, y, browse); } else if (scrolly > 0) { mouse_wheel_up(x, y, browse); } }
void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bool browse) { if(is_middle_click(event) && !preferences::middle_click_scrolls()) { simple_warp_ = true; } show_menu_ = false; map_location loc = gui().hex_clicked_on(event.x,event.y); mouse_update(browse, loc); #if !SDL_VERSION_ATLEAST(2,0,0) int scrollx = 0; int scrolly = 0; #endif if (is_left_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_left_); left_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); left_mouse_up(event.x, event.y, browse); } } else if (is_right_click(event)) { if (event.state == SDL_PRESSED) { cancel_dragging(); init_dragging(dragging_right_); right_click(event.x, event.y, browse); } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; clear_dragging(event, browse); right_mouse_up(event.x, event.y, browse); } } else if (is_middle_click(event)) { if (event.state == SDL_PRESSED) { set_scroll_start(event.x, event.y); scroll_started_ = true; map_location loc = gui().minimap_location_on(event.x,event.y); minimap_scrolling_ = false; if(loc.valid()) { simple_warp_ = false; minimap_scrolling_ = true; last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } else if(simple_warp_) { // middle click not on minimap, check gamemap instead loc = gui().hex_clicked_on(event.x,event.y); if(loc.valid()) { last_hex_ = loc; gui().scroll_to_tile(loc,display::WARP,false); } } } else if (event.state == SDL_RELEASED) { minimap_scrolling_ = false; simple_warp_ = false; scroll_started_ = false; } } #if !SDL_VERSION_ATLEAST(2,0,0) 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 (s && sdl::point_in_rect(event.x, event.y, s->location())) { scrollx = 0; scrolly = 0; } } if (scrollx != 0 || scrolly != 0) { CKey pressed; // Alt + mousewheel do an 90° rotation on the scroll direction if (pressed[SDLK_LALT] || pressed[SDLK_RALT]) gui().scroll(scrolly,scrollx); else gui().scroll(scrollx,scrolly); } #endif if (!dragging_left_ && !dragging_right_ && dragging_started_) { dragging_started_ = false; cursor::set_dragging(false); } mouse_update(browse, loc); }
void app_mouse_wheel( SDL_MouseWheelEvent * _event ) { //printf("mouse wheel = { x = %d, y = %d }\n", _event->x, _event->y); if(_event->y > 0) { mouse_wheel_up(); input_buffer_send( UP_MOUSE ); } if(_event->y < 0) { mouse_wheel_down(); input_buffer_send( DOWN_MOUSE ); } }