internal void GenerateDimmerTexture()
        {
            if (this.DimmerTexture != null)
            {
                return;
            }

            // Get top left corner.
            var topLeft = new Point(
                this.MapItems.Min(i => i.Position.X),
                this.MapItems.Min(i => i.Position.Y)
                );

            // Get bottom right corner by adding position on screen + size, then subtracting the top left corners position from that.
            var bottomRight = new Point(
                (int)this.MapItems.Max(i => FrameDrawer.GetRealPosition(i).X + i.Size.X),
                (int)this.MapItems.Max(i => FrameDrawer.GetRealPosition(i).Y + i.Size.Y)
                );

            // Subtract from top left corner
            topLeft.X -= this.BorderSize;
            topLeft.Y -= this.BorderSize;

            // Add border size * 2 to width & height
            //  Once to compensate for the extra width/height from the shifted top left corner;
            //  Once for shifting bottom right corner by borderSize
            bottomRight.X += this.BorderSize;
            bottomRight.Y += this.BorderSize;

            // Generate the texture definition.
            this.DimmerTexture = new MapTexture
            {
                KeyColor = Microsoft.Xna.Framework.Color.White,
                Position = new PositionDefinition(
                    topLeft.X,
                    topLeft.Y),
                PositionAlignment = MapItemAlignment.Top | MapItemAlignment.Left,
                Size = new Microsoft.Xna.Framework.Vector2(
                    bottomRight.X - topLeft.X,
                    bottomRight.Y - topLeft.Y),
                Texture = API.Content.Textures.GuiBackgroundDimmer50
            };
        }
Esempio n. 2
0
        public IMapItem[] ToMapItems()
        {
            var items = new IMapItem[2];

            items[0] = this.texture;

            if (this.text == null)
            {
                items[1] = null;
                return(items);
            }

            var text = this.text.Clone() as MapText;

            if (this.AutoTextAlignment)
            {
                text.PositionAlignment = MapItemAlignment.Center;
            }
            var texturePos = FrameDrawer.GetRealPosition(this.texture);

            // Adjust vertical stuff.
            if (this.PositionAlignment.HasFlag(MapItemAlignment.Bottom))
            {
                if (this.AutoTextAlignment)
                {
                    text.PositionAlignment = MapItemAlignment.Top;
                }
                text.Position.Y = (int)(texturePos.Y + texture.Size.Y + this.textSpacing);
            }

            else if (this.PositionAlignment.HasFlag(MapItemAlignment.Top))
            {
                if (this.AutoTextAlignment)
                {
                    text.PositionAlignment = MapItemAlignment.Bottom;
                }
                text.Position.Y = (int)(texturePos.Y - this.textSpacing);
            }
            else
            {
                text.Position.Y = (int)(texturePos.Y + (texture.Size.Y / 2));
            }

            // Adjust horizontal stuff
            if (this.PositionAlignment.HasFlag(MapItemAlignment.Left))
            {
                if (this.AutoTextAlignment)
                {
                    text.PositionAlignment |= MapItemAlignment.Right;
                }
                text.Position.X = (int)(texturePos.X - this.textSpacing);
            }
            else if (this.PositionAlignment.HasFlag(MapItemAlignment.Right))
            {
                if (this.AutoTextAlignment)
                {
                    text.PositionAlignment |= MapItemAlignment.Left;
                }
                text.Position.X = (int)(texturePos.X + texture.Size.X + textSpacing);
            }
            else
            {
                text.Position.X = (int)(texturePos.X + (texture.Size.X / 2));
            }
            items[1] = text;

            return(items);
        }