Example #1
0
        // Render the dirtied window
        void OnExpose(object sender, ExposeEventArgs args)
        {
            DrawingArea area = (DrawingArea)sender;

            Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);

            // Clear background
            cr.SetSourceRGB(1.0, 1.0, 1.0);
            cr.Paint();

            // Set the coordinate system origin at bottom left
            cr.Translate(0, area.Allocation.Height);
            cr.Scale(1.0, -1.0);

            // Render all Drawables, resetting the coordinate transform for each
            foreach (Drawable d in drawable)
            {
                cr.Save();
                d.Draw(cr);
                cr.Restore();
            }

            cr.GetTarget().Dispose();
            ((IDisposable)cr).Dispose();
        }
Example #2
0
 public static void DrawCircle(DrawingArea da,
                               int width,
                               int height,
                               double lineWidth,
                               double[] lineColor,
                               double[] fillColor,
                               Position position,
                               double size)
 {
     Cairo.Context cr = Gdk.CairoHelper.Create(da.GdkWindow);
     cr.SetSourceRGB(lineColor[0], lineColor[1], lineColor[2]);
     cr.LineWidth = lineWidth;
     cr.Translate(position.x * width, position.y * height);
     cr.Arc(0, 0, size * width / 100f, 0, 2 * Math.PI);
     cr.StrokePreserve();
     cr.SetSourceRGB(fillColor[0], fillColor[1], fillColor[2]);
     cr.Fill();
     ((IDisposable)cr.GetTarget()).Dispose();
     ((IDisposable)cr).Dispose();
 }
Example #3
0
        public static void DrawLine(DrawingArea da,
                                    int width,
                                    int height,
                                    double lineWidth,
                                    Cairo.Color lineColor,
                                    Position positionStart,
                                    Position positionEnd
                                    )
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(da.GdkWindow);

            cr.Translate(positionStart.x * width, positionStart.y * height);
            cr.LineWidth = lineWidth * width / (3 * 100f);
            cr.SetSourceColor(lineColor);
            cr.MoveTo(0, 0);

            cr.LineTo((positionEnd.x - positionStart.x) * width, (positionEnd.y - positionStart.y) * height);

            cr.Stroke();

            ((IDisposable)cr.GetTarget()).Dispose();
            ((IDisposable)cr).Dispose();
        }