Fill() публичный Метод

public Fill ( ) : void
Результат void
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.Color = new Color (0, 0, 0, progress);
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.PaintWithAlpha (progress);
                cr.Restore ();
            }
        }
Пример #2
0
	void FillChecks (Context cr, int x, int y, int width, int height)
	{
		int CHECK_SIZE = 32;
		
		cr.Save ();
		Surface check = cr.Target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
		
		// draw the check
		using (Context cr2 = new Context (check)) {
			cr2.Operator = Operator.Source;
			cr2.Color = new Color (0.4, 0.4, 0.4);
			cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
			cr2.Fill ();

			cr2.Color = new Color (0.7, 0.7, 0.7);
			cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();

			cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();
		}

		// Fill the whole surface with the check
		SurfacePattern check_pattern = new SurfacePattern (check);
		check_pattern.Extend = Extend.Repeat;
		cr.Source = check_pattern;
		cr.Rectangle (0, 0, width, height);
		cr.Fill ();

		check_pattern.Destroy ();
		check.Destroy ();
		cr.Restore ();
	}
Пример #3
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        gr.AddColorStop(0, Tabstrip.ActiveGradientStart);
                        gr.AddColorStop(1, Tabstrip.ActiveGradientEnd);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                    cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1);
                    cr.SetSourceRGBA(1, 1, 1, 0.05);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        var c1 = Tabstrip.ActiveGradientStart;
                        var c2 = Tabstrip.ActiveGradientEnd;
                        c1.A = 0.2;
                        c2.A = 0.2;
                        gr.AddColorStop(0, c1);
                        gr.AddColorStop(1, c2);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceRGB(1, 1, 1);
            }
            else
            {
                cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor());
            }

            cr.MoveTo(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }
Пример #4
0
        public static void RenderThumbnail(Cairo.Context cr, ImageSurface image, bool dispose,
                                           double x, double y, double width, double height, bool drawBorder, double radius,
                                           bool fill, Color fillColor, CairoCorners corners)
        {
            if (image == null || image.Handle == IntPtr.Zero)
            {
                return;
            }

            double p_x = x;
            double p_y = y;

            p_x += image.Width < width ? (width - image.Width) / 2 : 0;
            p_y += image.Height < height ? (height - image.Height) / 2 : 0;

            cr.Antialias = Cairo.Antialias.Default;

            if (fill)
            {
                cr.Rectangle(x, y, width, height);
                cr.Color = fillColor;
                cr.Fill();
            }

            CairoExtensions.RoundedRectangle(cr, p_x, p_y, image.Width, image.Height, radius, corners);
            cr.SetSource(image, p_x, p_y);
            cr.Fill();

            if (!drawBorder)
            {
                if (dispose)
                {
                    ((IDisposable)image).Dispose();
                }

                return;
            }

            cr.LineWidth = 1.0;
            if (radius < 1)
            {
                cr.Antialias = Antialias.None;

                CairoExtensions.RoundedRectangle(cr, x + 1.5, y + 1.5, width - 3, height - 3, radius, corners);
                cr.Color = cover_border_light_color;
                cr.Stroke();
            }

            CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1, radius, corners);
            cr.Color = cover_border_dark_color;
            cr.Stroke();

            if (dispose)
            {
                ((IDisposable)image).Dispose();
            }
        }
Пример #5
0
        void DrawDataPoint(Cairo.Context cr, int cellWidth, double height, int max, int day, int temp)
        {
            cr.Color = new Cairo.Color(0, 0, 0, 0.4);
            cr.Arc(BUTTON_SIZE + day * cellWidth * 2 + cellWidth / 2 + 2, 7 + height * (max - temp), 3, 0, 2 * Math.PI);
            cr.Fill();

            cr.Color = colorTitle;
            cr.Arc(BUTTON_SIZE + day * cellWidth * 2 + cellWidth / 2, 5 + height * (max - temp), 3, 0, 2 * Math.PI);
            cr.Fill();
        }
Пример #6
0
        public override void RealRenderCairo(Cairo.Context context)
        {
            if (Camera.IsRendererOutOfScreen(this))
            {
                return;
            }
            Vector2 screenPos = Camera.WorldToScreenPosition(gameObject.transform.position);
            float   realRad   = gameObject.transform.LocalToWorldLength(radius);
            double  screenRad = (double)realRad * Camera.instance.zoom;

            context.Arc((double)screenPos.x,
                        (double)screenPos.y,
                        screenRad,
                        0, 2 * Math.PI);


            if (surf == null)
            {
                if (useShadow)
                {
                    LinearGradient g = new LinearGradient(screenPos.x - screenRad, screenPos.y + screenRad, screenPos.x + screenRad, screenPos.y - screenRad);

                    //g.AddColorStopRgb (0.75, new Cairo.Color (ColorR, ColorG, ColorB, ColorA));
                    g.AddColorStop(0, new Cairo.Color(ColorR * 0.5, ColorG * 0.5, ColorB * 0.5, ColorA * 0.5));
                    g.AddColorStop(1, new Cairo.Color(ColorR, ColorG, ColorB, ColorA));

                    context.SetSource(g);
                    context.Fill();
                    g.Dispose();
                }
                else
                {
                    context.SetSourceRGBA(ColorR, ColorG, ColorB, ColorA);
                    context.Fill();
                }
            }
            else
            {
                context.SetSourceSurface(surf, (int)(screenPos.x - screenRad), (int)(screenPos.y - screenRad));

                context.Fill();
                context.GetSource().Dispose();
                //surf.Dispose ();
            }

            /*context.SetSourceRGBA (1,1,1,1);
             * context.Arc ((double)screenPos.x,
             *      (double)screenPos.y,
             *      (double)realRad * Camera.instance.zoom,
             *      MyMath.FixAngleRad(-Math.PI/4 - gameObject.transform.rotation), MyMath.FixAngleRad(Math.PI /4 - gameObject.transform.rotation));
             *
             * context.Fill ();*/
        }
Пример #7
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (this.isDirty)
            {
                this.Rebuild();
            }

            bool baseDrawnResult = base.OnDrawn(cr);

            cr.SetFontSize(FONT_HEIGHT);
            cr.SelectFontFace("Mono", FontSlant.Normal, FontWeight.Normal);

            cr.Rectangle(0.0, 0.0, this.allocRect.Width, this.allocRect.Height);
            cr.SetSourceRGB(1, 1, 1);
            cr.Fill();

            var gradient = new LinearGradient(0.0, 0.0, 0.0, this.allocRect.Height);

            gradient.AddColorStopRgb(0.0, new Color(0.4, 0.4, 0.4));
            gradient.AddColorStopRgb(0.1, new Color(1.0, 1.0, 1.0));
            gradient.AddColorStopRgb(0.2, new Color(0.6, 0.6, 0.6));
            gradient.AddColorStopRgb(1.0, new Color(0.1, 0.1, 0.1));

            cr.LineWidth = 1;

            foreach (var box in this.boxen)
            {
                this.RoundedRect(cr, box.Rect, 4.0);
                cr.SetSource(gradient);
                cr.FillPreserve();
                cr.SetSourceRGB(0, 0, 0);
                cr.Stroke();


                int x = (int)(box.Rect.X + TAGBOX_PADDING * 2 + TAGBOX_XSIZE);
                int y = (int)(box.Rect.Y + box.Rect.Height / 2 + cr.FontExtents.Height / 2 - cr.FontExtents.Descent / 2);
                cr.MoveTo(x, y);
                cr.TextPath(box.Tag);
                cr.SetSourceRGB(1.0, 1.0, 1.0);
                cr.Fill();

                cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XOFFSET);
                cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, TAGBOX_XSIZE - TAGBOX_XOFFSET * 2);
                cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XSIZE - TAGBOX_XOFFSET);
                cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, -TAGBOX_XSIZE + TAGBOX_XOFFSET * 2);
                cr.Stroke();
            }

            return(baseDrawnResult);
        }
