コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: GLLoader.cs プロジェクト: zhwk022/LGame
        public static void CopyArea(LImage image, LGraphics g, int x, int y, int width, int height, int dx, int dy)
        {
            LImage tmp = image.GetSubImage(x, y, width, height);

            g.DrawImage(tmp, x + dx, y + dy);
            tmp.Dispose();
            tmp = null;
        }
コード例 #4
0
ファイル: PShadowEffect.cs プロジェクト: zx8326123/LGame
 public void Dispose()
 {
     this.isClose = true;
     this.EndUsePixelThread();
     this.finalDrawPixels = null;
     this.nowDrawPixels   = null;
     if (image != null)
     {
         image.Dispose();
         image = null;
     }
 }
コード例 #5
0
 public LTexture Pack(Loon.Core.Graphics.Opengl.LTexture.Format format)
 {
     if (texture != null && !packing)
     {
         return(texture);
     }
     if (fileName != null)
     {
         texture       = new LTexture(GLLoader.GetTextureData(fileName), format);
         texture.isExt = true;
     }
     else
     {
         LImage image = PackImage();
         if (image == null)
         {
             return(null);
         }
         if (texture != null)
         {
             texture.Destroy();
             texture = null;
         }
         if (colorMask != null)
         {
             Color[] pixels = image.GetPixels();
             int     size   = pixels.Length;
             uint    color  = colorMask.GetRGB();
             for (int i = 0; i < size; i++)
             {
                 if (pixels[i].PackedValue == color)
                 {
                     pixels[i].PackedValue = LSystem.TRANSPARENT;
                 }
             }
             image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
         }
         texture       = new LTexture(GLLoader.GetTextureData(image), format);
         texture.isExt = true;
         if (image != null)
         {
             image.Dispose();
             image = null;
         }
     }
     return(texture);
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: LTexture.cs プロジェクト: zx8326123/LGame
        public Shape GetShape()
        {
            if (shapeCache != null)
            {
                return(shapeCache);
            }
            LImage shapeImage = GetImage();

            if (shapeImage != null)
            {
                Polygon polygon = CollisionMask.MakePolygon(shapeImage);
                if (shapeImage != null)
                {
                    shapeImage.Dispose();
                    shapeImage = null;
                }
                return(shapeCache = polygon);
            }
            throw new RuntimeException("Create texture for shape fail !");
        }
コード例 #9
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);
        }
コード例 #10
0
ファイル: PShadowEffect.cs プロジェクト: zx8326123/LGame
        public PShadowEffect(LImage img, LImage back, int x, int y, int w, int h)
        {
            if (deasilTrans == null || widdershinTrans == null)
            {
                deasilTrans = new Color[max_pixel];
                for (int i = 0; i < max_pixel; i++)
                {
                    deasilTrans[i] = new Color(i, i, i);
                }
                int count = 0;
                widdershinTrans = new Color[max_pixel];
                for (int i = 0; i < max_pixel; i++)
                {
                    widdershinTrans[count++] = deasilTrans[i];
                }
            }
            this.SetLocation(x, y);
            this.width   = w;
            this.height  = h;
            this.visible = true;
            LImage temp = null;

            if (back == null)
            {
                this.scaleWidth      = width / 2;
                this.scaleHeight     = height / 2;
                temp                 = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
                this.image           = LImage.CreateImage(scaleWidth, scaleHeight, true);
                this.finalDrawPixels = temp.GetPixels();
                this.nowDrawPixels   = (Color[])CollectionUtils.CopyOf(finalDrawPixels);
                if (temp != null)
                {
                    temp.Dispose();
                    temp = null;
                }
            }
            else
            {
                this.scaleWidth  = width / 2;
                this.scaleHeight = height / 2;
                temp             = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
                this.image       = LImage.CreateImage(scaleWidth, scaleHeight, true);
                if (back.GetWidth() == scaleWidth &&
                    back.GetHeight() == scaleHeight)
                {
                    this.finalBackgroundPixels = back.GetPixels();
                    this.backgroundPixels      = (Color[])CollectionUtils
                                                 .CopyOf(finalBackgroundPixels);
                }
                else
                {
                    LImage tmp = GraphicsUtils.GetResize(back, scaleWidth,
                                                         scaleHeight);
                    this.finalBackgroundPixels = tmp.GetPixels();
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }
                    this.backgroundPixels = (Color[])CollectionUtils
                                            .CopyOf(finalBackgroundPixels);
                }
                this.finalDrawPixels = temp.GetPixels();
                this.nowDrawPixels   = (Color[])CollectionUtils.CopyOf(finalDrawPixels);
            }
            this.SetBlackToWhite(flag);
            if (temp != null)
            {
                temp.Dispose();
                temp = null;
            }
            if (img != null)
            {
                img.Dispose();
                img = null;
            }
            if (back != null)
            {
                back.Dispose();
                back = null;
            }
        }
