/// <summary> /// update the movement value according the dimension placement value. /// copies from ctrl.cpp updateMoveValue /// </summary> /// <param name="placementData"></param> /// <param name="actualMove"></param> /// <param name="placementDim"></param> /// <returns></returns> static int updateMoveValue(PlacementData placementData, int actualMove, PlacementDim placementDim, int prevAxeMove, bool containerRightToLeft) { float remainder; float result; int move; int place = placementData.getPlacement(placementDim, containerRightToLeft); float accMove = placementData.getAccCtrlMove(placementDim); if (place > 0 && place < 100) { result = (float)(actualMove * place) / 100; move = (int)((actualMove * place) / 100); remainder = result - move; accMove += remainder; if (accMove >= 1 || accMove <= -1) { move += (int)accMove; if (move > 0) { accMove -= 1; } else { accMove += 1; } } } else if (place == 0) // no placement { move = 0; } else { move = actualMove; // placement is 100% } placementData.setAccCtrlMove(placementDim, accMove); return(move); }
/// <summary> /// Fix Rounding mistakes caused by placement calculations /// </summary> /// <param name="originPlacement"> placement of the origine (x or y placement) </param> /// <param name="lengthPlacement"> widht or height placement (dx or dy placement)</param> /// <param name="totalChange"> total change for control</param> /// <param name="axe"> X or Y axe</param> /// <param name="placementData"> placement data</param> /// <param name="containerRightToLeft">RightToLeft</param> /// <returns></returns> static int fixRounding(int originPlacement, int lengthPlacement, int totalChange, Axe axe, PlacementData placementData, bool containerRightToLeft) { PlacementDim originPlacementDim = axe == Axe.X ? PlacementDim.PLACE_X : PlacementDim.PLACE_Y; PlacementDim lengthPlacementDim = axe == Axe.X ? PlacementDim.PLACE_DX : PlacementDim.PLACE_DY; if (placementData.getPlacement(originPlacementDim, containerRightToLeft) + placementData.getPlacement(lengthPlacementDim, containerRightToLeft) == 100) { //total placement is 100% this means that originPlacement + lengthPlacement MUST BE EQUAL to totalChange //there are may be some mistakes caused by rounding of float numbers to integer, we must fix them //If these small mistakes are not fix - scroll bar might be created when it is not needed if (Math.Abs(originPlacement + lengthPlacement) != Math.Abs(totalChange)) { int diff = totalChange - (originPlacement + lengthPlacement); float accMove = placementData.getAccCtrlMove(lengthPlacementDim); //recalculate length placement lengthPlacement += diff; //update AccCtrlMove for future placement placementData.setAccCtrlMove(lengthPlacementDim, accMove + diff); } } return(lengthPlacement); }