Пример #8
0
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.SetSourceColor (new Color (0, 0, 0));
            if (prev != null) {
                double scale = Math.Min ((double)width/(double)prev.Width, (double)height/(double)prev.Height);
                cr.Save ();
                cr.Translate (-progress * width, 0);

                cr.Rectangle (0, 0, width, .5 * (height - scale*prev.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*prev.Height), width, .5 * (height - scale*prev.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*prev.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*prev.Width), 0, .5 * (width - scale*prev.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, prev, .5 * ((double)width/scale - prev.Width), .5 * ((double)height/scale - prev.Height));
                cr.Fill ();
                cr.Restore ();
            }
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();
                cr.Translate (width * (1.0 - progress), 0);

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.Fill ();
                cr.Restore ();
            }
        }
Пример #9
0
        public void DrawFooterBackground(Cairo.Context cr, Gdk.Rectangle alloc, int top_offset, bool fill)
        {
            Color gtk_background_color = GetWidgetColor(GtkColorClass.Background, StateType.Normal);
            Color gtk_base_color       = GetWidgetColor(GtkColorClass.Base, StateType.Normal);
            Color light_color          = gtk_background_color.ColorShade(1.1);
            Color dark_color           = gtk_background_color.ColorShade(0.95);

            const CairoCorners corners = CairoCorners.BottomLeft | CairoCorners.BottomRight;

            if (fill)
            {
                LinearGradient grad = new LinearGradient(alloc.X, alloc.Y, alloc.X, alloc.Y + alloc.Height);
                grad.AddColorStop(0, light_color);
                grad.AddColorStop(0.75, dark_color);
                grad.AddColorStop(0, light_color);

                cr.Pattern = grad;
                cr.RoundedRectangle(alloc.X, alloc.Y + top_offset, alloc.Width, alloc.Height - top_offset, BORDER_RADIUS, corners);
                cr.Fill();

                cr.Color = gtk_base_color;
                cr.Rectangle(alloc.X, alloc.Y, alloc.Width, top_offset);
                cr.Fill();
            }
            else
            {
                cr.Color = gtk_base_color;
                cr.RoundedRectangle(alloc.X, alloc.Y, alloc.Width, alloc.Height, BORDER_RADIUS, corners);
                cr.Fill();
            }

            cr.LineWidth = 1.0;
            cr.Translate(alloc.Y + 0.5, alloc.Y - 0.5);

            cr.Color = border_color;
            cr.RoundedRectangle(alloc.X, alloc.Y - 4, alloc.Width - 1, alloc.Height + 4, BORDER_RADIUS, corners);
            cr.Stroke();

            if (fill)
            {
                cr.LineWidth = 1;
                cr.Antialias = Cairo.Antialias.None;
                cr.MoveTo(alloc.X + 1, alloc.Y + 1 + top_offset);
                cr.LineTo(alloc.X + alloc.Width - 1, alloc.Y + 1 + top_offset);
                cr.Stroke();
                cr.Antialias = Cairo.Antialias.Default;
            }
        }
Пример #10
0
  protected override FlowReturn OnTransformIp (Gst.Buffer buf) {
    if (!buf.IsWritable)
      return FlowReturn.Error;

    Cairo.ImageSurface img = new Cairo.ImageSurface (buf.Data, Cairo.Format.Rgb24, width, height, width*4);

    using (Cairo.Context context = new Cairo.Context (img)) {
      double dx = (double) ( (buf.Timestamp / Clock.MSecond) % 2180) / 5;
      context.Save ();
      context.Scale (width / 640.0, height / 480.0);
      context.MoveTo (300, 10 + dx);
      context.LineTo (500 - dx, 400);
      context.LineWidth = 4.0;
      context.Color = new Color (0, 0, 1.0);
      context.Stroke();
      context.Restore ();

      if (lastX != -1 && lastY != -1) {
        context.Color = new Color (1.0, 0, 0);
        context.Translate (lastX, lastY);
        context.Scale (Math.Min (width / 640.0, height / 480.0), Math.Min (width / 640.0, height / 480.0));
        context.Arc (0, 0, 10.0, 0.0, 2 * Math.PI);
        context.Fill();
      }
    }

    img.Destroy ();
    return base.OnTransformIp (buf);
  }
Пример #11
0
        public override void Apply (CanvasItem item, Context cr)
        {
            int steps = ShadowSize;
            double opacity_step = ShadowOpacity / ShadowSize;
            Color color = new Color (0, 0, 0);

            double width = Math.Round (item.Allocation.Width);
            double height = Math.Round (item.Allocation.Height);

            if (Fill != null) {
                cr.Rectangle (shadow_size, shadow_size, width - ShadowSize * 2, height - ShadowSize * 2);
                Fill.Apply (cr);
                cr.Fill ();
            }

            cr.LineWidth = 1.0;

            for (int i = 0; i < steps; i++) {
                CairoExtensions.RoundedRectangle (cr,
                    i + 0.5,
                    i + 0.5,
                    (width - 2 * i) - 1,
                    (height - 2 * i) - 1,
                    steps - i);

                color.A = opacity_step * (i + 1);
                cr.Color = color;
                cr.Stroke ();
            }
        }
        public void Render(DrawingArea area, SettingsModel settings)
        {
            var width = area.Allocation.Width;
            var height = area.Allocation.Height;

            var kaleidoscope = _factory.Get (settings.Type);
            var rootNode = kaleidoscope.Generate (
                settings.GeometyWidth,
                settings.ImageUri,
                width, height);

            ImageSurface surface = new ImageSurface(Format.Argb32, width, height);

            using (var context = new Context (surface)) {
                context.Translate(width / 2, height / 2);
                rootNode.Render (context);
            }
            rootNode.Geometry.Dispose ();

            using (Context context = Gdk.CairoHelper.Create (area.GdkWindow)) {
                context.Rectangle(0, 0, width, height);
                context.SetSource(surface);
                context.Fill();
                context.GetTarget ().Dispose ();
            }
            surface.Dispose ();
        }
Пример #13
0
        private void RenderNetwork(Network network, Cairo.Context gc)
        {
            lock (network) {
                Rectangle rect       = (Rectangle)network.Properties["rect"];
                SizeD     titleSize  = CalculateNetworkTitleSize(network, gc);
                Hashtable nodegroups = network.Properties["nodegroups"] as Hashtable;

                gc.Save();

                // Draw network box
                gc.Color = networkBG;
                gc.Rectangle(rect);
                gc.Fill();

                // Draw title, 2px/2px offset from top/left corner
                gc.Color = white;
                gc.MoveTo(rect.X + 2, rect.Y + 2 /* + titleSize.Height */);

                Pango.Layout layout = new Pango.Layout(this.PangoContext);
                layout.FontDescription      = this.PangoContext.FontDescription.Copy();
                layout.FontDescription.Size = Pango.Units.FromDouble(NetworkNameFontSize);
                layout.SetText(network.NetworkName);
                Pango.CairoHelper.ShowLayout(gc, layout);

                foreach (NodeGroup ng in nodegroups.Values)
                {
                    RenderNodeGroup(ng, network, gc);
                }

                gc.Restore();

                RenderConnections(network, gc);
            }
        }
