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;
    }