@@ -1382,6 +1382,8 @@ void GuiControl::parentResized(const RectI &oldParentRect, const RectI &newParen
13821382
13831383 S32 deltaX = newParentRect.extent .x - oldParentRect.extent .x ;
13841384 S32 deltaY = newParentRect.extent .y - oldParentRect.extent .y ;
1385+ F32 nudgeX = (deltaX > 0 ) ? -0 .001f : 0 .001f ;
1386+ F32 nudgeY = (deltaY > 0 ) ? -0 .001f : 0 .001f ;
13851387
13861388 if (mHorizSizing == horizResizeCenter)
13871389 newPosition.x = (newParentRect.extent .x - getWidth ()) >> 1 ;
@@ -1391,40 +1393,34 @@ void GuiControl::parentResized(const RectI &oldParentRect, const RectI &newParen
13911393 newPosition.x += deltaX;
13921394 else if (mHorizSizing == horizResizeRelative && oldParentRect.extent .x != 0 )
13931395 {
1394- S32 newLeft = mRoundToNearest ( ( F32 ( newPosition.x ) / F32 ( oldParentRect.extent .x ) ) * F32 ( newParentRect.extent .x ) );
1395- S32 newWidth = mRoundToNearest ( ( F32 ( newExtent.x ) / F32 ( oldParentRect.extent .x ) ) * F32 ( newParentRect.extent .x ) );
1396+ S32 newLeft = mRoundToNearest ( ( F32 ( newPosition.x ) / F32 ( oldParentRect.extent .x ) ) * F32 ( newParentRect.extent .x ) + nudgeX );
1397+ S32 newWidth = mRoundToNearest ( ( F32 ( newExtent.x ) / F32 ( oldParentRect.extent .x ) ) * F32 ( newParentRect.extent .x ) + nudgeX );
13961398
13971399 newPosition.x = newLeft;
13981400 newExtent.x = newWidth;
13991401 }
14001402 else if (mHorizSizing == horizResizeAspectLeft && oldParentRect.extent .x != 0 )
14011403 {
1402- S32 newLeft = mRoundToNearest (( F32 (newPosition. x ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect. extent . x ) );
1403- S32 newWidth = mRoundToNearest (( F32 (newExtent.x ) / F32 (oldParentRect. extent . y )) * F32 (newParentRect. extent . y ) );
1404+ F32 heightRatio = F32 (newParentRect. extent . y ) / F32 (oldParentRect.extent .y );
1405+ S32 newWidth = mRoundToNearest (F32 (newExtent.x ) * heightRatio + nudgeX );
14041406
1405- newPosition.x = newLeft;
1407+ S32 newRight = newPosition.x + newExtent.x + deltaX;
1408+ newPosition.x = newRight - newWidth;
14061409 newExtent.x = newWidth;
14071410 }
14081411 else if (mHorizSizing == horizResizeAspectRight && oldParentRect.extent .x != 0 )
14091412 {
1410- S32 newLeft = mRoundToNearest ((F32 (newPosition.x ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect.extent .x ));
1411- S32 newWidth = mRoundToNearest ((F32 (newExtent.x ) / F32 (oldParentRect.extent .y )) * F32 (newParentRect.extent .y )); // origional aspect ratio corrected width
1412- S32 rWidth = mRoundToNearest ((F32 (newExtent.x ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect.extent .x )); // parent aspect ratio relative width
1413-
1414- S32 offset = rWidth - newWidth; // account for change in relative width
1415- newLeft += offset;
1416- newPosition.x = newLeft;
1413+ F32 heightRatio = F32 (newParentRect.extent .y ) / F32 (oldParentRect.extent .y );
1414+ S32 newWidth = mRoundToNearest (F32 (newExtent.x ) * heightRatio + nudgeX);
14171415 newExtent.x = newWidth;
14181416 }
14191417 else if (mHorizSizing == horizResizeAspectCenter && oldParentRect.extent .x != 0 )
14201418 {
1421- S32 newLeft = mRoundToNearest ((F32 (newPosition.x ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect.extent .x ));
1422- S32 newWidth = mRoundToNearest ((F32 (newExtent.x ) / F32 (oldParentRect.extent .y )) * F32 (newParentRect.extent .y )); // origional aspect ratio corrected width
1423- S32 rWidth = mRoundToNearest ((F32 (newExtent.x ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect.extent .x )); // parent aspect ratio relative width
1424-
1425- S32 offset = rWidth - newWidth; // account for change in relative width
1426- newLeft += offset/2 ;
1427- newPosition.x = newLeft;
1419+ F32 heightRatio = F32 (newParentRect.extent .y ) / F32 (oldParentRect.extent .y );
1420+ S32 newWidth = mRoundToNearest (F32 (newExtent.x ) * heightRatio + nudgeX);
1421+ S32 center = newPosition.x + (newExtent.x >> 1 );
1422+ center += deltaX >> 1 ;
1423+ newPosition.x = center - (newWidth >> 1 );
14281424 newExtent.x = newWidth;
14291425 }
14301426
@@ -1436,40 +1432,32 @@ void GuiControl::parentResized(const RectI &oldParentRect, const RectI &newParen
14361432 newPosition.y += deltaY;
14371433 else if (mVertSizing == vertResizeRelative && oldParentRect.extent .y != 0 )
14381434 {
1439- S32 newTop = mRoundToNearest ( ( F32 ( newPosition .y ) / F32 ( oldParentRect.extent .y ) ) * F32 ( newParentRect.extent .y ) );
1440- S32 newHeight = mRoundToNearest ( ( F32 ( newExtent .y ) / F32 ( oldParentRect.extent .y ) ) * F32 ( newParentRect.extent .y ) );
1435+ S32 newHeight = mRoundToNearest ( ( F32 ( newExtent .y ) / F32 ( oldParentRect.extent .y ) ) * F32 ( newParentRect.extent .y ) + nudgeY );
1436+ S32 newTop = mRoundToNearest ( ( F32 ( newPosition .y ) / F32 ( oldParentRect.extent .y ) ) * F32 ( newParentRect.extent .y ) + nudgeY );
14411437
14421438 newPosition.y = newTop;
14431439 newExtent.y = newHeight;
14441440 }
14451441 else if (mVertSizing == vertResizeAspectTop && oldParentRect.extent .y != 0 )
14461442 {
1447- S32 newTop = mRoundToNearest ((F32 (newPosition.y ) / F32 (oldParentRect.extent .y )) * F32 (newParentRect.extent .y ));
1448- S32 newHeight = mRoundToNearest ((F32 (newExtent.y ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect.extent .x ));
1449-
1450- newPosition.y = newTop;
1443+ F32 widthRatio = F32 (newParentRect.extent .x ) / F32 (oldParentRect.extent .x );
1444+ S32 newHeight = mRoundToNearest (F32 (newExtent.y ) * widthRatio + nudgeY);
1445+ newPosition.y += deltaY;
14511446 newExtent.y = newHeight;
14521447 }
14531448 else if (mVertSizing == vertResizeAspectBottom && oldParentRect.extent .y != 0 )
14541449 {
1455- S32 newTop = mRoundToNearest ((F32 (newPosition.y ) / F32 (oldParentRect.extent .y )) * F32 (newParentRect.extent .y ));
1456- S32 newHeight = mRoundToNearest ((F32 (newExtent.y ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect.extent .x )); // origional aspect ratio corrected hieght
1457- S32 rHeight = mRoundToNearest ((F32 (newExtent.y ) / F32 (oldParentRect.extent .y )) * F32 (newParentRect.extent .y )); // parent aspect ratio relative hieght
1458-
1459- S32 offset = rHeight - newHeight; // account for change in relative hieght
1460- newTop += offset;
1461- newPosition.y = newTop;
1450+ F32 widthRatio = F32 (newParentRect.extent .x ) / F32 (oldParentRect.extent .x );
1451+ S32 newHeight = mRoundToNearest (F32 (newExtent.y ) * widthRatio + nudgeY);
14621452 newExtent.y = newHeight;
14631453 }
14641454 else if (mVertSizing == vertResizeAspectCenter && oldParentRect.extent .y != 0 )
14651455 {
1466- S32 newTop = mRoundToNearest ((F32 (newPosition.y ) / F32 (oldParentRect.extent .y )) * F32 (newParentRect.extent .y ));
1467- S32 newHeight = mRoundToNearest ((F32 (newExtent.y ) / F32 (oldParentRect.extent .x )) * F32 (newParentRect.extent .x )); // origional aspect ratio corrected hieght
1468- S32 rHeight = mRoundToNearest ((F32 (newExtent.y ) / F32 (oldParentRect.extent .y )) * F32 (newParentRect.extent .y )); // parent aspect ratio relative hieght
1469-
1470- S32 offset = rHeight - newHeight; // account for change in relative hieght
1471- newTop += offset / 2 ;
1472- newPosition.y = newTop;
1456+ F32 widthRatio = F32 (newParentRect.extent .x ) / F32 (oldParentRect.extent .x );
1457+ S32 newHeight = mRoundToNearest (F32 (newExtent.y ) * widthRatio + nudgeY);
1458+ S32 center = newPosition.y + (newExtent.y >> 1 );
1459+ center += deltaY >> 1 ;
1460+ newPosition.y = center - (newHeight >> 1 );
14731461 newExtent.y = newHeight;
14741462 }
14751463
0 commit comments