Пример #14
0
        private void HandlePintaCoreActionsEditEraseSelectionActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            Cairo.ImageSurface old = doc.Layers.CurrentUserLayer.Surface.Clone();

            using (var g = new Cairo.Context(doc.Layers.CurrentUserLayer.Surface)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;

                g.Operator = Cairo.Operator.Clear;
                g.Fill();
            }

            doc.Workspace.Invalidate();

            if (sender is string && (sender as string) == "Cut")
            {
                doc.History.PushNewItem(new SimpleHistoryItem(Resources.StandardIcons.EditCut, Translations.GetString("Cut"), old, doc.Layers.CurrentUserLayerIndex));
            }
            else
            {
                doc.History.PushNewItem(new SimpleHistoryItem(Resources.Icons.EditSelectionErase, Translations.GetString("Erase Selection"), old, doc.Layers.CurrentUserLayerIndex));
            }
        }
Пример #15
0
        public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height,
                                     bool filled, bool stroked, Cairo.Color color, CairoCorners corners)
        {
            color.A *= 0.85;
            Cairo.Color selection_color  = color;
            Cairo.Color selection_stroke = CairoExtensions.ColorShade(selection_color, 0.85);
            selection_stroke.A = color.A;

            if (filled)
            {
                Cairo.Color selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.05);
                Cairo.Color selection_fill_dark  = selection_color;

                selection_fill_light.A = color.A;
                selection_fill_dark.A  = color.A;

                LinearGradient grad = new LinearGradient(x, y, x, y + height);
                grad.AddColorStop(0, selection_fill_dark);
                grad.AddColorStop(1, selection_fill_light);

                cr.SetSource(grad);
                cr.Rectangle(x, y, width, height);
                cr.Fill();
                grad.Dispose();
            }

            if (stroked && !filled)
            {
                cr.LineWidth = 1.0;
                cr.SetSourceColor(selection_stroke);
                cr.Rectangle(x + 0.5, y + 0.5, width - 1, height - 1);
                cr.Stroke();
            }
        }
Пример #16
0
        public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height,
                                     bool filled, bool stroked, Cairo.Color color, CairoCorners corners, bool flat_fill)
        {
            var selection_color     = color;
            var selection_highlight = CairoExtensions.ColorShade(selection_color, 1.24);
            var selection_stroke    = CairoExtensions.ColorShade(selection_color, 0.85);

            selection_highlight.A = 0.5;
            selection_stroke.A    = color.A;
            LinearGradient grad = null;

            if (filled)
            {
                if (flat_fill)
                {
                    cr.SetSourceColor(selection_color);
                }
                else
                {
                    var selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.12);
                    var selection_fill_dark  = selection_color;

                    selection_fill_light.A = color.A;
                    selection_fill_dark.A  = color.A;

                    grad = new LinearGradient(x, y, x, y + height);
                    grad.AddColorStop(0, selection_fill_light);
                    grad.AddColorStop(0.4, selection_fill_dark);
                    grad.AddColorStop(1, selection_fill_light);

                    cr.SetSource(grad);
                }

                CairoExtensions.RoundedRectangle(cr, x, y, width, height, Context.Radius, corners, true);
                cr.Fill();

                if (grad != null)
                {
                    grad.Dispose();
                }
            }

            if (filled && stroked)
            {
                cr.LineWidth = 1.0;
                cr.SetSourceColor(selection_highlight);
                CairoExtensions.RoundedRectangle(cr, x + 1.5, y + 1.5, width - 3, height - 3,
                                                 Context.Radius - 1, corners, true);
                cr.Stroke();
            }

            if (stroked)
            {
                cr.LineWidth = 1.0;
                cr.SetSourceColor(selection_stroke);
                CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1,
                                                 Context.Radius, corners, true);
                cr.Stroke();
            }
        }
Пример #17
0
        public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer)
        {
            if (_regionSettings != null)
            {
                xPos += _regionSettings.Indent;

                if (layer == PrintLayer.Background && _regionSettings.HasBackground)
                {
                    TextExtents extents = GetExtents(cr);

                    // If there is a background, draw it here.
                    cr.SetSourceRGB(_regionSettings.Background.Red, _regionSettings.Background.Green, _regionSettings.Background.Blue);

                    cr.Rectangle(xPos
                                 , yPos - extents.Height - extents.YAdvance
                                 , extents.Width - _regionSettings.Indent
                                 , extents.Height + extents.YAdvance);
                    cr.Fill();
                }
                else if (layer == PrintLayer.Text)
                {
                    xPos += _regionSettings.PaddingLeft;
                    yPos -= _regionSettings.PaddingBottom;
                }
            }
            _children.VerticalDraw(cr, xPos, yPos, layer);
        }
Пример #18
0
	void Draw3Circles (Context cr, int xc, int yc, double radius, double alpha)
	{
		double subradius = radius * (2 / 3.0 - 0.1);

		cr.Color = new Color (1.0, 0.0, 0.0, alpha);
		OvalPath (cr, xc + radius / 3.0 * Math.Cos (Math.PI * 0.5), yc - radius / 3.0 * Math.Sin (Math.PI * 0.5), subradius, subradius);
		cr.Fill ();

		cr.Color = new Color (0.0, 1.0, 0.0, alpha);
		OvalPath (cr, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 2 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 2 / 0.3)), subradius, subradius);
		cr.Fill ();

		cr.Color = new Color (0.0, 0.0, 1.0, alpha);
    	OvalPath (cr, xc + radius / 3.0 * Math.Cos (Math.PI * (0.5 + 4 / 0.3)), yc - radius / 3.0 * Math.Sin (Math.PI * (0.5 + 4 / 0.3)), subradius, subradius);
		cr.Fill ();
	}
Пример #19
0
        public void DrawObject(Context ctx, DrawingObject body)
        {
            if (body == null)
                return;
            ctx.Save ();
            ctx.Color = new Cairo.Color (0, 0, 0);

            ctx.LineWidth = 1;
            foreach (Tuple<PointDouble, PointDouble> line in body.lines) {
                ctx.MoveTo (line.Item1.toPointD());
                ctx.LineTo (line.Item2.toPointD());
            }

            if (body.points.Count > 1)
                ctx.Rectangle(body._centerOfMass.X - 5, body._centerOfMass.Y - 5, 10, 10);
            ctx.Stroke ();

            foreach (PointDouble point in body.points) {
                ctx.Rectangle (point.X - 5, point.Y - 5, 10, 10);
                ctx.Fill ();
            }
            foreach (Tuple<PointDouble, double, double> force in body._forces) {
                DrawForce (ctx, force);
            }

            foreach (Tuple<PointDouble, double> moment in body._moments) {
                DrawMoment (ctx, moment);
            }

            ctx.Restore ();
        }
Пример #20
0
	static void draw (Context cr, int width, int height)
	{
		double xc = 0.5;
		double yc = 0.5;
		double radius = 0.4;
		double angle1 = 45.0  * (Math.PI / 180.0);  // angles are specified
		double angle2 = 180.0 * (Math.PI / 180.0);  // in radians
		
		cr.Scale (width, height);
		cr.LineWidth = 0.04;

		cr.Arc (xc, yc, radius, angle1, angle2);
		cr.Stroke ();
		
		// draw helping lines
		cr.Color = new Color(1, 0.2, 0.2, 0.6);
		cr.Arc (xc, yc, 0.05, 0, 2 * Math.PI);
		cr.Fill ();
		cr.LineWidth = 0.03;
		cr.Arc (xc, yc, radius, angle1, angle1);
		cr.LineTo (new PointD (xc, yc));
		cr.Arc (xc, yc, radius, angle2, angle2);
		cr.LineTo (new PointD (xc, yc));
		cr.Stroke ();
	}
