Exemple #1
0
 protected virtual void OnPaintBackground(FluidPaintEventArgs e)
 {
     if (PaintBackground != null)
     {
         PaintBackground(this, e);
     }
     else
     {
         if (!BackColor.IsEmpty && BackColor != Color.Transparent)
         {
             Graphics g = e.Graphics;
             if (BackColor.A == 255 || BackColor.A == 0)
             {
                 SolidBrush brush = Brushes.GetBrush(BackColor);
                 g.FillRectangle(brush, e.ControlBounds);
             }
             else
             {
                 using (GraphicsPlus gp = new GraphicsPlus(g))
                 {
                     using (SolidBrushPlus brush = new SolidBrushPlus(BackColor))
                     {
                         gp.FillRectangle(brush, e.ControlBounds);
                     }
                 }
             }
         }
     }
 }
        /// <summary>
        /// Creates and paints the button bitmap of the virtual scrollbar.
        /// </summary>
        /// <param name="width">The width of the button.</param>
        /// <param name="height">The height of the button.</param>
        /// <returns>The button image.</returns>
        protected virtual Image CreateScrollButtonBitmap(int width, int height)
        {
            Bitmap bm = new Bitmap(width, height);

            using (Graphics g = Graphics.FromImage(bm))
            {
                int r = Math.Min(width, height / 2) - 1;
                if (r < 1)
                {
                    r = 1;
                }

                backgroundBrush.Color = Color.Fuchsia;
                //g.Clear(Color.Fuchsia);
                g.FillRectangle(backgroundBrush, 0, 0, width, height);

                using (GraphicsPlus gp = new GraphicsPlus(g))
                {
                    Rectangle bounds = new Rectangle(0, 0, width - 1, height - 1);
                    gp.SmoothingMode = SmoothingMode.None;
                    Color color = scrollbarButtonColor;
                    using (SolidBrushPlus brush = new SolidBrushPlus(color, true))
                    {
                        gp.FillRoundRectangle(bounds, r, brush);
                    }
                    using (PenPlus pen = new PenPlus(ScrollBarButtonBorderColor, 1, true))
                    {
                        gp.DrawRoundRectangle(bounds, r, pen);
                    }
                }
            }

            return(bm);
        }
        public void PaintHeaderBackground()
        {
            Graphics  g = Graphics;
            Rectangle r = ClientBounds;

            Color color      = BackColor;
            Color startColor = ColorConverter.AlphaBlendColor(Color.White, color, 100);

            if (IsTransparent)
            {
                color      = ColorConverter.AlphaColor(color, 200);
                startColor = ColorConverter.AlphaColor(startColor, 150);
                using (GraphicsPlus gp = new GraphicsPlus(g))
                {
                    PointF p1 = new PointF(r.X, r.Y);
                    PointF p2 = new PointF(r.X, r.Bottom);
                    using (LinearGradientBrush backGround = new LinearGradientBrush(p1, p2, startColor, color))
                    {
                        gp.FillRectangle(backGround, r);
                    }
                }
            }
            else
            {
                GdiExt.GradientFill(g, r, startColor, color, GdiExt.FillDirection.TopToBottom);
            }
        }
Exemple #4
0
 GetBounds(out GpRect rect,
           GraphicsPlus g)
 {
     return(SetStatus(NativeMethods.GdipGetRegionBoundsI(nativeRegion,
                                                         g.nativeGraphics,
                                                         out rect)));
 }
        private void PaintTemplateBackground()
        {
            Graphics  g = Graphics;
            Rectangle r = ClientBounds;

            Color color = BackColor;

            if (IsTransparent)
            {
                color = ColorConverter.AlphaColor(color, 220);
                using (GraphicsPlus gp = new GraphicsPlus(g))
                {
                    using (SolidBrushPlus backGround = new SolidBrushPlus(color))
                    {
                        gp.FillRectangle(backGround, r);
                    }
                }
            }
            else
            {
                using (SolidBrush brush = new SolidBrush(color))
                {
                    g.FillRectangle(brush, r);
                }
            }
        }
