Exemple #1
0
		void DrawBrush (double x, double y)
		{
			using (Cairo.Context ctx = new Cairo.Context (surface)) {
				ctx.Rectangle ((int) x - 3, (int) y - 3, 6, 6);
				ctx.Fill ();
			}

			QueueDrawArea ((int) x - 3, (int) y - 3, 6, 6);
		}
        protected override void DrawInnerFunction(Cairo.Context graphics, double uw, double x, double y, double width, double height)
        {
            double marg  = uw * 3;
            double bmarg = uw * 5;

            double quart = (width - 2 * bmarg) / 4;
            double half  = (width - 2 * bmarg) / 2;

            graphics.MoveTo(x + bmarg, y + height - bmarg);
            graphics.CurveTo(x + bmarg + quart, y + height - bmarg, x + bmarg + quart, y + bmarg, x + bmarg + half, y + bmarg);
            graphics.CurveTo(x + half + quart + bmarg, y + bmarg, x + half + quart + bmarg, y + height - bmarg, x + bmarg + half + half, y + height - bmarg);

            graphics.SetSourceRGB(0.3, 0.3, 0.6);
            graphics.Stroke();

            graphics.Arc(x + bmarg, y + height - bmarg, marg, 0, System.Math.PI * 2);
            graphics.Fill();

            graphics.Arc(x + bmarg + half, y + bmarg, marg, 0, System.Math.PI * 2);
            graphics.Fill();

            graphics.Arc(x + bmarg + half + half, y + height - bmarg, marg, 0, System.Math.PI * 2);
            graphics.Fill();
        }
Exemple #3
0
            void FillGradient(Cairo.Context cr, double y, double h)
            {
                cr.Rectangle(0.5, y, Allocation.Width, h);

                // FIXME: VV: Remove gradient features
                using (var grad = new Cairo.LinearGradient(0, y, Allocation.Width, y)) {
                    var col = (HslColor)Style.Base(StateType.Normal);
                    col.L *= 0.95;
                    grad.AddColorStop(0, col);
                    grad.AddColorStop(0.7, (HslColor)Style.Base(StateType.Normal));
                    grad.AddColorStop(1, col);
                    cr.SetSource(grad);
                    cr.Fill();
                }
            }
        public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

            cr.Rectangle(Math.Floor(x), Math.Floor(metrics.LineYRenderStartPosition) + (line == editor.GetLineByOffset(startOffset) ? editor.LineHeight - tagMarkerHeight : 0), tagMarkerWidth, tagMarkerHeight);
            cr.SetSourceColor((HslColor.Brightness(SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Background)) < 0.5 ? Ide.Gui.Styles.Editor.SmartTagMarkerColorDark : Ide.Gui.Styles.Editor.SmartTagMarkerColorLight).ToCairoColor());
            cr.Fill();
        }
        protected void DrawCaret(Cairo.Context cr)
        {
            if (TextEditor.ColorStyle == null || caretLine < 0)
            {
                return;
            }
            double y = GetYPosition(caretLine);

            cr.MoveTo(0, y - 4);
            cr.LineTo(7, y);
            cr.LineTo(0, y + 4);
            cr.ClosePath();
            cr.SetSourceColor(TextEditor.ColorStyle.PlainText.Foreground);
            cr.Fill();
        }
Exemple #6
0
        TimerApp()
        {
            win = new Window("Timer Example");
            win.SetDefaultSize(260, 110);

            da = new DrawingArea();

            // For DeleteEvent
            Observable.FromEventPattern <DeleteEventArgs>(win, "DeleteEvent")
            .Subscribe(delegate
            {
                Application.Quit();
            });

            // For Timer
            Observable.Interval(TimeSpan.FromSeconds(1))
            .Subscribe(_ =>
            {
                Gtk.Application.Invoke(delegate
                {
                    da.QueueDraw();
                });
            });

            // For DrawingArea event
            Observable.FromEventPattern <DrawnArgs>(da, "Drawn")
            .Subscribe(args =>
            {
                Cairo.Context cr = args.EventArgs.Cr;

                cr.SetSourceRGB(0.5, 0.5, 0.5);
                cr.Paint();

                cr.SetFontSize(48);
                cr.MoveTo(20, 68);
                string date = DateTime.Now.ToString("HH-mm-ss");
                cr.SetSourceRGB(0.2, 0.23, 0.9);
                cr.ShowText(date);
                cr.Fill();

                ((IDisposable)cr).Dispose();

                args.EventArgs.RetVal = true;
            });

            win.Add(da);
            win.ShowAll();
        }