Пример #21
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            Rectangle r = ClientRectangle;

            Gradient.Type gt = Gradient.Type.Horizontal;
            if (Orientation == Orientation.Vertical)
            {
                gt = Gradient.Type.Vertical;
            }

            Crow.Gradient grad = new Gradient(gt);

            grad.Stops.Add(new Gradient.ColorStop(0, new Color(1, 0, 0, 1)));
            grad.Stops.Add(new Gradient.ColorStop(0.167, new Color(1, 1, 0, 1)));
            grad.Stops.Add(new Gradient.ColorStop(0.333, new Color(0, 1, 0, 1)));
            grad.Stops.Add(new Gradient.ColorStop(0.5, new Color(0, 1, 1, 1)));
            grad.Stops.Add(new Gradient.ColorStop(0.667, new Color(0, 0, 1, 1)));
            grad.Stops.Add(new Gradient.ColorStop(0.833, new Color(1, 0, 1, 1)));
            grad.Stops.Add(new Gradient.ColorStop(1, new Color(1, 0, 0, 1)));

            grad.SetAsSource(gr, r);
            CairoHelpers.CairoRectangle(gr, r, CornerRadius);
            gr.Fill();
        }
Пример #22
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        int          w, h;
        ImageSurface image;

        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Clip();
        gr.NewPath();

        image = new ImageSurface("data/e.png");
        w     = image.Width;
        h     = image.Height;

        gr.Scale(1.0 / w, 1.0 / h);

        image.Show(gr, 0, 0);

        image.Destroy();

        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Clip();

        gr.NewPath();
        gr.Rectangle(new PointD(0, 0), 1, 1);
        gr.Fill();
        gr.Color = new Color(0, 1, 0, 1);
        gr.MoveTo(new PointD(0, 0));
        gr.LineTo(new PointD(1, 1));
        gr.MoveTo(new PointD(1, 0));
        gr.LineTo(new PointD(0, 1));
        gr.Stroke();
    }
Пример #23
0
        public static SurfacePattern CreateImageBrush(ImageBrush brush, Size targetSize)
        {
            if (brush.Source == null)
            {
                return null;
            }

            // TODO: This is directly ported from Direct2D and could probably be made more
            // efficient on cairo by taking advantage of the fact that cairo has Extend.None.
            var image = ((BitmapImpl)brush.Source.PlatformImpl).Surface;
            var imageSize = new Size(brush.Source.PixelWidth, brush.Source.PixelHeight);
            var tileMode = brush.TileMode;
            var sourceRect = brush.SourceRect.ToPixels(imageSize);
            var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);

			var intermediate = new ImageSurface (Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height);
            using (var context = new Context(intermediate))
            {
                Rect drawRect;
                var transform = CalculateIntermediateTransform(
                    tileMode,
                    sourceRect,
                    destinationRect,
                    scale,
                    translate,
                    out drawRect);
                context.Rectangle(drawRect.ToCairo());
                context.Clip();
                context.Transform(transform.ToCairo());
                Gdk.CairoHelper.SetSourcePixbuf(context, image, 0, 0);
                context.Rectangle(0, 0, imageSize.Width, imageSize.Height);
                context.Fill();

                var result = new SurfacePattern(intermediate);

                if ((brush.TileMode & TileMode.FlipXY) != 0)
                {
                    // TODO: Currently always FlipXY as that's all cairo supports natively. 
                    // Support separate FlipX and FlipY by drawing flipped images to intermediate
                    // surface.
                    result.Extend = Extend.Reflect;
                }
                else
                {
                    result.Extend = Extend.Repeat;
                }

                if (brush.TileMode != TileMode.None)
                {
                    var matrix = result.Matrix;
                    matrix.InitTranslate(-destinationRect.X, -destinationRect.Y);
                    result.Matrix = matrix;
                }

                return result;
            }
        }
Пример #24
0
        public static void DrawRoundedRectangle(Cairo.Context gr, double x, double y,
                                                double width, double height, double radius,
                                                Cairo.Color color, Cairo.Color borderColor)
        {
            gr.Save();

            if ((radius > height / 2) || (radius > width / 2))
            {
                radius = Math.Min(height / 2, width / 2);
            }

            gr.MoveTo(x, y + radius);
            gr.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2);
            gr.LineTo(x + width - radius, y);
            gr.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0);
            gr.LineTo(x + width, y + height - radius);
            gr.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2);
            gr.LineTo(x + radius, y + height);
            gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
            gr.ClosePath();
            gr.Restore();

            gr.LineJoin = LineJoin.Round;
            gr.Color    = borderColor;
            gr.StrokePreserve();
            gr.Color = color;
            gr.Fill();
        }
Пример #25
0
    void Draw(Context cr, int width, int height)
    {
        cr.LineWidth = 1.0;
        cr.Color = new Color(1.0, 1.0, 1.0);
        cr.Rectangle(0, 0, width, height);
        cr.Fill();

        cr.Save();
        cr.Scale(scale_factor, scale_factor);
        try
        {
            if(diagram != null)
            {
                DiagramRenderer dr = new DiagramRenderer(cr, width, height, diagram);
                cr.Color = new Color(0.0, 0.0, 0.0);
                dr.Render();
                dr.Draw();
            }
        }
        catch
        {
            error_counter++;
        }
        cr.Restore();
    }
Пример #26
0
 public virtual void Draw(Context cr, Gdk.Rectangle clip)
 {
     cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height);
     cr.Color = BackgroundColor;
     cr.Fill();
     cr.Stroke();
 }
        public void DrawHist(TimeList<Complex[]> list, double t)
        {
            using (Context context = new Context(Surface)) {

                context.Rectangle(0, 0, Width, Height);
                context.Color = Background;
                context.Fill();

                int index = list.Index (t);
                int times = 30;

                double xl = (double)(Width - 60) / N;
                double yl = (double)Height / times;

                Complex[] points;
                Color c;
                int ii;
                for (int i = index; i >= Math.Max(0, index - times); i--) {
                    points = list.Get (i);
                    N = points.Length;
                    ii = index - i;
                    for (int j = 0; j < points.Length; j++) {
                        DrawHistArea (context, xl, yl, ii, j, _valueExtractor(points [j]));
                    }
                }
            }

            DrawExpose (null, null);
        }
Пример #28
0
        /*override (Gdk.EventButton evnt)
         * {
         *  var res = base.OnButtonPressEvent(evnt);
         *  if ((evnt.Button & (uint)Gdk.ModifierType.Button1Mask) != 0)
         *  {
         *      if ((evnt.Button & (uint)Gdk.ModifierType.ShiftMask) != 0)
         *      {
         *          // if is left click + shift
         *          EnableMode = EnableMode.ActiveWithLimit;
         *      }
         *      else
         *      {
         *          // if is left click
         *          EnableMode = EnableMode.Active;
         *      }
         *  }else if ((evnt.Button & (uint)Gdk.ModifierType.Button3Mask) != 0)
         *  {
         *      //right clicked
         *      EnableMode = EnableMode.Disabled;
         *  }
         *
         *  QueueDraw();
         *
         *  return res;
         * }*/

        void SetBgColor(EnableMode enableMode, Gdk.EventExpose evnt)
        {
            //this.ModifyBg(StateType.Normal, Colors[(int)EnableMode]);
            Cairo.Context cr = Gdk.CairoHelper.Create(this.GdkWindow);
            cr.Rectangle(0, 0, Allocation.Width, Allocation.Height);
            Color c = new Color(0, 0, 0);

            cr.SetSourceColor(c);
            cr.Stroke();

            cr.Rectangle(1, 1, Allocation.Width - 1, Allocation.Height - 1);
            if (enableMode == EnableMode.Active)
            {
                c = Colors[1];
            }
            else if (enableMode == EnableMode.ActiveWithLimit)
            {
                c = Colors[2];
            }
            else if (enableMode == EnableMode.Disabled)
            {
                c = Colors[0];
            }

            cr.SetSourceColor(c);
            cr.Fill();

            cr.Target.Dispose();
            cr.Dispose();

            // set tooltip
            HasTooltip  = true;
            TooltipText = enableMode.ToString();
        }
