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);
		}
Exemple #2
0
            void FillGradient(Cairo.Context cr, double y, double h)
            {
                cr.Rectangle(0.5, y, Allocation.Width, h);
                var grad = new Cairo.LinearGradient(0, y, Allocation.Width, y);
                var col  = (Mono.TextEditor.HslColor)Style.Base(StateType.Normal);

                col.L *= 0.95;
                grad.AddColorStop(0, col);
                grad.AddColorStop(0.7, (Mono.TextEditor.HslColor)Style.Base(StateType.Normal));
                grad.AddColorStop(1, col);
                cr.Pattern = grad;

                cr.Fill();
            }
Exemple #3
0
        public static void RoundedRectangle(this Cairo.Context cr, double x, double y, double w, double h, double r)
        {
            if (r < 0.0001)
            {
                cr.Rectangle(x, y, w, h);
                return;
            }

            cr.MoveTo(x + r, y);
            cr.Arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2);
            cr.Arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5);
            cr.Arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI);
            cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
        }
Exemple #4
0
        void DrawTabs(Pango.Layout la, Gdk.Window win, Gdk.GC gc, Cairo.Context cairo, int currentTab)
        {
            int tx = ALeft + Xpad;
            int ty = ATop + Ypad;



            float left = 0;

            for (int i = 0; i < mTabs.Count(); i++)
            {
                var t        = mTabs.ElementAt(i);
                int x1       = (int)(tx + left + 0.5f);
                var cliprect = new Gdk.Rectangle(x1, 0, (int)(t.CurrentWidth + 0.5f), Allocation.Height);
                gc.ClipRectangle = cliprect;
                cairo.Rectangle(cliprect.ToCairoRect());
                cairo.Clip();

                Color color;
                if (i == ActiveIndex && t.DockItemTitleTab.Active)
                {
                    color = Style.Background(StateType.Selected);
                }
                else if (i == currentTab)
                {
                    color = Style.Background(StateType.Normal);
                }
                else
                {
                    color = Style.Mid(StateType.Normal);
                }

                DrawRectangle(cairo, cliprect.X, cliprect.Y, cliprect.Width, cliprect.Height, color.ToCairo(), true);

                x1 += space;
                if (t.Image != null)
                {
                    win.DrawPixbuf(gc, t.Image, 0, 0, x1, (Allocation.Height - t.Image.Height + Ypad) / 2, -1, -1, Gdk.RgbDither.None, 0, 0);
                    x1 += t.Image.Width;
                    x1 += space;
                }

                la.SetMarkup(t.Label);
                DrawText(win, gc, x1, ty, System.Drawing.Color.Black.ToGdk(), la);
                left += t.CurrentWidth;

                gc.ClipRectangle = new Gdk.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                cairo.ResetClip();
            }
        }
Exemple #5
0
        public override void DrawRectangle(Brush brush, Pen pen, Rect rectangle)
        {
            if (brush != null)
            {
                if (brush is SolidColorBrush)
                {
                    var b = brush as SolidColorBrush;
                    cr.Color = new Cairo.Color(b.Color.R, b.Color.G, b.Color.B, b.Color.Alfa);
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);

                    cr.Fill();
                }
                else if (brush is LinearGradientBrush)
                {
                    var b = brush as LinearGradientBrush;

                    var pattern = new Cairo.LinearGradient(b.StartPoint.X, b.StartPoint.Y, b.EndPoint.X, b.EndPoint.Y);
                    foreach (var stop in b.GradientStops)
                    {
                        pattern.AddColorStop(stop.Offset, new Cairo.Color(stop.Color.R, stop.Color.G, stop.Color.B, stop.Color.Alfa));
                    }

                    cr.Pattern = pattern;
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    cr.Fill();
                }
            }

            if (pen != null)
            {
                cr.Color     = new Cairo.Color(pen.Color.R, pen.Color.G, pen.Color.B, pen.Color.Alfa);
                cr.LineWidth = pen.Thickness;
                cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);

                cr.Stroke();
            }
        }
