예제 #1
0
 protected override void LoadContent()
 {
     base.LoadContent();
     this.font  = new XnaFont(this.GraphicsDevice, "돋움", 24);
     this.scene = new MapScene(this.GraphicsDevice);
     this.scene.LoadMap(this.mapImg);
 }
예제 #2
0
        private IWcR2Font LoadXnaFont(string assetName)
        {
            string[] fontDesc   = assetName.Split(new[] { ',' }, 3);
            string   familyName = fontDesc[0];
            float    size;

            System.Drawing.FontStyle fStyle;
            if (float.TryParse(fontDesc[1], out size) &&
                Enum.TryParse(fontDesc[2], out fStyle))
            {
                if (this.UseD2DFont)
                {
                    var d2dFont = new D2DFont(familyName, size,
                                              (fStyle & System.Drawing.FontStyle.Bold) != 0,
                                              (fStyle & System.Drawing.FontStyle.Italic) != 0
                                              );
                    return(new D2DFontAdapter(d2dFont));
                }
                else
                {
                    var baseFont = new System.Drawing.Font(familyName, size, fStyle, System.Drawing.GraphicsUnit.Pixel);
                    var xnaFont  = new XnaFont(GraphicsDevice, baseFont);
                    return(new XnaFontAdapter(xnaFont));
                }
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
 public XnaFontAdapter(XnaFont baseFont)
 {
     if (baseFont == null)
     {
         throw new ArgumentNullException("baseFont");
     }
     this._baseFont = baseFont;
 }
예제 #4
0
 public MapRenderFonts(GraphicsDevice graphicsDevice)
 {
     this.fonts              = new Dictionary <string, XnaFont>();
     this.graphicsDevice     = graphicsDevice;
     fonts["default"]        = new XnaFont(graphicsDevice, "宋体", 12f);
     fonts["npcName"]        = new XnaFont(graphicsDevice, new Font("宋体", 12f, FontStyle.Bold, GraphicsUnit.Pixel));
     fonts["mobName"]        = new XnaFont(graphicsDevice, new Font("宋体", 12f, GraphicsUnit.Pixel));
     fonts["tooltipTitle"]   = new XnaFont(graphicsDevice, new Font("宋体", 14f, FontStyle.Bold, GraphicsUnit.Pixel));
     fonts["tooltipContent"] = fonts["mobName"];
 }
예제 #5
0
        public override void DrawText(FontBase font, string text, PointF position, Size renderSize, ColorW color, PointF scale, float depth)
        {
            XnaFont nativeFont = font.GetNativeFont() as XnaFont;

            if (nativeFont != null)
            {
                spriteBatch.DrawStringEx(nativeFont,
                                         text,
                                         new Vector2(position.X, position.Y),
                                         new Color(color.R, color.G, color.B, color.A));
            }
        }
예제 #6
0
        /// <summary>
        /// Katkaisee merkkijonon loppupäästä niin että se sopii annettuun
        /// pikselileveyteen fontilla kirjoitettuna.
        /// </summary>
        /// <param name="str">Merkkijono</param>
        /// <param name="maxLineWidth">Maksimipikselimäärä merkkijonolle</param>
        /// <returns></returns>
        public string TruncateText(string str, double maxLineWidth)
        {
            StringBuilder builder   = new StringBuilder(str);
            double        realWidth = XnaFont.MeasureString(str).X;

            while (realWidth > maxLineWidth)
            {
                builder.Remove(builder.Length - 1, 1);
                realWidth = XnaFont.MeasureString(builder).X;
            }

            return(builder.ToString());
        }
예제 #7
0
        private void DrawNameTooltip(RenderEnv env, string name, XnaFont font, Vector2 mapPosition, Color color)
        {
            SpriteBatchEx sprite = env.Sprite;
            Vector2       size   = font.MeasureString(name);
            Rectangle     rect   = new Rectangle((int)(mapPosition.X - size.X / 2 - 2), (int)(mapPosition.Y + 2), (int)(size.X + 4), (int)(size.Y + 3));

            sprite.FillRectangle(rect, new Color(Color.Black, 0.7f), env.Camera.Origin);
            sprite.DrawStringEx(
                font,
                name,
                new Vector2(rect.X + 2, rect.Y + 2),
                color,
                env.Camera.Origin);
        }
예제 #8
0
        private void PrepareTextBlock(IList <TextBlock> list, XnaFont font, string text, ref Vector2 pos, Color color)
        {
            Vector2 size = font.MeasureString(text);

            TextBlock block = new TextBlock();

            block.Font      = font;
            block.Text      = text;
            block.Position  = pos;
            block.ForeColor = color;
            list.Add(block);

            pos.X += size.X;
        }
예제 #9
0
        public static TextBlock PrepareTextBlock(XnaFont font, string text, ref Vector2 pos, Color color)
        {
            Vector2 size = font.MeasureString(text);

            TextBlock block = new TextBlock();

            block.Font      = font;
            block.Text      = text;
            block.Position  = pos;
            block.ForeColor = color;

            pos.X += size.X;
            return(block);
        }
예제 #10
0
        /// <summary>
        /// Rivittää tekstin.
        /// </summary>
        /// <param name="text">Rivitettävä teksti.</param>
        /// <param name="softLineWidth">Leveys jonka jälkeen seuraava sana rivitetään seuraavalle riville.</param>
        /// <param name="hardLineWidth">Leveys jonka jälkeen sana katkaistaan keskeltä.</param>
        public string WrapText(string text, double softLineWidth, double hardLineWidth)
        {
            if (softLineWidth <= 0 || hardLineWidth <= 0)
            {
                throw new ArgumentException("Width must be positive.");
            }

            StringBuilder src       = new StringBuilder(text);
            StringBuilder word      = new StringBuilder();
            StringBuilder line      = new StringBuilder();
            StringBuilder dest      = new StringBuilder();
            double        lineWidth = 0;

            while (src.Length > 0 || word.Length > 0)
            {
                if (word.Length == 0)
                {
                    src.TakeFirstWord(word);
                }

                var wordWidth = XnaFont.MeasureString(word).X;

                if (lineWidth + wordWidth > softLineWidth)
                {
                    appendLine(dest, line);
                    word.PutTo(line);
                    lineWidth = 0;
                }
                else if (lineWidth + wordWidth > hardLineWidth)
                {
                    int wi = FindWrapIndex(word, hardLineWidth - lineWidth, false);
                    word.PutTo(line, 0, wi + 1);
                    appendLine(dest, line);
                    lineWidth = 0;
                }
                else
                {
                    word.PutTo(line);
                    lineWidth += wordWidth;
                }
            }

            if (line.Length > 0)
            {
                appendLine(dest, line);
            }

            return(dest.ToString());
        }
예제 #11
0
        private void PrepareTextLine(IList <TextBlock> list, XnaFont font, string text, ref Vector2 pos, Color color, ref float maxWidth)
        {
            Vector2 size = font.MeasureString(text);

            TextBlock block = new TextBlock();

            block.Font      = font;
            block.Text      = text;
            block.Position  = pos;
            block.ForeColor = color;
            list.Add(block);

            maxWidth = Math.Max(pos.X + size.X, maxWidth);
            pos.X    = 0;
            pos.Y   += size.Y;
        }
예제 #12
0
        public static TextBlock[] PrepareFormatText(XnaFont font, string formatText, ref Vector2 pos, int width, ref float maxWidth)
        {
            var layouter = new TextLayouter();
            int y        = (int)pos.Y;
            var blocks   = layouter.LayoutFormatText(font, formatText, width, ref y);

            for (int i = 0; i < blocks.Length; i++)
            {
                blocks[i].Position.X += pos.X;
                var blockWidth = blocks[i].Font.MeasureString(blocks[i].Text).X;
                maxWidth = Math.Max(maxWidth, blocks[i].Position.X + blockWidth);
            }
            pos.X = 0;
            pos.Y = y;
            return(blocks);
        }
예제 #13
0
        /// <summary>
        /// Palauttaa annetun merkin koon tässä fontissa.
        /// </summary>
        /// <param name="c">Merkki</param>
        /// <returns>Kokovektori, nollavektori jos merkkiä ei ole määritelty</returns>
        public Vector GetCharacterSize(char c)
        {
            int index = XnaFont.Characters.IndexOf(c);

            if (index < 0)
            {
                return(Vector.Zero);
            }

            if (charsizes[index] == Vector.Zero)
            {
                XnaV2 xnaSize = XnaFont.MeasureString(c.ToString());
                charsizes[index] = new Vector(xnaSize.X, xnaSize.Y);
            }

            return(charsizes[index]);
        }
예제 #14
0
        public static TextBlock PrepareTextLine(XnaFont font, string text, ref Vector2 pos, Color color, ref float maxWidth)
        {
            Vector2 size = font.MeasureString(text);

            TextBlock block = new TextBlock();

            block.Font      = font;
            block.Text      = text;
            block.Position  = pos;
            block.ForeColor = color;

            maxWidth = Math.Max(pos.X + size.X, maxWidth);
            pos.X    = 0;
            pos.Y   += font.Height;

            if (size.Y >= font.Height)
            {
                pos.Y += size.Y - font.BaseFont.Size;
            }

            return(block);
        }
예제 #15
0
        public MapRenderFonts(GraphicsDevice graphicsDevice)
        {
            this.fonts          = new Dictionary <string, XnaFont>();
            this.graphicsDevice = graphicsDevice;

            var    config = MapRender.Config.MapRenderConfig.Default;
            string defaultFontName;

            switch (config.DefaultFontIndex)
            {
            default:
            case 0: defaultFontName = "SimSun"; break;

            case 1: defaultFontName = "Dotum"; break;
            }
            fonts["default"]        = new XnaFont(graphicsDevice, defaultFontName, 12f);
            fonts["npcName"]        = fonts["default"];
            fonts["mobName"]        = fonts["default"];
            fonts["mobLevel"]       = new XnaFont(graphicsDevice, "Tahoma", 9f);
            fonts["tooltipTitle"]   = new XnaFont(graphicsDevice, new Font(defaultFontName, 14f, FontStyle.Bold, GraphicsUnit.Pixel));
            fonts["tooltipContent"] = fonts["default"];
        }
예제 #16
0
 public TextBlock[] LayoutFormatText(XnaFont font, string s, int width, ref int y)
 {
     this.blocks = new List <TextBlock>();
     base.DrawFormatString(s, font, width, ref y, font.Height);
     return(this.blocks.ToArray());
 }