Пример #29
0
        public override void DrawColumnHeaderFocus(Cairo.Context cr, Gdk.Rectangle alloc)
        {
            double top_offset   = 2.0;
            double right_offset = 2.0;

            double margin     = 0.5;
            double line_width = 0.7;

            var stroke_color = CairoExtensions.ColorShade(
                Colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected), 0.8);

            stroke_color.A = 0.1;
            cr.SetSourceColor(stroke_color);

            CairoExtensions.RoundedRectangle(cr,
                                             alloc.X + margin + line_width + right_offset,
                                             alloc.Y + margin + line_width + top_offset,
                                             alloc.Width - (margin + line_width) * 2.0 - right_offset,
                                             alloc.Height - (margin + line_width) * 2.0 - top_offset,
                                             Context.Radius / 2.0, CairoCorners.None);

            cr.Fill();

            stroke_color.A = 1.0;
            cr.LineWidth   = line_width;
            cr.SetSourceColor(stroke_color);
            CairoExtensions.RoundedRectangle(cr,
                                             alloc.X + margin + line_width + right_offset,
                                             alloc.Y + margin + line_width + top_offset,
                                             alloc.Width - (line_width + margin) * 2.0 - right_offset,
                                             alloc.Height - (line_width + margin) * 2.0 - right_offset,
                                             Context.Radius / 2.0, CairoCorners.All);
            cr.Stroke();
        }
Пример #30
0
        /// <summary>Paint on the graphics context</summary>
        /// <param name="context">The graphics context to draw on</param>
        public override void Paint(Cairo.Context context)
        {
            if (Selected)
            {
                context.SetSourceColor(OxyColors.Blue);
            }
            else
            {
                context.SetSourceColor(ForegroundColour);
            }

            // Draw circle
            context.LineWidth = 3;
            context.NewPath();
            context.Arc(Location.X, Location.Y, Width / 2, 0, 2 * Math.PI);
            context.StrokePreserve();
            context.SetSourceColor(Colour);
            context.Fill();

            // Write text
            context.LineWidth = 1;
            context.SetSourceColor(OxyColors.Black);
            context.SetFontSize(13);

            DrawCentredText(context, Name, Location);
        }
Пример #31
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(true);
            }

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                cr.Save();

                cr.Color    = new Cairo.Color(0, 0, 0, 0);
                cr.Operator = Operator.Source;
                cr.Paint();

                cr.Restore();

                int width, height;
                GetSizeRequest(out width, out height);

                double opacity = Math.Min(1, (DateTime.UtcNow - shown_time).TotalMilliseconds / AnimationTime);
                if (!curtainDown)
                {
                    opacity = 1 - opacity;
                }

                cr.Rectangle(0, 0, width, height);
                cr.Color = new Cairo.Color(0, 0, 0, CurtainOpacity * opacity);
                cr.Fill();

                (cr.Target as IDisposable).Dispose();
            }

            return(false);
        }
Пример #32
0
        protected override void RenderCoverArt(Cairo.Context cr, ImageSurface image)
        {
            if (image == null)
            {
                return;
            }

            Gdk.Rectangle alloc     = RenderAllocation;
            int           asr       = ArtworkSizeRequest;
            int           reflect   = (int)(image.Height * 0.2);
            int           surface_w = image.Width;
            int           surface_h = image.Height + reflect;
            int           x         = alloc.X + alloc.Width - asr;
            int           y         = alloc.Y;

            Surface scene = null;

            if (!surfaces.TryGetValue(image, out scene))
            {
                scene = CreateScene(cr, image, reflect);
                surfaces.Add(image, scene);
            }

            cr.Rectangle(x, y, asr, alloc.Height);
            cr.Color = BackgroundColor;
            cr.Fill();

            x += (asr - surface_w) / 2;
            y += surface_h > asr ? 0 : (asr - surface_h) / 2;

            cr.SetSource(scene, x, y);
            cr.Paint();
        }
Пример #33
0
        void DrawButtonTabs(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            int topPadding = 2;

            if (Active || HoverPosition.X >= 0)
            {
                cr.NewPath();
                cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding);
                cr.ClosePath();
                if (Active)
                {
                    cr.Color = (HslColor)parent.Style.Background(StateType.Prelight);
                }
                else if (HoverPosition.X >= 0)
                {
                    double rx = rectangle.X + HoverPosition.X;
                    double ry = rectangle.Y + HoverPosition.Y;
                    Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5,
                                                                             rx, ry, 2);
                    var color = (HslColor)parent.Style.Dark(StateType.Normal);
                    color.L *= 1.1;
                    gradient.AddColorStop(0, color);
                    color.L *= 1.1;
                    gradient.AddColorStop(1, color);
                    cr.Pattern = gradient;
                }
                if (!Active)
                {
                    cr.Fill();
                }
                else
                {
                    cr.FillPreserve();
                    cr.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
            }

            cr.Save();
            cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2 + topPadding);
            cr.Color = (HslColor)parent.Style.Text(StateType.Normal);

            cr.ShowLayout(layout);

            cr.Restore();
        }
Пример #34
0
        public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer)
        {
            if (layer == PrintLayer.Text)
            {
                cr.SetFont(_fontInfo);

                yPos -= _extents.YAdvance;

                if (_fontInfo.Underline == true)
                {
                    TextExtents extents = GetExtents(cr);

                    cr.Rectangle(xPos
                                 , yPos - _fontInfo.UnderlineHeight
                                 , extents.Width
                                 , _fontInfo.UnderlineHeight);

                    cr.Fill();

                    yPos -= _fontInfo.UnderlineHeight + 2.0;
                }

                cr.MoveTo(xPos, yPos);
                cr.ShowText(_text);
            }
        }
Пример #35
0
        public override void DrawColumnHeaderFocus(Cairo.Context cr, Gdk.Rectangle alloc)
        {
            double top_offset   = 2.0;
            double right_offset = 2.0;

            double margin     = 0.5;
            double line_width = 0.7;

            Cairo.Color stroke_color = CairoExtensions.ColorShade(
                CairoExtensions.GdkRGBAToCairoColor(
                    Widget.StyleContext.GetBackgroundColor(StateFlags.Selected)), 0.8);

            stroke_color.A = 0.1;
            cr.Color       = stroke_color;

            CairoExtensions.RoundedRectangle(cr,
                                             alloc.X + margin + line_width + right_offset,
                                             alloc.Y + margin + line_width + top_offset,
                                             alloc.Width - (margin + line_width) * 2.0 - right_offset,
                                             alloc.Height - (margin + line_width) * 2.0 - top_offset,
                                             Context.Radius / 2.0, CairoCorners.None);

            cr.Fill();

            stroke_color.A = 1.0;
            cr.LineWidth   = line_width;
            cr.Color       = stroke_color;
            CairoExtensions.RoundedRectangle(cr,
                                             alloc.X + margin + line_width + right_offset,
                                             alloc.Y + margin + line_width + top_offset,
                                             alloc.Width - (line_width + margin) * 2.0 - right_offset,
                                             alloc.Height - (line_width + margin) * 2.0 - right_offset,
                                             Context.Radius / 2.0, CairoCorners.All);
            cr.Stroke();
        }
