Exemple #1
0
 public ImageObject(IImage image, UIEngine engine, String name)
     : base("ImageObject", name)
 {
     this.engine = engine;
     this.missing = false;
     this.image = image;
 }
        public override void DrawImage(int x, int y, int w, int h, IImage image, float us, float vs, float ue, float ve, Color color, bool outLineOnly)
        {
            Texture2D texture = ((XNAImage)image).Texture;
            Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, w, h);
            Microsoft.Xna.Framework.Color imageColor = new Microsoft.Xna.Framework.Color(color.R, color.G, color.B, color.A);
            Microsoft.Xna.Framework.Rectangle sourceRectangle = new Microsoft.Xna.Framework.Rectangle((int)(us * texture.Width), (int)(ue * texture.Height), (int)(vs * texture.Width), (int)(ve * texture.Height));

            this.spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, imageColor);
        }
Exemple #3
0
 public BitmapLetter(IImage image, int width, int height, float s1, float t1, float s2, float t2, int letterWidth)
 {
     this.letterWidth = letterWidth;
     this.texture = image;
     this.width = width;
     this.height = height;
     this.texCoords[0] = s1;
     this.texCoords[1] = t1;
     this.texCoords[2] = s2;
     this.texCoords[3] = t2;
 }
Exemple #4
0
        public void Render(Graphics graphics, int x, int y, int w, int h, Color color, float opacity, ImageLayout layout)
        {
            if (false == this.missing)
            {
                if (null == this.image)
                {
                    this.image = this.engine.CreateImage(this.Name);

                    if (null == this.image)
                    {
                        this.missing = true;

                        return;
                    }
                }

                if ((0.0f == this.image.Width) || (0.0f == this.image.Height))
                {
                    return;
                }

                if ((null == color) || (opacity <= 0.0f) || (opacity == 1.0f && (color.A <= 0.0f)))
                {
                    return;
                }

                graphics.SetColor(color, opacity);

                switch (layout)
                {
                    case ImageLayout.ImageLayoutNone: // +
                        {
                            graphics.SetRegion(x, y, w, h);
                            graphics.DrawImage(x, y, this.image.Width, this.image.Height, this.image);
                            graphics.ClearRegion();
                        }
                        break;
                    case ImageLayout.ImageLayoutCenter: // +
                        {
                            int offX = (w - this.image.Width) / 2;
                            int offY = (h - this.image.Height) / 2;
                            graphics.SetRegion(x, y, w, h);
                            graphics.DrawImage(x + offX, y + offY, this.image.Width, this.image.Height, this.image);
                            graphics.ClearRegion();
                        }
                        break;
                    case ImageLayout.ImageLayoutStretch:
                        graphics.DrawImage(x, y, w, h, this.image);
                        break;
                    case ImageLayout.ImageLayoutTile: // +
                        {
                            float u = (float)(w) / (float)(this.image.Width);
                            float v = (float)(h) / (float)(this.image.Height);
                            graphics.DrawImage(x, y, w, h, this.image, u, v);
                        }
                        break;
                    case ImageLayout.ImageLayoutZoom: // +
                        {
                            float ri = (float)(this.image.Width) / (float)(this.image.Height);

                            int newW = w;
                            int newH = (int)((float)(newW) / ri);
                            int px = x;
                            int py = y + (h - newH) / 2;

                            if (newH > h)
                            {
                                newH = h;
                                newW = (int)((float)(newH) * ri);
                                px = x + (w - newW) / 2;
                                py = y;
                            }

                            graphics.DrawImage(px, py, newW, newH, this.image);
                        }
                        break;
                    case ImageLayout.ImageLayoutFillWidth:
                        {
                            int dy = (int)((w - h) / 2);

                            graphics.SetRegion(x, y, w, h);

                            graphics.DrawImage(x, y - dy, w, h + dy * 2, this.image);

                            graphics.ClearRegion();
                        }
                        break;
                    default:
                        break;
                }
            }
        }
