Exemplo n.º 1
0
        public TextSprite(string text, Font efont, Emugen.Image.Primitive.Vector2D position, Type type = Type.Separation, Emugen.OpenTK.View.IView view = null, int fadeTimer = -1, int fadeTimerAdd = 100)
        {
            //this.position = position;
            this.Rect         = new Rect(position, new Vector2D(0, 0));
            this.fadeTimer    = fadeTimer;
            this.fadeTimerAdd = fadeTimerAdd;
            Color             = new Color(1, 1, 1, 1);

            switch (type)
            {
            case Type.Separation:
                _TextSprite_Separation(text, efont, position, view, fadeTimer, fadeTimerAdd);
                break;

            case Type.Lump:
                break;
            }
        }
Exemplo n.º 2
0
        // Todo : こちらの文字描画に切り替えたいのだが...
        private void _TextSprite_Separation(string text, Font efont, Emugen.Image.Primitive.Vector2D position, Emugen.OpenTK.View.IView view = null, int fadeTimer = -1, int fadeTimerAdd = 100)
        {
            //this.position = position;
            //this.fadeTimer = fadeTimer;
            //this.fadeTimerAdd = fadeTimerAdd;
            this.lineTextMargin = efont.lineTextMargin;

            var frameSize    = 0.0;
            var frameSizeMax = 0.0;
            var rfontFrames  = new List <Font.FontFrame>();

            foreach (var frame in efont.fontFrames)
            {
                frameSizeMax += frame.size / 2;
                rfontFrames.Insert(0, frame);
            }
            frameSize = frameSizeMax;

            // Todo : フォントフレームの幅分だけマージンの対応が必要
            margin = (int)System.Math.Floor(frameSize);
            var saveMargin = 2;

            // Todo : Test用
            //lineTextMargin = 50;

            var k   = 0;
            var tmp = "";

            var subItems = new List <SubItem>();

            foreach (var t in text)
            {
                tmp += t;
                var subItem = new SubItem();
                var a       = Emugen.Image.Drawing.DrawText.Rect(t.ToString(), efont, new System.Drawing.PointF(0, 0));
                var b       = Emugen.Image.Drawing.DrawText.Rect(tmp, efont, new System.Drawing.PointF(0, 0));
                var x2      = b.Position.X + b.Size.X;
                var y2      = b.Position.Y + b.Size.Y;
                subItem.Rect       = new Rect(new Vector2D(x2 - a.Size.X, a.Position.Y), new Vector2D(a.Size.X, a.Size.Y));
                subItem.SingleRect = new Rect(a);
                subItems.Add(subItem);
            }

            k   = 0;
            tmp = "";
            var tmpX = 0;

            foreach (var t in text)
            {
                var subItem = subItems[k];
                tmp += t;
                var rectB = Emugen.Image.Drawing.DrawText.Rect(t.ToString(), efont, new System.Drawing.PointF(0, 0));

                var item = new Item();
                item.text = t.ToString();
                //item.bmp = new System.Drawing.Bitmap((int)(rectB.Position.X+rectB.Size.X + margin * 2), (int)(rectB.Position.Y+rectB.Size.Y + margin * 2));
                item.bmp = new System.Drawing.Bitmap((int)(subItem.Rect.Size.X + margin * 2 + saveMargin), (int)(subItem.Rect.Size.Y + margin * 2 + saveMargin));
                //item.bmp = new System.Drawing.Bitmap((int)(rectB.Position.X + rectB.Size.X), (int)(rectB.Position.Y + rectB.Size.Y));


                if (k == 0)
                {
                    var rectA = Emugen.Image.Drawing.DrawText.Rect(tmp, efont, new System.Drawing.PointF(0, 0));
                    //item.defaultRect = new Rect(new Vector2D(0, 0), new Vector2D(128, 128));
                    //item.defaultRect = new Rect(new Vector2D(rectA.Position.X, rectA.Position.Y), new Vector2D(rectA.Size.X, rectA.Size.Y));
                    item.defaultRect = new Rect(new Vector2D(subItem.Rect.Position.X, subItem.Rect.Position.Y), new Vector2D(item.bmp.Width, item.bmp.Height));
                }
                else
                {
                    var rectA = Emugen.Image.Drawing.DrawText.Rect(tmp, efont, new System.Drawing.PointF(0, 0));
                    item.defaultRect = new Rect(new Vector2D(subItem.Rect.Position.X, subItem.Rect.Position.Y), new Vector2D(item.bmp.Width, item.bmp.Height));
                    //item.defaultRect = new Rect(new Vector2D( margin + rectA.Position.X + rectA.Size.X - rectB.Size.X, margin), new Vector2D(item.bmp.Width, item.bmp.Height));
                    //item.defaultRect = new Rect(new Vector2D( margin, margin), new Vector2D(item.bmp.Width, item.bmp.Height));
                    //item.defaultRect = new Rect(new Vector2D(rectA.Position.X + rectA.Size.X - rectA.Size.X, 10), new Vector2D(128, 128));
                    //item.defaultRect = new Rect(new Vector2D(bB.X + bB.Width - bA.Width, bA.Y), new Vector2D(System.Math.Ceiling(bA.Width), System.Math.Ceiling(bA.Height)));
                    //item.defaultRect = new Rect(new Vector2D(rectB.Position.X + rectB.Size.X - rectA.Size.X, rectA.Position.Y), new Vector2D(rectA.Size.X, rectA.Size.Y));
                }
                //item.singleRect = new Rect(new Vector2D(0, 0), new Vector2D(128, 128));
                using (var g = System.Drawing.Graphics.FromImage(item.bmp))
                {
                    if (false)
                    {
                        g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 255, 0, 0)), 0, 0, 1000, 1000);
                    }

                    Emugen.Image.Drawing.DrawText.Do(item.text, efont, g, new System.Drawing.PointF((float)(margin - subItem.SingleRect.Position.X), (float)(margin - subItem.SingleRect.Position.Y)));


                    if (false)
                    {
                        g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, 255, 255, 255)),
                                        (float)rectB.Position.X, (float)rectB.Position.Y, (float)(rectB.Position.X + rectB.Size.X), (float)(rectB.Position.Y + rectB.Size.Y));
                    }
                    //Emugen.Image.Drawing.DrawText.Do(item.text, efont, g, new System.Drawing.PointF((float)-rectB.Size.X+margin, (float)-rectB.Size.Y + margin));
                    //Emugen.Image.Drawing.DrawText.Do(item.text, efont, g, new System.Drawing.PointF((float)-rectB.Position.X, (float)-rectB.Position.Y));
                    //Emugen.Image.Drawing.DrawText.Do(item.text, efont, g, new System.Drawing.PointF((float)-rectB.Position.X, (float)-rectB.Position.Y));
                }
                var texture = new Texture(item.bmp);
                var w       = item.bmp.Width;
                var h       = item.bmp.Height;
                //var x = item.defaultRect.Position.X + position.X - margin + lineTextMargin * i;
                //var y = item.defaultRect.Position.Y + position.Y - margin;
                var x = item.defaultRect.Position.X + position.X - margin + lineTextMargin * k;
                var y = item.defaultRect.Position.Y + position.Y - margin;

                item.imageSprite = new ImageSprite(texture, new Rect(new Vector2D(x, y), new Vector2D(w, h)), new Color(1, 1, 1, 1));

                items.Add(item);
                layer.Add(item.imageSprite, 10);
                k++;
                //tmpX += item.bmp.Width - efont.lineTextMargin;
                tmpX += item.bmp.Width;
            }

            // Todo : あとで、文字送りするときだけするように変更する
            if (this.fadeTimer != -1)
            {
                foreach (var item in items)
                {
                    item.color.A = 0;
                }
            }
        }