MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / Mouse_Cursor_Handle

Method Mouse_Cursor_Handle

Source/Fodder.cpp:3188–3278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3186}
3187
3188void cFodder::Mouse_Cursor_Handle() {
3189 static bool WasClicked = false;
3190
3191 const cPosition WindowPos = mWindow->GetWindowPosition();
3192 const cDimension ScreenSize = mWindow->GetScreenSize();
3193 const cDimension WindowSize = mWindow->GetWindowSize();
3194 const cDimension scale = mWindow->GetScale();
3195 static bool CursorGrabbed = true;
3196
3197 mMouseButtonStatus = mMouse_EventLastButtonsPressed;
3198 if (mMouseButtonStatus) {
3199 mMouseButtonStatus = mMouseButtonStatus;
3200 }
3201
3202 if (!mWindow_Focus && CursorGrabbed) {
3203 CursorGrabbed = false;
3204 }
3205
3206 if (mStartParams->mMouseAlternative) {
3207 mInputMouseX = (mMouse_EventLastPosition.mX / scale.getWidth()) + MOUSE_POSITION_X_ADJUST;
3208 mInputMouseY = (mMouse_EventLastPosition.mY / scale.getHeight()) + MOUSE_POSITION_Y_ADJUST;
3209 return;
3210 }
3211
3212 // Check if the system mouse is grabbed
3213 if (!CursorGrabbed) {
3214
3215 if (!mWindow_Focus && mWindow->isMouseInside()) {
3216 // Register mouse position even when not focused but cursor on window
3217 mInputMouseX = (mMouse_EventLastPosition.mX / scale.getWidth()) + MOUSE_POSITION_X_ADJUST;
3218 mInputMouseY = (mMouse_EventLastPosition.mY / scale.getHeight()) + MOUSE_POSITION_Y_ADJUST;
3219 }
3220
3221 if (SDL_GetTicks() - mMouse_LeftWindow < 100)
3222 return;
3223
3224 // Check if the system cursor x/y is inside our window
3225 // and ensure the mouse button has been released before we focus
3226 if (mWindow_Focus && mWindow->isMouseInside() && !mMouseButtonStatus) {
3227 WasClicked = true;
3228 CursorGrabbed = true;
3229
3230 if (!mWindow->isFullscreen()) {
3231 // Ensure X not too close to a border
3232 if (mInputMouseX <= MOUSE_POSITION_X_ADJUST)
3233 mInputMouseX = MOUSE_POSITION_X_ADJUST + 1;
3234 else if (mInputMouseX >= ScreenSize.getWidth() + MOUSE_POSITION_X_ADJUST - 1)
3235 mInputMouseX = ScreenSize.getWidth() + MOUSE_POSITION_X_ADJUST - 2;
3236
3237 // Ensure Y not too close to a border
3238 if (mInputMouseY <= MOUSE_POSITION_Y_ADJUST)
3239 mInputMouseY = MOUSE_POSITION_Y_ADJUST + 1;
3240 else if (mInputMouseY >= ScreenSize.getHeight() + MOUSE_POSITION_Y_ADJUST - 1)
3241 mInputMouseY = ScreenSize.getHeight() + MOUSE_POSITION_Y_ADJUST - 2;
3242 }
3243 mWindow->SetRelativeMouseMode(true);
3244 }
3245 } else {

Callers

nothing calls this directly

Calls 13

GetWindowPositionMethod · 0.80
GetWindowSizeMethod · 0.80
GetScaleMethod · 0.80
isMouseInsideMethod · 0.80
isFullscreenMethod · 0.80
SetRelativeMouseModeMethod · 0.80
SetMousePositionMethod · 0.80
isResizedMethod · 0.80
ClearResizedMethod · 0.80
GetScreenSizeMethod · 0.45
getWidthMethod · 0.45

Tested by

no test coverage detected