Пример #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 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));
        }
Пример #3
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 - item.Dimensions.Width;
                }
                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 - item.Dimensions.Height;
                }
                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));
        }
Пример #4
0
 public static GUILayerItem AlignItem(GUILayerItem item, LayoutRules.Positioning xPos,
                                      LayoutRules.Positioning yPos)
 {
     item.LayoutRules.XAxisPositionRule = xPos;
     item.LayoutRules.YAxisPositionRule = yPos;
     return item;
 }
Пример #5
0
        private static void ParseLayout(string text, out LayoutRules.Positioning xLayout, out LayoutRules.Positioning yLayout)
        {
            string[] match = text.Split(' ');
            //Match match = Regex.Match(text, "[a-z]+ [a-z]+");
            if (match/*.Groups*/[0]/*.Value*/ == "near")
                xLayout = LayoutRules.Positioning.Near;
            else /*(match.Groups[0].Value == "far")*/
                xLayout = LayoutRules.Positioning.Far;

            if (match/*.Groups*/[1]/*.Value*/ == "near")
                yLayout = LayoutRules.Positioning.Near;
            else /*(match.Groups[1].Value == "far")*/
                yLayout = LayoutRules.Positioning.Far;
        }