Ejemplo n.º 1
0
        public static LTexture FilterColor(string res, LColor height, Loon.Core.Graphics.Opengl.LTexture.Format format)
        {
            uint      color = height.GetRGB();
            LImage    tmp   = LImage.CreateImage(res);
            LImage    image = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true);
            LGraphics g     = image.GetLGraphics();

            g.DrawImage(tmp, 0, 0);
            g.Dispose();
            if (tmp != null)
            {
                tmp.Dispose();
                tmp = null;
            }
            Color[] pixels = image.GetPixels();
            int     size   = pixels.Length;

            for (int i = 0; i < size; i++)
            {
                if (pixels[i].PackedValue == color)
                {
                    pixels[i].PackedValue = LSystem.TRANSPARENT;
                }
            }
            image.SetFormat(format);
            image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
            LTexture texture = image.GetTexture();

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            return(texture);
        }
Ejemplo n.º 2
0
        public virtual LImage SetTileBackground(LImage image, bool isReturn)
        {
            if (image == null)
            {
                return(null);
            }
            int layerWidth  = GetWidth();
            int layerHeight = GetHeight();
            int tileWidth   = image.GetWidth();
            int tileHeight  = image.GetHeight();

            LImage    tempImage = LImage.CreateImage(layerWidth, layerHeight, false);
            LGraphics g         = tempImage.GetLGraphics();

            for (int x = 0; x < layerWidth; x += tileWidth)
            {
                for (int y = 0; y < layerHeight; y += tileHeight)
                {
                    g.DrawImage(image, x, y);
                }
            }
            g.Dispose();
            if (isReturn)
            {
                return(tempImage);
            }
            tempImage.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED);
            SetBackground(tempImage.GetTexture());
            if (tempImage != null)
            {
                tempImage.Dispose();
                tempImage = null;
            }
            return(null);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public static LImage DrawCropImage(LImage image, int x, int y,
                                           int objectWidth, int objectHeight)
        {
            LImage buffer = LImage.CreateImage(objectWidth,
                                               objectHeight, true);
            LGraphics g = buffer.GetLGraphics();

            g.DrawImage(image, 0, 0, objectWidth, objectHeight, x, y, objectWidth, objectHeight);
            g.Dispose();
            return(buffer);
        }
Ejemplo n.º 5
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);
            }
Ejemplo n.º 6
0
        public static LImage DrawClipImage(LImage image,
                                           int objectWidth, int objectHeight, int x1, int y1, int x2, int y2)
        {
            LImage buffer = LImage.CreateImage(objectWidth,
                                               objectHeight, true);
            LGraphics g = buffer.GetLGraphics();

            g.DrawImage(image, 0, 0, objectWidth, objectHeight, x1, y1,
                        x2 - x1, y2 - y1);
            g.Dispose();
            return(buffer);
        }
Ejemplo n.º 7
0
        public static LTexture CreateTexture(int width, int height, LColor c)
        {
            LImage    image = LImage.CreateImage(width, height, false);
            LGraphics g     = image.GetLGraphics();

            g.SetColor(c);
            g.FillRect(0, 0, width, height);
            g.Dispose();
            LTexture tex2d = image.GetTexture();

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            return(tex2d);
        }
Ejemplo n.º 8
0
        public static LImage GetResize(LImage image, int w, int h)
        {
            if (image == null)
            {
                return(null);
            }
            if (image.width == w && image.height == h)
            {
                return(image);
            }
            LImage    result = LImage.CreateImage(w, h, image.HasAlpha());
            LGraphics g      = result.GetLGraphics();

            g.DrawImage(image, 0, 0, w, h, 0, 0, image.GetWidth(),
                        image.GetHeight());
            g.Dispose();
            return(result);
        }