Exemple #6
0
        private void drawOffScreen()
        {
            Graphics g = Graphics.FromImage(this.off_screen);

            g.Clear(this.BackColor);
            drawMap(g);

            // GDI Plus
            IntPtr hdc = g.GetHdc();

            using (GraphicsPlus graphics = new GraphicsPlus(hdc))
            {
                if (this.directionLineVisible)
                {
                    drawDirectionLinePlus(graphics);
                }
                //drawDirectionLine(g);
                if (this.courseArrowVisible)
                {
                    drawRotatedArrow(graphics);
                }
            }
            g.ReleaseHdc(hdc);

            //if (hasMap)
            //    drawPositionMarkerImg(g);

            //Bitmap rotated = rotate();
            //g.DrawImage(rotated, this.Width / 2, this.Height / 2);
        }
Exemple #7
0
        private void TestGdiPlus(GraphicsPlus graphics)
        {
            graphics.DrawImage(bmp, 0, 0, ClientRectangle.Width, ClientRectangle.Height);

            PenPlus pen;

            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

            pen = new PenPlus(Color.Black, 15);
            pen.SetEndCap(LineCap.LineCapRound);
            pen.SetStartCap(LineCap.LineCapRound);

            pen.SetWidth(3);

            pen.SetColor(Color.FromArgb(0x7f7f7f7f));
            pen.SetWidth(40);
            graphics.DrawLine(pen, 20, 20, ClientRectangle.Right - 20, ClientRectangle.Bottom - 20);
            graphics.DrawLine(pen, ClientRectangle.Right - 20, 20, 20, ClientRectangle.Bottom - 20);

            SmoothingMode mode = graphics.GetSmoothingMode();

            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);
            foreach (GraphicsPath p in allPaths)
            {
                graphics.DrawPath(penWrite, p);
            }
            graphics.SetSmoothingMode(mode);
            pen.Dispose();
        }
Exemple #8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            IntPtr hdc = e.Graphics.GetHdc();

            using (GraphicsPlus g = new GraphicsPlus(hdc))
                Draw(e.Graphics, g);
            e.Graphics.ReleaseHdc(hdc);
        }
Exemple #9
0
        public bool IsVisible(float x,
                              float y,
                              GraphicsPlus g)
        {
            bool ret;

            SetStatus(NativeMethods.GdipIsVisiblePathPoint(nativePath, x, y, g.nativeGraphics, out ret));
            return(ret);
        }
Exemple #10
0
        public bool IsVisible(int x,
                              int y,
                              GraphicsPlus g)
        {
            bool ret;

            NativeMethods.GdipIsVisiblePathPoint(nativePath, x, y, g.nativeGraphics, out ret);
            return(ret);
        }
Exemple #11
0
        IsInfinite(GraphicsPlus g)
        {
            bool booln = false;

            SetStatus(NativeMethods.GdipIsInfiniteRegion(nativeRegion,
                                                         g.nativeGraphics,
                                                         out booln));

            return(booln);
        }
Exemple #12
0
        GetHRGN(GraphicsPlus g)
        {
            HRGN hrgn;

            SetStatus(NativeMethods.GdipGetRegionHRgn(nativeRegion,
                                                      g.nativeGraphics,
                                                      out hrgn));

            return(hrgn);
        }
Exemple #13
0
        Equals(RegionPlus region,
               GraphicsPlus g)
        {
            bool booln = false;

            SetStatus(NativeMethods.GdipIsEqualRegion(nativeRegion,
                                                      region.nativeRegion,
                                                      g.nativeGraphics,
                                                      out booln));
            return(booln);
        }
Exemple #14
0
        IsVisible(GpPointF point,
                  GraphicsPlus g)
        {
            bool booln = false;

            SetStatus(NativeMethods.GdipIsVisibleRegionPoint(nativeRegion,
                                                             point.X, point.Y,
                                                             (g == null) ? new GpGraphics() : g.nativeGraphics,
                                                             out booln));
            return(booln);
        }
