Example #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var count = Enum.GetValues(typeof(LineDashStyle)).Length;


            using (var bitmap = Current.Engine.CreateBitmap(PreferredWidth, (count + 1) * 22))
                using (var canvas = bitmap.CreateCanvas())
                    using (var selectedBrush = Current.Engine.CreateSolidBrush(CustomColors.ButtonHoverDark.ToArgbColor()))
                        using (var selectedPen = Current.Engine.CreatePen(CustomColors.SelectedBorder.ToArgbColor(), 1))
                            using (var pen = Current.Engine.CreatePen(ArgbColor.Black, 3))
                            {
                                int x = 0, y = 0, i = 0;
                                foreach (LineDashStyle style in Enum.GetValues(typeof(LineDashStyle)))
                                {
                                    pen.DashStyle = style;

                                    if (_selectedIndex == i)
                                    {
                                        var buttonRec = new CanvasRectangle(x, y, PreferredWidth, 22);

                                        canvas.FillRectangle(selectedBrush, buttonRec);
                                        canvas.DrawRectangle(selectedPen, buttonRec);
                                    }
                                    canvas.DrawLine(pen, 3, y + 11, PreferredWidth - 6, y + 11);
                                    y += 22;
                                    i++;
                                }

                                e.Graphics.DrawImage(bitmap.ToGdiBitmap(), 0, 0);
                            }
        }
        public void DrawRectangleToCanvas(CanvasRectangle c)
        {
            var x = new IHTMLDiv();

            x.style.overflow = IStyle.OverflowEnum.hidden;

            c._Dispose =
                delegate(CanvasRectangle u)
            {
                if (x == null)
                {
                    return;
                }
                x.Orphanize();
                x = null;
            };

            c._Update =
                delegate(CanvasRectangle u)
            {
                if (x == null)
                {
                    return;
                }

                var r = u.Location;

                x.style.SetLocation(r.Left, r.Top, r.Width, r.Height);
                x.style.backgroundColor = u.BackgroundColor;
            };

            c.Update();

            this.Layers.Canvas.appendChild(x);
        }
        /// <summary>
        /// 获取指定宽高压缩后的百分比
        /// </summary>
        /// <param name="width">目标宽</param>
        /// <param name="height">目标高</param>
        /// <param name="containerRect">原始对象</param>
        /// <returns>目标与原始对象百分比</returns>
        public static float GetPercentage(float width, float height, CanvasRectangle containerRect)
        {
            float percentage = 0;

            if (height > width)
            {
                percentage = containerRect.RectHeight / height;

                if (width * percentage > containerRect.RectWidth)
                {
                    percentage = containerRect.RectWidth / width;
                }
            }
            else
            {
                percentage = containerRect.RectWidth / width;

                if (height * percentage > containerRect.RectHeight)
                {
                    percentage = containerRect.RectHeight / height;
                }
            }

            return(percentage);
        }
Example #4
0
 public CanvasRectangle(CanvasRectangle rectangle)
 {
     this.Left   = rectangle.Left;
     this.Top    = rectangle.Top;
     this.Width  = rectangle.Width;
     this.Height = rectangle.Height;
 }
 static public Rectangle ToGdiRectangle(this CanvasRectangle canvasRectangle)
 {
     return(new Rectangle(
                canvasRectangle.Left,
                canvasRectangle.Top,
                canvasRectangle.Width,
                canvasRectangle.Height));
 }
Example #6
0
 public void DrawBitmap(IBitmap bitmap, CanvasRectangle dest, CanvasRectangle source, float opacity = 1)
 {
     _canvas?.DrawBitmap((SKBitmap)bitmap.EngineElement, source.ToSKRect(), dest.ToSKRect(), new SKPaint()
     {
         FilterQuality = this.InterpolationMode.ToSKFilterQuality(),
         Color         = SKColors.Black.WithAlpha((byte)(255 * opacity))
     });;
 }
