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

Method setSize

Engine/source/windowManager/win32/win32Window.cpp:479–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477}
478
479bool Win32Window::setSize( const Point2I &newSize )
480{
481 // Create the window rect (screen centered if not owned by a parent)
482 RECT newRect;
483 newRect.left = 0;
484 newRect.top = 0;
485 newRect.bottom = newRect.top + newSize.y;
486 newRect.right = newRect.left + newSize.x;
487
488 // Adjust the window rect to ensure the client rectangle is the desired resolution
489 AdjustWindowRect( &newRect, mWindowedWindowStyle, false);//(bool)(getMenuHandle() != NULL) );
490
491 // Center the window on the screen if we're not a child
492 if( !mOwningManager->mParentWindow )
493 {
494 HMONITOR hMon = MonitorFromWindow(mWindowHandle, MONITOR_DEFAULTTONEAREST);
495
496 // Get the monitor's extents.
497 MONITORINFO monInfo;
498 dMemset(&monInfo, 0, sizeof(MONITORINFO));
499 monInfo.cbSize = sizeof(MONITORINFO);
500 GetMonitorInfo(hMon, &monInfo);
501
502 // Calculate the offset to center the window in the working area
503 S32 deltaX = ((monInfo.rcWork.right - monInfo.rcWork.left) / 2) - ((newRect.right - newRect.left) / 2);
504 S32 deltaY = ((monInfo.rcWork.bottom - monInfo.rcWork.top) / 2) - ((newRect.bottom - newRect.top) / 2);
505
506 // Calculate the new left and top position for the window
507 S32 newLeft = newRect.left + deltaX;
508 S32 newTop = newRect.top + deltaY;
509
510 // Clamp these to be greater than 0 so that the top left corner is never offscreen
511 newLeft = mClamp(newLeft, 0, newLeft);
512 newTop = mClamp(newLeft, 0, newTop);
513
514 // Calculate the new width and height
515 S32 newWidth = newRect.right - newRect.left;
516 S32 newHeight = newRect.bottom - newRect.top;
517
518 // If the new width and height of the window is larger
519 // than the working area of the monitor but is smaller
520 // than the monitor size then have it max out at the
521 // working area so that it will remain uncovered. We
522 // leave it alone if it is bigger than the monitor size
523 // (with a small fudge) to support multiple monitors.
524 if (newLeft + newWidth > (monInfo.rcWork.right - monInfo.rcWork.left) &&
525 newLeft + newWidth <= (monInfo.rcMonitor.right - monInfo.rcMonitor.left) + 4)
526 newWidth = (monInfo.rcWork.right - monInfo.rcWork.left) - newLeft;
527 if (newTop + newHeight > (monInfo.rcWork.bottom - monInfo.rcWork.top) &&
528 newTop + newHeight <= (monInfo.rcMonitor.bottom - monInfo.rcMonitor.top) + 4)
529 newHeight = (monInfo.rcWork.bottom - monInfo.rcWork.top) - newTop;
530
531 MoveWindow( mWindowHandle, newLeft, newTop, newWidth, newHeight, true );
532 }
533 else // Just position it according to the mPosition plus new extent
534 MoveWindow(mWindowHandle, newRect.left, newRect.top, newRect.right - newRect.left, newRect.bottom - newRect.top, true);
535
536 // Make sure the resolution matches the client extent

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