예제 #1
0
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        Graphics1 = e.Graphics;
        Surface1  = new Win32Surface(Graphics1.GetHdc());
        Context1  = new Context(Surface1);
        var p1 = new PointD(10, 10);
        var p2 = new PointD(100, 10);
        var p3 = new PointD(100, 100);
        var p4 = new PointD(10, 100);

        Context1.MoveTo(p1);
        Context1.LineTo(p2);
        Context1.LineTo(p3);
        Context1.LineTo(p4);
        Context1.LineTo(p1);
        Context1.ClosePath();
        Context1.Fill();
        Context1.MoveTo(140, 110);
        Context1.SetFontSize(32);
        Context1.SetSourceColor(new Color(0, 0, 0.8, 1));
        Context1.ShowText("Hello Cairo!");
        Graphics1.Dispose();
        Context1.Dispose();
        Surface1.Dispose();
    }
예제 #2
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     using (System.Drawing.Graphics graphics = e.Graphics)
     {
         using (Win32Surface surface = new Win32Surface(graphics.GetHdc()))
         {
             using (Context context = new Context(surface))
             {
                 context.LineWidth = 2.0;
                 context.SetSourceColor(this.bugColor);
                 context.MoveTo(7.0, 64.0);
                 context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0);
                 context.MoveTo(25.0, 80.0);
                 context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0);
                 context.MoveTo(10.0, 41.0);
                 context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0);
                 context.LineWidth = 1.0;
                 context.MoveTo(1.0, 26.0);
                 context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0);
                 context.LineTo(12.0, 14.0);
                 context.Stroke();
                 context.MoveTo(30.0, 74.0);
                 context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0);
                 context.LineTo(10.0, 45.0);
                 context.LineTo(10.0, 40.0);
                 context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0);
                 context.Stroke();
             }
         }
     }
 }
예제 #3
0
파일: Form1.cs 프로젝트: MacMinhHoang/Paint
        private void pnCanvas_Paint(object sender, PaintEventArgs e)
        {
            if (isPainting)
            {
                CommonGraphics          lib;
                System.Drawing.Graphics g = e.Graphics;
                if (radioGdi.Checked)
                {
                    lib = new GdiPlus(g);
                }
                else
                {
                    Surface s = new Win32Surface(g.GetHdc());
                    Context c = new Context(s);
                    lib = new Cairo(c);
                }
                foreach (Shape shape in shapes)
                {
                    shape.draw(lib);
                }
                diagram.draw(lib);

                g.Dispose();
            }
        }
예제 #4
0
파일: Form1.cs 프로젝트: zwcloud/CairoSharp
        private void DrawAnimated(PaintEventArgs e)
        {
            if (backSurface == null)
            {
                backSurface = new ImageSurface(Format.Rgb24,
                                               this.ClientSize.Width, this.ClientSize.Height);
            }

            using (Graphics graphics = e.Graphics)
            {
                var hdc = graphics.GetHdc();
                using (Win32Surface surface = new Win32Surface(hdc))
                {
                    //draw to image surface
                    Context context = new Context(backSurface);
                    context.LineWidth = 2.0;
                    context.SetSourceRGB(1, 1, 1);
                    context.Paint();//clear the background to white
                    context.SetSourceRGB(0, 0, 0);
                    context.MoveTo(100, 100);
                    context.LineTo(100 + 80 * Math.Cos(angle), 100 + 80 * Math.Sin(angle));
                    angle += Math.PI / 180;
                    context.Stroke();

                    //paint image surface to win32 surface
                    Context context1 = new Context(surface);
                    context1.SetSource(backSurface);
                    context1.Paint();

                    context.Dispose();
                    context1.Dispose();
                }
                graphics.ReleaseHdc();
            }
        }
예제 #5
0
파일: Form1.cs 프로젝트: zwcloud/CairoSharp
        private void DrawStatic(PaintEventArgs e)
        {
            using (System.Drawing.Graphics graphics = e.Graphics)
                using (Win32Surface surface = new Win32Surface(graphics.GetHdc()))

                    using (Context context = new Context(surface))
                    {
                        //clear the background to white
                        context.SetSourceRGB(1, 1, 1);
                        context.Paint();

                        //stroke the bug
                        context.LineWidth = 2.0;
                        context.SetSourceColor(this.bugColor);
                        context.MoveTo(7.0, 64.0);
                        context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0);
                        context.MoveTo(25.0, 80.0);
                        context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0);
                        context.MoveTo(10.0, 41.0);
                        context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0);
                        context.LineWidth = 1.0;
                        context.MoveTo(1.0, 26.0);
                        context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0);
                        context.LineTo(12.0, 14.0);
                        context.Stroke();
                        context.MoveTo(30.0, 74.0);
                        context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0);
                        context.LineTo(10.0, 45.0);
                        context.LineTo(10.0, 40.0);
                        context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0);
                        context.Stroke();
                    }
        }