Ejemplo n.º 9
0
        public LTexture LoadBarColor(LColor c1, LColor c2, LColor c3)
        {
            if (colors.Count > 10)
            {
                lock (colors)
                {
                    foreach (LTexture tex2d in colors.Values)
                    {
                        if (tex2d != null)
                        {
                            tex2d.Destroy();
                        }
                    }
                    colors.Clear();
                }
            }
            int hash = 1;

            hash = LSystem.Unite(hash, c1.GetRGB());
            hash = LSystem.Unite(hash, c2.GetRGB());
            hash = LSystem.Unite(hash, c3.GetRGB());
            LTexture texture = null;

            lock (colors)
            {
                texture = (LTexture)CollectionUtils.Get(colors, hash);
            }
            if (texture == null)
            {
                LImage    image = LImage.CreateImage(8, 8, false);
                LGraphics g     = image.GetLGraphics();
                g.SetColor(c1);
                g.FillRect(0, 0, 4, 4);
                g.SetColor(c2);
                g.FillRect(4, 0, 4, 4);
                g.SetColor(c3);
                g.FillRect(0, 4, 4, 4);
                g.Dispose();
                texture = image.GetTexture();
                CollectionUtils.Put(colors, hash, texture);
            }
            return(this.texture = texture);
        }
Ejemplo n.º 10
0
        public static LTexture FilterLimitColor(string res, LColor start,
                                                LColor end, Loon.Core.Graphics.Opengl.LTexture.Format format)
        {
            int       sred   = start.R;
            int       sgreen = start.G;
            int       sblue  = start.B;
            int       ered   = end.R;
            int       egreen = end.G;
            int       eblue  = end.B;
            LImage    tmp    = LImage.CreateImage(res);
            LImage    image  = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true);
            LGraphics g      = image.GetLGraphics();

            g.DrawImage(tmp, 0, 0);
            g.Dispose();
            if (tmp != null)
            {
                tmp.Dispose();
                tmp = null;
            }
            Color[] pixels = image.GetPixels();
            int     size   = pixels.Length;

            for (int i = 0; i < size; i++)
            {
                Color pixel = pixels[i];
                if ((pixel.R >= sred && pixel.G >= sgreen && pixel.B >= sblue) &&
                    (pixel.R <= ered && pixel.G <= egreen && pixel.B <= eblue))
                {
                    pixels[i].PackedValue = LSystem.TRANSPARENT;
                }
            }
            image.SetFormat(format);
            image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
            LTexture texture = image.GetTexture();

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            return(texture);
        }
Ejemplo n.º 11
0
        public void DrawImage(LImage img, int dstX, int dstY, int dstWidth, int dstHeight,
                int srcX, int srcY, int srcWidth, int srcHeight)
        {
            if (isClose || img == null || img.IsClose())
            {
                return;
            }

            LGraphics pixel = img.GetLGraphics();

            pixel.UpdatePixels();

            dstX += translateX;
            dstY += translateY;
            srcX += translateX;
            srcY += translateY;

            if (pixel == null || dstWidth <= 0 || dstHeight <= 0 || srcWidth <= 0 || srcHeight <= 0)
            {
                return;
            }
            if (dstWidth == srcWidth && dstHeight == srcHeight)
            {
                DrawImage(pixel, dstX, dstY, dstWidth, dstHeight, srcX, srcY);
                return;
            }

            Color[] currentPixels = pixel.pixels;

            int spitch = pixel.width;
            int dpitch = this.width;

            float x_ratio = ((float)srcWidth - 1) / dstWidth;
            float y_ratio = ((float)srcHeight - 1) / dstHeight;
            float x_diff = 0F;
            float y_diff = 0F;

            int dx = dstX;
            int dy = dstY;
            int sx = srcX;
            int sy = srcY;
            int i = 0;
            int j = 0;

            for (; i < dstHeight; i++)
            {
                sy = (int)(i * y_ratio) + srcY;
                dy = i + dstY;
                y_diff = (y_ratio * i + srcY) - sy;
                if (sy < 0 || dy < 0)
                {
                    continue;
                }
                if (sy >= pixel.height || dy >= this.height)
                {
                    break;
                }

                for (j = 0; j < dstWidth; j++)
                {
                    sx = (int)(j * x_ratio) + srcX;
                    dx = j + dstX;
                    x_diff = (x_ratio * j + srcX) - sx;
                    if (sx < 0 || dx < 0)
                    {
                        continue;
                    }
                    if (sx >= pixel.width || dx >= this.width)
                    {
                        break;
                    }

                    int src_ptr = sx + sy * spitch;
                    int dst_ptr = dx + dy * dpitch;
                    Color src_color = currentPixels[src_ptr];
                    uint src_pixel = src_color.PackedValue;

                    if (src_pixel != LSystem.TRANSPARENT)
                    {
                        float ta = (1 - x_diff) * (1 - y_diff);
                        float tb = (x_diff) * (1 - y_diff);
                        float tc = (1 - x_diff) * (y_diff);
                        float td = (x_diff) * (y_diff);

                        uint a = (uint)(((src_pixel & 0xff000000) >> 24) * ta +
                                                ((src_pixel & 0xff000000) >> 24) * tb +
                                                ((src_pixel & 0xff000000) >> 24) * tc +
                                                ((src_pixel & 0xff000000) >> 24) * td) & 0xff;
                        uint b = (uint)(((src_pixel & 0xff0000) >> 16) * ta +
                                                ((src_pixel & 0xff0000) >> 16) * tb +
                                                ((src_pixel & 0xff0000) >> 16) * tc +
                                                ((src_pixel & 0xff0000) >> 16) * td) & 0xff;
                        uint g = (uint)(((src_pixel & 0xff00) >> 8) * ta +
                                                ((src_pixel & 0xff00) >> 8) * tb +
                                                ((src_pixel & 0xff00) >> 8) * tc +
                                                ((src_pixel & 0xff00) >> 8) * td) & 0xff;
                        uint r = (uint)((src_pixel & 0xff) * ta +
                                                (src_pixel & 0xff) * tb +
                                                (src_pixel & 0xff) * tc +
                                                (src_pixel & 0xff) * td) & 0xff;

                        Color dst_color = pixels[dst_ptr];
                        DrawPoint(pixels, dst_ptr, Blend(r, g, b, a, dst_color));
                    }
                    else
                    {
                        DrawPoint(pixels, dst_ptr, LSystem.TRANSPARENT);
                    }
                }
            }

        }