Пример #36
0
    protected override FlowReturn OnTransformIp(Gst.Buffer buf)
    {
        if (!buf.IsWritable)
        {
            return(FlowReturn.Error);
        }

        Cairo.ImageSurface img = new Cairo.ImageSurface(buf.Data, Cairo.Format.Rgb24, width, height, width * 4);

        using (Cairo.Context context = new Cairo.Context(img)) {
            double dx = (double)((buf.Timestamp / Clock.MSecond) % 2180) / 5;
            context.Save();
            context.Scale(width / 640.0, height / 480.0);
            context.MoveTo(300, 10 + dx);
            context.LineTo(500 - dx, 400);
            context.LineWidth = 4.0;
            context.Color     = new Color(0, 0, 1.0);
            context.Stroke();
            context.Restore();

            if (lastX != -1 && lastY != -1)
            {
                context.Color = new Color(1.0, 0, 0);
                context.Translate(lastX, lastY);
                context.Scale(Math.Min(width / 640.0, height / 480.0), Math.Min(width / 640.0, height / 480.0));
                context.Arc(0, 0, 10.0, 0.0, 2 * Math.PI);
                context.Fill();
            }
        }

        img.Destroy();
        return(base.OnTransformIp(buf));
    }
Пример #37
0
 private void Image_Loaded(object sender, RoutedEventArgs e)
 {
     Image image = (Image)sender;
     using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height))
     {
         using (Context context = new Context(surface))
         {
             PointD p = new PointD(10.0, 10.0);
             PointD p2 = new PointD(100.0, 10.0);
             PointD p3 = new PointD(100.0, 100.0);
             PointD p4 = new PointD(10.0, 100.0);
             context.MoveTo(p);
             context.LineTo(p2);
             context.LineTo(p3);
             context.LineTo(p4);
             context.LineTo(p);
             context.ClosePath();
             context.Fill();
             context.MoveTo(140.0, 110.0);
             context.SetFontSize(32.0);
             context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0));
             context.ShowText("Hello Cairo!");
             surface.Flush();
             RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width);
             image.Source = source;
         }
     }
 }
Пример #38
0
        void DrawVertConditionText(Cairo.Context cr, int yCenter, string text)
        {
            using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) {
                Pango.Rectangle inkRect, logicalRect;

                layout.FontDescription        = new Gtk.Style().FontDescription;
                layout.FontDescription.Weight = Pango.Weight.Bold;
                layout.Ellipsize = Pango.EllipsizeMode.None;
                layout.Width     = Pango.Units.FromPixels(Allocation.Width);

                if (WeatherController.Weather.ForecastDays < 6)
                {
                    layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(Allocation.Width / 10));
                }
                else
                {
                    layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(Allocation.Width / 7));
                }

                cr.Color = new Cairo.Color(1, 1, 1, 0.9);
                layout.SetText(text);
                layout.GetPixelExtents(out inkRect, out logicalRect);
                cr.MoveTo((Allocation.Width - logicalRect.Width) / 2, yCenter - logicalRect.Height / 2);
                Pango.CairoHelper.LayoutPath(cr, layout);
                cr.Fill();

                layout.FontDescription.Dispose();
                layout.Context.Dispose();
            }
        }
Пример #39
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        double xc     = 0.5;
        double yc     = 0.5;
        double radius = 0.4;
        double angle1 = 45.0 * (M_PI / 180.0);         /* angles are specified */
        double angle2 = 180.0 * (M_PI / 180.0);        /* in radians           */

        gr.Scale(width, height);
        gr.LineWidth = 0.04;


        gr.Arc(xc, yc, radius, angle1, angle2);
        gr.Stroke();

        /* draw helping lines */
        gr.Color = new Color(1, 0.2, 0.2, 0.6);
        gr.Arc(xc, yc, 0.05, 0, 2 * M_PI);
        gr.Fill();
        gr.LineWidth = 0.03;
        gr.Arc(xc, yc, radius, angle1, angle1);
        gr.LineTo(new PointD(xc, yc));
        gr.Arc(xc, yc, radius, angle2, angle2);
        gr.LineTo(new PointD(xc, yc));
        gr.Stroke();
    }
Пример #40
0
        void imprime_encabezado(Cairo.Context cr, Pango.Layout layout)
        {
            Gtk.Image image5 = new Gtk.Image();
            image5.Name = "image5";
            //image5.Pixbuf = new Gdk.Pixbuf(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "osiris.jpg"));
            image5.Pixbuf = new Gdk.Pixbuf("/opt/osiris/bin/OSIRISLogo.jpg");               // en Linux
            //image5.Pixbuf.ScaleSimple(128, 128, Gdk.InterpType.Bilinear);
            //Gdk.CairoHelper.SetSourcePixbuf(cr,image5.Pixbuf,1,-30);
            //Gdk.CairoHelper.SetSourcePixbuf(cr,image5.Pixbuf.ScaleSimple(145, 50, Gdk.InterpType.Bilinear),1,1);
            Gdk.CairoHelper.SetSourcePixbuf(cr, image5.Pixbuf, 1, 1);
            cr.Fill();
            //cr.Restore();
            cr.Paint();
            cr.Restore();

            Pango.FontDescription desc = Pango.FontDescription.FromString("Sans");
            // cr.Rotate(90)  Imprimir Orizontalmente rota la hoja cambian las posiciones de las lineas y columna
            fontSize  = 6.0;
            desc.Size = (int)(fontSize * pangoScale);                                       layout.FontDescription = desc;
            layout.FontDescription.Weight = Weight.Bold;
            //cr.MoveTo(20*escala_en_linux_windows,10*escala_en_linux_windows);					layout.SetText(classpublic.nombre_empresa);		Pango.CairoHelper.ShowLayout (cr, layout);
            //cr.MoveTo(20*escala_en_linux_windows,20*escala_en_linux_windows);					layout.SetText(classpublic.direccion_empresa);	Pango.CairoHelper.ShowLayout (cr, layout);
            //cr.MoveTo(20*escala_en_linux_windows,30*escala_en_linux_windows);					layout.SetText(classpublic.telefonofax_empresa);		Pango.CairoHelper.ShowLayout (cr, layout);
            //cr.MoveTo(20*escala_en_linux_windows,70*escala_en_linux_windows);					layout.SetText("Sistema Hospitalario OSIRIS");		Pango.CairoHelper.ShowLayout (cr, layout);
            // Cambiando el tamaño de la fuente
            fontSize  = 12.0;
            desc.Size = (int)(fontSize * pangoScale);                                       layout.FontDescription = desc;
            cr.MoveTo(230 * escala_en_linux_windows, 55 * escala_en_linux_windows);                                                                             layout.SetText("PROTOCOLO DE ADMISION");
            Pango.CairoHelper.ShowLayout(cr, layout);
            cr.MoveTo(280 * escala_en_linux_windows, 65 * escala_en_linux_windows);                                                                     layout.SetText("REGISTRO");
            Pango.CairoHelper.ShowLayout(cr, layout);
            layout.FontDescription.Weight = Weight.Normal;                      // Letra Normal
            fontSize  = 8.0;
            desc.Size = (int)(fontSize * pangoScale);               layout.FontDescription = desc;
        }