コード例 #11
0
ファイル: GLLoader.cs プロジェクト: keppelcao/LGame
        private void Create(LImage image)
        {

            if (image == null)
            {
                return;
            }
            if (buffer != null)
            {
                return;
            }

            fileName = image.GetPath();


            this.isExt = image.isExt;
            this.hasAlpha = image.hasAlpha;
            int srcWidth = image.Width;
            int srcHeight = image.Height;

            if (GLEx.IsPowerOfTwo(srcWidth) && GLEx.IsPowerOfTwo(srcHeight))
            {
                this.width = srcWidth;
                this.height = srcHeight;
                this.texHeight = srcHeight;
                this.texWidth = srcWidth;
                this.buffer = image.GetBitmap();
                if (image.IsAutoDispose())
                {
                    image.Dispose();
                    image = null;
                }
                return;
            }

            int texWidth = GLEx.ToPowerOfTwo(srcWidth);
            int texHeight = GLEx.ToPowerOfTwo(srcHeight);

            this.width = srcWidth;
            this.height = srcHeight;
            this.texHeight = texHeight;
            this.texWidth = texWidth;
            Color[] src = image.GetPixels();
            Color[] dst = new Color[texWidth * texHeight];
            for (int size = 0; size < height; size++)
            {
                Array.Copy(src, size * width
                        , dst, size * texWidth, width);
            }
            if (buffer == null)
            {
                buffer = new Texture2D(GL.device, texWidth, texHeight);
            }
            buffer.SetData<Color>(dst);
            src = null;
            dst = null;
            if (image != null && image.IsAutoDispose())
            {
                image.Dispose();
                image = null;
            }
        }
コード例 #12
0
        public virtual void SetField2DBackground(Field2D field, Dictionary <object, object> pathMap,
                                                 string fileName)
        {
            SetField2D(field);
            LImage background = null;

            if (fileName != null)
            {
                LImage tmp = LImage.CreateImage(fileName);
                background = SetTileBackground(tmp, true);
                if (tmp != null)
                {
                    tmp.Dispose();
                    tmp = null;
                }
            }
            else
            {
                background = LImage.CreateImage(GetWidth(), GetHeight(), false);
            }
            int srcWidth  = GetWidth();
            int srcHeight = GetHeight();

            //在C#环境下LGraphics采取像素渲染,得不到硬件加速,此处直接将像素操作方法粘过来了(虽然也快不了几毫秒……)
            int[] dstColors = background.GetIntPixels();
            int[] srcColors = null;
            for (int i = 0; i < field.GetWidth(); i++)
            {
                for (int j = 0; j < field.GetHeight(); j++)
                {
                    int    index = field.GetType(j, i);
                    object o     = CollectionUtils.Get(pathMap, index);
                    if (o != null)
                    {
                        if (o is LImage)
                        {
                            LImage img = (LImage)o;
                            srcColors = img.GetIntPixels();
                            int w = img.Width;
                            int h = img.Height;
                            int y = field.TilesToHeightPixels(j);
                            int x = field.TilesToWidthPixels(i);
                            if (x < 0)
                            {
                                w += x;
                                x  = 0;
                            }
                            if (y < 0)
                            {
                                h += y;
                                y  = 0;
                            }
                            if (x + w > srcWidth)
                            {
                                w = srcWidth - x;
                            }
                            if (y + h > srcHeight)
                            {
                                h = srcHeight - y;
                            }
                            if (img.hasAlpha)
                            {
                                int findIndex = y * srcWidth + x;
                                int drawIndex = 0;
                                int moveFind  = srcWidth - w;
                                for (int col = 0; col < h; col++)
                                {
                                    for (int row = 0; row < w;)
                                    {
                                        if (srcColors[drawIndex] != 0)
                                        {
                                            dstColors[findIndex] = srcColors[drawIndex];
                                        }
                                        row++;
                                        findIndex++;
                                        drawIndex++;
                                    }
                                    findIndex += moveFind;
                                }
                            }
                            else
                            {
                                for (int size = 0; size < h; size++)
                                {
                                    System.Array.Copy(srcColors, size * w, dstColors,
                                                      (y + size) * srcWidth + x, w);
                                }
                            }
                        }
                        else if (o is Actor)
                        {
                            AddObject(((Actor)o), field.TilesToWidthPixels(i),
                                      field.TilesToHeightPixels(j));
                        }
                    }
                }
            }
            background.SetIntPixels(dstColors);
            background.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED);
            SetBackground(background.GetTexture());
            srcColors = null;
            dstColors = null;
            if (background != null)
            {
                background.Dispose();
                background = null;
            }
        }