Ejemplo n.º 12
0
 public void DrawImage(LImage pixel)
 {
     if (isClose)
     {
         return;
     }
     LGraphics g = pixel.GetLGraphics();
     int w = pixel.width;
     int h = pixel.height;
     Color[] currentPixels = g.pixels;
     for (int size = 0; size < h; size++)
     {
         Array.Copy(currentPixels, size * pixel.width
                 , pixels, size * width, w);
     }
 }
Ejemplo n.º 13
0
        private void InitDesktop()
        {
            if (desktop != null && sprites != null)
            {
                return;
            }
            this.desktop = new Desktop(this, GetWidth(), GetHeight());
            this.sprites = new Sprites(GetWidth(), GetHeight());
            if (dialog == null)
            {
                LImage tmp = LImage.CreateImage(GetWidth() - 20,
                                                GetHeight() / 2 - 20, true);
                LGraphics g = tmp.GetLGraphics();
                g.SetColor(0, 0, 0, 125);
                g.FillRect(0, 0, tmp.GetWidth(), tmp.GetHeight());
                g.Dispose();
                g      = null;
                dialog = new LTexture(GLLoader.GetTextureData(tmp));
                if (tmp != null)
                {
                    tmp.Dispose();
                    tmp = null;
                }
            }
            this.message = new LMessage(dialog, 0, 0);
            this.message.SetFontColor(LColor.white);
            int size = message.GetWidth() / (message.GetMessageFont().GetSize());

            if (LSystem.scaleWidth != 1 || LSystem.scaleHeight != 1)
            {
                if (size % 2 != 0)
                {
                    size = size + 2;
                }
                else
                {
                    size = size + 3;
                }
            }
            else
            {
                if (size % 2 != 0)
                {
                    size = size - 3;
                }
                else
                {
                    size = size - 4;
                }
            }
            this.message.SetMessageLength(size);
            this.message.SetLocation((GetWidth() - message.GetWidth()) / 2,
                                     GetHeight() - message.GetHeight() - 10);
            this.message.SetVisible(false);
            this.select = new LSelect(dialog, 0, 0);
            this.select.SetLocation(message.X(), message.Y());
            this.scrCG = new AVGCG();
            this.desktop.Add(message);
            this.desktop.Add(select);
            this.select.SetVisible(false);
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
0
        private static LTexture GetRMXPDialog(LImage rmxpImage, int width,
                                              int height, int size, int offset)
        {
            if (lazyImages == null)
            {
                lazyImages = new Dictionary <string, LTexture>(10);
            }
            string   keyName = "dialog" + width + "|" + height;
            LTexture lazy    = (LTexture)CollectionUtils.Get(lazyImages, keyName);

            if (lazy == null)
            {
                try
                {
                    int objWidth  = 64;
                    int objHeight = 64;
                    int x1        = 128;
                    int x2        = 192;
                    int y1        = 0;
                    int y2        = 64;

                    int center_size = objHeight - size * 2;

                    LImage lazyImage = null;

                    LImage image = null;

                    LImage messageImage = null;

                    image = GraphicsUtils.DrawClipImage(rmxpImage, objWidth,
                                                        objHeight, x1, y1, x2, y2);

                    LImage centerTop = GraphicsUtils.DrawClipImage(image,
                                                                   center_size, size, size, 0);

                    LImage centerDown = GraphicsUtils.DrawClipImage(image,
                                                                    center_size, size, size, objHeight - size);

                    LImage leftTop = GraphicsUtils.DrawClipImage(image, size, size,
                                                                 0, 0);

                    LImage leftCenter = GraphicsUtils.DrawClipImage(image, size,
                                                                    center_size, 0, size);

                    LImage leftDown = GraphicsUtils.DrawClipImage(image, size,
                                                                  size, 0, objHeight - size);

                    LImage rightTop = GraphicsUtils.DrawClipImage(image, size,
                                                                  size, objWidth - size, 0);

                    LImage rightCenter = GraphicsUtils.DrawClipImage(image, size,
                                                                     center_size, objWidth - size, size);

                    LImage rightDown = GraphicsUtils.DrawClipImage(image, size,
                                                                   size, objWidth - size, objHeight - size);

                    lazyImage = centerTop;

                    lazyImage = LImage.CreateImage(width, height, true);

                    LGraphics g = lazyImage.GetLGraphics();

                    g.SetAlpha(0.5f);

                    messageImage = GraphicsUtils.DrawClipImage(rmxpImage, 128, 128,
                                                               0, 0, 128, 128);

                    messageImage = GraphicsUtils.GetResize(messageImage, width
                                                           - offset, height - offset);
                    messageImage.XNAUpdateAlpha(125);

                    g.DrawImage(messageImage, (lazyImage.Width - messageImage.Width) / 2 + 1, (lazyImage.Height - messageImage
                                                                                               .Height) / 2 + 1);

                    LImage tmp = GraphicsUtils.GetResize(centerTop, width
                                                         - (size * 2), size);

                    g.DrawImage(tmp, size, 0);
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }

                    tmp = GraphicsUtils.GetResize(centerDown, width - (size * 2),
                                                  size);

                    g.DrawImage(tmp, size, height - size);
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }

                    g.DrawImage(leftTop, 0, 0);

                    tmp = GraphicsUtils.GetResize(leftCenter,
                                                  leftCenter.GetWidth(), width - (size * 2));

                    g.DrawImage(tmp, 0, size);
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }
                    g.DrawImage(leftDown, 0, height - size);

                    int right = width - size;

                    g.DrawImage(rightTop, right, 0);

                    tmp = GraphicsUtils.GetResize(rightCenter, leftCenter
                                                  .Width, width - (size * 2));

                    g.DrawImage(tmp, right, size);
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }
                    g.DrawImage(rightDown, right, height - size);
                    g.Dispose();
                    lazy = lazyImage.GetTexture();

                    lazyImages.Add(keyName, lazy);

                    image.Dispose();
                    messageImage.Dispose();
                    centerTop.Dispose();
                    centerDown.Dispose();
                    leftTop.Dispose();
                    leftCenter.Dispose();
                    leftDown.Dispose();
                    rightTop.Dispose();
                    rightCenter.Dispose();
                    rightDown.Dispose();

                    image        = null;
                    messageImage = null;
                    centerTop    = null;
                    centerDown   = null;
                    leftTop      = null;
                    leftCenter   = null;
                    leftDown     = null;
                    rightTop     = null;
                    rightCenter  = null;
                    rightDown    = null;
                }
                catch (Exception ex)
                {
                    Loon.Utils.Debugging.Log.Exception(ex);
                }
            }
            return(lazy);
        }