예제 #6
0
        public static Cairo.Context CreateDrawable(Gdk.Drawable drawable)
        {
            IntPtr x_drawable = IntPtr.Zero;
            int    x_off = 0, y_off = 0;

            int x, y, w, h, d;

            ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);

            bool is_gdk_window = drawable is Gdk.Window;

            if (is_gdk_window)
            {
                ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable,
                                                            out x_off, out y_off);
            }

            Cairo.Surface surface;

            PlatformID os = Environment.OSVersion.Platform;

            if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
                os == PlatformID.Win32S || os == PlatformID.WinCE)
            {
                Gdk.GC gcc   = new Gdk.GC(drawable);
                IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0);
                surface = new Win32Surface(windc);

                gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0);
            }
            else
            {
                x_drawable = drawable.Handle;
                IntPtr visual = gdk_drawable_get_visual(x_drawable);

                IntPtr Xdisplay  = gdk_x11_drawable_get_xdisplay(x_drawable);
                IntPtr Xvisual   = gdk_x11_visual_get_xvisual(visual);
                IntPtr Xdrawable = gdk_x11_drawable_get_xid(x_drawable);

                surface = new Cairo.XlibSurface(Xdisplay,
                                                Xdrawable,
                                                Xvisual,
                                                w, h);
            }

            Cairo.Context g = new Cairo.Context(surface);

            // this can be safely removed now, just keep it for a bit more
            //Cairo.Context g = new Cairo.Context (
            //                    gdk_cairo_create (x_drawable ));

            if (is_gdk_window)
            {
                g.Translate(-(double)x_off, -(double)y_off);
            }
            return(g);
        }
예제 #7
0
    protected override void OnPaint(PaintEventArgs a)
    {
        IntPtr       hdc = a.Graphics.GetHdc();
        Win32Surface s   = new Win32Surface(hdc);
        Context      cr  = new Context(s);

        draw(cr, this.Width, this.Height);

        a.Graphics.ReleaseHdc(hdc);
    }
예제 #8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            IntPtr hdc = e.Graphics.GetHdc();
            // will only work on win32
            Win32Surface s  = new Win32Surface(hdc);
            Context      cr = new Context(s);

            Snippets.InvokeSnippet(snips, name, cr, w, h);
            e.Graphics.ReleaseHdc(hdc);
        }
예제 #9
0
        public CairoCommonGraphics(System.Drawing.Graphics g, System.Drawing.Color l, System.Drawing.Color f, bool i, int t, int w)
        {
            IntPtr hdc = g.GetHdc();

            surface      = new Win32Surface(hdc);
            ct           = new Context(surface);
            line         = l;
            fill         = f;
            isFilled     = i;
            trans        = t;
            lineWidth    = w;
            ct.LineWidth = lineWidth;
        }
예제 #10
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            using (Graphics1 = e.Graphics)
                using (Surface1 = new Win32Surface(Graphics1.GetHdc()))
                    using (Context1 = new Context(Surface1))
                    {
                        if (OnPaintAction != null)
                        {
                            OnPaintAction(Context1);
                        }
                    }
        }
