public EmulatorButton(LTexture img, int w, int h, int x, int y,
                bool flag, int sizew, int sizeh)
        {
            this.color = new LColor(LColor.gray.R, LColor.gray.G,
                            LColor.gray.B, 125);
            img.LoadTexture();
            if (flag)
               {
                this.bitmap = img.GetSubTexture(x, y, w, h);
            }
            else
            {
                this.bitmap = img;
            }
            if (bitmap.GetWidth() != sizew || bitmap.GetHeight() != sizeh)
            {

                LTexture tmp = bitmap;
                this.bitmap = bitmap.Scale(sizew, sizeh);

                if (tmp != null)
                {
                    tmp.Dispose();
                    tmp = null;
                }
            }
            this.bounds = new RectBox(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
        }
        public void Draw(LTexture texture, float x, float y, float originX,
            float originY, float width, float height, float scaleX,
            float scaleY, float rotation, float srcX, float srcY,
            float srcWidth, float srcHeight, bool flipX, bool flipY,
            bool off)
        {
            if (isClose)
            {
                return;
            }
            if (texture == null)
            {
                return;
            }
            if (!texture.isLoaded)
            {
                texture.LoadTexture();
            }
            if (texture.IsChild)
            {
                float xOff = ((srcX / texture.width) * texture.widthRatio) + texture.xOff;
                float yOff = ((srcY / texture.height) * texture.heightRatio) + texture.yOff;
                float widthRatio = ((srcWidth / texture.width) * texture.widthRatio);
                float heightRatio = ((srcHeight / texture.height) * texture.heightRatio);

                int newX = (int)(xOff * texture.texWidth);
                int newY = (int)(yOff * texture.texHeight);
                int newWidth = (int)((texture.texWidth * widthRatio)) - newX;
                int newHeight = (int)((texture.texHeight * heightRatio)) - newY;

                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = (int)(width * scaleX);
                texDst.Height = (int)(height * scaleY);
                texSrc.X = newX;
                texSrc.Y = newY;
                texSrc.Width = newWidth;
                texSrc.Height = newHeight;
            }
            else
            {
                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = (int)(width * scaleX);
                texDst.Height = (int)(height * scaleY);
                texSrc.X = (int)srcX;
                texSrc.Y = (int)srcY;
                texSrc.Width = (int)(srcWidth - srcX);
                texSrc.Height = (int)(srcHeight - srcY);
            }

            Load(texture);

            SpriteEffects e = SpriteEffects.None;

            if (flipX && !flipY)
            {
                e = SpriteEffects.FlipHorizontally;
            }
            else
                if (flipY && !flipX)
                {
                    e = SpriteEffects.FlipVertically;
                }
                else
                    if (flipX && flipY)
                    {
                        e = SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically;
                    }

            if (rotation != 0)
            {
                float centerX = texSrc.Width / 2;
                float centerY = texSrc.Height / 2;
                texDst.X += (int)texDst.Width / 2;
                texDst.Y += (int)texDst.Height / 2;
                origin.X = centerX;
                origin.Y = centerY;
                batch.Draw(texture.Texture, texDst, texSrc, color, MathUtils.ToRadians(rotation), origin, e, 0);
            }
            else if (originX != 0 || originX != 0)
            {
                texDst.X += (int)originX;
                texDst.Y += (int)originY;
                origin.X = originX;
                origin.Y = originY;
                batch.Draw(texture.Texture, texDst, texSrc, color, 0, origin, e, 0);
            }
            else
            {
                batch.Draw(texture.Texture, texDst, texSrc, color, 0, Vector2.Zero, e, 0);
            }
            idx++;
        }
        public void Draw(LTexture texture, float x, float y, float width,
            float height, float srcX, float srcY, float srcWidth,
            float srcHeight, bool flipX, bool flipY)
        {
            if (isClose)
            {
                return;
            }
            if (texture == null)
            {
                return;
            }
            if (!texture.isLoaded)
            {
                texture.LoadTexture();
            }
            if (texture.IsChild)
            {
                float xOff = ((srcX / texture.width) * texture.widthRatio) + texture.xOff;
                float yOff = ((srcY / texture.height) * texture.heightRatio) + texture.yOff;
                float widthRatio = ((srcWidth / texture.width) * texture.widthRatio);
                float heightRatio = ((srcHeight / texture.height) * texture.heightRatio);

                int newX = (int)(xOff * texture.texWidth);
                int newY = (int)(yOff * texture.texHeight);
                int newWidth = (int)((texture.texWidth * widthRatio)) - newX;
                int newHeight = (int)((texture.texHeight * heightRatio)) - newY;

                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = (int)(width);
                texDst.Height = (int)(height);
                texSrc.X = newX;
                texSrc.Y = newY;
                texSrc.Width = newWidth;
                texSrc.Height = newHeight;
            }
            else
            {
                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = (int)(width);
                texDst.Height = (int)(height);
                texSrc.X = (int)srcX;
                texSrc.Y = (int)srcY;
                texSrc.Width = (int)(srcWidth - srcX);
                texSrc.Height = (int)(srcHeight - srcY);
            }

            Load(texture);

            SpriteEffects e = SpriteEffects.None;

            if (flipX && !flipY)
            {
                e = SpriteEffects.FlipHorizontally;
            }
            else
                if (flipY && !flipX)
                {
                    e = SpriteEffects.FlipVertically;
                }
                else
                    if (flipX && flipY)
                    {
                        e = SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically;
                    }

            batch.Draw(texture.Texture, texDst, texSrc, color, 0, Vector2.Zero, e, 0);

            idx++;
        }
        public void Draw(LTexture texture, float x, float y, float rotation)
        {
            if (isClose)
            {
                return;
            }
            if (texture == null)
            {
                return;
            }

            if (!texture.isLoaded)
            {
                texture.LoadTexture();
            }
            if (texture.IsChild)
            {
                float xOff = texture.xOff;
                float yOff = texture.yOff;
                float widthRatio = (1f * texture.widthRatio);
                float heightRatio = (1f * texture.heightRatio);
                int newX = (int)(xOff * texture.texWidth);
                int newY = (int)(yOff * texture.texHeight);
                int newWidth = (int)((texture.texWidth * widthRatio)) - newX;
                int newHeight = (int)((texture.texHeight * heightRatio)) - newY;

                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = texture.width;
                texDst.Height = texture.height;
                texSrc.X = newX;
                texSrc.Y = newY;
                texSrc.Width = newWidth;
                texSrc.Height = newHeight;
            }
            else
            {
                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = texture.Width;
                texDst.Height = texture.Height;
                texSrc.X = 0;
                texSrc.Y = 0;
                texSrc.Width = texture.Width;
                texSrc.Height = texture.Height;
            }

            Load(texture);

            if (rotation != 0)
            {
                float centerX = texSrc.Width / 2;
                float centerY = texSrc.Height / 2;
                texDst.X += (int)texture.Width / 2;
                texDst.Y += (int)texture.Height / 2;
                origin.X = centerX;
                origin.Y = centerY;
                batch.Draw(texture, texDst, texSrc, color, MathUtils.ToRadians(rotation), origin, SpriteEffects.None, 0);
            }
            else
            {
                batch.Draw(texture, texDst, texSrc, color);
            }
            idx++;
        }
        public void Draw(LTexture texture, float x, float y, float width, float height)
        {
            if (isClose)
            {
                return;
            }
            if (texture == null)
            {
                return;
            }

            if (!texture.isLoaded)
            {
                texture.LoadTexture();
            }
            if (texture.IsChild)
            {
                float xOff = texture.xOff;
                float yOff = texture.yOff;
                float widthRatio = (1f * texture.widthRatio);
                float heightRatio = (1f * texture.heightRatio);
                int newX = (int)(xOff * texture.texWidth);
                int newY = (int)(yOff * texture.texHeight);
                int newWidth = (int)((texture.texWidth * widthRatio)) - newX;
                int newHeight = (int)((texture.texHeight * heightRatio)) - newY;

                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = (int)width;
                texDst.Height = (int)height;
                texSrc.X = newX;
                texSrc.Y = newY;
                texSrc.Width = newWidth;
                texSrc.Height = newHeight;
            }
            else
            {
                texDst.X = (int)x;
                texDst.Y = (int)y;
                texDst.Width = (int)width;
                texDst.Height = (int)height;
                texSrc.X = 0;
                texSrc.Y = 0;
                texSrc.Width = texture.Width;
                texSrc.Height = texture.Height;
            }

            Load(texture);

            batch.Draw(texture, texDst, texSrc, color);

            idx++;
        }
Exemple #6
0
        public void LoadTexture()
        {
            lock (this)
            {
                if (isLoaded)
                {
                    return;
                }
                if (parent != null)
                {
                    textureID = parent.textureID;
                    isLoaded  = parent.isLoaded;
                    parent.LoadTexture();
                    isOpaque = parent.isOpaque;
                    if (width == 0)
                    {
                        width = parent.Width;
                    }
                    if (height == 0)
                    {
                        height = parent.Height;
                    }
                    if (texWidth == 0)
                    {
                        texWidth = width;
                    }
                    if (texHeight == 0)
                    {
                        texHeight = height;
                    }
                    isLoaded = true;
                    return;
                }

                if (!isLoaded)
                {
                    if (isBitmapTexture)
                    {
                        if (format.Equals(null))
                        {
                            tex2d = new Texture2D(GLEx.Device, width, height);
                        }
                        else
                        {
                            tex2d = new Texture2D(GLEx.Device, width, height, false, format);
                        }
                        bool    alpha  = SurfaceFormat.Color.Equals(format);
                        int     size   = width * height;
                        Color[] pixels = new Color[size];
                        for (int i = 0; i < size; i++)
                        {
                            if (alpha)
                            {
                                pixels[i] = new Color(0, 0, 0, 0);
                            }
                            else
                            {
                                pixels[i] = new Color(0, 0, 0, 255);
                            }
                        }
                        tex2d.SetData(pixels);
                    }
                    else
                    {
                        if (!isExt)
                        {
                            if (tex2d == null)
                            {
                                this.tex2d = LFXPlus.Get.Load <Texture2D>(fileName);
                            }
                        }
                        else
                        {
                            if (zoom)
                            {
                                if (tex2d == null)
                                {
                                    tex2d = Texture2D.FromStream(GLEx.Device, ins, width, height, zoom);
                                }
                            }
                            else
                            {
                                if (tex2d == null)
                                {
                                    tex2d = Texture2D.FromStream(GLEx.Device, ins);
                                }
                            }
                        }
                    }
                    this.isLoaded  = true;
                    this.width     = tex2d.Width;
                    this.height    = tex2d.Height;
                    this.texWidth  = width;
                    this.texHeight = height;
                    if (ins != null)
                    {
                        ins.Close();
                        ins = null;
                    }
                    LTextures.LoadTexture(this);
                }
            }

            this.isOpaque    = (BlendState.Opaque == tex2d.GraphicsDevice.BlendState) && !isExt;
            this.widthRatio  = (float)width / (texWidth < 1 ? width : texWidth);
            this.heightRatio = (float)height / (texHeight < 1 ? height : texHeight);
            this.CheckPowerOfTwoSize();
        }
Exemple #7
0
 public void GLBegin(BlendState state)
 {
     texture.LoadTexture();
     batch.Begin(SpriteSortMode.Deferred, state, null, null, null, null, GLEx.cemera.viewMatrix);
     useBegin = true;
 }
 public static LTexture[] GetSplitTextures(LTexture image, int width, int height)
 {
     if (image == null)
     {
         return null;
     }
     image.LoadTexture();
     int frame = 0;
     int wlength = image.Width / width;
     int hlength = image.Height / height;
     int total = wlength * hlength;
     LTexture[] images = new LTexture[total];
     for (int y = 0; y < hlength; y++)
     {
         for (int x = 0; x < wlength; x++)
         {
             images[frame] = image.GetSubTexture((x * width), (y * height), width,
                     height);
             frame++;
         }
     }
     return images;
 }
        public static LTexture[][] GetSplit2Textures(LTexture image, int row,
                int col)
        {
            if (image == null) {
                return null;
            }
            image.LoadTexture();

            int wlength = image.Width / row;
            int hlength = image.Height / col;
            LTexture[][] textures = (LTexture[][])CollectionUtils.XNA_CreateJaggedArray(typeof(LTexture), wlength, hlength);
            for (int y = 0; y < hlength; y++) {
                for (int x = 0; x < wlength; x++) {
                    textures[x][y] = image.GetSubTexture((x * row), (y * col), row,
                            col);
                }
            }
            return textures;
        }
Exemple #10
0
 public void DrawBatch(LTexture texture, float x, float y, float width,
         float height, float srcX, float srcY, float srcWidth,
         float srcHeight, float rotation, Color c)
 {
     if (isClose)
     {
         return;
     }
     if (texture == null)
     {
         return;
     }
     if (!texture.isLoaded)
     {
         texture.LoadTexture();
     }
     initAlphaBlend = !texture.isExt;
     if (texture.IsChild)
     {
         float xOff = ((srcX / texture.width) * texture.widthRatio) + texture.xOff;
         float yOff = ((srcY / texture.height) * texture.heightRatio) + texture.yOff;
         float widthRatio = ((srcWidth / texture.width) * texture.widthRatio);
         float heightRatio = ((srcHeight / texture.height) * texture.heightRatio);
         int newX = (int)(xOff * texture.texWidth);
         int newY = (int)(yOff * texture.texHeight);
         int newWidth = (int)((texture.texWidth * widthRatio)) - newX;
         int newHeight = (int)((texture.texHeight * heightRatio)) - newY;
         texDst.X = (int)x;
         texDst.Y = (int)y;
         texDst.Width = (int)width;
         texDst.Height = (int)height;
         texSrc.X = newX;
         texSrc.Y = newY;
         texSrc.Width = newWidth;
         texSrc.Height = newHeight;
     }
     else
     {
         texDst.X = (int)x;
         texDst.Y = (int)y;
         texDst.Width = (int)width;
         texDst.Height = (int)height;
         texSrc.X = (int)srcX;
         texSrc.Y = (int)srcY;
         texSrc.Width = (int)(srcWidth - srcX);
         texSrc.Height = (int)(srcHeight - srcY);
     }
     if (c == null)
     {
         c = Color.White;
     }
     if (rotation != 0)
     {
         float centerX = texSrc.Width / 2;
         float centerY = texSrc.Height / 2;
         texDst.X += (int)width / 2;
         texDst.Y += (int)height / 2;
         UPos(centerX, centerY);
         batchSprite.Draw(texture.Texture, texDst, texSrc, c, MathUtils.ToRadians(rotation), postion, SpriteEffects.None, 0);
     }
     else
     {
         batchSprite.Draw(texture.Texture, texDst, texSrc, c);
     }
 }