Exemple #7
0
 public override void Draw(Cairo.Context dc)
 {
     if (TheFill != null)
     {
         dc.Rectangle(BB.ToCairoRectangle()); //TheFill,
         dc.Fill();
     }
     if (ThePen != null)
     {
         var r = BB;
         dc.Rectangle(r.ToCairoRectangle());//ThePen,
         dc.Stroke();
         //dc.DrawRectangle(Pens.Green, new RectangleF(20, 20, 200, 200));
         //GlobalUI.UI.AddStatusLine(this, "p " + BB.Width + " " + BB.Height + " " + r);
     }
 }
 protected void DrawSearchResults(Cairo.Context cr)
 {
     foreach (var region in TextEditor.TextViewMargin.SearchResults)
     {
         int    line            = TextEditor.OffsetToLineNumber(region.Offset);
         double y               = GetYPosition(line);
         bool   isMainSelection = false;
         if (!TextEditor.TextViewMargin.MainSearchResult.IsInvalid)
         {
             isMainSelection = region.Offset == TextEditor.TextViewMargin.MainSearchResult.Offset;
         }
         cr.Color = isMainSelection ? TextEditor.ColorStyle.SearchTextMainBg : TextEditor.ColorStyle.SearchTextBg;
         cr.Rectangle(3 + 0.5, y - 1 + 0.5, Allocation.Width - 5, 2);
         cr.Fill();
     }
 }
Exemple #9
0
        protected override void TileDrawer(int index, Cairo.Context cr)
        {
            if (index >= ObjectGroup.GetNumObjects())
            {
                return;
            }

            ObjectDefinition obj = ObjectGroup.GetObject(index);

            cr.SetSourceColor(ObjectGroupEditor.GetObjectColor(obj.GetObjectType()));
            cr.Rectangle(0, 0, 18, 18);
            cr.Fill();
            cr.Rectangle(1, 1, 16, 16); // Cut off object drawing outside 16x16 area
            cr.Clip();
            DrawObject(obj, cr, 9, 9);
        }
Exemple #10
0
        void DrawButtonBorder(Cairo.Context ctx, double x, double width)
        {
            x     -= buttonPadding;
            width += buttonPadding;
            double y      = topPadding - buttonPadding;
            double height = Allocation.Height - topPadding - bottomPadding + buttonPadding * 2;

            ctx.Rectangle(x, y, width, height);
            ctx.SetSourceColor(Styles.BreadcrumbButtonFillColor);
            ctx.Fill();

            ctx.Rectangle(x + 0.5, y + 0.5, width - 1, height - 1);
            ctx.SetSourceColor(Styles.BreadcrumbButtonBorderColor);
            ctx.LineWidth = 1;
            ctx.Stroke();
        }
Exemple #11
0
        protected virtual void DrawInner(Cairo.Context graphics, double uw, double x, double y, double width, double height)
        {
            if (d_radius > 0)
            {
                DrawRoundedRectangle(graphics, x, y, width, height, d_radius);
            }
            else
            {
                graphics.Rectangle(x, y, width, height);
            }

            graphics.StrokePreserve();

            graphics.Source = d_inner;
            graphics.Fill();
        }
 protected void DrawSearchResults(Cairo.Context cr)
 {
     foreach (var region in TextEditor.TextViewMargin.SearchResults)
     {
         int    line            = TextEditor.OffsetToLineNumber(region.Offset);
         double y               = GetYPosition(line);
         bool   isMainSelection = false;
         if (!TextEditor.TextViewMargin.MainSearchResult.IsInvalid)
         {
             isMainSelection = region.Offset == TextEditor.TextViewMargin.MainSearchResult.Offset;
         }
         cr.Color = isMainSelection ? TextEditor.ColorStyle.SearchResultMain.Color : TextEditor.ColorStyle.SearchResult.Color;
         cr.Rectangle(barPadding, Math.Round(y) - 1, Allocation.Width - barPadding * 2, 2);
         cr.Fill();
     }
 }