예제 #11
0
        private void saveAsPngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter   = "PNG|*.png";
            dialog.FileName = lastSelected;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                using (this.Graphics1 = this.CreateGraphics())
                    using (Surface1 = new Win32Surface(Graphics1.GetHdc()))
                        using (Context1 = new Context(Surface1))
                        {
                            Surface1.WriteToPng(dialog.FileName);
                        }
            }
        }
        public static Cairo.Context CreateDrawable(Gdk.Drawable drawable, bool double_buffered)
        {
            int x, y, w, h, d;

            Cairo.Surface surface;
            bool          needs_xlate;

            ((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);

            PlatformID os = Environment.OSVersion.Platform;

            needs_xlate = drawable is Gdk.Window && double_buffered;

            if (needs_xlate)
            {
                ((Gdk.Window)drawable).GetInternalPaintInfo(out drawable, out x, out y);
            }

            if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
                os == PlatformID.Win32S || os == PlatformID.WinCE)
            {
                Gdk.GC gcc   = new Gdk.GC(drawable);
                IntPtr windc = gdk_win32_hdc_get(drawable.Handle, gcc.Handle, 0);
                surface = new Win32Surface(windc);

                if (double_buffered)
                {
                    gdk_win32_hdc_release(drawable.Handle, gcc.Handle, 0);
                }
            }
            else
            {
                IntPtr display   = gdk_x11_drawable_get_xdisplay(drawable.Handle);
                IntPtr visual    = gdk_drawable_get_visual(drawable.Handle);
                IntPtr xvisual   = gdk_x11_visual_get_xvisual(visual);
                IntPtr xdrawable = gdk_x11_drawable_get_xid(drawable.Handle);
                surface = new XlibSurface(display, xdrawable, xvisual, w, h);
            }

            Cairo.Context ctx = new Cairo.Context(surface);

            if (needs_xlate)
            {
                ctx.Translate(-(double)x, -(double)y);
            }
            return(ctx);
        }
예제 #13
0
        public Image Render(WebMapView mapView, out string mimeType)
        {
            using (Surface s = CreateImageSurface())
            {
                Context c = new Context(s);
                c.FillRule  = FillRule.EvenOdd;
                c.Antialias = Antialias.Subpixel;
                if (!MapView.Presenter.IsRenderingSelection)
                {
                    SetColour(c, MapView.BackgroundColor);
                }
                else
                {
                    SetColour(c, new StyleColor(0, 0, 0, 0));
                }

                c.FillExtents();

                while (_renderQueue.Count > 0)
                {
                    RenderObject(_renderQueue.Dequeue(), c);
                }

                Bitmap bmp = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
                using (Graphics graphics = Graphics.FromImage(bmp))
                    using (Win32Surface winSurface = new Win32Surface(graphics.GetHdc()))
                        using (Context context = new Context(winSurface))
                        {
                            context.SetSourceRGBA(0, 0, 0, 0);
                            context.FillExtents();

                            context.SetSource(s);
                            context.Paint();
                        }

                mimeType = "image/bmp";
                return(bmp);
            }
        }
예제 #14
0
 public CairoContext(System.Windows.Forms.PaintEventArgs e) : base(e)
 {
     Graphics1 = e.Graphics;
     Surface1  = new Win32Surface(Graphics1.GetHdc());
     Context1  = new Context(Surface1);
 }
예제 #15
0
        private void panelcontrol_MouseUp(object sender, MouseEventArgs e)
        {
            End.X = e.X;
            End.Y = e.Y;
            g     = panelcontrol.CreateGraphics();
            DiagramFactory fac  = new DfdFactory();
            ShapeInfo      temp = new ShapeInfo(Start, End);
            DiagramFactory fac2 = new FCFactory();
            CommonGraphics gdi1 = new GdiPlusCommonGraphics(g, panelcontrol);

            //chon graphic
            if (GraphicType == 0)
            {
                gdi = gdi1;
            }
            else
            {
                try
                {
                    Surface s = new Win32Surface(g.GetHdc());
                    Context c = new Context(s);
                    gdi = new CairoCommonGraphics(c);
                }catch (System.DllNotFoundException)
                {
                    GraphicType = 0;
                    MessageBox.Show("DllNotFoundException", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            //chon hinh ve
            switch (ShapeType)
            {
            case 0:
                Shape line = new Line(Start, End);
                line.draw(gdi);

                break;

            case 1:
                Shape rect = new Rect(Start, End);
                rect.draw(gdi);
                break;

            case 2:
                Shape eclip = new Eclip(Start, End);
                eclip.draw(gdi);
                break;

            case 3:

                ABlock startblock = fac.createStartBlock(temp);
                startblock.draw(gdi);
                break;

            case 4:
                ABlock input = fac.createInputBlock(temp);
                input.draw(gdi);
                break;

            case 5:
                ABlock startbl = fac2.createStartBlock(temp);
                startbl.draw(gdi);
                break;

            case 6:
                ABlock inputbl = fac2.createInputBlock(temp);
                inputbl.draw(gdi);
                break;

            case 7:
                Shape star = new Star(Start, End);
                star.draw(gdi);
                break;

            default:
                break;
            }
        }