Пример #41
0
        //        public override TextExtents GetExtents(Cairo.Context cr)
        //        {
        //            TextExtents extents = new TextExtents();
        //            extents.Height = _pageSettings.PageHeight;
        //            extents.Width = _pageSettings.PageWidth;
        //            return extents;
        //        }

        public override void Draw(Cairo.Context cr, double xPos, double yPos, PrintLayer layer)
        {
            if (layer == PrintLayer.DisplayBackground)
            {
                // Create the shadow effect
                cr.SetSourceRGBA(0.5, 0.5, 0.5, 0.5);
                cr.Rectangle(xPos + Constants.SHADOW_WIDTH
                             , yPos + Constants.SHADOW_WIDTH
                             , _pageSettings.PaperWidth
                             , _pageSettings.PaperHeight);
                cr.Fill();



                cr.SetSourceRGB(1, 1, 1);
                cr.Rectangle(xPos
                             , yPos
                             , _pageSettings.PaperWidth
                             , _pageSettings.PaperHeight);
                cr.Fill();
            }

            double pageTop = yPos;

            yPos += _pageSettings.TopMargin;
            xPos += _pageSettings.LeftMargin;

            if (_header != null)
            {
                yPos += _header.GetExtents(cr).Height;
                _header.Draw(cr, xPos, yPos, layer);
            }

            // Move the cursor to the bottom of the page elements.
            TextExtents extents = GetExtents(cr);

            yPos += extents.Height + extents.YAdvance;

            // Draw the page elements in reverse order.
            base.Draw(cr, xPos, yPos, layer);

            if (_footer != null)
            {
                yPos = pageTop + _pageSettings.PageHeight;
                _footer.Draw(cr, xPos, yPos, layer);
            }
        }
Пример #42
0
		protected override void onDraw (Cairo.Context gr)
		{
			base.onDraw (gr);

			if (lines == null)
				return;

			gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
			gr.SetFontSize (Font.Size);

			Rectangle r = ClientRectangle;

			Foreground.SetAsSource (gr);

			double y = ClientRectangle.Y;
			double x = ClientRectangle.X;
			Fill errorFill = new SolidColor (Color.Carmine);
			for (int i = 0; i < visibleLines; i++) {
				if (i + Scroll >= Lines.Count)
					break;
				if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) {
					errorFill.SetAsSource (gr);
					gr.Rectangle (x, y, (double)r.Width, fe.Height);
					gr.Fill ();
					Foreground.SetAsSource (gr);
				}
				gr.MoveTo (x, y + fe.Ascent);
				gr.ShowText (lines[i+Scroll] as string);
				y += fe.Height;
				gr.Fill ();
			}

			if (Lines.Count <= visibleLines)
				return;
			Rectangle scrBar = ClientRectangle;
			scrBar.X += ClientRectangle.Width - scrBarWidth;
			scrBar.Width = scrBarWidth;

			new SolidColor (Color.LightGray.AdjustAlpha(0.5)).SetAsSource (gr);
			CairoHelpers.CairoRectangle(gr, scrBar, 2.0);
			gr.Fill ();
			new SolidColor (Color.BlueCrayola.AdjustAlpha(0.7)).SetAsSource (gr);
			scrBar.Y += (int)((double)scrBar.Height * (double)Scroll / (double)Lines.Count);
			scrBar.Height = (int)((double)scrBar.Height * (double)visibleLines / (double)Lines.Count);
			CairoHelpers.CairoRectangle(gr, scrBar, 2.0);
			gr.Fill ();
		}
Пример #43
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(Styles.SubTabBarSeparatorColor.ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    cr.SetSourceColor(Styles.SubTabBarActiveBackgroundColor.ToCairoColor());
                    cr.Fill();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    cr.SetSourceColor(Styles.SubTabBarHoverBackgroundColor.ToCairoColor());
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceColor(Styles.SubTabBarActiveTextColor.ToCairoColor());
                layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11, Pango.Weight.Bold);
            }
            else
            {
                cr.SetSourceColor(Styles.SubTabBarTextColor.ToCairoColor());
                layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11);
            }

            layout.Width = (int)rectangle.Width;

            cr.MoveTo(rectangle.X + (int)(rectangle.Width / 2), (rectangle.Height - h) / 2 - 1);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }
Пример #44
0
        protected void DrawBackground(Cairo.Context cr)
        {
            var totalRect = GetTotalBounds();

            cr.SetSourceColor(BackgroundColor);
            cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height);
            cr.Fill();

            cr.Save();
            cr.Translate(XOffset, YOffset);
            cr.Scale(Scale, Scale);

            if (Surface != null)
            {
                cr.SetSource(Surface, 0, 0);

                using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                    pattern.Filter = Filter.Nearest;
                }

                cr.Paint();
            }
            else if (Image != null)
            {
                using (Surface source = new BitmapSurface(Image)) {
                    cr.SetSource(source, 0, 0);

                    using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                        pattern.Filter = Filter.Nearest;
                    }

                    cr.Paint();
                }
            }
            else
            {
                Cairo.Rectangle extents = cr.ClipExtents();
                for (int i = 0; i < Width * Height; i++)
                {
                    int             tileX = i % Width;
                    int             tileY = i / Width;
                    Cairo.Rectangle rect  = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false);

                    if (!CairoHelper.RectsOverlap(extents, rect))
                    {
                        continue;
                    }

                    cr.Save();
                    cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY);
                    cr.Rectangle(0, 0, TileWidth, TileHeight);
                    cr.Clip();
                    TileDrawer(i, cr);
                    cr.Restore();
                }
            }

            cr.Restore(); // Undo scale, offset
        }
Пример #45
0
 public void clear(Context ctx)
 {
     foreach (Rectangle r in list)
         ctx.Rectangle(r);
     ctx.Operator = Operator.Clear;
     ctx.Fill();
     ctx.Operator = Operator.Over;
 }
Пример #46
0
        public override void Render(Node node, Context context)
        {
            BoxNode box = node as BoxNode;

            LayoutOutline (node, context);
            context.Color = box.Color.MultiplyAlpha (node.Opacity).ToCairo ();
            context.Fill ();
        }
Пример #47
0
        public override void Render(Node node, Context context)
        {
            PolygonNode poly = node as PolygonNode;

            LayoutOutline (poly, context);
            context.Color = poly.Color.MultiplyAlpha (poly.Opacity).ToCairo ();
            context.Fill ();
        }
Пример #48
0
 protected void OnRender(Context cr, int width, int height)
 {
     cr.Save();
     cr.SetSourceRGBA(1, 0, 0, mTick*0.1);
     cr.Rectangle(0, 0, width, height);
     cr.Fill();
     cr.Restore();
 }
Пример #49
0
 public static void DrawPoints(List<PointD> points,Context cr)
 {
     foreach (PointD p in points){
         cr.MoveTo(p);
         cr.SetSourceRGB (0.3, 0.3, 0.3);
         cr.Arc (p.X, p.Y, 2, 0, 2 * Math.PI);
         cr.Fill ();
     }
 }
Пример #50
0
        protected override void ClippedRender (Context cr)
        {
            if (!color_set || ChangeOnRender) {
                color = CairoExtensions.RgbToColor ((uint)rand.Next (0, 0xffffff));
                color_set = true;
            }

            CairoExtensions.RoundedRectangle (cr, 0, 0, RenderSize.Width, RenderSize.Height, 5);
	    cr.SetSourceColor (color);
            cr.Fill ();
        }
Пример #51
0
        public void clearAndClip(Context ctx)
        {
            if (list.Count == 0)
                return;
            foreach (Rectangle r in list)
                ctx.Rectangle(r);

            ctx.ClipPreserve();
            ctx.Operator = Operator.Clear;
            ctx.Fill();
            ctx.Operator = Operator.Over;
        }
Пример #52
0
        /// <summary>
        /// Erase the handle that was drawn in a previous call to Render ().
        /// </summary>
        public void Clear (Context g)
        {
            g.Save ();

            var rect = GetHandleRect ().Inflate (2, 2);
            using (var path = g.CreateRectanglePath (rect))
                g.AppendPath (path);
            g.Operator = Operator.Clear;
            g.Fill ();

            g.Restore ();
        }
