MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / mouseClick

Method mouseClick

src/Battlescape/MiniMapView.cpp:210–271  ·  view source on GitHub ↗

* Handles mouse clicks on the minimap. Will change the camera center to the clicked point. * @param action Pointer to an action. * @param state State that the action handlers belong to. */

Source from the content-addressed store, hash-verified

208 * @param state State that the action handlers belong to.
209 */
210void MiniMapView::mouseClick(Action *action, State *state)
211{
212 InteractiveSurface::mouseClick(action, state);
213
214 // The following is the workaround for a rare problem where sometimes
215 // the mouse-release event is missed for any reason.
216 // However if the SDL is also missed the release event, then it is to no avail :(
217 // (this part handles the release if it is missed and now an other button is used)
218 if (_isMouseScrolling) {
219 if (action->getDetails()->button.button != Options::battleDragScrollButton
220 && 0==(SDL_GetMouseState(0,0)&SDL_BUTTON(Options::battleDragScrollButton))) { // so we missed again the mouse-release :(
221 // Check if we have to revoke the scrolling, because it was too short in time, so it was a click
222 if ((!_mouseMovedOverThreshold) && (SDL_GetTicks() - _mouseScrollingStartTime <= (Options::dragScrollTimeTolerance)))
223 { _camera->centerOnPosition(_posBeforeMouseScrolling); _redraw = true; }
224 _isMouseScrolled = _isMouseScrolling = false;
225 stopScrolling(action);
226 }
227 }
228
229 // Drag-Scroll release: release mouse-scroll-mode
230 if (_isMouseScrolling)
231 {
232 // While scrolling, other buttons are ineffective
233 if (action->getDetails()->button.button == Options::battleDragScrollButton)
234 {
235 _isMouseScrolling = false;
236 stopScrolling(action);
237 }
238 else
239 {
240 return;
241 }
242 // Check if we have to revoke the scrolling, because it was too short in time, so it was a click
243 if ((!_mouseMovedOverThreshold) && (SDL_GetTicks() - _mouseScrollingStartTime <= (Options::dragScrollTimeTolerance)))
244 {
245 _isMouseScrolled = false;
246 stopScrolling(action);
247 _camera->centerOnPosition(_posBeforeMouseScrolling);
248 _redraw = true;
249 }
250 if (_isMouseScrolled) return;
251 }
252
253 if (action->getDetails()->button.button == SDL_BUTTON_RIGHT)
254 {
255 ((MiniMapState*)(state))->btnOkClick(action);
256 }
257
258 if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
259 {
260 int origX = action->getRelativeXMouse() / action->getXScale();
261 int origY = action->getRelativeYMouse() / action->getYScale();
262 // get offset (in cells) of the click relative to center of screen
263 int xOff = (origX / CELL_WIDTH) - ((getWidth() / 2) / CELL_WIDTH);
264 int yOff = (origY / CELL_HEIGHT) - ((getHeight() / 2) / CELL_HEIGHT);
265 // center the camera on this new position
266 int newX = _camera->getCenterPosition().x + xOff;
267 int newY = _camera->getCenterPosition().y + yOff;

Callers

nothing calls this directly

Calls 10

getDetailsMethod · 0.80
centerOnPositionMethod · 0.80
getRelativeXMouseMethod · 0.80
getRelativeYMouseMethod · 0.80
getCenterPositionMethod · 0.80
getViewLevelMethod · 0.80
PositionClass · 0.70
btnOkClickMethod · 0.45
getXScaleMethod · 0.45
getYScaleMethod · 0.45

Tested by

no test coverage detected