Exemple #13
0
        public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
                                    double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0)
        {
            Cairo.PointD vDir = p2.Substract(p1);
            vDir = vDir.GetNormalized();
            Cairo.PointD vPerp = vDir.GetPerp();

            Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength));
            Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength));

            Cairo.PointD vA = vPerp.Multiply(arrowWidth);

            ctx.MoveTo(p1);
            ctx.LineTo(pA0.Add(vA));
            if (fill)
            {
                ctx.LineTo(pA0.Substract(vA));
            }
            else
            {
                ctx.MoveTo(pA0.Substract(vA));
            }

            ctx.LineTo(p1);

            ctx.MoveTo(p2);
            ctx.LineTo(pA1.Add(vA));
            if (fill)
            {
                ctx.LineTo(pA1.Substract(vA));
            }
            else
            {
                ctx.MoveTo(pA1.Substract(vA));
            }
            ctx.LineTo(p2);

            if (fill)
            {
                ctx.Fill();
            }

            ctx.MoveTo(p1);
            ctx.LineTo(p2);
            ctx.LineWidth = stroke;
            ctx.Stroke();
        }
Exemple #14
0
 protected override bool OnDrawn(Cairo.Context cr)
 {
     if (surface != null)
     {
         cr.Save();
         Gtk.CairoHelper.TransformToWindow(cr, this, Window);
         cr.SetSource(surface);
         cr.Rectangle(widget_alloc.X, widget_alloc.Y, widget_alloc.Width, widget_alloc.Height);
         cr.Fill();
         cr.Restore();
         return(true);
     }
     else
     {
         return(base.OnDrawn(cr));
     }
 }
            protected override bool OnExposeEvent(Gdk.EventExpose evnt)
            {
                using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                    const int triangleWidth  = 8;
                    const int triangleHeight = 4;

                    cr.SetSourceColor(SyntaxHighlightingService.GetColor(DefaultSourceEditorOptions.Instance.GetEditorTheme(), EditorThemeColors.LineNumbers));
                    var topPosition = Allocation.Height / 2 - triangleHeight / 2;

                    cr.MoveTo(Allocation.Width / 2 + triangleWidth / 2, topPosition);
                    cr.LineTo(Allocation.Width / 2 - triangleWidth / 2, topPosition);
                    cr.LineTo(Allocation.Width / 2, topPosition + triangleHeight);
                    cr.LineTo(Allocation.Width / 2 + triangleWidth / 2, topPosition);
                    cr.Fill();
                }
                return(true);
            }
Exemple #16
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            // draw background fill before child widget so child appears on top
            // use Cairo drawing API (Gtk+ uses it internally as well)
            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                // Gtk deprecated warning: cr.Color = this.color;
                // available on Linux GTK# but not yet on Windows (gtk-sharp-2.12.26.msi): cr.SetSourceColor (this.color);
                // Windows: warning CS0618: 'Cairo.Context.Color' is obsolete: 'Use SetSourceRGBA method'
                // solution for now, Gtk# Context method SetSourceColor (Color) does this anyway: NativeMethods.cairo_set_source_rgba (handle, color.R, color.G, color.B, color.A);
                cr.SetSourceRGBA(this.color.R, this.color.G, this.color.B, this.color.A);
                cr.Rectangle(this.Allocation.Left, this.Allocation.Top, this.Allocation.Width, this.Allocation.Height);
                cr.Fill();
            }

            // display child
            return(base.OnExposeEvent(evnt));
        }
