Пример #1
0
        public GUILayerItem(Point origin, Size dimensions)
        {
            enabled         = true;
            visible         = true;
            this.origin     = origin;
            this.dimensions = dimensions;
            layoutRules     = new LayoutRules();
            layoutRules.XAxisPositionRule      = LayoutRules.Positioning.Absolute;
            layoutRules.XAxisPositionValueType = LayoutRules.ValueType.Pixel;
            layoutRules.XAxisPositionValue     = origin.X;
            layoutRules.YAxisPositionRule      = LayoutRules.Positioning.Absolute;
            layoutRules.YAxisPositionValueType = LayoutRules.ValueType.Pixel;
            layoutRules.YAxisPositionValue     = origin.Y;

            int xDist = dimensions.Width / 2;
            int yDist = dimensions.Height / 2;

            center = new Point(origin.X + xDist, origin.Y + yDist);
            radius = (int)Math.Sqrt((xDist * xDist) + (yDist * yDist));
        }
Пример #2
0
        public void PlaceItem(GUILayerItem item, ILayer layer)
        {
            LayoutRules rules = item.LayoutRules;

            // position
            int xValue = 0;

            switch (rules.XAxisPositionRule)
            {
            case LayoutRules.Positioning.Near:
            case LayoutRules.Positioning.Absolute:
                xValue = rules.XAxisPositionValue;
                break;

            case LayoutRules.Positioning.Far:
                if (rules.XAxisPositionValueType == LayoutRules.ValueType.Percentage)
                {
                    xValue = 100 - rules.XAxisPositionValue;
                }
                else
                {
                    xValue = layer.Dimensions.Width + rules.XAxisPositionValue;
                }
                break;

            case LayoutRules.Positioning.Center:
                if (rules.XAxisPositionValueType == LayoutRules.ValueType.Percentage)
                {
                    xValue = 50 + rules.XAxisPositionValue;
                }
                else
                {
                    xValue = (layer.Dimensions.Width / 2) + rules.XAxisPositionValue;
                }
                break;
            }
            if (rules.XAxisPositionValueType == LayoutRules.ValueType.Percentage)
            {
                xValue = (int)(100f * (xValue / (float)layer.Dimensions.Width));
            }
            xValue += layer.Position.X;

            int yValue = 0;

            switch (rules.YAxisPositionRule)
            {
            case LayoutRules.Positioning.Near:
            case LayoutRules.Positioning.Absolute:
                yValue = rules.YAxisPositionValue;
                break;

            case LayoutRules.Positioning.Far:
                if (rules.YAxisPositionValueType == LayoutRules.ValueType.Percentage)
                {
                    yValue = 100 - rules.YAxisPositionValue;
                }
                else
                {
                    yValue = layer.Dimensions.Height + rules.YAxisPositionValue;
                }
                break;

            case LayoutRules.Positioning.Center:
                if (rules.YAxisPositionValueType == LayoutRules.ValueType.Percentage)
                {
                    yValue = 50 + rules.YAxisPositionValue;
                }
                else
                {
                    yValue = (layer.Dimensions.Height / 2) + rules.YAxisPositionValue;
                }
                break;
            }
            if (rules.YAxisPositionValueType == LayoutRules.ValueType.Percentage)
            {
                yValue = (int)(100f * (yValue / (float)layer.Dimensions.Height));
            }
            yValue += layer.Position.Y;

            item.Origin = new Point(xValue, yValue);
            item.Center = new Point(xValue + (item.Dimensions.Width / 2), yValue + (item.Dimensions.Height / 2));
        }