Exemple #5
0
        public void DrawImage(int x, int y, int w, int h, IImage image, float us, float vs, float ue, float ve, ThW.UI.Utils.Color color, bool outLineOnly)
        {
            if ((null != this.graphics) && (null != image))
            {
                if (true == outLineOnly)
                {
                    Pen pen = new Pen(System.Drawing.Color.FromArgb((int)(color.A * 0xff), (int)(color.R * 0xff), (int)(color.G * 0xff), (int)(color.B * 0xff)));

                    this.graphics.DrawRectangle(pen, x, y, w, h);
                }
                else
                {
                    Image bmp = ((GDIImage)image).Image;

                    System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(x, y, w, h);

                    ImageAttributes imageAttributes = new ImageAttributes();

                    float[][] pointsArray =
                    {
                        new float[] { color.R,  0,  0,  0, 0 },
                        new float[] { 0,  color.G,  0,  0, 0 },
                        new float[] { 0,  0,  color.B,  0, 0 },
                        new float[] { 0,  0,  0,  color.A, 0 },
                        new float[] { 0, 0, 0, 0, 1}
                    };

                    try
                    {
                        ColorMatrix clrMatrix = new ColorMatrix(pointsArray);
                        imageAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Default);
                        imageAttributes.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile);
                        this.graphics.DrawImage(bmp, rectangle, us * bmp.Width, vs * bmp.Height, bmp.Width * (ue - us), bmp.Height * (ve - vs), GraphicsUnit.Pixel, imageAttributes);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// Sets letter iamge data. assigns bitmap and position where on it resides cached letter.
 /// </summary>
 /// <param name="image">image containing several rendered letter bitmaps.</param>
 /// <param name="us">us texture coordinate for this letter.</param>
 /// <param name="vs">vs texture coordinate for this letter.</param>
 /// <param name="ue">ue texture coordinate for this letter.</param>
 /// <param name="ve">ve texture coordinate for this letter.</param>
 internal void SetCachedData(IImage image, int us, int vs, int ue, int ve)
 {
     this.loaded = true;
     this.Image = image;
     //            this.internalImage = false;
     this.uv[0] = us;
     this.uv[1] = vs;
     this.uv[2] = ue;
     this.uv[3] = ve;
     this.textureWidth = this.uv[2] - this.uv[0];
     this.textureHeight = this.uv[3] - this.uv[1];
     this.uvs[0] = (float)this.uv[0] / (float)WinFontCached.cacheTextureSize;//(float)image.Width;
     this.uvs[1] = (float)this.uv[1] / (float)WinFontCached.cacheTextureSize;//(float)image.Height;
     this.uvs[2] = (float)this.uv[2] / (float)WinFontCached.cacheTextureSize;//(float)image.Width;
     this.uvs[3] = (float)this.uv[3] / (float)WinFontCached.cacheTextureSize;//(float)image.Height;
 }
Exemple #7
0
 public void DrawImage(int x, int y, int w, int h, IImage image, float us, float vs, float ue, float ve, Color color, bool outLineOnly)
 {
 }
Exemple #8
0
        /// <summary>
        /// Renders checkbox tick
        /// </summary>
        /// <param name="graphics">graphics t orender to</param>
        /// <param name="X">X position</param>
        /// <param name="Y">Y position</param>
        protected void RenderCheck(Graphics graphics, int x, int y)
        {
            if (true == this.Checked)
            {
                if (null == this.tick)
                {
                    this.tick = this.Engine.CreateImage(this.Window.Desktop.Theme.ThemeFolder + "/images/checkbox_tick");
                }

                if (null != this.tick)
                {
                    int off = (this.Bounds.Height - this.tick.Height) / 2;

                    graphics.DrawImage(off + x + this.Bounds.X, off + y + this.Bounds.Y, this.tick.Width, this.tick.Height, this.tick);
                }
            }
        }
Exemple #9
0
 public ImageObject(IImage image, UIEngine engine, String name) : base("ImageObject", name)
 {
     this.engine  = engine;
     this.missing = false;
     this.image   = image;
 }
Exemple #10
0
 /// <summary>
 /// Draws image.
 /// </summary>
 /// <param name="u">u texture coord value</param>
 /// <param name="v">v texture coord value</param>
 public void DrawImage(int x, int y, int w, int h, IImage image, float u, float v)
 {
     DrawImage(x, y, w, h, image, 0.0f, 0.0f, u, v, false);
 }
Exemple #11
0
 public void DrawImage(int x, int y, int w, int h, IImage image, float[] uvs)
 {
     DrawImage(x, y, w, h, image, uvs[0], uvs[1], uvs[2], uvs[3], false);
 }
Exemple #12
0
 /// <summary>
 /// Draws image.
 /// </summary>
 public void DrawImage(int x, int y, int w, int h, IImage image)
 {
     DrawImage(x, y, w, h, image, 1.0f, 1.0f);
 }
Exemple #13
0
 internal void SetRender(IRender render)
 {
     if (null != render)
     {
         this.render = render;
         this.whiteImage = this.render.CreateImage(2, 2, new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } );
     }
     else
     {
         this.render = new NullRender();
         this.whiteImage = null;
     }
 }
Exemple #14
0
        public void DrawImage(int x, int y, int w, int h, IImage image, float u0, float v0, float u, float v, bool outLineOnly)
        {
            // X = (int)((float)X * 1.5f);
               // Y = (int)((float)Y * 1.5f);
             //   Width = (int)((float)Width * 1.5f);
               //     Height = (int)((float)Height * 1.5f);

            if (null != this.clipView)
            {
                if (y > this.clipView.Y + this.clipView.Height)
                {
                    return;
                }

                if (x > this.clipView.X + this.clipView.Width)
                {
                    return;
                }

                if (x + w < this.clipView.X)
                {
                    return;
                }

                if (y + h < this.clipView.Y)
                {
                    return;
                }

                int h_ = h;

                if ((y <= this.clipView.Y + this.clipView.Height) && (y + h >= this.clipView.Y + this.clipView.Height))
                {
                    v = v * (float)(this.clipView.Y + this.clipView.Height - y) / (float)h_;
                    h = this.clipView.Y + this.clipView.Height - y;
                }

                if ((y <= this.clipView.Y) && (y + h >= this.clipView.Y))
                {
                    v0 = 0.0f + (float)(this.clipView.Y - y) / (float)h_;
                    h = y - this.clipView.Y + h;
                    y = this.clipView.Y;
                }

                if ((x <= this.clipView.X + this.clipView.Width) && (x + w >= this.clipView.X + this.clipView.Width))
                {
                    u = u * (float)(this.clipView.X + this.clipView.Width - x) / (float)w;
                    w = this.clipView.X + this.clipView.Width - x;
                }

                if ((x <= this.clipView.X) && (x + w >= this.clipView.X))
                {
                    u0 = 0.0f + (float)(this.clipView.X - x) / (float)w;
                    w = x - this.clipView.X + w;
                    x = this.clipView.X;
                }

            }

            this.render.DrawImage(x, y, w, h, image, u0, v0, u, v, this.activeColor, outLineOnly);
        }
Exemple #15
0
        public virtual void DrawImage(int x, int y, int w, int h, IImage image, float us, float vs, float ue, float ve, ThW.UI.Utils.Color color, bool outLineOnly)
        {
            float d = -0.5f;

            XNAVertex[] v = new XNAVertex[4];
            v[0].Position.X = (float)x + d;
            v[0].Position.Y = (float)y + d;
            v[0].Position.Z = 0.0f;
            v[0].TextureCoordinate.X = us;
            v[0].TextureCoordinate.Y = vs;
            v[0].Color.R = (byte)(255 * color.R);
            v[0].Color.G = (byte)(255 * color.G);
            v[0].Color.B = (byte)(255 * color.B);
            v[0].Color.A = (byte)(255 * color.A);

            v[1].Position.X = (float)x + (float)w + d;
            v[1].Position.Y = (float)y + d;
            v[1].Position.Z = 0.0f;
            v[1].TextureCoordinate.X = ue;
            v[1].TextureCoordinate.Y = vs;
            v[1].Color.R = (byte)(255 * color.R);
            v[1].Color.G = (byte)(255 * color.G);
            v[1].Color.B = (byte)(255 * color.B);
            v[1].Color.A = (byte)(255 * color.A);

            v[2].Position.X = (float)x + d;
            v[2].Position.Y = (float)y + (float)h + d;
            v[2].Position.Z = 0.0f;
            v[2].TextureCoordinate.X = us;
            v[2].TextureCoordinate.Y = ve;
            v[2].Color.R = (byte)(255 * color.R);
            v[2].Color.G = (byte)(255 * color.G);
            v[2].Color.B = (byte)(255 * color.B);
            v[2].Color.A = (byte)(255 * color.A);

            v[3].Position.X = (float)x + (float)w + d;
            v[3].Position.Y = (float)y + (float)h + d;
            v[3].Position.Z = 0.0f;
            v[3].TextureCoordinate.X = ue;
            v[3].TextureCoordinate.Y = ve;
            v[3].Color.R = (byte)(255 * color.R);
            v[3].Color.G = (byte)(255 * color.G);
            v[3].Color.B = (byte)(255 * color.B);
            v[3].Color.A = (byte)(255 * color.A);

            short[] indx = { 0, 1, 3, 3, 2, 0 };

            this.effect2d.Texture = ((XNAImage)image).Texture;

            foreach (EffectPass pass in this.effect2d.CurrentTechnique.Passes)
            {
                pass.Apply();

                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, v, 0, 4, indx, 0, 2, this.vertexShaderDeclaration);
            }
        }