コード例 #13
0
ファイル: AVGDialog.cs プロジェクト: zx8326123/LGame
        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);
        }
コード例 #14
0
ファイル: GLLoader.cs プロジェクト: zhwk022/LGame
        private void Create(LImage image)
        {
            if (image == null)
            {
                return;
            }
            if (buffer != null)
            {
                return;
            }

            fileName = image.GetPath();


            this.isExt    = image.isExt;
            this.hasAlpha = image.hasAlpha;
            int srcWidth  = image.Width;
            int srcHeight = image.Height;

            if (GLEx.IsPowerOfTwo(srcWidth) && GLEx.IsPowerOfTwo(srcHeight))
            {
                this.width     = srcWidth;
                this.height    = srcHeight;
                this.texHeight = srcHeight;
                this.texWidth  = srcWidth;
                this.buffer    = image.GetBitmap();
                if (image.IsAutoDispose())
                {
                    image.Dispose();
                    image = null;
                }
                return;
            }

            int texWidth  = GLEx.ToPowerOfTwo(srcWidth);
            int texHeight = GLEx.ToPowerOfTwo(srcHeight);

            this.width     = srcWidth;
            this.height    = srcHeight;
            this.texHeight = texHeight;
            this.texWidth  = texWidth;
            Color[] src = image.GetPixels();
            Color[] dst = new Color[texWidth * texHeight];
            for (int size = 0; size < height; size++)
            {
                Array.Copy(src, size * width
                           , dst, size * texWidth, width);
            }
            if (buffer == null)
            {
                buffer = new Texture2D(GL.device, texWidth, texHeight);
            }
            buffer.SetData <Color>(dst);
            src = null;
            dst = null;
            if (image != null && image.IsAutoDispose())
            {
                image.Dispose();
                image = null;
            }
        }
コード例 #15
0
        private void Init(LTexture tex2d, float limit, bool remove, float scale)
        {
            this.isVisible    = true;
            this.expandLimit  = limit;
            this.width        = tex2d.GetWidth();
            this.height       = tex2d.GetHeight();
            this.scaleWidth   = (int)(width * scale);
            this.scaleHeight  = (int)(height * scale);
            this.loopMaxCount = (MathUtils.Max(scaleWidth, scaleHeight) / 2) + 1;
            this.fractions    = new float[(scaleWidth * scaleHeight) * maxElements];
            this.exWidth      = (int)(scaleWidth * expandLimit);
            this.exHeigth     = (int)(scaleHeight * expandLimit);
            LImage image = tex2d.GetImage().ScaledInstance(scaleWidth, scaleHeight);

            Color[] pixels = image.GetPixels();
            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            this.size   = pixels.Length;
            this.pixmap = new LPixmapData(exWidth, exHeigth, true);
            int   no = 0, idx = 0;
            int   length = fractions.Length;
            float angle  = 0;
            float speed  = 0;

            System.Random random = LSystem.random;
            for (int y = 0; y < scaleHeight; y++)
            {
                for (int x = 0; x < scaleWidth; x++)
                {
                    if (idx + maxElements < length)
                    {
                        no    = y * scaleWidth + x;
                        angle = random.Next(360);
                        speed = 10f / random.Next(30);
                        fractions[idx + 0] = x;
                        fractions[idx + 1] = y;
                        fractions[idx + 2] = (MathUtils.Cos(angle * MathUtils.PI
                                                            / 180) * speed);
                        fractions[idx + 3] = (MathUtils.Sin(angle * MathUtils.PI
                                                            / 180) * speed);
                        fractions[idx + 4] = (pixels[no].PackedValue == 0xff00 ? 0xffffff
                                                        : pixels[no].PackedValue);
                        fractions[idx + 5] = x / 6 + random.Next(10);
                        idx += maxElements;
                    }
                }
            }
            if (remove)
            {
                if (tex2d != null)
                {
                    tex2d.Destroy();
                    tex2d = null;
                }
            }
            this.tmp = tex2d;
            this.StartUsePixelThread();
        }