libraries/ManiaLib/Gui/Tools.php
final public static function getAlignedPosX($posX, $sizeX, $halign, $newAlign)
    {
        if (!$halign) {
            $halign = 'left';
        }
        $alignmentString = $halign . '|' . $newAlign;
        switch ($alignmentString) {
            case 'center|center':
            case 'center|center2':
            case 'left|left':
            case 'right|right':
                $factor = 0;
                break;

            case 'center|left':
            case 'right|center':
            case 'right|center2':
                $factor = -0.5;
                break;

            case 'center|right':
            case 'left|center':
            case 'left|center2':
                $factor = 0.5;
                break;

            case 'left|right':
                $factor = 1;
                break;

            case 'right|left':
                $factor = -1;
                break;

            default:
                throw new \Exception('GUITools: Unsupported positions: ' . $alignmentString);
        }
        return $posX + $factor * $sizeX;
    }
final public static function getAlignedPosX($posX, $sizeX, $halign, $newAlign)
    {
        if (!$halign) {
            $halign = 'left';
        }
        $alignmentString = $halign . '|' . $newAlign;
        switch ($alignmentString) {
            case 'center|center':
            case 'center|center2':
            case 'left|left':
            case 'right|right':
                $factor = 0;
                break;

            case 'center|left':
            case 'right|center':
            case 'right|center2':
                $factor = -0.5;
                break;

            case 'center|right':
            case 'left|center':
            case 'left|center2':
                $factor = 0.5;
                break;

            case 'left|right':
                $factor = 1;
                break;

            case 'right|left':
                $factor = -1;
                break;

            default:
                throw new \Exception('GUITools: Unsupported positions: ' . $alignmentString);
        }
        return $posX + $factor * $sizeX;
    }
Returns the X position of an element in relation to another element and
according to their respective alignments

@param int X position of the parent element
@param int Width of the parent element
@param string Horizontal alignement of the parent element
@param string Horizontal alignement of the element you want to place
@return int Calculated X position of the element you want to place