コード例 #1
0
 public DispatcherLabel(WorldLocation position, Color color, string text, WindowTextFont font)
 {
     Position = position;
     Color    = color;
     Text     = text;
     Font     = font;
     TextSize = new Vector2(Font.MeasureString(text), Font.Height);
 }
コード例 #2
0
 void SetNotice(string noticeText)
 {
     NoticeText = noticeText;
     NoticeSize = new Point(Font.MeasureString(noticeText), Font.Height);
     if (Animation)
     {
         AnimationStart = Owner.Viewer.RealTime - AnimationFade;
     }
     else
     {
         Animation      = true;
         AnimationStart = Owner.Viewer.RealTime;
     }
 }
コード例 #3
0
        void Reflow()
        {
            Lines = new List <string>();
            var position = 0;

            while (position < Text.Length)
            {
                var wrap   = position;
                var search = position;
                while (search != -1 && Text[search] != '\n' && Font.MeasureString(Text.Substring(position, search - position)) < Position.Width)
                {
                    wrap   = search;
                    search = Text.IndexOfAny(Whitespace, search + 1);
                }
                // Possible cases here:
                //   SEARCH    NEWLINE   FITS      WRAP=POS  WRAP AT?
                //   no        no        no        no        wrap
                //   no        no        no        yes       text.length
                //   no        no        yes       no        text.length
                //   no        no        yes       yes       text.length
                //   yes       no        no        no        wrap
                //   yes       no        no        yes       search
                //   yes       yes       no        no        wrap
                //   yes       yes       no        yes       search
                //   yes       yes       yes       no        search
                //   yes       yes       yes       yes       search
                var width = Font.MeasureString(search == -1 ? Text.Substring(position) : Text.Substring(position, search - position));
                if (width < Position.Width || wrap == position)
                {
                    wrap = search == -1 ? Text.Length : search;
                }
                Lines.Add(Text.Substring(position, wrap - position));
                position = wrap + 1;
            }
            Position.Height = Lines.Count * Font.Height;
        }
コード例 #4
0
        internal override void Draw(SpriteBatch spriteBatch, Point offset)
        {
            if (CompassTexture == null)
            {
                CompassTexture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, 1, TextureUsage.None, SurfaceFormat.Color);
                CompassTexture.SetData(new[] { Color.White });
            }
            if (HeadingHalfWidths == null)
            {
                HeadingHalfWidths = new int[12];
                for (var i = 0; i < 12; i++)
                {
                    HeadingHalfWidths[i] = Font.MeasureString((i * 30).ToString()) / 2;
                }
            }
            const int headingScale = 2;
            var       height       = (int)((Position.Height - Font.Height) / 3);

            for (float heading = 0; heading < 360; heading += 10)
            {
                var x = Position.Width / 2 + (int)(((heading - Heading + 360 + 180) % 360 - 180) * headingScale);
                if ((x >= 0) && (x < Position.Width))
                {
                    if (heading % 30 == 0)
                    {
                        var textHalfWidth = HeadingHalfWidths[(int)heading / 30];
                        if ((x - textHalfWidth >= 0) && (x + textHalfWidth < Position.Width))
                        {
                            Font.Draw(spriteBatch, new Point(offset.X + Position.X + x - textHalfWidth, offset.Y + Position.Y), heading.ToString(), Color.White);
                        }
                        spriteBatch.Draw(CompassTexture, new Rectangle(offset.X + Position.X + x, offset.Y + Position.Y + Font.Height, 1, height * 2), Color.White);
                    }
                    else
                    {
                        spriteBatch.Draw(CompassTexture, new Rectangle(offset.X + Position.X + x, offset.Y + Position.Y + Font.Height, 1, height), Color.White);
                    }
                }
            }
            spriteBatch.Draw(CompassTexture, new Rectangle(offset.X + Position.X + Position.Width / 2, offset.Y + Position.Bottom - height, 1, height), Color.White);
        }