Exemple #17
0
        internal static void FillPolygon(this Cairo.Context g, Point[] vPoint, Color color)
        {
            if (vPoint.Length <= 2)
            {
                throw new ArgumentException("vPoint should contains 3 ore more points!");
            }

            g.NewPath();
            g.SetSourceColor(color);
            g.MoveTo(vPoint[0].ToPointD());
            foreach (var t in vPoint)
            {
                g.LineTo(t.ToPointD());
            }
            g.ClosePath();
            g.Fill();
        }
Exemple #18
0
 public override void Draw(Cairo.Context g)
 {
     if (Sleep)
     {
         g.Color = new Cairo.Color(.05, .4, .05);
     }
     else if (Poison)
     {
         g.Color = new Cairo.Color(0, 1, .4);
     }
     else
     {
         g.Color = new Cairo.Color(1, 1, 1);
     }
     g.Rectangle(X, Y, 20, 20);
     g.Fill();
 }
Exemple #19
0
        private void OnExpose(object obj, Gtk.ExposeEventArgs args)
        {
            Gtk.DrawingArea area = (Gtk.DrawingArea)obj;

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

            int width, height;

            width  = Allocation.Width;
            height = Allocation.Height;
            double radius = Math.Min(width, height) / 4;

            //draw face
            cr.Arc(width / 2, height / 2, radius, 0, 2 * Math.PI);
            cr.StrokePreserve();
            cr.SetSourceRGB(0, 0, 0);
            cr.Fill();

            //draw hands
            double hoursHandSize   = 0.35 * radius;
            double minutesHandSize = 0.5 * radius;
            double secondsHandSize = 0.75 * radius;
            double x = width / 2;
            double y = height / 2;

            cr.LineWidth = 2 * cr.LineWidth;
            cr.SetSourceRGB(0, 255, 0);

            cr.MoveTo(x, y);
            cr.LineTo(x + hoursHandSize * Math.Cos(ToRadian(hoursHand)), y + hoursHandSize * Math.Sin(ToRadian(hoursHand)));
            cr.Stroke();

            cr.MoveTo(x, y);
            cr.LineTo(x + minutesHandSize * Math.Cos(ToRadian(minutesHand)), y + minutesHandSize * Math.Sin(ToRadian(minutesHand)));
            cr.Stroke();

            cr.LineWidth = 0.25 * cr.LineWidth;
            cr.SetSourceRGB(255, 0, 0);
            cr.MoveTo(x, y);
            cr.LineTo(x + secondsHandSize * Math.Cos(ToRadian(secondsHand)), y + secondsHandSize * Math.Sin(ToRadian(secondsHand)));
            cr.Stroke();

            ((IDisposable)cr.Target).Dispose();
            ((IDisposable)cr).Dispose();
        }
Exemple #20
0
            void DrawBar(Cairo.Context cr, double y, double h)
            {
                int barPadding = 3;
                int barWidth   = Allocation.Width - barPadding - barPadding;

                MonoDevelop.Components.CairoExtensions.RoundedRectangle(cr,
                                                                        barPadding,
                                                                        y,
                                                                        barWidth,
                                                                        h,
                                                                        barWidth / 2);

                var color = Ide.Gui.Styles.BaseBackgroundColor;

                color.Light = 0.5;
                cr.SetSourceColor(color.WithAlpha(0.6).ToCairoColor());
                cr.Fill();
            }
Exemple #21
0
        public static void Gradient(Cairo.Context cr, Theme theme, Rect rect, double opacity)
        {
            cr.Save();
            cr.Translate(rect.X, rect.Y);

            var x = rect.Width / 2.0;
            var y = rect.Height / 2.0;

            using (var grad = new Cairo.RadialGradient(x, y, 0, x, y, rect.Width / 2.0)) {
                grad.AddColorStop(0, new Cairo.Color(0, 0, 0, 0.1 * opacity));
                grad.AddColorStop(1, new Cairo.Color(0, 0, 0, 0.35 * opacity));
                cr.SetSource(grad);
                CairoExtensions.RoundedRectangle(cr, rect.X, rect.Y, rect.Width, rect.Height, theme.Context.Radius);
                cr.Fill();
            }

            cr.Restore();
        }