Exemple #6
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (canvas_child == null || !canvas_child.Visible || !Visible || !IsMapped)
            {
                return(true);
            }

            foreach (Gdk.Rectangle damage in evnt.Region.GetRectangles())
            {
                cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height);
                cr.Clip();

                cr.Translate(Allocation.X, Allocation.Y);
                canvas_child.Render(cr);
                cr.Translate(-Allocation.X, -Allocation.Y);

                if (Debug)
                {
                    cr.LineWidth = 1.0;
                    cr.Color     = CairoExtensions.RgbToColor(
                        (uint)(rand = rand ?? new Random()).Next(0, 0xffffff));
                    cr.Rectangle(damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1);
                    cr.Stroke();
                }

                cr.ResetClip();
            }

            CairoExtensions.DisposeContext(cr);

            if (fps.Update())
            {
                // Console.WriteLine ("FPS: {0}", fps.FramesPerSecond);
            }

            return(true);
        }
Exemple #7
0
        protected override void OnDrawn(Cairo.Context cr, Gdk.Rectangle rect)
        {
            if (BackgroundColor.HasValue)
            {
                cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
                cr.SetSourceColor(BackgroundColor.Value.ToCairoColor());
                cr.Fill();
            }

            if (GradientBackround)
            {
                Color gcol = Style.Background(Gtk.StateType.Normal).ToXwtValue();

                cr.NewPath();
                cr.MoveTo(rect.X, rect.Y);
                cr.RelLineTo(rect.Width, 0);
                cr.RelLineTo(0, rect.Height);
                cr.RelLineTo(-rect.Width, 0);
                cr.RelLineTo(0, -rect.Height);
                cr.ClosePath();
                using (var pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Bottom)) {
                    Cairo.Color color1 = gcol.ToCairoColor();
                    pat.AddColorStop(0, color1);
                    gcol.Light -= 0.1;
                    pat.AddColorStop(1, gcol.ToCairoColor());
                    cr.SetSource(pat);
                    cr.FillPreserve();
                }
            }

            cr.SetSourceColor(color.HasValue ? color.Value.ToCairoColor() : Style.Dark(Gtk.StateType.Normal).ToXwtValue().ToCairoColor());
            cr.Rectangle(rect.X, rect.Y, rect.Width, topMargin);
            cr.Rectangle(rect.X, rect.Y + rect.Height - bottomMargin, rect.Width, bottomMargin);
            cr.Rectangle(rect.X, rect.Y, leftMargin, rect.Height);
            cr.Rectangle(rect.X + rect.Width - rightMargin, rect.Y, rightMargin, rect.Height);
            cr.Fill();
        }
Exemple #8
0
        void DrawShadow(Cairo.Context ctx, Gdk.Rectangle ar, PositionType pos, List <Section> secs)
        {
            foreach (Section s in secs)
            {
                Cairo.Gradient pat = null;
                Gdk.Rectangle  r   = ar;
                switch (pos)
                {
                case PositionType.Top:
                    r.Height = shadowSize > r.Height ? r.Height / 2 : shadowSize;
                    r.X     += s.Offset;
                    r.Width  = s.Size;
                    pat      = new Cairo.LinearGradient(r.X, r.Y, r.X, r.Bottom);
                    break;

                case PositionType.Bottom:
                    r.Y      = r.Bottom - shadowSize;
                    r.Height = shadowSize > r.Height ? r.Height / 2 : shadowSize;
                    r.X      = r.X + s.Offset;
                    r.Width  = s.Size;
                    pat      = new Cairo.LinearGradient(r.X, r.Bottom, r.X, r.Y);
                    break;

                case PositionType.Left:
                    r.Width  = shadowSize > r.Width ? r.Width / 2 : shadowSize;
                    r.Y     += s.Offset;
                    r.Height = s.Size;
                    pat      = new Cairo.LinearGradient(r.X, r.Y, r.Right, r.Y);
                    break;

                case PositionType.Right:
                    r.X      = r.Right - shadowSize;
                    r.Width  = shadowSize > r.Width ? r.Width / 2 : shadowSize;
                    r.Y     += s.Offset;
                    r.Height = s.Size;
                    pat      = new Cairo.LinearGradient(r.Right, r.Y, r.X, r.Y);
                    break;
                }
                Cairo.Color c = darkColor.ToCairoColor();
                pat.AddColorStop(0, c);
                c.A = 0;
                pat.AddColorStop(1, c);
                ctx.NewPath();
                ctx.Rectangle(r.X, r.Y, r.Width, r.Height);
                ctx.SetSource(pat);
                ctx.Fill();
                pat.Dispose();
            }
        }
