MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / centerWindow

Method centerWindow

Engine/source/windowManager/win32/win32Window.cpp:422–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420}
421
422void Win32Window::centerWindow()
423{
424 RECT newRect;
425 GetWindowRect(mWindowHandle,&newRect);
426 newRect.bottom -= newRect.top;
427 newRect.right -= newRect.left;
428 newRect.top = 0;
429 newRect.left = 0;
430
431 HMONITOR hMon = MonitorFromWindow(mWindowHandle, MONITOR_DEFAULTTONEAREST);
432
433 // Get the monitor's extents.
434 MONITORINFO monInfo;
435 dMemset(&monInfo, 0, sizeof(MONITORINFO));
436 monInfo.cbSize = sizeof(MONITORINFO);
437 GetMonitorInfo(hMon, &monInfo);
438
439 // Calculate the offset to center the window in the working area
440 S32 deltaX = ((monInfo.rcWork.right - monInfo.rcWork.left) / 2) - ((newRect.right - newRect.left) / 2);
441 S32 deltaY = ((monInfo.rcWork.bottom - monInfo.rcWork.top) / 2) - ((newRect.bottom - newRect.top) / 2);
442
443 // Calculate the new left and top position for the window
444 S32 newLeft = newRect.left + deltaX;
445 S32 newTop = newRect.top + deltaY;
446
447 // Clamp these to be greater than 0 so that the top left corner is never offscreen
448 newLeft = mClamp(newLeft, 0, newLeft);
449 newTop = mClamp(newLeft, 0, newTop);
450
451 // Calculate the new width and height
452 S32 newWidth = newRect.right - newRect.left;
453 S32 newHeight = newRect.bottom - newRect.top;
454
455 // If the new width and height of the window is larger
456 // than the working area of the monitor but is smaller
457 // than the monitor size then have it max out at the
458 // working area so that it will remain uncovered. We
459 // leave it alone if it is bigger than the monitor size
460 // (with a small fudge) to support multiple monitors.
461 if (newLeft + newWidth > (monInfo.rcWork.right - monInfo.rcWork.left) &&
462 newLeft + newWidth <= (monInfo.rcMonitor.right - monInfo.rcMonitor.left) + 4)
463 newWidth = (monInfo.rcWork.right - monInfo.rcWork.left) - newLeft;
464 if (newTop + newHeight > (monInfo.rcWork.bottom - monInfo.rcWork.top) &&
465 newTop + newHeight <= (monInfo.rcMonitor.bottom - monInfo.rcMonitor.top) + 4)
466 newHeight = (monInfo.rcWork.bottom - monInfo.rcWork.top) - newTop;
467
468 MoveWindow( mWindowHandle, newLeft, newTop, newWidth, newHeight, true );
469
470 // Make sure the resolution matches the client extent
471 Point2I clientExt = getClientExtent();
472 mVideoMode.resolution.set( clientExt.x, clientExt.y );
473
474 // Let GFX get an update about the new resolution
475 if (mTarget.isValid())
476 mTarget->resetMode();
477}
478
479bool Win32Window::setSize( const Point2I &newSize )

Callers

nothing calls this directly

Calls 5

mClampFunction · 0.85
dMemsetFunction · 0.50
setMethod · 0.45
isValidMethod · 0.45
resetModeMethod · 0.45

Tested by

no test coverage detected