Exemple #22
0
        internal protected override void Draw(Cairo.Context ctx, Cairo.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            bool backgroundIsDrawn = false;

            if (lineSegment != null)
            {
                foreach (var marker in editor.Document.GetMarkersOrderedByInsertion(lineSegment))
                {
                    var marginMarker = marker as MarginMarker;
                    if (marginMarker != null && marginMarker.CanDrawBackground(this))
                    {
                        backgroundIsDrawn = marginMarker.DrawBackground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                    }
                }
            }

            if (!backgroundIsDrawn)
            {
                ctx.Rectangle(x, y, Width, lineHeight);
                ctx.SetSourceColor(backgroundColor);
                ctx.Fill();

                ctx.MoveTo(x + Width - 0.5, y);
                ctx.LineTo(x + Width - 0.5, y + lineHeight);
                ctx.SetSourceColor(separatorColor);
                ctx.Stroke();
            }

            if (lineSegment != null && line <= editor.Document.LineCount)
            {
                foreach (var marker in editor.Document.GetMarkersOrderedByInsertion(lineSegment))
                {
                    var marginMarker = marker as MarginMarker;
                    if (marginMarker != null && marginMarker.CanDrawForeground(this))
                    {
                        marginMarker.DrawForeground(editor, ctx, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
                    }
                }
                if (DrawEvent != null)
                {
                    DrawEvent(this, new BookmarkMarginDrawEventArgs(editor, ctx, lineSegment, line, x, y));
                }
            }
        }
        protected virtual void SetupBackground()
        {
            background.Clear();
            Cairo.Context context = background.Create();

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            double margin = Margin;

            //left curvature:
            context.MoveTo(-hlwidth, -hlwidth);
            context.CurveTo(margin * 0.33, -hlwidth,
                            margin * 0.5, Height * 0.4,
                            margin * 0.5, Height * 0.5);
            context.CurveTo(margin * 0.5, Height * 0.6,
                            margin * 0.66, Height - hlwidth,
                            margin - hlwidth, Height - hlwidth);


            //straight bottom:
            context.LineTo(Width - margin - hlwidth, Height - hlwidth);

            //right curvature:
            context.CurveTo(Width - margin * 0.66, Height - hlwidth,
                            Width - margin * 0.5, Height * 0.6,
                            Width - margin * 0.5, Height * 0.5);
            context.CurveTo(Width - margin * 0.5, Height * 0.4,
                            Width - margin * 0.33, -hlwidth,
                            Width - hlwidth, -hlwidth);

            //straight top:
            context.LineTo(-hlwidth, -hlwidth);
            context.ClosePath();

            context.LineWidth = lwidth;
            context.SetSourceRGBA(1.0, 1.0, 1.0, 1.0);
            context.StrokePreserve();
            context.SetSourceRGBA(1.0, 1.0, 1.0, 0.10);
            context.Fill();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Exemple #24
0
        /// <summary>
        /// Creates window which emulates selection.
        /// </summary>
        private void CreateWindow()
        {
            this.window = new Gtk.Window(Gtk.WindowType.Toplevel);
            this.window.SetDefaultSize(1, 1);
            this.window.AppPaintable    = true;
            this.window.Decorated       = false;
            this.window.KeepAbove       = true;
            this.window.SkipPagerHint   = true;
            this.window.SkipTaskbarHint = true;
            this.composited             = this.window.Screen.IsComposited;

            Colormap map = this.composited ? this.window.Screen.RgbaColormap : this.window.Screen.RgbColormap;

            this.window.ScreenChanged += (s, e) => this.window.Colormap = map;
            this.window.ExposeEvent   += (object s, Gtk.ExposeEventArgs args) =>
            {
                if (this.rectangle == null)
                {
                    return;
                }

                using (Cairo.Context context = CairoHelper.Create(this.window.GdkWindow))
                {
                    context.Operator = Cairo.Operator.Source;

                    if (this.composited)
                    {
                        context.SetSourceRGBA(0.0, 0.0, 0.0, 0.3);
                    }
                    else
                    {
                        context.SetSourceRGB(0.3, 0.3, 0.3);
                    }

                    context.Rectangle(0, 0, this.rectangle.Width, this.rectangle.Height);
                    context.Fill();
                    context.Stroke();
                }
            };

            this.window.Colormap = map;
            this.window.ShowAll();
        }
            void DrawArrow(Cairo.Context g, int x, int y)
            {
                TextEditor editor      = mode.editor;
                double     phi         = 1.618;
                double     arrowLength = editor.LineHeight * phi;
                double     arrowHeight = editor.LineHeight / phi;

                g.MoveTo(x - arrowLength, y - arrowHeight);
                g.LineTo(x, y);
                g.LineTo(x - arrowLength, y + arrowHeight);

                g.LineTo(x - arrowLength / phi, y);
                g.ClosePath();
                g.Color = new Cairo.Color(1.0, 0, 0);
                g.StrokePreserve();

                g.Color = new Cairo.Color(1.0, 0, 0, 0.1);
                g.Fill();
            }
            void DrawArrow(Cairo.Context g, double x, double y)
            {
                var    editor      = mode.editor;
                double phi         = 1.618;
                double arrowLength = editor.LineHeight * phi;
                double arrowHeight = editor.LineHeight / phi;

                g.MoveTo(x - arrowLength, y - arrowHeight);
                g.LineTo(x, y);
                g.LineTo(x - arrowLength, y + arrowHeight);

                g.LineTo(x - arrowLength / phi, y);
                g.ClosePath();
                g.SetSourceRGB(1.0, 0, 0);
                g.StrokePreserve();

                g.SetSourceRGBA(1.0, 0, 0, 0.1);
                g.Fill();
            }
Exemple #27
0
        public override void Fill(object backend)
        {
            var gtkc = (CairoContextBackend)backend;

            Cairo.Context ctx   = gtkc.Context;
            var           alpha = gtkc.GlobalAlpha * gtkc.PatternAlpha;

            if (alpha == 1)
            {
                ctx.Fill();
            }
            else
            {
                ctx.Save();
                ctx.Clip();
                ctx.PaintWithAlpha(alpha);
                ctx.Restore();
            }
        }
        protected void DrawSearchResults(Cairo.Context cr, IEnumerator <TextSegment> searchResults, ref bool nextStep)
        {
            if (!searchResults.MoveNext())
            {
                nextStep = true;
                return;
            }
            var    region          = searchResults.Current;
            int    line            = TextEditor.OffsetToLineNumber(region.Offset);
            double y               = GetYPosition(line);
            bool   isMainSelection = false;

            if (!TextEditor.TextViewMargin.MainSearchResult.IsInvalid)
            {
                isMainSelection = region.Offset == TextEditor.TextViewMargin.MainSearchResult.Offset;
            }
            cr.SetSourceColor(isMainSelection ? TextEditor.ColorStyle.SearchResultMain.Color : TextEditor.ColorStyle.SearchResult.Color);
            cr.Rectangle(barPadding, Math.Round(y) - 1, Allocation.Width - barPadding * 2, 2);
            cr.Fill();
        }
        void DrawSelection(Rectangle exposeArea)
        {
            if (!isRectSelection)
            {
                return;
            }

            if (!exposeArea.Intersect(rect_select, out var region))
            {
                return;
            }

            // draw selection
            using (Cairo.Context cairo_g = CairoHelper.Create(BinWindow)) {
                Color color = Style.Background(StateType.Selected);
                cairo_g.SetSourceColor(new Cairo.Color(color.Red / 65535.0, color.Green / 65535.0, color.Blue / 65535.0, 0.5));
                cairo_g.Rectangle(region.X, region.Y, region.Width, region.Height);
                cairo_g.Fill();
            }
        }
Exemple #30
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();
 }
Exemple #31
0
        private void OnWidgetDestroyed(object sender, EventArgs args)
        {
            if (!IsRealized)
            {
                return;
            }

            // Copy the widget's pixels to surface, we'll use it to draw the animation
            surface = Window.CreateSimilarSurface(Cairo.Content.ColorAlpha, widget_alloc.Width, widget_alloc.Height);
            using (var cr = new Cairo.Context(surface)) {
                Gdk.CairoHelper.SetSourceWindow(cr, Window, widget_alloc.X, widget_alloc.Y);
                cr.Rectangle(0, 0, widget_alloc.Width, widget_alloc.Height);
                cr.Fill();

                if (AnimationState != AnimationState.Going)
                {
                    WidgetDestroyed(this, args);
                }
            }
        }
        // Draw a rectangle on the screen
        private void DrawBrush(Widget widget, double x, double y)
        {
            var update_rect = new Gdk.Rectangle ((int)x - 3, (int)y - 3, 6, 6);
            var cr = new Cairo.Context (surface);

            Gdk.CairoHelper.Rectangle (cr, update_rect);
            cr.Fill ();

            ((IDisposable)cr).Dispose ();

            widget.Window.InvalidateRect (update_rect, false);
        }
Exemple #33
0
        private void OnWidgetDestroyed(object sender, EventArgs args)
        {
            if (!IsRealized) {
                return;
            }

            // Copy the widget's pixels to surface, we'll use it to draw the animation
            surface = Window.CreateSimilarSurface (Cairo.Content.ColorAlpha, widget_alloc.Width, widget_alloc.Height);
            using (var cr = new Cairo.Context (surface)) {
                Gdk.CairoHelper.SetSourceWindow (cr, Window, widget_alloc.X, widget_alloc.Y);
                cr.Rectangle (0, 0, widget_alloc.Width, widget_alloc.Height);
                cr.Fill ();

                if (AnimationState != AnimationState.Going) {
                    WidgetDestroyed (this, args);
                }

            }
        }
Exemple #34
0
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault (stockId);
            if (iconset != null) {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit (width);
                result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor) {
                    var gsize2x = Util.GetBestSizeFit (width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon (Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon (stockId))
                result = Gtk.IconTheme.Default.LoadIcon (stockId, (int)width, (Gtk.IconLookupFlags)0);

            if (result == null)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                #if XWT_GTK3
                Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap = Cairo.LineCap.Round;
                cr.LineJoin = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap (Gdk.Screen.Default.RootWindow, w, h))
                using (Gdk.GC gc = new Gdk.GC (pmap)) {
                    gc.RgbFgColor = new Gdk.Color (255, 255, 255);
                    pmap.DrawRectangle (gc, true, 0, 0, w, h);
                    gc.RgbFgColor = new Gdk.Color (0, 0, 0);
                    pmap.DrawRectangle (gc, false, 0, 0, (w - 1), (h - 1));
                    gc.SetLineAttributes (3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                    gc.RgbFgColor = new Gdk.Color (255, 0, 0);
                    pmap.DrawLine (gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                    pmap.DrawLine (gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                    result = Gdk.Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                }
                #endif
            }
            return result;
        }
				public BgBufferUpdate (Minimpap mode)
				{
					this.mode = mode;
					
					cr = Gdk.CairoHelper.Create (mode.backgroundBuffer);
					
					cr.LineWidth = 1;
					int w = mode.backgroundBuffer.ClipRegion.Clipbox.Width;
					int h = mode.backgroundBuffer.ClipRegion.Clipbox.Height;
					cr.Rectangle (0, 0, w, h);
					if (mode.TextEditor.ColorStyle != null)
						cr.Color = mode.TextEditor.ColorStyle.Default.CairoBackgroundColor;
					cr.Fill ();
					
					maxLine = mode.TextEditor.GetTextEditorData ().VisibleLineCount;
					sx = w / (double)mode.TextEditor.Allocation.Width;
					sy = Math.Min (1, lineHeight * maxLine / (double)mode.TextEditor.GetTextEditorData ().TotalHeight );
					cr.Scale (sx, sy);
					
					handler = GLib.Idle.Add (BgBufferUpdater);
				}