Exemple #9
0
        public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            int markerStart = Offset;
            int markerEnd   = EndOffset;

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from <= to)
            {
                if (metrics.TextEndOffset < markerEnd)
                {
                    to = metrics.WholeLineWidth + metrics.TextRenderStartPosition;
                }
                var c1 = editor.Options.GetColorStyle().PlainText.Background;
                var c2 = editor.Options.GetColorStyle().SelectedText.Background;
                cr.SetSourceRGB((c1.R + c2.R) / 2, (c1.G + c2.G) / 2, (c1.B + c2.B) / 2);
                cr.Rectangle(@from, y, to - @from, metrics.LineHeight);
                cr.Fill();
            }
        }
Exemple #10
0
        private void CheckerboardDrawn(object o, DrawnArgs args)
        {
            const int CheckSize = 10;
            const int Spacing   = 2;

            Widget widget = o as Widget;

            Cairo.Context cr = args.Cr;

            int i, j, xcount, ycount;

            // At the start of a draw handler, a clip region has been set on
            // the Cairo context, and the contents have been cleared to the
            // widget's background color.

            Rectangle alloc = widget.Allocation;

            // Start redrawing the Checkerboard
            xcount = 0;
            i      = Spacing;
            while (i < alloc.Width)
            {
                j      = Spacing;
                ycount = xcount % 2;                 // start with even/odd depending on row
                while (j < alloc.Height)
                {
                    if (ycount % 2 != 0)
                    {
                        cr.SetSourceRGB(0.45777, 0, 0.45777);
                    }
                    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;
            }

            // return true because we've handled this event, so no
            // further processing is required.
            args.RetVal = true;
        }
Exemple #11
0
//        public Enemy Clone()
//        {
//            return new Enemy(Resource.CreateID(Name));
//        }


        protected override void DrawIcon(Gdk.Drawable d, Cairo.Context g)
        {
            g.Color = Colors.ENEMY_RED;
            g.Rectangle(X - _icon_half_width, Y - _icon_half_height, Character.PROFILE_WIDTH_TINY, Character.PROFILE_HEIGHT_TINY);
            g.Fill();

#if DEBUG
            string variables = GetVariableText();

            if (variables.Length > 0)
            {
                Text.ShadowedText(g, Colors.WHITE, variables, X + _text_offset_x, Y + _text_offset_y - _text_spacing_y, Text.MONOSPACE_FONT, 12);
            }
#endif
        }
        public void DrawSelectionRectangle(Cairo.Context cr, int x, int y, int width, int height)
        {
            cr.Rectangle(x + DEFUZZ, y + DEFUZZ,
                         width, height);

            //cr.Color = CairoHelper.GetCairoColorWithAlpha (gtk_style.Foreground (state), 0.1f);
            cr.SetSourceRGBA(CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).R, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).G, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).B, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.1f).A);
            cr.FillPreserve();

            //cr.Color = CairoHelper.GetCairoColorWithAlpha (gtk_style.Foreground (state), 0.7f);
            cr.SetSourceRGBA(CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).R, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).G, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).B, CairoHelper.GetCairoColorWithAlpha(gtk_style.Foreground(state), 0.7f).A);

            cr.LineWidth = 1.0f;
            cr.Stroke();
        }
Exemple #13
0
        // From MonoDevelop:
        // https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Ide/gtk-gui/generated.cs
        private static Pixbuf CreateMissingImage(int size)
        {
            using (var surf = new Cairo.ImageSurface(Cairo.Format.Argb32, size, size))
                using (var g = new Cairo.Context(surf)) {
                    g.SetSourceColor(new Cairo.Color(1, 1, 1));
                    g.Rectangle(0, 0, size, size);
                    g.Fill();

                    g.SetSourceColor(new Cairo.Color(0, 0, 0));
                    g.Rectangle(0, 0, size - 1, size - 1);
                    g.Fill();

                    g.LineWidth = 3;
                    g.LineCap   = Cairo.LineCap.Round;
                    g.LineJoin  = Cairo.LineJoin.Round;
                    g.SetSourceColor(new Cairo.Color(1, 0, 0));
                    g.MoveTo(size / 4, size / 4);
                    g.LineTo((size - 1) - (size / 4), (size - 1) - (size / 4));
                    g.MoveTo((size - 1) - (size / 4), size / 4);
                    g.LineTo(size / 4, (size - 1) - (size / 4));

                    return(new Pixbuf(surf, 0, 0, surf.Width, surf.Height));
                }
        }
