Esempio n. 1
0
        public static LImage CreateFontImage(LFont font, LColor color, string text)
        {
            LImage    image = LImage.CreateImage(font.StringWidth(text), font.GetHeight());
            LGraphics g     = image.GetLGraphics();

            g.SetFont(font);
            g.DrawString(text, 0, 0, color);
            g.Dispose();
            return(image);
        }
Esempio n. 2
0
            public Menu()
                : base(128, 240)
            {
                // 设定menu层级高于MapLayer
                SetLayer(101);
                // 不锁定menu移动
                SetLocked(false);
                SetLimitMove(false);
                // 锁定Actor拖拽
                SetActorDrag(false);
                SetDelay(500);
                // 设定Menu背景
                LImage image = LImage.CreateImage(this.GetWidth(),
                                                  this.GetHeight(), true);
                LGraphics g = image.GetLGraphics();

                g.SetColor(0, 0, 0, 125);
                g.FillRect(0, 0, GetWidth(), GetHeight());
                g.SetColor(LColor.white);
                g.SetFont(15);
                g.DrawString("我是可拖拽菜单", 12, 25);
                g.Dispose();
                SetBackground(image.GetTexture());

                BulletTurret bulletTurret = new BulletTurret();

                bulletTurret.SetLocation(18, 64);


                BombTurret bombTurret = new BombTurret();

                bombTurret.SetLocation(78, 64);


                PoisonTurret poisonTurret = new PoisonTurret();

                poisonTurret.SetLocation(18, 134);


                LaserTurret laserTurret = new LaserTurret();

                laserTurret.SetLocation(78, 134);

                Button button = new Button();

                button.SetLocation(27, 196);

                // 复合LPaper到Layer
                Add(bulletTurret);
                Add(bombTurret);
                Add(poisonTurret);
                Add(laserTurret);
                Add(button);
            }
Esempio n. 3
0
        private void Make(LFont font, char[] customCharsArray)
        {
            if (charArray == null)
            {
                charArray = new IntObject[totalCharSet];
            }
            if (customCharsArray != null && customCharsArray.Length > totalCharSet)
            {
                textureWidth *= 2;
            }
            try
            {
                LImage    imgTemp = LImage.CreateImage(textureWidth, textureHeight, true);
                LGraphics g       = imgTemp.GetLGraphics();
                g.SetFont(font);
                int rowHeight         = 0;
                int positionX         = 0;
                int positionY         = 0;
                int customCharsLength = (customCharsArray != null) ? customCharsArray.Length
                        : 0;
                this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0;
                StringBuilder sbr = new StringBuilder(totalCharSet);
                for (int i = 0; i < totalCharSet + customCharsLength; i++)
                {
                    char ch = (i < totalCharSet) ? (char)i : customCharsArray[i
                                                                              - totalCharSet];

                    int charwidth = font.CharWidth(ch);
                    if (charwidth <= 0)
                    {
                        charwidth = 1;
                    }
                    int charheight = font.GetHeight();
                    if (charheight <= 0)
                    {
                        charheight = font.GetSize();
                    }

                    IntObject newIntObject = new IntObject();

                    newIntObject.width  = charwidth;
                    newIntObject.height = charheight;

                    if (positionX + newIntObject.width >= textureWidth)
                    {
                        g.DrawString(sbr.ToString(), 0, positionY);
                        sbr.Clear();
                        positionX  = 0;
                        positionY += rowHeight;
                        rowHeight  = 0;
                    }

                    newIntObject.storedX = positionX;
                    newIntObject.storedY = positionY;

                    if (newIntObject.height > fontHeight)
                    {
                        fontHeight = newIntObject.height;
                    }

                    if (newIntObject.height > rowHeight)
                    {
                        rowHeight = newIntObject.height;
                    }

                    sbr.Append(ch);

                    positionX += newIntObject.width;

                    if (i < totalCharSet)
                    {
                        charArray[i] = newIntObject;
                    }
                    else
                    {
                        CollectionUtils.Put(customChars, ch, newIntObject);
                    }
                }
                if (sbr.Length > 0)
                {
                    g.DrawString(sbr.ToString(), 0, positionY);
                    sbr = null;
                }
                g.Dispose();
                g = null;

                fontBatch = new LTextureBatch(imgTemp.GetTexture());
            }
            catch (Exception ex)
            {
                Loon.Utils.Debugging.Log.Exception(ex);
            }
        }