Exemple #15
0
        private void Draw(Graphics graphics, GraphicsPlus g)
        {
            StringFormat sf = new StringFormat();

            sf.LineAlignment = sf.Alignment = System.Drawing.StringAlignment.Center;
            int        deltaH = ClientRectangle.Height / 8;
            GpRectF    rc     = new GpRectF(0, 0, ClientRectangle.Width, deltaH);
            RectangleF rcf    = new RectangleF(0, 0, ClientRectangle.Width, deltaH);

            using (SolidBrush brText = new SolidBrush(Color.Black))
                using (Font fnt = new Font("Tahoma", 9, System.Drawing.FontStyle.Bold))
                {
                    penSolid.SetWidth(15);
                    g.DrawLine(penSolid, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                    graphics.DrawString("Solid with caps", fnt, brText, rcf, sf);
                    rcf.Y += deltaH; rc.Offset(0, deltaH);

                    SmoothingMode mode = g.GetSmoothingMode();
                    g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

                    penSolid.SetColor(Color.Blue);
                    g.DrawLine(penSolid, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                    graphics.DrawString("Solid with caps and anitalising", fnt, brText, rcf, sf);
                    rcf.Y += deltaH; rc.Offset(0, deltaH);

                    g.DrawLine(penHatch, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                    graphics.DrawString("Hatched", fnt, brText, rcf, sf);
                    rcf.Y += deltaH; rc.Offset(0, deltaH);

                    penSolidTrans.SetWidth(20);
                    penSolidTrans.SetLineCap(LineCap.LineCapRound, LineCap.LineCapDiamondAnchor, DashCap.DashCapRound);
                    graphics.DrawString("Solid with transparency", fnt, brText, rcf, sf);
                    g.DrawLine(penSolidTrans, 15, rcf.Top + 10, rc.Width - 30, rcf.Top + 10);
                    rcf.Y += deltaH; rc.Offset(0, deltaH);

                    g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);
                    brText.Color = Color.White;
                    g.DrawLine(penSolidCustomCap, 15, rcf.Top + 15, rc.Width - 50, rcf.Top + 15);
                    graphics.DrawString("Custom cap", fnt, brText, rcf, sf);
                    rcf.Y += deltaH; rc.Offset(0, deltaH);
                    g.SetSmoothingMode(mode);

                    brText.Color = Color.Gray;
                    g.DrawLine(penDash, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                    graphics.DrawString("Dash (round)", fnt, brText, rcf, sf);
                    rcf.Y += deltaH; rc.Offset(0, deltaH);

                    brText.Color = Color.White;
                    g.DrawLine(penGradient, 15, rcf.Top + 20, rc.Width - 30, rcf.Top + 20);
                    graphics.DrawString("Gradient brush-based", fnt, brText, rcf, sf);
                    rcf.Y += deltaH; rc.Offset(0, deltaH);
                }
        }
Exemple #16
0
        private void drawDirectionLinePlus(GraphicsPlus graphics)
        {
            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

            PenPlus pen = new PenPlus(TARGET_LINE_COLOR, 3);

            pen.SetEndCap(LineCap.LineCapRound);
            pen.SetStartCap(LineCap.LineCapRound);

            graphics.DrawLine(pen, this.Width / 2, this.Height / 2, targetPoint.X, targetPoint.Y);
            pen.Dispose();
        }
Exemple #17
0
        IsVisible(GpRectF rect,
                  GraphicsPlus g)
        {
            bool booln = false;

            SetStatus(NativeMethods.GdipIsVisibleRegionRect(nativeRegion, rect.X,
                                                            rect.Y, rect.Width,
                                                            rect.Height,
                                                            (g == null) ?
                                                            new GpGraphics() : g.nativeGraphics,
                                                            out booln));
            return(booln);
        }
Exemple #18
0
        public BitmapPlus(
            int width,
            int height,
            GraphicsPlus target)
        {
            GpBitmap bitmap = new GpBitmap();

            lastResult = NativeMethods.GdipCreateBitmapFromGraphics(width,
                                                                    height,
                                                                    target.nativeGraphics,
                                                                    out bitmap);

            SetNativeImage((GpImage)(IntPtr)bitmap);
        }
Exemple #19
0
        protected override void OnPaint(PaintEventArgs e)
        {
            IntPtr hdc = e.Graphics.GetHdc();

            using (GraphicsPlus g = new GraphicsPlus(hdc))
                TestGdiPlus(g);
            e.Graphics.ReleaseHdc(hdc);

            StringFormat fmt = new StringFormat();

            fmt.Alignment = fmt.LineAlignment = System.Drawing.StringAlignment.Center;
            using (SolidBrush brText = new SolidBrush(Color.LightGray))
                using (Font font = new Font("Tahoma", 8, System.Drawing.FontStyle.Bold))
                    e.Graphics.DrawString("Use stylus to write on this screen", font, brText, new Rectangle(0, 0, ClientRectangle.Width, 30), fmt);
        }
Exemple #20
0
        protected virtual void PaintButtonBackground(FluidPaintEventArgs e)
        {
            const int const_radius = 8;

            if (this.shape != ButtonShape.Flat || IsDown)
            {
                Rectangle rect = ButtonRectangle;
                rect.Width--;
                rect.Height--;
                if (rect.Width < 1 || rect.Height < 1)
                {
                    return;
                }

                rect.Offset(e.ControlBounds.X, e.ControlBounds.Y);

                Graphics g = e.Graphics;


                int radius = e.ScaleX(const_radius);
                if (radius > rect.Width / 2)
                {
                    radius = rect.Width / 2;
                }

                Color endColor = this.BackColor;
                if (!Enabled)
                {
                    endColor = ColorConverter.AlphaBlendColor(Color.Black, endColor, 128);
                }
                int   alpha       = Enabled ? 127 : 32;
                Color startColor  = ColorConverter.AlphaBlendColor(endColor, Color.White, alpha); //Color.FromArgb(0x7fffffff);
                Color borderColor = ColorConverter.AlphaBlendColor(endColor, Color.White, 100);

                GraphicShape shape = ButtonShapeToGraphic(this.shape);
                using (GraphicsPlus gp = new GraphicsPlus(g))
                {
                    GraphicsPlus.GradientMode mode = IsDown ? GraphicsPlus.GradientMode.Bottom : GraphicsPlus.GradientMode.Top;
                    gp.GradientFillShape(rect, radius, startColor, endColor, mode, shape, corners);
                    using (PenPlus pen = new PenPlus(borderColor, (float)1))
                    {
                        gp.DrawShape(rect, radius, pen, shape, corners);
                    }
                }
            }
            PerformPaintButtonContent(e);
        }
Exemple #21
0
        private void Draw(Graphics graphics, GraphicsPlus g)
        {
            int     deltaH = ClientRectangle.Height / 5;
            GpRectF rc     = new GpRectF(0, 0, ClientRectangle.Width, deltaH);

            g.FillRectangle(brPathGrad, rc);
            rc.Offset(0, deltaH);

            g.FillRectangle(brSolid, rc);
            rc.Offset(0, deltaH);

            g.FillRectangle(brHatch, rc);
            rc.Offset(0, deltaH);

            g.FillRectangle(brLinGrad, rc);
            rc.Offset(0, deltaH);

            g.FillRectangle(brTexture, rc);
            rc.Offset(0, deltaH);

            Rectangle    rcText = new Rectangle(0, 0, ClientRectangle.Width, deltaH);
            StringFormat sf     = new StringFormat();

            sf.LineAlignment = sf.Alignment = System.Drawing.StringAlignment.Center;

            using (SolidBrush brText = new SolidBrush(Color.White))
                using (Font fnt = new Font("Tahoma", 9, System.Drawing.FontStyle.Bold))
                {
                    graphics.DrawString("PathGradient Brush", fnt, brText, rcText, sf);
                    rcText.Offset(0, deltaH);

                    brText.Color = Color.Black;
                    graphics.DrawString("Solid Brush", fnt, brText, rcText, sf);
                    rcText.Offset(0, deltaH);

                    graphics.DrawString("Hatch Brush", fnt, brText, rcText, sf);
                    rcText.Offset(0, deltaH);

                    graphics.DrawString("LinearGradient Brush", fnt, brText, rcText, sf);
                    rcText.Offset(0, deltaH);

                    graphics.DrawString("Texture Brush", fnt, brText, rcText, sf);
                    rcText.Offset(0, deltaH);
                }
        }
Exemple #22
0
        private void drawRotatedArrow(GraphicsPlus graphics)
        {
            Debug.WriteLine("drawRotatedArrow: " + this.rotationAngle, this.ToString());

            Point center = new Point(this.Width / 2, this.Height / 2);

            int arWidthHalf = ARROW_WIDTH / 2;

            //int arHeightHalf = ARROW_HEIGHT / 2;

            Point[] arrowPoints =
            {
                new Point(center.X,                       center.Y - arWidthHalf),
                new Point(center.X - 2 * arWidthHalf / 3, center.Y + arWidthHalf),
                new Point(center.X + 2 * arWidthHalf / 3, center.Y + arWidthHalf),
                new Point(center.X,                       center.Y + arWidthHalf / 2)
            };
            Debug.WriteLine("drawRotatedArrow: points "
                            + PointUtil.pointsStr(arrowPoints), this.ToString());

            PointMath.RotatePoints(arrowPoints, center, this.rotationAngle);
            Debug.WriteLine("drawRotatedArrow: points "
                            + PointUtil.pointsStr(arrowPoints), this.ToString());

            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

            PenPlus pen = new PenPlus(ARROW_COLOR, 3);

            pen.SetEndCap(LineCap.LineCapRound);
            pen.SetStartCap(LineCap.LineCapRound);


            graphics.DrawLine(pen, new GpPoint(arrowPoints[0].X, arrowPoints[0].Y),
                              new GpPoint(arrowPoints[1].X, arrowPoints[1].Y));
            graphics.DrawLine(pen, new GpPoint(arrowPoints[1].X, arrowPoints[1].Y),
                              new GpPoint(arrowPoints[3].X, arrowPoints[3].Y));
            graphics.DrawLine(pen, new GpPoint(arrowPoints[3].X, arrowPoints[3].Y),
                              new GpPoint(arrowPoints[2].X, arrowPoints[2].Y));
            graphics.DrawLine(pen, new GpPoint(arrowPoints[2].X, arrowPoints[2].Y),
                              new GpPoint(arrowPoints[0].X, arrowPoints[0].Y));
            pen.Dispose();
        }
Exemple #23
0
 private void AddStroke(int x, int y)
 {
     allPoints.Add(new GpPointF(x, y));
     if (allPoints.Count == 1)
     {
         return;
     }
     path.AddLine(allPoints[allPoints.Count - 2], allPoints[allPoints.Count - 1]);
     using (Graphics graphics = CreateGraphics())
     {
         IntPtr hdc = graphics.GetHdc();
         using (GraphicsPlus g = new GraphicsPlus(hdc))
         {
             SmoothingMode mode = g.GetSmoothingMode();
             g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);
             g.DrawLine(penWrite, allPoints[allPoints.Count - 2], allPoints[allPoints.Count - 1]);
             g.SetSmoothingMode(mode);
         }
         graphics.ReleaseHdc(hdc);
     }
 }
Exemple #24
0
 public bool IsOutlineVisible(GpPoint point,
                              PenPlus pen,
                              GraphicsPlus g)
 {
     return(IsOutlineVisible(point.X, point.Y, pen, g));
 }
Exemple #25
0
 public bool IsVisible(GpPoint point,
                       GraphicsPlus g)
 {
     return(IsVisible(point.X, point.Y, g));
 }
Exemple #26
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="g">The graphics.</param>
 /// <param name="clip">The clip bounds for the control.</param>
 /// <param name="scaleFactor">The scale factor of the form.</param>
 /// <param name="doubleBuffered">Specifies wether the parent control uses double buffering.</param>
 /// <param name="gp">The gdi plus class for painting.</param>
 public FluidPaintEventArgs(Graphics g, Rectangle clip, SizeF scaleFactor, bool doubleBuffered, GraphicsPlus gp)
     : base()
 {
     this.Graphics       = g;
     this.ControlBounds  = clip;
     this.DoubleBuffered = true;
     this.GdiPlus        = gp;
     this.ScaleFactor    = scaleFactor;
     Region = g.Clip;
 }