Exemple #16
0
        /// <summary>
        /// Deletes image.
        /// </summary>
        internal void DeleteImage(ref IImage image)
        {
            if (null == image)
            {
                return;
            }

            if (image.Release() <= 0)
            {
                this.cachedImages.Remove(image.Name);
                image.Dispose();
            }
        }
Exemple #17
0
 internal void SetIcon(IImage pImage)
 {
     this.engine.DeleteImage(ref this.image);
     this.image = pImage;
 }
Exemple #18
0
 /// <summary>
 /// Sets letter iamge data. assigns bitmap and position where on it resides cached letter.
 /// </summary>
 /// <param name="image">image containing several rendered letter bitmaps.</param>
 /// <param name="us">us texture coordinate for this letter.</param>
 /// <param name="vs">vs texture coordinate for this letter.</param>
 /// <param name="ue">ue texture coordinate for this letter.</param>
 /// <param name="ve">ve texture coordinate for this letter.</param>
 /// <param name="Width">letter Width.</param>
 /// <param name="offX">letter X offset.</param>
 /// <param name="offY">letter Y offset.</param>
 internal void SetCachedData(IImage image, int us, int vs, int ue, int ve, int w, int offX, int offY)
 {
     SetCachedData(image, us, vs, ue, ve);
     this.width = w;
     this.offsetX = offX;
     this.offsetY = offY;
 }
