internal void RenderTopImage(GaugeGraphics g)
 {
     if (base.TopImage != "")
     {
         ImageAttributes imageAttributes = new ImageAttributes();
         if (base.TopImageTransColor != Color.Empty)
         {
             imageAttributes.SetColorKey(base.TopImageTransColor, base.TopImageTransColor, ColorAdjustType.Default);
         }
         Image     image    = Common.ImageLoader.LoadImage(base.TopImage);
         Rectangle destRect = Rectangle.Round(g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f)));
         if (!base.TopImageHueColor.IsEmpty)
         {
             Color       color       = g.TransformHueColor(base.TopImageHueColor);
             ColorMatrix colorMatrix = new ColorMatrix();
             colorMatrix.Matrix00 = (float)(int)color.R / 255f;
             colorMatrix.Matrix11 = (float)(int)color.G / 255f;
             colorMatrix.Matrix22 = (float)(int)color.B / 255f;
             imageAttributes.SetColorMatrix(colorMatrix);
         }
         ImageSmoothingState imageSmoothingState = new ImageSmoothingState(g);
         imageSmoothingState.Set();
         g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
         imageSmoothingState.Restore();
     }
 }
Beispiel #2
0
        internal void DrawImage(GaugeGraphics g, string imageName, bool drawShadow)
        {
            if (drawShadow && ShadowOffset == 0f)
            {
                return;
            }
            Image image = Common.ImageLoader.LoadImage(imageName);

            if (image.Width == 0 || image.Height == 0)
            {
                return;
            }
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
            Rectangle  empty             = Rectangle.Empty;

            if (ResizeMode == ResizeMode.AutoFit)
            {
                empty = new Rectangle((int)absoluteRectangle.X, (int)absoluteRectangle.Y, (int)absoluteRectangle.Width, (int)absoluteRectangle.Height);
            }
            else
            {
                empty = new Rectangle(0, 0, image.Width, image.Height);
                PointF absolutePoint = g.GetAbsolutePoint(new PointF(50f, 50f));
                empty.X = (int)(absolutePoint.X - (float)(empty.Size.Width / 2));
                empty.Y = (int)(absolutePoint.Y - (float)(empty.Size.Height / 2));
            }
            ImageAttributes imageAttributes = new ImageAttributes();

            if (ImageTransColor != Color.Empty)
            {
                imageAttributes.SetColorKey(ImageTransColor, ImageTransColor, ColorAdjustType.Default);
            }
            float num  = (100f - Transparency) / 100f;
            float num2 = Common.GaugeCore.ShadowIntensity / 100f;

            if (drawShadow)
            {
                ColorMatrix colorMatrix = new ColorMatrix();
                colorMatrix.Matrix00 = 0f;
                colorMatrix.Matrix11 = 0f;
                colorMatrix.Matrix22 = 0f;
                colorMatrix.Matrix33 = num2 * num;
                imageAttributes.SetColorMatrix(colorMatrix);
            }
            else if (Transparency > 0f)
            {
                ColorMatrix colorMatrix2 = new ColorMatrix();
                colorMatrix2.Matrix33 = num;
                imageAttributes.SetColorMatrix(colorMatrix2);
            }
            if (Angle != 0f)
            {
                PointF point     = new PointF(absoluteRectangle.X + absoluteRectangle.Width / 2f, absoluteRectangle.Y + absoluteRectangle.Height / 2f);
                Matrix transform = g.Transform;
                Matrix matrix    = g.Transform.Clone();
                float  offsetX   = matrix.OffsetX;
                float  offsetY   = matrix.OffsetY;
                point.X += offsetX;
                point.Y += offsetY;
                matrix.RotateAt(Angle, point, MatrixOrder.Append);
                if (drawShadow)
                {
                    matrix.Translate(ShadowOffset, ShadowOffset, MatrixOrder.Append);
                }
                g.Transform = matrix;
                ImageSmoothingState imageSmoothingState = new ImageSmoothingState(g);
                imageSmoothingState.Set();
                g.DrawImage(image, empty, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
                imageSmoothingState.Restore();
                g.Transform = transform;
            }
            else
            {
                if (drawShadow)
                {
                    empty.X += (int)ShadowOffset;
                    empty.Y += (int)ShadowOffset;
                }
                ImageSmoothingState imageSmoothingState2 = new ImageSmoothingState(g);
                imageSmoothingState2.Set();
                g.DrawImage(image, empty, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
                imageSmoothingState2.Restore();
            }
            if (drawShadow)
            {
                return;
            }
            GraphicsPath graphicsPath = new GraphicsPath();

            graphicsPath.AddRectangle(empty);
            if (Angle != 0f)
            {
                PointF point2 = new PointF(absoluteRectangle.X + absoluteRectangle.Width / 2f, absoluteRectangle.Y + absoluteRectangle.Height / 2f);
                using (Matrix matrix2 = new Matrix())
                {
                    matrix2.RotateAt(Angle, point2, MatrixOrder.Append);
                    graphicsPath.Transform(matrix2);
                }
            }
            Common.GaugeCore.HotRegionList.SetHotRegion(this, Point.Empty, graphicsPath);
        }
        internal void DrawFrameImage(GaugeGraphics g)
        {
            GraphicsPath graphicsPath = null;
            Pen          pen          = null;
            Region       region       = null;

            try
            {
                graphicsPath = GetFramePath(g, 0f);
                RectangleF frameRectangle = GetFrameRectangle(g);
                Region     clip           = null;
                if (ClipImage)
                {
                    RenderShadow(g);
                    region = new Region(graphicsPath);
                    clip   = g.Clip;
                    g.Clip = region;
                }
                else if (ShadowOffset != 0f)
                {
                    using (Brush brush = g.GetShadowBrush())
                    {
                        RectangleF rect = frameRectangle;
                        rect.Offset(ShadowOffset, ShadowOffset);
                        g.FillRectangle(brush, rect);
                    }
                }
                ImageAttributes imageAttributes = new ImageAttributes();
                if (ImageTransColor != Color.Empty)
                {
                    imageAttributes.SetColorKey(ImageTransColor, ImageTransColor, ColorAdjustType.Default);
                }
                Image     image    = Common.ImageLoader.LoadImage(Image);
                Rectangle destRect = new Rectangle((int)Math.Round(frameRectangle.X), (int)Math.Round(frameRectangle.Y), (int)Math.Round(frameRectangle.Width), (int)Math.Round(frameRectangle.Height));
                if (!ImageHueColor.IsEmpty)
                {
                    Color       color       = g.TransformHueColor(ImageHueColor);
                    ColorMatrix colorMatrix = new ColorMatrix();
                    colorMatrix.Matrix00 = (float)(int)color.R / 255f;
                    colorMatrix.Matrix11 = (float)(int)color.G / 255f;
                    colorMatrix.Matrix22 = (float)(int)color.B / 255f;
                    imageAttributes.SetColorMatrix(colorMatrix);
                }
                ImageSmoothingState imageSmoothingState = new ImageSmoothingState(g);
                imageSmoothingState.Set();
                g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
                imageSmoothingState.Restore();
                if (ClipImage)
                {
                    g.Clip = clip;
                }
                if (BorderWidth > 0 && BorderStyle != 0)
                {
                    pen           = new Pen(BorderColor, BorderWidth);
                    pen.DashStyle = g.GetPenStyle(BorderStyle);
                    pen.Alignment = PenAlignment.Center;
                    if (ClipImage)
                    {
                        g.DrawPath(pen, graphicsPath);
                    }
                    else
                    {
                        g.DrawRectangle(pen, frameRectangle.X, frameRectangle.Y, frameRectangle.Width, frameRectangle.Height);
                    }
                }
            }
            finally
            {
                graphicsPath?.Dispose();
                pen?.Dispose();
                region?.Dispose();
            }
        }
Beispiel #4
0
        internal void DrawImage(GaugeGraphics g, bool primary, bool drawShadow)
        {
            if (!Visible || (drawShadow && base.ShadowOffset == 0f))
            {
                return;
            }
            float width = Width;

            width = g.GetAbsoluteDimension(width);
            Image image = null;

            image = ((!primary) ? Common.ImageLoader.LoadImage(CapImage) : Common.ImageLoader.LoadImage(Image));
            if (image.Width == 0 || image.Height == 0)
            {
                return;
            }
            Point empty = Point.Empty;

            empty = ((!primary) ? CapImageOrigin : ImageOrigin);
            if (empty.IsEmpty)
            {
                empty.X = image.Width / 2;
                empty.Y = image.Height / 2;
            }
            int num = (image.Height <= image.Width) ? image.Width : image.Height;

            if (num != 0)
            {
                float           num2            = (!primary) ? (g.GetAbsoluteDimension(CapWidth * 2f) / (float)num) : (g.GetAbsoluteDimension(Width * 2f) / (float)num);
                Rectangle       rectangle       = new Rectangle(0, 0, (int)((float)image.Width * num2), (int)((float)image.Height * num2));
                ImageAttributes imageAttributes = new ImageAttributes();
                if (primary && ImageTransColor != Color.Empty)
                {
                    imageAttributes.SetColorKey(ImageTransColor, ImageTransColor, ColorAdjustType.Default);
                }
                if (!primary && CapImageTransColor != Color.Empty)
                {
                    imageAttributes.SetColorKey(CapImageTransColor, CapImageTransColor, ColorAdjustType.Default);
                }
                Matrix transform         = g.Transform;
                Matrix matrix            = g.Transform.Clone();
                float  positionFromValue = GetScale().GetPositionFromValue(base.Position);
                PointF absolutePoint     = g.GetAbsolutePoint(GetScale().GetPivotPoint());
                PointF pointF            = new PointF((float)empty.X * num2, (float)empty.Y * num2);
                float  offsetX           = matrix.OffsetX;
                float  offsetY           = matrix.OffsetY;
                matrix.Translate(absolutePoint.X - pointF.X, absolutePoint.Y - pointF.Y, MatrixOrder.Append);
                absolutePoint.X += offsetX;
                absolutePoint.Y += offsetY;
                matrix.RotateAt(positionFromValue, absolutePoint, MatrixOrder.Append);
                if (drawShadow)
                {
                    ColorMatrix colorMatrix = new ColorMatrix();
                    colorMatrix.Matrix00 = 0f;
                    colorMatrix.Matrix11 = 0f;
                    colorMatrix.Matrix22 = 0f;
                    colorMatrix.Matrix33 = Common.GaugeCore.ShadowIntensity / 100f;
                    imageAttributes.SetColorMatrix(colorMatrix);
                    matrix.Translate(base.ShadowOffset, base.ShadowOffset, MatrixOrder.Append);
                }
                else if (primary && !ImageHueColor.IsEmpty)
                {
                    Color       color        = g.TransformHueColor(ImageHueColor);
                    ColorMatrix colorMatrix2 = new ColorMatrix();
                    colorMatrix2.Matrix00 = (float)(int)color.R / 255f;
                    colorMatrix2.Matrix11 = (float)(int)color.G / 255f;
                    colorMatrix2.Matrix22 = (float)(int)color.B / 255f;
                    imageAttributes.SetColorMatrix(colorMatrix2);
                }
                else if (!primary && !CapImageHueColor.IsEmpty)
                {
                    Color       color2       = g.TransformHueColor(CapImageHueColor);
                    ColorMatrix colorMatrix3 = new ColorMatrix();
                    colorMatrix3.Matrix00 = (float)(int)color2.R / 255f;
                    colorMatrix3.Matrix11 = (float)(int)color2.G / 255f;
                    colorMatrix3.Matrix22 = (float)(int)color2.B / 255f;
                    imageAttributes.SetColorMatrix(colorMatrix3);
                }
                g.Transform = matrix;
                ImageSmoothingState imageSmoothingState = new ImageSmoothingState(g);
                imageSmoothingState.Set();
                g.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
                imageSmoothingState.Restore();
                g.Transform = transform;
                if (!drawShadow)
                {
                    matrix.Translate(0f - offsetX, 0f - offsetY, MatrixOrder.Append);
                    GraphicsPath graphicsPath = new GraphicsPath();
                    graphicsPath.AddRectangle(rectangle);
                    graphicsPath.Transform(matrix);
                    AddHotRegion(graphicsPath, primary);
                }
            }
        }