Пример #53
0
 /// <summary>
 /// Draws black in the areas outside the view.
 /// Assumes that controlBounds is starting at (0, 0) in upper left corner.
 /// </summary>
 /// <param name="context">A context to perform drawing.</param>
 /// <param name="controlBounds">Bounds of the control.</param>
 /// <param name="view">The bounds of the view.</param>
 public static void Draw(Context context, Rectangle controlBounds, Rectangle view)
 {
     context.Color = new Cairo.Color (0.0, 0.0, 0.0);
     context.NewPath ();
     context.Rectangle (0.0, 0.0, view.X, controlBounds.Height);
     var wRight = controlBounds.Width - view.X - view.Width;
     context.Rectangle (view.X + view.Width, 0.0, wRight, controlBounds.Height);
     context.Rectangle (view.X, 0.0, view.Width, view.Y);
     var hBottom = controlBounds.Height - view.Y - view.Height;
     context.Rectangle (view.X, view.Y + view.Height, view.Width, hBottom);
     context.Fill ();
 }
Пример #54
0
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            Rectangle rBack = ClientRectangle;

            rBack.Width = (int)((double)rBack.Width / Maximum * Value);

            Foreground.SetAsSource (gr, rBack);

            CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);
            gr.Fill();
        }
Пример #55
0
        public void draw(Context cr)
        {
            Triangle t = model.tri;
            switch (model.alignment) {
            case ActiveTriangle.TriangleAlignment.ChaoticEvil:
                cr.SetSourceRGB (0.5, 0, 0);
                break;
            case ActiveTriangle.TriangleAlignment.TrueNeutral:
                cr.SetSourceRGB (0, 0.8, 0);
                break;
            default:
                cr.SetSourceRGB (1.0, 1.0, 0);
                break;

            }
            cr.LineWidth = 1.1;
            cr.MoveTo (t.a);
            cr.LineTo (t.b);
            cr.MoveTo (t.b);
            cr.LineTo (t.c);
            cr.MoveTo (t.c);
            cr.LineTo (t.a);
            cr.Stroke ();

            cr.Fill();

            Tuple<PointD,PointD,PointD,PointD> points;

            points = model.getSharpestPointAndAssociatedMidpointAndDullestPoints ();
            PointD sharpest = points.Item1;
            PointD midPoint = points.Item2;

            cr.SetSourceRGB (1.0, 0.3, 0.3);
            cr.Arc (sharpest.X, sharpest.Y, 2, 0, 2 * Math.PI);
            cr.Fill ();

            cr.Arc (midPoint.X, midPoint.Y, 2, 0, 2 * Math.PI);
            cr.Fill ();
        }
Пример #56
0
        private ImageSurface copySurfacePart(ImageSurface surf, Gdk.Rectangle dest_rect)
        {
            ImageSurface tmp_surface = new ImageSurface (Format.Argb32, dest_rect.Width, dest_rect.Height);

            using (Context g = new Context (tmp_surface)) {
                g.Operator = Operator.Source;
                g.SetSourceSurface (surf, -dest_rect.Left, -dest_rect.Top);
                g.Rectangle (new Rectangle (0, 0, dest_rect.Width, dest_rect.Height));
                g.Fill ();
            }
            //Flush to make sure all drawing operations are finished
            tmp_surface.Flush ();
            return tmp_surface;
        }
Пример #57
0
	public void CreatePng ()
	{
		const int Width = 480;
		const int Height = 160;
		const int CheckSize = 10;
		const int Spacing = 2;

		// Create an Image-based surface with data stored in ARGB32 format and a context,
		// "using" is used here to ensure that they are Disposed once we are done
		using (ImageSurface surface = new ImageSurface (Format.ARGB32, Width, Height))
		using (Context cr = new Cairo.Context (surface))
		{
			// Start drawing a checkerboard
			int i, j, xcount, ycount;
			xcount = 0;
			i = Spacing;
			while (i < Width) {
				j = Spacing;
				ycount = xcount % 2; // start with even/odd depending on row
				while (j < Height) {
					if (ycount % 2 != 0)
						cr.SetSourceRGB (1, 0, 0);
					else
						cr.SetSourceRGB (1, 1, 1);
					// If we're outside the clip, this will do nothing.
					cr.Rectangle (i, j, CheckSize, CheckSize);
					cr.Fill ();

					j += CheckSize + Spacing;
					++ycount;
				}
				i += CheckSize + Spacing;
				++xcount;
			}

			// Select a font to draw with
			cr.SelectFontFace ("serif", FontSlant.Normal, FontWeight.Bold);
			cr.SetFontSize (64.0);

			// Select a color (blue)
			cr.SetSourceRGB (0, 0, 1);

			// Draw
			cr.MoveTo (20, 100);
			cr.ShowText ("Hello, World");

			surface.WriteToPng ("test.png");
		}
	}
		protected void OnCustomWidgetChanged (Gtk.Widget widget)
		{
			OnCustomWidgetApply (widget);
			using (ImageSurface surface = new ImageSurface (Format.ARGB32, 360, 254)) {
				using (Context gr = new Context (surface)) {
					gr.Color = new Color (1, 1, 1);
					gr.Rectangle (0, 0, 360, 254);
					gr.Fill ();
					using (Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("flower.png")) {
						DrawImage (gr, pixbuf,0, 0, 360, 254);
					}
				}
				(widget as CustomPrintWidget).PreviewImage.Pixbuf = CreatePixbuf (surface);
			}
		}
Пример #59
0
    void Draw(Context cr, int width, int height)
    {
        double radius = 0.5 * Math.Min (width, height) - 10;
        int xc = width / 2;
        int yc = height / 2;

        Surface overlay = cr.Target.CreateSimilar (Content.ColorAlpha, width, height);
        Surface punch   = cr.Target.CreateSimilar (Content.Alpha, width, height);
        Surface circles = cr.Target.CreateSimilar (Content.ColorAlpha, width, height);

        FillChecks (cr, 0, 0, width, height);
        cr.Save ();

        // Draw a black circle on the overlay
        using (Context cr_overlay = new Context (overlay)) {
            cr_overlay.Color = new Color (0.0, 0.0, 0.0);
            OvalPath (cr_overlay, xc, yc, radius, radius);
            cr_overlay.Fill ();

            // Draw 3 circles to the punch surface, then cut
            // that out of the main circle in the overlay
            using (Context cr_tmp = new Context (punch))
                Draw3Circles (cr_tmp, xc, yc, radius, 1.0);

            cr_overlay.Operator = Operator.DestOut;
            cr_overlay.SetSourceSurface (punch, 0, 0);
            cr_overlay.Paint ();

            // Now draw the 3 circles in a subgroup again
            // at half intensity, and use OperatorAdd to join up
            // without seams.
            using (Context cr_circles = new Context (circles)) {
                cr_circles.Operator = Operator.Over;
                Draw3Circles (cr_circles, xc, yc, radius, 0.5);
            }

            cr_overlay.Operator = Operator.Add;
            cr_overlay.SetSourceSurface (circles, 0, 0);
            cr_overlay.Paint ();
        }

        cr.SetSourceSurface (overlay, 0, 0);
        cr.Paint ();

        overlay.Destroy ();
        punch.Destroy ();
        circles.Destroy ();
    }
Пример #60
0
 public static void DrawVertexStructure(VertexStructure vs, Context cr)
 {
     VertexStructure head = vs;
     int i = 0;
     do {
         cr.MoveTo (vs.v);
         cr.SetSourceRGB (0, 0, 0.8);
         cr.Arc (vs.v.X, vs.v.Y, 2, 0, 2 * Math.PI);
         cr.Fill ();
         cr.LineWidth = 1;
         cr.MoveTo (vs.v);
         cr.LineTo(vs.next.v);
         cr.Stroke();
         vs = vs.next;
         //Logger.Log("Meh..." + i);
         i++;
     } while(!ReferenceEquals(vs,head));
 }