Exemple #19
0
 public void DrawImage(int x, int y, int w, int h, IImage image, float us, float vs, float ue, float ve, Color color, bool outLineOnly)
 {
 }
Exemple #20
0
        /// <summary>
        /// Creates requested image. If image file not found creates dotted texture.
        /// </summary>
        internal IImage CreateImage(String fileName, UIEngine engine, Graphics graphics)
        {
            if (null == fileName)
            {
                var img = new Image(fileName, new byte[2 * 2 * 4], 2, 2, 32);

                return(graphics.CreateImage((int)img.Width, (int)img.Height, img.Bytes));
            }

            IImage image = null;
            Object file  = null;

            try
            {
                this.cachedImages.TryGetValue(fileName, out image);

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

                if (true == fileName.StartsWith("#shell32,"))
                {
                    image = engine.GetIcon(int.Parse(fileName.Substring("#shell32,".Length)), true, null);

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

                image = graphics.CreateImage(fileName);

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

                byte[] imageData = null;
                uint   size      = 0;


                if (true == engine.OpenFile(fileName, out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName);
                }
                else if (true == engine.OpenFile(fileName + ".png", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".png");
                }
                else if (true == engine.OpenFile(fileName + ".jpg", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".jpg");
                }
                else if (true == engine.OpenFile(fileName + ".tga", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".tga");

                    if (null == image)
                    {
                        IImageLoader imageLoader = new TgaImageLoader(engine);

                        Image img = imageLoader.CreateImage(fileName);

                        if (null != img)
                        {
                            image = graphics.CreateImage((int)img.Width, (int)img.Height, img.Bytes);
                        }
                    }
                }

                return(image);
            }
            finally
            {
                if (null != image)
                {
                    image.Name = fileName;

                    image.AddRef();

                    this.cachedImages[fileName] = image;
                }

                if (null != file)
                {
                    engine.CloseFile(ref file);
                }
            }
        }