* Handles moving over the minimap. * Will change the camera center when the mouse is moved in mouse-moving mode. * @param action Pointer to an action. * @param state State that the action handlers belong to. */
| 277 | * @param state State that the action handlers belong to. |
| 278 | */ |
| 279 | void MiniMapView::mouseOver(Action *action, State *state) |
| 280 | { |
| 281 | InteractiveSurface::mouseOver(action, state); |
| 282 | |
| 283 | if (_isMouseScrolling && action->getDetails()->type == SDL_MOUSEMOTION) |
| 284 | { |
| 285 | // The following is the workaround for a rare problem where sometimes |
| 286 | // the mouse-release event is missed for any reason. |
| 287 | // However if the SDL is also missed the release event, then it is to no avail :( |
| 288 | // (checking: is the dragScroll-mouse-button still pressed?) |
| 289 | if (0==(SDL_GetMouseState(0,0)&SDL_BUTTON(Options::battleDragScrollButton))) { // so we missed again the mouse-release :( |
| 290 | // Check if we have to revoke the scrolling, because it was too short in time, so it was a click |
| 291 | if ((!_mouseMovedOverThreshold) && (SDL_GetTicks() - _mouseScrollingStartTime <= (Options::dragScrollTimeTolerance))) |
| 292 | { |
| 293 | _camera->centerOnPosition(_posBeforeMouseScrolling); |
| 294 | _redraw = true; |
| 295 | } |
| 296 | _isMouseScrolled = _isMouseScrolling = false; |
| 297 | stopScrolling(action); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | _isMouseScrolled = true; |
| 302 | |
| 303 | // Set the mouse cursor back |
| 304 | SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); |
| 305 | SDL_WarpMouse(_xBeforeMouseScrolling, _yBeforeMouseScrolling); |
| 306 | SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); |
| 307 | |
| 308 | // Check the threshold |
| 309 | _totalMouseMoveX += action->getDetails()->motion.xrel; |
| 310 | _totalMouseMoveY += action->getDetails()->motion.yrel; |
| 311 | if (!_mouseMovedOverThreshold) |
| 312 | _mouseMovedOverThreshold = ((std::abs(_totalMouseMoveX) > Options::dragScrollPixelTolerance) || (std::abs(_totalMouseMoveY) > Options::dragScrollPixelTolerance)); |
| 313 | |
| 314 | // Calculate the move |
| 315 | int newX, newY; |
| 316 | int scrollX, scrollY; |
| 317 | |
| 318 | if (Options::battleDragScrollInvert) |
| 319 | { |
| 320 | scrollX = action->getDetails()->motion.xrel; |
| 321 | scrollY = action->getDetails()->motion.yrel; |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | scrollX = -action->getDetails()->motion.xrel; |
| 326 | scrollY = -action->getDetails()->motion.yrel; |
| 327 | } |
| 328 | _mouseScrollX += scrollX; |
| 329 | _mouseScrollY += scrollY; |
| 330 | newX = _posBeforeMouseScrolling.x + _mouseScrollX / action->getXScale() / 4; |
| 331 | newY = _posBeforeMouseScrolling.y + _mouseScrollY / action->getYScale() / 4; |
| 332 | |
| 333 | // Keep the limits... |
| 334 | if (newX < -1 || _camera->getMapSizeX() < newX) |
| 335 | { |
| 336 | _mouseScrollX -= scrollX; |
nothing calls this directly
no test coverage detected