예제 #1
0
        public void LoadImage(string filepath, IGUIContext ctx, float opacity = 1f)
        {
            if (m_ImageFilePath != filepath)
            {
                m_ImageFilePath = filepath;

                if (Image != null)
                {
                    Image.Dispose();
                    Image = null;
                }

                if (String.IsNullOrEmpty(filepath) || ctx == null)
                {
                    return;
                }

                try {
                    Image         = TextureImage.FromFile(filepath, ctx);
                    Image.Opacity = opacity;
                } catch (Exception ex) {
                    ex.LogError();
                }
            }
        }
예제 #2
0
        public static TextureImage FromBitmap(Bitmap bmp, IGUIContext ctx, string key, Size size = default(Size))
        {
            if (bmp == null || bmp.Width < 1 || bmp.Height < 1)
            {
                return(null);
            }

            try {
                TextureImage retVal = new TextureImage(key);
                if (size != Size.Empty && size != bmp.Size)
                {
                    using (Bitmap bmpScaled = new Bitmap(bmp, size))
                    {
                        retVal.TextureID = LoadTexture(bmpScaled, ctx);
                        retVal.Size      = bmpScaled.Size;
                        retVal.PixFormat = bmpScaled.PixelFormat;
                    }
                }
                else
                {
                    retVal.TextureID = LoadTexture(bmp, ctx);
                    retVal.Size      = bmp.Size;
                    retVal.PixFormat = bmp.PixelFormat;
                }
                return(retVal);
            } catch (Exception ex) {
                ex.LogError();
                throw;
            }
        }
예제 #3
0
        public void LoadTextureImageFromFile(string filepath, IGUIContext ctx)
        {
            filepath = filepath.FixedExpandedPath();

            if (m_ImageFilePath != filepath)
            {
                m_ImageFilePath = filepath;

                if (Image != null)
                {
                    Image.Dispose();
                    Image = null;
                }

                if (String.IsNullOrEmpty(filepath) || ctx == null)
                {
                    return;
                }

                try {
                    Image = TextureImage.FromFile(filepath, ctx);
                } catch (Exception ex) {
                    ex.LogError();
                }
            }
        }
예제 #4
0
 public bool AddImage(TextureImage image)
 {
     if (image == null || String.IsNullOrEmpty(image.Key))
     {
         this.LogWarning("Cannot add empty image or image with empty Key");
         return(false);
     }
     return(m_Images.TryAdd(image.Key, image));
 }
예제 #5
0
 public bool TryGetValue(string key, out TextureImage image)
 {
     if (String.IsNullOrEmpty(key))
     {
         image = null;
         return(false);
     }
     return(m_Images.TryGetValue(key, out image));
 }
예제 #6
0
 public ImagePanel(string name, Docking dock, TextureImage image, WidgetStyle style)
     : base(name, dock, style)
 {
     SizeMode           = ImageSizeModes.ShrinkToFit;
     VAlign             = Alignment.Center;
     HAlign             = Alignment.Center;
     Image              = image;
     ShouldDisposeImage = false;
 }
예제 #7
0
 public bool AddImage(string key, string filePath)
 {
     try {
         TextureImage image = TextureImage.FromFile(filePath, Context, key, ImageSize);
         return(m_Images.TryAdd(key, image));
     } catch (Exception ex) {
         ex.LogError();
         return(false);
     }
 }
예제 #8
0
        public void AddOrReplaceImage(TextureImage image)
        {
            if (image == null || String.IsNullOrEmpty(image.Key))
            {
                return;
            }
            TextureImage img;

            if (m_Images.TryGetValueAndAddOrReplace(image.Key, image, out img) && ShouldDisposeImages)
            {
                img.Dispose();
            }
        }
예제 #9
0
        public void LoadImageAsync(string filePath, IGUIContext ctx)
        {
            if (IsDisposed || String.IsNullOrEmpty(filePath))
            {
                return;
            }

            try {
                if (Image != null && ShouldDisposeImage)
                {
                    Image.Dispose();
                }
                Image = TextureImage.FromFile(filePath.FixedExpandedPath(), ctx);
                //Image.Opacity = 0.999f;
            } catch (Exception ex) {
                ex.LogError();
            }
            finally {
                Update(true);
                m_InitialFilePath = null;
            }
        }
예제 #10
0
 void LoadMissingImage()
 {
     try {
         if (!String.IsNullOrEmpty(MissingImagePath) && File.Exists(MissingImagePath))
         {
             Task.Run(() => {
                 TextureImage oldImage = MissingImage;
                 try {
                     MissingImage = TextureImage.FromFile(MissingImagePath, Context, null, ImageSize);
                 } catch (Exception ex) {
                     ex.LogError();
                 } finally {
                     if (oldImage != null)
                     {
                         oldImage.Dispose();
                     }
                 }
             });
         }
     } catch (Exception ex) {
         ex.LogError();
     }
 }
예제 #11
0
 public ImagePanel(string name, Docking dock, TextureImage image)
     : this(name, dock, image, new EmptyWidgetStyle())
 {
 }
예제 #12
0
        public static void Paint(this TextureImage image, IGUIContext ctx, Rectangle dest)
        {
            if (image.IsDisposed || image.TextureID < 0)
            {
                image.LogWarning("Image is not loaded (has no TextureID).");
                return;
            }

            if (dest.Width < 0 || dest.Height < 0 || !ctx.ClipBoundStack.IsOnScreen(dest))
            {
                return;
            }

            using (new PaintWrapper(RenderingFlags.HighQuality)) {
                GL.Enable(EnableCap.Blend);
                BlendingFactor    srcBlend  = BlendingFactor.SrcAlpha;
                BlendingFactor    destBlend = BlendingFactor.OneMinusSrcAlpha;
                BlendEquationMode mode      = BlendEquationMode.FuncAdd;

                if (image.Opacity < 1)
                {
                    // Multiply
                    srcBlend  = BlendingFactor.DstColor;
                    destBlend = BlendingFactor.OneMinusSrcAlpha;
                    GL.Color4(image.Opacity, image.Opacity, image.Opacity, image.Opacity);
                }
                else
                {
                    // mandatory here,
                    // but take care not to forget the f for float
                    // otherwise there is a dangreous overloading with uint
                    // which would set a very different value
                    if (image.BlendColor != Color.Empty)
                    {
                        GL.Color4(image.BlendColor);
                    }
                    else
                    {
                        GL.Color4(1f, 1f, 1f, 1f);
                    }
                }


                GL.BlendEquation(mode);
                GL.BlendFunc(srcBlend, destBlend);

                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, image.TextureID);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);

                GL.Begin(PrimitiveType.Quads);

                GL.TexCoord2(0, 0);
                GL.Vertex3(dest.X, dest.Y, 0);

                GL.TexCoord2(1, 0);
                GL.Vertex3(dest.X + dest.Width, dest.Y, 0);

                GL.TexCoord2(1, 1);
                GL.Vertex3(dest.X + dest.Width, dest.Y + dest.Height, 0);

                GL.TexCoord2(0, 1);
                GL.Vertex3(dest.X, dest.Y + dest.Height, 0);

                GL.End();
            };
        }
예제 #13
0
 public static void Paint(this TextureImage image, IGUIContext ctx, RectangleF dest)
 {
     image.Paint(ctx, Rectangle.Round(dest));
 }