Example #7
0
        public void DrawPoint(IDisplay display, IPoint point)
        {
            if (!String.IsNullOrEmpty(_filename))
            {
                float sizeX = _sizeX, sizeY = _sizeY;

                if (display.IsLegendItemSymbol())
                {
                    sizeX = Math.Min(_sizeY, display.iWidth);
                    sizeY = Math.Min(_sizeY, display.iHeight);
                }
                float x = _xOffset - sizeX / 2;
                float y = _yOffset - sizeY / 2;

                try
                {
                    display.Canvas.TranslateTransform(new CanvasPointF((float)point.X, (float)point.Y));
                    display.Canvas.RotateTransform(_angle + _rotation);

                    var rect = new CanvasRectangle((int)x, (int)y, (int)sizeX, (int)sizeY);

                    try
                    {
                        if (_image == null)
                        {
                            if (_filename.StartsWith("resource:"))
                            {
                                _image = Current.Engine.CreateBitmap(new MemoryStream(display.Map.ResourceContainer[_filename.Substring(9)]));
                            }
                            else
                            {
                                _image = Current.Engine.CreateBitmap(_filename);
                            }
                        }

                        if (_image != null)
                        {
                            display.Canvas.DrawBitmap(
                                _image,
                                rect,
                                new CanvasRectangle(0, 0, _image.Width, _image.Height));
                        }
                    }
                    catch
                    {
                    }
                }
                finally
                {
                    display.Canvas.ResetTransform();
                }
            }
        }
Example #8
0
        public void DrawBitmap(IBitmap bitmap, CanvasRectangle dest, CanvasRectangle source, float opacity = 1.0f)
        {
            CheckUsability();

            var imageAttributes = CreateImageAttributes(opacity);

            if (imageAttributes != null)
            {
                _graphics.DrawImage((Bitmap)bitmap.EngineElement,
                                    dest.ToGdiRectangle(),
                                    source.Left, source.Top, source.Width, source.Height,
                                    System.Drawing.GraphicsUnit.Pixel,
                                    imageAttrs: imageAttributes);
            }
            else
            {
                _graphics.DrawImage((Bitmap)bitmap.EngineElement,
                                    dest.ToGdiRectangle(),
                                    source.ToGdiRectangle(),
                                    System.Drawing.GraphicsUnit.Pixel);
            }
        }
        public void DrawRectangleToCanvas(CanvasRectangle c)
        {
            var x = new IHTMLDiv();

            x.style.overflow = IStyle.OverflowEnum.hidden;

            c._Dispose =
                delegate(CanvasRectangle u)
                {
                    if (x == null)
                        return;
                    x.Orphanize();
                    x = null;
                };

            c._Update =
                delegate(CanvasRectangle u)
                {
                    if (x == null)
                        return;

                    var r = u.Location;

                    x.style.SetLocation(r.Left, r.Top, r.Width, r.Height);
                    x.style.backgroundColor = u.BackgroundColor;
                };

            c.Update();

            this.Layers.Canvas.appendChild(x);

        }
Example #10
0
 static public SKRect ToSKRect(this CanvasRectangle rect)
 {
     return new SKRect(rect.Left, rect.Top, rect.Left + rect.Width, rect.Top + rect.Height);
 }
Example #11
0
 public void FillRectangle(IBrush brush, CanvasRectangle rectangle)
 {
     _canvas?.DrawRect(rectangle.ToSKRect(), GetSKPaint(brush));
 }
Example #12
0
 public void DrawRectangle(IPen pen, CanvasRectangle rectangle)
 {
     _canvas?.DrawRect(rectangle.ToSKRect(), GetSKPaint(pen));
 }
Example #13
0
        public void FillRectangle(IBrush brush, CanvasRectangle rectangle)
        {
            CheckUsability();

            _graphics.FillRectangle((Brush)brush.EngineElement, rectangle.ToGdiRectangle());
        }
Example #14
0
        public void DrawRectangle(IPen pen, CanvasRectangle rectangle)
        {
            CheckUsability();

            _graphics.DrawRectangle((Pen)pen.EngineElement, rectangle.ToGdiRectangle());
        }
Example #15
0
 public GdiCanvas(Bitmap bitmap)
 {
     _graphics = Graphics.FromImage(bitmap);
     _bounds   = new CanvasRectangle(0, 0, bitmap.Width, bitmap.Height);
 }