Exemple #14
0
        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) + editor.LineHeight - tagMarkerHeight, 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();
        }
Exemple #15
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();
                }
            }
Exemple #16
0
        void DrawSearchResults(Cairo.Context cr)
        {
            int h = Allocation.Height - Allocation.Width - 6;

            foreach (var region in TextEditor.TextViewMargin.SearchResults)
            {
                int    line            = TextEditor.OffsetToLineNumber(region.Offset);
                double y               = h * TextEditor.LineToY(line) / Math.Max(TextEditor.EditorLineThreshold * TextEditor.LineHeight + TextEditor.GetTextEditorData().TotalHeight, TextEditor.Allocation.Height);
                bool   isMainSelection = false;
                if (TextEditor.TextViewMargin.MainSearchResult != null)
                {
                    isMainSelection = region.Offset == TextEditor.TextViewMargin.MainSearchResult.Offset;
                }
                var color = (HslColor)(isMainSelection ? TextEditor.ColorStyle.SearchTextMainBg : TextEditor.ColorStyle.SearchTextBg);
                cr.Color = color;
                cr.Rectangle(3, y - 1, Allocation.Width - 5, 4);
                cr.FillPreserve();

                color.L *= 0.7;
                cr.Color = color;
                cr.Rectangle(3, y - 1, Allocation.Width - 5, 4);
                cr.Stroke();
            }
        }
 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 #18
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) {
                cr.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
                cr.ClipPreserve();

                cr.SetSourceRGB(1.00, 0.98, 0.91);
                cr.FillPreserve();

                cr.SetSourceRGB(0.87, 0.83, 0.74);
                cr.LineWidth = 2;
                cr.Stroke();
            }

            return(base.OnExposeEvent(evnt));
        }
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) {
                cr.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
                cr.ClipPreserve();

                cr.SetSourceColor(Styles.ExceptionCaughtDialog.InfoFrameBackgroundColor.ToCairoColor());
                cr.FillPreserve();

                cr.SetSourceColor(Styles.ExceptionCaughtDialog.InfoFrameBorderColor.ToCairoColor());
                cr.LineWidth = 2;
                cr.Stroke();
            }

            return(base.OnExposeEvent(evnt));
        }
Exemple #20
0
 protected virtual void GetFrame(Cairo.Context cairo)
 {
     if (radius == 0)
     {
         cairo.MoveTo(x, y);
         cairo.Rectangle(x, y, width, height);
     }
     else
     {
         cairo.MoveTo(x + radius, y);
         cairo.Arc(x + width - radius, y + radius, radius, (Math.PI * 1.5), (Math.PI * 2));
         cairo.Arc(x + width - radius, y + height - radius, radius, 0, (Math.PI * 0.5));
         cairo.Arc(x + radius, y + height - radius, radius, (Math.PI * 0.5), Math.PI);
         cairo.Arc(x + radius, y + radius, radius, Math.PI, (Math.PI * 1.5));
     }
 }
Exemple #21
0
 protected override void GetFrame(Cairo.Context cairo)
 {
     if (radius == 0)
     {
         cairo.MoveTo(x, y);
         cairo.Rectangle(x, y, width, height);
     }
     else
     {
         cairo.MoveTo(x, y);
         cairo.LineTo(x + width, y);
         cairo.Arc(x + width - radius, y + height - radius, radius, 0, (Math.PI * 0.5));
         cairo.Arc(x + radius, y + height - radius, radius, (Math.PI * 0.5), Math.PI);
         cairo.ClosePath();
     }
 }
Exemple #22
0
        public void Wire(Cairo.Context cr, Wire wire)
        {
            int vertical   = wire.Direction == Direction.Vertical ? 1 : 0;
            int horizontal = 1 - vertical;

            double x = wire.Pos.X * CircuitEditor.DotSpacing - HalfWireWidth;
            double y = wire.Pos.Y * CircuitEditor.DotSpacing - HalfWireWidth;

            double length = CircuitEditor.DotSpacing * wire.Length;
            // If we are drawing a horizontal line the width is length, othervise it's WireWidth.
            double width = (horizontal * (length + WireWidth)) + (vertical * WireWidth);
            // The opposite of the above.
            double height = (vertical * (length + WireWidth)) + (horizontal * WireWidth);

            cr.Rectangle(x, y, width, height);
        }
Exemple #23
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.SearchTextMainBg : TextEditor.ColorStyle.SearchTextBg;
         cr.Rectangle(3 + 0.5, y - 1 + 0.5, Allocation.Width - 5, 2);
         cr.Fill();
     }
 }
        public void DrawField(Cairo.Context cr, int x, int y, int width, int height)
        {
            cr.Rectangle(x + DEFUZZ, y + DEFUZZ, width - 1.0f, height - 1.0f);

            cr.SetSourceRGBA(CairoHelper.GetCairoColor(gtk_style.Base(state)).R, CairoHelper.GetCairoColor(gtk_style.Base(state)).G, CairoHelper.GetCairoColor(gtk_style.Base(state)).B, CairoHelper.GetCairoColor(gtk_style.Base(state)).A);

            //cr.Color = CairoHelper.GetCairoColor (gtk_style.Base (state));
            cr.FillPreserve();

            cr.SetSourceRGBA(CairoHelper.GetCairoColor(gtk_style.Foreground(state)).R, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).G, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).B, CairoHelper.GetCairoColor(gtk_style.Foreground(state)).A);

            //cr.Color = CairoHelper.GetCairoColor (gtk_style.Foreground (state));

            cr.LineWidth = FIELD_LINE_THICKNESS;
            cr.Stroke();
        }
Exemple #26
0
        public Gdk.Pixbuf Icon(int size)
        {
            Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.Argb32, size, size);
            Gdk.Pixbuf         ret;

            Style         = DrawStyle.Icon;
            Cache.Enabled = false;

            using (Cairo.Context ct = new Cairo.Context(surface))
            {
                ct.Rectangle(0, 0, size, size);
                ct.Clip();

                ct.Translate(0, 0);
                ct.Scale(size, size);

                ct.LineWidth = 1.0 / size;

                Draw(ct);

                byte[] data = ConvertColorSpace(surface.Data);

                try
                {
                    ret = new Gdk.Pixbuf(data, Gdk.Colorspace.Rgb, true, 8, size, size, surface.Stride);
                }
                catch
                {
                    // Some stupid bug in older mono, fallback strategy
                    string filename = System.IO.Path.GetTempFileName();

                    if (System.IO.File.Exists(filename))
                    {
                        System.IO.File.Delete(filename);
                    }

                    surface.WriteToPng(filename);
                    ret = new Gdk.Pixbuf(filename);
                    System.IO.File.Delete(filename);
                }
            }

            Cache.Enabled = true;
            Style         = DrawStyle.Normal;

            return(ret);
        }
Exemple #27
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            base.OnDrawn(cr);

            if (!Selectable)
            {
                return(true);
            }

            cr.NewPath();
            cr.SetSourceColor(SelectionColor);
            cr.Rectangle(XOffset + SelectedX * TileWidth * Scale + 0.5, SelectedY * TileHeight * Scale + 0.5, TileWidth * Scale - 1, TileHeight * Scale - 1);
            cr.LineWidth = 1;
            cr.Stroke();

            return(true);
        }
            public override void Draw(TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
            {
                var line = editor.GetLine(loc.Line);
                var x    = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

                cr.Rectangle(Math.Floor(x) + 0.5, Math.Floor(y) + 0.5 + (line == editor.GetLineByOffset(startOffset) ? editor.LineHeight - tagMarkerHeight - 1 : 0), tagMarkerWidth * cr.LineWidth, tagMarkerHeight * cr.LineWidth);

                if (HslColor.Brightness(editor.ColorStyle.PlainText.Background) < 0.5)
                {
                    cr.SetSourceRGBA(0.8, 0.8, 1, 0.9);
                }
                else
                {
                    cr.SetSourceRGBA(0.2, 0.2, 1, 0.9);
                }
                cr.Stroke();
            }
Exemple #29
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 #30
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 #31
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));
     }
 }
				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);
				}
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
            void OnConfigured(object o, ConfigureEventArgs args)
            {
                pixmap = new Pixmap (args.Event.Window,
                             Allocation.Width,
                             Allocation.Height);
                cairo = Gdk.CairoHelper.Create (pixmap);
                cairo.Rectangle (0, 0,
                         Allocation.Width,
                         Allocation.Height);
                cairo.Clip ();

                ArrayList oldlist = points;
                points = new ArrayList ();

                ComputePositions ();
                foreach (GraphPoint point in oldlist)
                {
                    __AddGameInfo (point.info);
                }

                UpdatePixmap ();
            }
Exemple #35
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;
        }