public DrawInRegionVisitor(Gdk.Region region, Cairo.Context context, IDrawingView view)
 {
     this.context = context;
     this.region = region;
     this.view = view;
     this.figures = new List<Figure> ();
 }
        private void Activated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));

            if (cb.WaitIsImageAvailable ()) {
                PintaCore.Tools.Commit ();

                Gdk.Pixbuf image = cb.WaitForImage ();

                Layer l = PintaCore.Layers.AddNewLayer (string.Empty);

                using (Cairo.Context g = new Cairo.Context (l.Surface))
                    g.DrawPixbuf (image, new Cairo.Point (0, 0));

                // Make new layer the current layer
                PintaCore.Layers.SetCurrentLayer (l);

                PintaCore.Workspace.Invalidate ();

                AddLayerHistoryItem hist = new AddLayerHistoryItem (Stock.Paste, Catalog.GetString ("Paste Into New Layer"), PintaCore.Layers.IndexOf (l));
                PintaCore.History.PushNewItem (hist);
            } else {
                ClipboardEmptyError ();
            }
        }
Exemple #3
0
 public void RefreshBackground(Field[,] fields)
 {
     background = new Cairo.ImageSurface (Cairo.Format.ARGB32, width * fieldSize, height * fieldSize);
     using (Cairo.Context context = new Cairo.Context(background)) {
         paintBackground (context, fields);
     }
 }
Exemple #4
0
		void ClearSurface ()
		{
			using (Cairo.Context ctx = new Cairo.Context (surface)) {
				ctx.SetSourceRGB (1, 1, 1);
				ctx.Paint ();
			}
		}
Exemple #5
0
		public void Import (string fileName, Gtk.Window parent)
		{
			Pixbuf bg;

			// Handle any EXIF orientation flags
			using (var fs = new FileStream (fileName, FileMode.Open, FileAccess.Read))
				bg = new Pixbuf (fs);

			bg = bg.ApplyEmbeddedOrientation ();

			Size imagesize = new Size (bg.Width, bg.Height);

			Document doc = PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize);
			doc.HasFile = true;
			doc.ImageSize = imagesize;
			doc.Workspace.CanvasSize = imagesize;

			Layer layer = doc.AddNewLayer (Path.GetFileName (fileName));

			using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
				CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
				g.Paint ();
			}

			bg.Dispose ();
		}
Exemple #6
0
        private void HandlePintaCoreActionsFileNewActivated(object sender, EventArgs e)
        {
            NewImageDialog dialog = new NewImageDialog ();

            dialog.ParentWindow = main_window.GdkWindow;
            dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;

            int response = dialog.Run ();

            if (response == (int)Gtk.ResponseType.Ok) {
                PintaCore.Workspace.ImageSize = new Cairo.PointD (dialog.NewImageWidth, dialog.NewImageHeight);
                PintaCore.Workspace.CanvasSize = new Cairo.PointD (dialog.NewImageWidth, dialog.NewImageHeight);

                PintaCore.Layers.Clear ();
                PintaCore.History.Clear ();
                PintaCore.Layers.DestroySelectionLayer ();
                PintaCore.Layers.ResetSelectionPath ();

                // Start with an empty white layer
                Layer background = PintaCore.Layers.AddNewLayer ("Background");

                using (Cairo.Context g = new Cairo.Context (background.Surface)) {
                    g.SetSourceRGB (255, 255, 255);
                    g.Paint ();
                }

                PintaCore.Workspace.Filename = "Untitled1";
                PintaCore.Workspace.IsDirty = false;
                PintaCore.Actions.View.ZoomToWindow.Activate ();
            }

            dialog.Destroy ();
        }
        public byte[] GetFileBytes(Report report)
        {
            var pages = report.BuildPages();
            int width = (int)report.PageWidthPoints;
            int height = (int)report.PageHeightPoints;
            string filename = string.Format("gen-{0}.pdf", Guid.NewGuid());
			
            try
            {
                using (Cairo.PdfSurface pdf = new Cairo.PdfSurface(filename, width, height))
                {
                    using (Cairo.Context g = new Cairo.Context(pdf))
                    {
						
                        var render = new  fyiReporting.RdlGtkViewer.RenderCairo(g);
                        render.RunPages(pages);
                    }
                }
                byte[] bytes = File.ReadAllBytes(filename);
                return bytes;
				
            }
            finally
            {
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
            }
        }
 internal bool FillContains(Point point)
 {
     using (var context = new Cairo.Context(new Cairo.ImageSurface(Cairo.Format.Argb32, 0, 0)))
     {
         context.AppendPath(Path);
         return context.InFill(point.X, point.Y); 
     }
 }
        public RenderCairo(Cairo.Context g, float scale)
        {
            this.g = g;
            this.layout = Pango.CairoHelper.CreateLayout(g);
			
            dpiX *= scale;
            dpiY *= scale;
        }
Exemple #10
0
 public void OnContextInitialize(RenderContextInitEventArgs args)
 {
     DrawingArea area = args.Widget as DrawingArea;
     if (area != null)
     {
         _context = Gdk.CairoHelper.Create(area.GdkWindow);
     }
 }
Exemple #11
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 #12
0
        public static Gdk.Pixbuf WithAlpha (this Gdk.Pixbuf image, double opacity)
        {
            using (var surf = new Cairo.ImageSurface (Cairo.Format.Argb32, image.Width, image.Height)) {
                using (var g = new Cairo.Context (surf)) {
                    CairoHelper.SetSourcePixbuf (g, image, 0, 0);
                    g.PaintWithAlpha (opacity);
                }

                return new Gdk.Pixbuf (surf.Data, true, 8, surf.Width, surf.Height, surf.Stride);
            }
        }
Exemple #13
0
 void HandleMyWinExposeEvent(object o, ExposeEventArgs args)
 {
     GLib.Idle.Add (new GLib.IdleHandler (delegate() {
         if (cr == null) {
             Gtk.Widget widget = ((Gtk.Widget)o);
             cr = Gdk.CairoHelper.Create (widget.GdkWindow);
         }
         WindowController.DrawPixbuf (cr, pixbuf);
         return false;
     }));
 }
Exemple #14
0
        public void Dispose ()
        {
            if (Surface != null && Surface.Handle != IntPtr.Zero) {
                ((IDisposable)Surface).Dispose ();
            }
            Surface = null;

            if (Context != null) {
                Hyena.Gui.CairoExtensions.DisposeContext (Context);
                Context = null;
            }
        }
		public StreamGeometryContextImpl(Cairo.Path path = null)
        {

			_surf = new Cairo.ImageSurface (Cairo.Format.Argb32, 0, 0);
			_context = new Cairo.Context (_surf);
			this.Path = path;

			if (this.Path != null) 
			{
				_context.AppendPath(this.Path);
			}
        }
 public override object Create(object img)
 {
     Gdk.Pixbuf pb = (Gdk.Pixbuf)img;
     var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, pb.Width, pb.Height);
     var ic = new Cairo.Context (imgs);
     Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
     ic.Paint ();
     imgs.Flush ();
     ((IDisposable)ic).Dispose ();
     var p = new Cairo.SurfacePattern (imgs);
     p.Extend = Cairo.Extend.Repeat;
     return p;
 }
Exemple #17
0
		private void UpdateThumbnail ()
		{
			double scalex = (double)Allocation.Width / (double)PintaCore.Workspace.ImageSize.Width;
			double scaley = (double)Allocation.Height / (double)PintaCore.Workspace.ImageSize.Height;
			
			thumbnail = new Cairo.ImageSurface (Cairo.Format.Argb32, Allocation.Width, Allocation.Height);
			
			using (Cairo.Context g = new Cairo.Context (thumbnail)) {
				g.Scale (scalex, scaley);
				foreach (Layer layer in PintaCore.Layers.GetLayersToPaint ()) {
					layer.Draw(g);
				}
			}
		}
Exemple #18
0
 public object CreateContext(Widget w)
 {
     GtkContext ctx = new GtkContext ();
     var b = (IGtkWidgetBackend)WidgetRegistry.GetBackend (w);
     if (!b.Widget.IsRealized) {
         Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
         Cairo.Context c = new Cairo.Context (sf);
         ctx.Context = c;
         ctx.TempSurface = sf;
     } else {
         ctx.Context = Gdk.CairoHelper.Create (b.Widget.GdkWindow);
     }
     return ctx;
 }
		public void NativeCallback (IntPtr cr, IntPtr attr, bool do_path, IntPtr data)
		{
			Cairo.Context mycr = null;

			try {
				mycr = new Cairo.Context (cr, false);

				managed (mycr, Pango.Attribute.GetAttribute (attr), do_path);
				if (release_on_call)
					gch.Free ();
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}
            public CairoPositionSnapshot(ArrayList pos,
						      int width, int height)
            {
                fm = new FigureManager ();
                Gtk.Window win =
                    new Gtk.Window (Gtk.WindowType.
                            Toplevel);
                win.Realize ();
                map = new Gdk.Pixmap (win.GdkWindow, width,
                              height);
                cairo = Gdk.CairoHelper.Create (map);

                FontDescription fontdesc =
                    GetFontDesc (width, height);
                  GetCoordLayoutDetails (win.PangoContext,
                             fontdesc);

                  border_color = new Cairo.Color (0, 0, 0);
                //                              blacksq_color = new Gdk.Color (200, 200, 200);
                //                              whitesq_color = new Gdk.Color (240, 240, 240);
                  blacksq_color =
                    new Cairo.Color (250 / 256.0,
                             120 / 256.0,
                             32 / 256.0);
                  whitesq_color =
                    new Cairo.Color (255 / 256.0,
                             250 / 256.0,
                             170 / 256.0);
                  background_color =
                    new Cairo.Color (1, 1, 1);
                  foreground_color =
                    new Cairo.Color (0, 0, 0);
                //                                arrow_color = new Gdk.Color (159, 148, 249);
                  arrow_color =
                    new Cairo.Color (117 / 256.0,
                             6 / 256.0,
                             6 / 256.0);

                //                      blacksq_color = new Gdk.Color(210, 60, 0);
                //                      whitesq_color = new Gdk.Color(236, 193, 130);
                // outer box, coord, inner box
                  ComputeSizes (width, height);

                  position = new Position (pos);

                  fm.SetSize (size);

                  DrawBackground ();
                  DrawPosition ();
            }
		private void Measure ()
		{
			var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
			
			using (Cairo.Context cr = new Cairo.Context(surface)) {			
				cr.SelectFontFace (FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
				cr.SetFontSize (FontSize);
			
				var textExtents = cr.TextExtents (Text);

				Width = textExtents.Width;
				Height = Math.Abs (textExtents.YBearing);		
				Extent = textExtents.Height;
			}
		}
Exemple #22
0
        public void TestDrawLine()
        {
            var bytes = new byte[1024 * 4];
            var format = Cairo.Format.ARGB32;
            var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
            var shape = new LineShape (0.0, 0.0, 32.0, 32.0);
            var look = new Look (SolidBrush.Red, SolidPen.Black);
            var op = new ShapeTree (look, shape);
            using (var context = new Cairo.Context (image)) {
                op.Draw (context);
            }

            image.WriteToPng ("testimages/line.png");
            image.Dispose ();
        }
Exemple #23
0
		public void Render (List<Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset)
		{
			dst.Flush ();

            // Our rectangle of interest
            var r = new Gdk.Rectangle (offset, dst.GetBounds ().Size).ToCairoRectangle ();

            using (var g = new Cairo.Context (dst)) {
                // Create the transparent checkerboard background
                g.Translate (-offset.X, -offset.Y);
                g.FillRectangle (r, tranparent_pattern, new Cairo.PointD (offset.X, offset.Y));

                for (var i = 0; i < layers.Count; i++) {
                    var layer = layers[i];

                    // If we're in LivePreview, substitute current layer with the preview layer
                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                        layer = CreateLivePreviewLayer (layer);

                    // If the layer is offset, handle it here
                    if (!layer.Transform.IsIdentity ())
                        layer = CreateOffsetLayer (layer);

                    // No need to resize the surface if we're at 100% zoom
                    if (scale_factor.Ratio == 1)
                        layer.Draw (g, layer.Surface, layer.Opacity, false);
                    else {
                        using (var scaled = new Cairo.ImageSurface (Cairo.Format.Argb32, dst.Width, dst.Height)) {
                            g.Save ();
                            // Have to undo the translate set above
                            g.Translate (offset.X, offset.Y);
                            CopyScaled (layer.Surface, scaled, r.ToGdkRectangle ());
                            layer.Draw (g, scaled, layer.Opacity, false);
                            g.Restore ();
                        }
                    }
                }
            }

            // If we are at least 200% and grid is requested, draw it
            if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Active && scale_factor.Ratio <= 0.5d)
                RenderPixelGrid (dst, offset);
			
			dst.MarkDirty ();
		}
Exemple #24
0
        public void Import(LayerManager layers, string fileName)
        {
            Pixbuf bg = new Pixbuf (fileName);
            Size imagesize = new Size (bg.Width, bg.Height);

            PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize);
            PintaCore.Workspace.ActiveDocument.HasFile = true;
            PintaCore.Workspace.ActiveDocument.ImageSize = imagesize;
            PintaCore.Workspace.ActiveWorkspace.CanvasSize = imagesize;

            Layer layer = layers.AddNewLayer (Path.GetFileName (fileName));

            using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                g.Paint ();
            }

            bg.Dispose ();
        }
Exemple #25
0
        public void Import(LayerManager layers, string fileName)
        {
            Pixbuf bg = new Pixbuf (fileName);

            layers.Clear ();
            PintaCore.History.Clear ();
            layers.DestroySelectionLayer ();

            PintaCore.Workspace.ImageSize = new Size (bg.Width, bg.Height);
            PintaCore.Workspace.CanvasSize = new Gdk.Size (bg.Width, bg.Height);
            layers.ResetSelectionPath ();

            Layer layer = layers.AddNewLayer (Path.GetFileName (fileName));

            using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                g.Paint ();
            }

            bg.Dispose ();
        }
Exemple #26
0
        public void TestDrawEllipse()
        {
            var bytes = new byte[1024 * 4];
            var format = Cairo.Format.ARGB32;
            var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
            var shape = new EllipseShape ();
            shape.Rectangle = new Rectangle () {
                X = 10.0,
                Y = 4.0,
                Width = 12.0,
                Height = 18.0
            };
            var look = new Look (SolidBrush.Red, SolidPen.Black);
            var op = new ShapeTree (look, shape);
            using (var context = new Cairo.Context (image)) {
                op.Draw (context);
            }

            image.WriteToPng ("testimages/ellipse.png");
            image.Dispose ();
        }
Exemple #27
0
        private void Activated(object sender, EventArgs e)
        {
            int delay = PintaCore.Settings.GetSetting<int> ("screenshot-delay", 0);

            SpinButtonEntryDialog dialog = new SpinButtonEntryDialog (Catalog.GetString ("Take Screenshot"),
                    PintaCore.Chrome.MainWindow, Catalog.GetString ("Delay before taking a screenshot (seconds):"), 0, 300, delay);

            if (dialog.Run () == (int)Gtk.ResponseType.Ok) {
                delay = dialog.GetValue ();

                PintaCore.Settings.PutSetting ("screenshot-delay", delay);
                PintaCore.Settings.SaveSettings ();

                GLib.Timeout.Add ((uint)delay * 1000, () => {
                    Screen screen = Screen.Default;
                    Document doc = PintaCore.Workspace.NewDocument (new Size (screen.Width, screen.Height), false);

                    using (Pixbuf pb = Pixbuf.FromDrawable (screen.RootWindow, screen.RootWindow.Colormap, 0, 0, 0, 0, screen.Width, screen.Height)) {
                        using (Cairo.Context g = new Cairo.Context (doc.UserLayers[0].Surface)) {
                            CairoHelper.SetSourcePixbuf (g, pb, 0, 0);
                            g.Paint ();
                        }
                    }

                    doc.IsDirty = true;

                    if (!PintaCore.Chrome.MainWindow.IsActive) {
                        PintaCore.Chrome.MainWindow.UrgencyHint = true;

                        // Don't flash forever
                        GLib.Timeout.Add (3 * 1000, () => PintaCore.Chrome.MainWindow.UrgencyHint = false);
                    }

                    return false;
                });
            }

            dialog.Destroy ();
        }
 public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
 {
     if (pattern == null || currentScaleFactor != scaleFactor) {
         if (pattern != null)
             pattern.Dispose ();
         Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame (actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
         var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor));
         var ic = new Cairo.Context (imgs);
         ic.Scale ((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
         Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
         ic.Paint ();
         imgs.Flush ();
         ((IDisposable)ic).Dispose ();
         pattern = new Cairo.SurfacePattern (imgs);
         pattern.Extend = Cairo.Extend.Repeat;
         var cm = new Cairo.Matrix ();
         cm.Scale (scaleFactor, scaleFactor);
         pattern.Matrix = cm;
         currentScaleFactor = scaleFactor;
     }
     return pattern;
 }
 public static void RenderLine(this Gtk.StyleContext style, Cairo.Context cr, PointF pt0, PointF pt1)
 {
     style.RenderLine(cr, pt0.X, pt0.Y, pt1.X, pt1.Y);
 }
 public static void RenderSlider(this Gtk.StyleContext style, Cairo.Context cr, RectangleF rect, Gtk.Orientation orientation)
 {
     style.RenderSlider(cr, rect.X, rect.Y, rect.Width, rect.Height, orientation);
 }
Exemple #31
0
        public override void Draw(TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            if (Debugger.DebuggingService.IsDebugging)
            {
                return;
            }
            int markerStart = Segment.Offset;
            int markerEnd   = Segment.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            bool drawOverlay = result.InspectionMark == IssueMarker.GrayOut;

            if (drawOverlay && editor.IsSomethingSelected)
            {
                var selectionRange = editor.SelectionRange;
                if (selectionRange.Contains(markerStart) && selectionRange.Contains(markerEnd))
                {
                    return;
                }
                if (selectionRange.Contains(markerEnd))
                {
                    markerEnd = selectionRange.Offset;
                }
                if (selectionRange.Contains(markerStart))
                {
                    markerStart = selectionRange.EndOffset;
                }
                if (markerEnd <= markerStart)
                {
                    return;
                }
            }

            double drawFrom;
            double drawTo;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                drawFrom = startXPos;
                drawTo   = endXPos;
            }
            else
            {
                int             start = startOffset < markerStart ? markerStart : startOffset;
                int             end   = endOffset < markerEnd ? endOffset : markerEnd;
                int /*lineNr,*/ x_pos;

                x_pos    = layout.IndexToPos(start - startOffset).X;
                drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                x_pos    = layout.IndexToPos(end - startOffset).X;

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

            drawFrom = System.Math.Max(drawFrom, editor.TextViewMargin.XOffset);
            drawTo   = System.Math.Max(drawTo, editor.TextViewMargin.XOffset);
            if (drawFrom >= drawTo)
            {
                return;
            }

            double height = editor.LineHeight / 5;

            cr.Color = GetColor(editor, Result);
            if (drawOverlay)
            {
                cr.Rectangle(drawFrom, y, drawTo - drawFrom, editor.LineHeight);
                var color = editor.ColorStyle.PlainText.Background;
                color.A  = 0.6;
                cr.Color = color;
                cr.Fill();
            }
            else if (Wave)
            {
                Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
            }
            else
            {
                cr.MoveTo(drawFrom, y + editor.LineHeight - 1);
                cr.LineTo(drawTo, y + editor.LineHeight - 1);
                cr.Stroke();
            }
        }
Exemple #32
0
        public virtual void DrawTicks(Gdk.Rectangle allocation, Cairo.Context cr)
        {
            if (!show_ticks)
            {
                return;
            }

            // no data in plots
            if (min == Double.PositiveInfinity &&
                max == Double.NegativeInfinity)
            {
                return;
            }

            // recalculate the tick interval, since our available
            // width probably has changed since SizeRequest
            double interval, start;

            GetTickStartAndInterval(allocation, out start, out interval);

            sig_figs = Math.Max(GetSignificantFigures(start),
                                GetSignificantFigures(interval)) + 2;

            for (double tick = start; tick < max; tick += interval)
            {
                int x = 0, y = 0;
                if (location == AxisLocation.Top)
                {
                    x = Convert.ToInt32((((double)ValueToGridCoords(tick) / GRID_MAX)
                                         * allocation.Width) + allocation.X);
                    y = allocation.Y + allocation.Height;

                    style.DrawAxisTick(cr, x, y, location);
                }
                else if (location == AxisLocation.Bottom)
                {
                    x = Convert.ToInt32((((double)ValueToGridCoords(tick) / GRID_MAX)
                                         * allocation.Width) + allocation.X);
                    y = allocation.Y;

                    style.DrawAxisTick(cr, x, y, location);
                }
                else if (location == AxisLocation.Left)
                {
                    x = allocation.X + allocation.Width - style.TickLineSize;
                    y = allocation.Y + allocation.Height
                        - Convert.ToInt32(((double)ValueToGridCoords(tick) / GRID_MAX)
                                          * allocation.Height);

                    style.DrawAxisTick(cr, x, y, AxisLocation.Left);
                }
                else if (location == AxisLocation.Right)
                {
                    x = allocation.X;
                    y = allocation.Y + allocation.Height
                        - Convert.ToInt32(((double)ValueToGridCoords(tick) / GRID_MAX)
                                          * allocation.Height);

                    style.DrawAxisTick(cr, x, y, AxisLocation.Left);
                }

                if (!show_tick_labels)
                {
                    continue;
                }

                int width, height;
                style.GetAxisLabelMetrics(GetTickLabelName(tick),
                                          out width,
                                          out height);

                int label_x = 0, label_y = 0;
                if (location == AxisLocation.Top)
                {
                    label_x = x - (width / 2);
                    label_y = y - style.TickLineSize - height;
                }
                else if (location == AxisLocation.Bottom)
                {
                    label_x = x - (width / 2);
                    label_y = y + style.TickLineSize + padding;
                }
                else if (location == AxisLocation.Left)
                {
                    label_x = x - padding - width;
                    label_y = y - (height / 2);
                }
                else if (location == AxisLocation.Right)
                {
                    label_x = x + style.TickLineSize + padding;
                    label_y = y - (height / 2);
                }

                // Don't draw an axis label if it won't
                // completely fit in the allocation
                if (allocation.Contains(label_x, label_y) &&
                    allocation.Contains(label_x + width, label_y + height))
                {
                    style.DrawAxisLabel(cr, GetTickLabelName(tick),
                                        label_x, label_y);
                }
            }
        }
 public static void SetSourceColor(this Cairo.Context cr, Cairo.Color color)
 {
     cr.SetSourceRGBA(color.R, color.G, color.B, color.A);
 }
 public static Cairo.Surface GetTarget(this Cairo.Context cr)
 {
     return(cr.Target);
 }
        protected override void OnDrawContent(Gdk.EventExpose evnt, Cairo.Context context)
        {
            context.LineWidth = 1;
            var alloc = ChildAllocation;
            var adjustedMarginSize = alloc.X - Allocation.X + headerMarginSize;

            var r = results.Where(res => res.Item2.ItemCount > 0).ToArray();

            if (r.Any())
            {
                context.Color = lightSearchBackground;
                context.Rectangle(Allocation.X, Allocation.Y, adjustedMarginSize, Allocation.Height);
                context.Fill();

                context.Color = darkSearchBackground;
                context.Rectangle(Allocation.X + adjustedMarginSize, Allocation.Y, Allocation.Width - adjustedMarginSize, Allocation.Height);
                context.Fill();
                context.MoveTo(0.5 + Allocation.X + adjustedMarginSize, 0);
                context.LineTo(0.5 + Allocation.X + adjustedMarginSize, Allocation.Height);
                context.Color = separatorLine;
                context.Stroke();
            }
            else
            {
                context.Color = new Cairo.Color(1, 1, 1);
                context.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
                context.Fill();
            }

            double y = alloc.Y + yMargin;
            int    w, h;

            if (topItem != null)
            {
                headerLayout.SetText(GettextCatalog.GetString("Top Result"));
                headerLayout.GetPixelSize(out w, out h);
                context.MoveTo(alloc.Left + headerMarginSize - w - xMargin, y);
                context.Color = headerColor;
                Pango.CairoHelper.ShowLayout(context, headerLayout);

                var category = topItem.Category;
                var dataSrc  = topItem.DataSource;
                var i        = topItem.Item;

                double x = alloc.X + xMargin + headerMarginSize;
                context.Color = new Cairo.Color(0, 0, 0);
                layout.SetMarkup(GetRowMarkup(dataSrc, i));
                layout.GetPixelSize(out w, out h);
                if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i)
                {
                    context.Color = selectionBackgroundColor;
                    context.Rectangle(alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h);
                    context.Fill();
                    context.Color = new Cairo.Color(1, 1, 1);
                }

                var px = dataSrc.GetIcon(i);
                if (px != null)
                {
                    evnt.Window.DrawPixbuf(Style.WhiteGC, px, 0, 0, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2, px.Width, px.Height, Gdk.RgbDither.None, 0, 0);
                    x += px.Width + iconTextSpacing + marginIconSpacing;
                }

                context.MoveTo(x, y);
                Pango.CairoHelper.ShowLayout(context, layout);

                y += h + itemSeparatorHeight;
            }

            foreach (var result in r)
            {
                var category = result.Item1;
                var dataSrc  = result.Item2;
                if (dataSrc.ItemCount == 0)
                {
                    continue;
                }
                if (dataSrc.ItemCount == 1 && topItem != null && topItem.DataSource == dataSrc)
                {
                    continue;
                }
                headerLayout.SetText(category.Name);
                headerLayout.GetPixelSize(out w, out h);
                context.MoveTo(alloc.X + headerMarginSize - w - xMargin, y);
                context.Color = headerColor;
                Pango.CairoHelper.ShowLayout(context, headerLayout);

                layout.Width = Pango.Units.FromPixels(Allocation.Width - adjustedMarginSize - 35);

                for (int i = 0; i < maxItems && i < dataSrc.ItemCount; i++)
                {
                    if (topItem != null && topItem.Category == category && topItem.Item == i)
                    {
                        continue;
                    }
                    double x = alloc.X + xMargin + headerMarginSize;
                    context.Color = new Cairo.Color(0, 0, 0);
                    layout.SetMarkup(GetRowMarkup(dataSrc, i));
                    layout.GetPixelSize(out w, out h);
                    if (selectedItem != null && selectedItem.Category == category && selectedItem.Item == i)
                    {
                        context.Color = selectionBackgroundColor;
                        context.Rectangle(alloc.X + headerMarginSize, y, Allocation.Width - adjustedMarginSize, h);
                        context.Fill();
                        context.Color = new Cairo.Color(1, 1, 1);
                    }

                    var px = dataSrc.GetIcon(i);
                    if (px != null)
                    {
                        evnt.Window.DrawPixbuf(Style.WhiteGC, px, 0, 0, (int)x + marginIconSpacing, (int)y + (h - px.Height) / 2, px.Width, px.Height, Gdk.RgbDither.None, 0, 0);
                        x += px.Width + iconTextSpacing + marginIconSpacing;
                    }

                    context.MoveTo(x, y);
                    Pango.CairoHelper.ShowLayout(context, layout);

                    y += h + itemSeparatorHeight;
                }
                if (result != r.Last())
                {
/*						context.MoveTo (alloc.X, y + categorySeparatorHeight / 2 + 0.5);
 *                                      context.LineTo (alloc.X + alloc.Width, y + categorySeparatorHeight / 2 + 0.5);
 *                                      context.Color = (HslColor)Style.Mid (StateType.Normal);
 *                                      context.Stroke ();*/
                    y += categorySeparatorHeight;
                }
            }
            if (y == alloc.Y + yMargin)
            {
                context.Color = new Cairo.Color(0, 0, 0);
                layout.SetMarkup(isInSearch ? GettextCatalog.GetString("Searching...") : GettextCatalog.GetString("No matches"));
                context.MoveTo(alloc.X + xMargin, y);
                Pango.CairoHelper.ShowLayout(context, layout);
            }
        }
 public static void RenderExtension(this Gtk.StyleContext style, Cairo.Context cr, RectangleF rect, Gtk.PositionType gap_side)
 {
     style.RenderExtension(cr, rect.X, rect.Y, rect.Width, rect.Height, gap_side);
 }
Exemple #37
0
		// Called from asynchronously from Renderer.OnCompletion ()
		void HandleApply ()
		{
			Debug.WriteLine ("LivePreviewManager.HandleApply()");

			using (var ctx = new Cairo.Context (layer.Surface)) {
				
				ctx.Save ();
				PintaCore.Workspace.ActiveDocument.Selection.Clip (ctx);
			
				ctx.Operator = Cairo.Operator.Source;
				
				layer.Draw(ctx, live_preview_surface, 1);
				ctx.Restore ();
			}
			
			PintaCore.History.PushNewItem (history_item);
			history_item = null;
			
			FireLivePreviewEndedEvent(RenderStatus.Completed, null);
			
			live_preview_enabled = false;
			
			PintaCore.Workspace.Invalidate (); //TODO keep track of dirty bounds.
			CleanUp ();
		}
Exemple #38
0
 public override void Draw(MonoTextEditor editor, Cairo.Context g, LineMetrics metrics)
 {
 }
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) {
                double xPos = padding, yPos = padding;
                var    layout = PangoUtil.CreateLayout(this);
                int    w, h;
                layout.SetText(new string ('X', maxLength));
                layout.GetPixelSize(out w, out h);

                foreach (Category cat in categories)
                {
                    yPos = padding;
                    cr.MoveTo(xPos, yPos);
                    layout.SetMarkup("<b>" + cat.Title + "</b>");
                    cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                    cr.ShowLayout(layout);

                    if (cat.Items.Count == 0)
                    {
                        continue;
                    }

                    layout.SetMarkup("");
                    int w2, h2;
                    layout.GetPixelSize(out w2, out h2);
                    yPos += h2;
                    yPos += headerDistance;
                    var startY     = yPos;
                    int curItem    = 0;
                    int row        = 0;
                    var iconHeight = Math.Max(h, cat.Items [0].Icon.Height + 2) + itemPadding * 2;
                    if (cat.FirstVisibleItem > 0)
                    {
                        Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None,
                                             new Rectangle((int)xPos, (int)yPos, w, h),
                                             this,
                                             "",
                                             ArrowType.Up,
                                             true,
                                             (int)xPos,
                                             (int)yPos,
                                             w,
                                             h);
                        yPos += iconHeight;
                        curItem++;
                    }

                    for (int i = cat.FirstVisibleItem; i < cat.Items.Count; i++)
                    {
                        var item = cat.Items [i];

                        if (curItem + 1 >= maxItems && row + 1 >= maxRows && i + 1 < cat.Items.Count)
                        {
                            Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None,
                                                 new Rectangle((int)xPos, (int)yPos, w, h),
                                                 this,
                                                 "",
                                                 ArrowType.Down,
                                                 true,
                                                 (int)xPos,
                                                 (int)yPos,
                                                 w,
                                                 h);
                            break;
                        }

                        if (item == ActiveItem)
                        {
                            int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2;
                            cr.Rectangle(xPos, yPos, itemWidth, iconHeight);
                            cr.LineWidth = 1;
                            cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                            cr.Fill();
                        }
                        else if (item == hoverItem)
                        {
                            int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2;
                            cr.Rectangle(xPos + 0.5, yPos + 0.5, itemWidth - 1, iconHeight);
                            cr.LineWidth = 1;
                            cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                            cr.Stroke();
                        }
                        cr.SetSourceColor(Style.Text(item == ActiveItem? StateType.Selected : StateType.Normal).ToCairoColor());
                        cr.MoveTo(xPos + item.Icon.Width + 2 + itemPadding, yPos + (iconHeight - h) / 2);
                        layout.SetText(Ellipsize(item.ListTitle ?? item.Title, maxLength));
                        cr.ShowLayout(layout);
                        cr.DrawImage(this, item.Icon, (int)xPos + itemPadding,
                                     (int)(yPos + (iconHeight - item.Icon.Height) / 2));
                        yPos += iconHeight;
                        if (++curItem >= maxItems)
                        {
                            curItem = 0;
                            yPos    = startY;
                            xPos   += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2;
                            row++;
                        }
                    }


                    xPos += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2;
                }
                layout.Dispose();
            }
            return(true);
        }
 public static void RenderFrameGap(this Gtk.StyleContext style, Cairo.Context cr, RectangleF rect, Gtk.PositionType gap_side, double xy0_gap, double xy1_gap)
 {
     style.RenderFrameGap(cr, rect.X, rect.Y, rect.Width, rect.Height, gap_side, xy0_gap, xy1_gap);
 }
Exemple #41
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);

            canvas_bounds.Intersect(e.Area);

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 3, PintaCore.Workspace.CanvasSize.Height + 3), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 5, PintaCore.Workspace.CanvasSize.Height + 5), new Cairo.Color(.9, .9, .9), 1);

                // Set up our clip rectangle
                g.Rectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip();

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = PintaCore.Layers.GetLayersToPaint();
                if (layers.Count == 0)
                {
                    canvas.Clear();
                }
                cr.Render(layers, canvas, canvas_bounds.Location);

                // Paint the surface to our canvas
                g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
                g.Paint();

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }
Exemple #42
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(e.Window);

            Gdk.Rectangle area = e.Area;

            if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage))
            {
                Pango.Layout messageLayout = new Pango.Layout(this.PangoContext);
                messageLayout.Alignment = Pango.Alignment.Center;
                messageLayout.Width     = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale);
                if (!string.IsNullOrEmpty(CustomMessage))
                {
                    messageLayout.SetText(CustomMessage);
                }
                else
                {
                    messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document."));
                }
                cr.MoveTo(Allocation.Width * 1 / 6, 12);
                cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                Pango.CairoHelper.ShowLayout(cr, messageLayout);
                messageLayout.Dispose();
                ((IDisposable)cr).Dispose();
                return(true);
            }

            var backColor = Style.Base(StateType.Normal).ToCairoColor();

            cr.SetSourceColor(backColor);
            cr.Rectangle(area.X, area.Y, area.Width, area.Height);
            cr.Fill();

            int      xpos             = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0);
            int      vadjustment      = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
            int      ypos             = -vadjustment;
            Category lastCategory     = null;
            int      lastCategoryYpos = 0;

            cr.LineWidth = 1;

            Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) {
                const int foldSegmentHeight = 8;

                ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }
                cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                using (var pat = new Cairo.LinearGradient(xpos, ypos, xpos, ypos + itemDimension.Height)) {
                    pat.AddColorStop(0, CategoryBackgroundGradientStartColor);
                    pat.AddColorStop(1, CategoryBackgroundGradientEndColor);
                    cr.SetSource(pat);
                    cr.Fill();
                }
                if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand)
                {
                    cr.MoveTo(xpos, ypos + 0.5);
                    cr.LineTo(itemDimension.Width, ypos + 0.5);
                }
                cr.MoveTo(0, ypos + itemDimension.Height - 0.5);
                cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5);
                cr.SetSourceColor(CategoryBorderColor);
                cr.Stroke();

                headerLayout.SetMarkup(category.Text);
                int width, height;
                cr.SetSourceColor(CategoryLabelColor);
                layout.GetPixelSize(out width, out height);
                cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                Pango.CairoHelper.ShowLayout(cr, headerLayout);

                var img = category.IsExpanded ? discloseUp : discloseDown;
                cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2));

                lastCategory     = category;
                lastCategoryYpos = ypos + itemDimension.Height;

                return(true);
            }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) {
                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }

                if (item == SelectedItem)
                {
                    cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                    cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                    cr.Fill();
                }
                if (listMode || !curCategory.CanIconizeItems)
                {
                    cr.DrawImage(this, item.Icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2));
                    layout.SetMarkup(item.Text);
                    int width, height;
                    layout.GetPixelSize(out width, out height);
                    cr.SetSourceColor(Style.Text(item != this.SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor());
                    cr.MoveTo(xpos + ItemLeftPadding + IconSize.Width + ItemIconTextItemSpacing, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
                else
                {
                    cr.DrawImage(this, item.Icon, xpos + Math.Round((itemDimension.Width - item.Icon.Width) / 2), ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2));
                }

                if (item == mouseOverItem)
                {
                    cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor());
                    cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1);
                    cr.Stroke();
                }

                return(true);
            });

            ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

            if (lastCategory != null && lastCategory.AnimatingExpand)
            {
                // Closing line when animating the last group of the toolbox
                cr.MoveTo(area.X, ypos + 0.5);
                cr.RelLineTo(area.Width, 0);
                cr.SetSourceColor(CategoryBorderColor);
                cr.Stroke();
            }

            ((IDisposable)cr).Dispose();
            return(true);
        }
 public static void SetSource(this Cairo.Context cr, Cairo.Pattern pattern)
 {
     cr.Pattern = pattern;
 }
Exemple #44
0
 public override void SetAsSource(Cairo.Context ctx, Rectangle bounds = default(Rectangle))
 {
     ctx.SetSourceRGBA(color.R, color.G, color.B, color.A);
 }
 public static void SharpLineY(this Cairo.Context cr, double x1, double y1, double x2, double y2)
 {
     cr.MoveTo(x1, y1 + 0.5);
     cr.LineTo(x2, y2 + 0.5);
 }
Exemple #46
0
        void DrawValue(Cairo.Context ctx, Gdk.GC gc, DateTime initialTime, int ytop, int lx, int tx, ref int ty, ref int maxx, ref int maxy, int indent, CounterValueInfo val)
        {
            Gdk.Color color;
            if (val.Counter != null)
            {
                color = val.Counter.GetColor();
            }
            else
            {
                color = Style.Black;
            }

            // Draw text
            gc.RgbFgColor = color;

            double ms = (val.Time - initialTime).TotalMilliseconds;

            string txt = (ms / 1000).ToString("0.00000") + ": " + (val.Duration.TotalMilliseconds / 1000).ToString("0.00000") + " " + val.Trace;

            layout.SetText(txt);
            GdkWindow.DrawLayout(gc, tx + indent, ty, layout);
            int tw, th;

            layout.GetPixelSize(out tw, out th);
            if (tx + tw + indent > maxx)
            {
                maxx = tx + tw + indent;
            }

            HotSpot hp     = AddHotSpot(tx + indent, ty, tw, th);
            int     tempTy = ty;

            hp.Action = delegate {
                int ytm = ytop + (int)((ms * scale) / 1000);
                SetBaseTime((int)(tempTy + (th / 2) + 0.5) - ytm);
            };
            hp.OnMouseOver += delegate {
                overValue = val;
                QueueDraw();
            };
            hp.Action += delegate {
                focusedValue = val;
                QueueDraw();
            };

            // Draw time marker
            int ytime = ytop + (int)((ms * scale) / 1000) + baseTime;

            if (val == focusedValue || val == overValue)
            {
                ctx.NewPath();
                double dx = val == focusedValue ? 0 : 2;
                ctx.Rectangle(lx + 0.5 + dx - SelectedValuePadding, ytime + 0.5, LineEndWidth - dx * 2 + SelectedValuePadding, ((val.Duration.TotalMilliseconds * scale) / 1000));
                HslColor hsl = color;
                hsl.L = val == focusedValue ? 0.9 : 0.8;
                ctx.SetSourceColor(hsl);
                ctx.Fill();
            }

            ctx.NewPath();
            ctx.LineWidth = 1;
            ctx.MoveTo(lx + 0.5, ytime + 0.5);
            ctx.LineTo(lx + LineEndWidth + 0.5, ytime + 0.5);
            ctx.LineTo(tx - 3 - LineEndWidth + 0.5, ty + (th / 2) + 0.5);
            ctx.LineTo(tx + indent - 3 + 0.5, ty + (th / 2) + 0.5);
            ctx.SetSourceColor(color.ToCairoColor());
            ctx.Stroke();

            // Expander

            bool incLine = true;

            if (val.CanExpand)
            {
                double ex = tx + indent - 3 - ExpanderSize - 2 + 0.5;
                double ey = ty + (th / 2) - (ExpanderSize / 2) + 0.5;
                hp = AddHotSpot(ex, ey, ExpanderSize, ExpanderSize);
                DrawExpander(ctx, ex, ey, val.Expanded, false);
                hp.OnMouseOver = delegate {
                    using (Cairo.Context c = CairoHelper.Create(GdkWindow)) {
                        DrawExpander(c, ex, ey, val.Expanded, true);
                    }
                };
                hp.OnMouseLeave = delegate {
                    using (Cairo.Context c = CairoHelper.Create(GdkWindow)) {
                        DrawExpander(c, ex, ey, val.Expanded, false);
                    }
                };
                hp.Action = delegate {
                    ToggleExpand(val);
                };

                if (val.Expanded && val.ExpandedTimerTraces.Count > 0)
                {
                    ty += th + LineSpacing;
                    foreach (CounterValueInfo cv in val.ExpandedTimerTraces)
                    {
                        DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, indent + ChildIndent, cv);
                    }
                    incLine = false;
                }
            }
            if (incLine)
            {
                ty += th + LineSpacing;
            }

            if (ytime > maxy)
            {
                maxy = ytime;
            }
        }
Exemple #47
0
 public void RenderCairo(Cairo.Context cr)
 {
     rsvg_handle_render_cairo(Handle, cr == null ? IntPtr.Zero : cr.Handle);
 }
Exemple #48
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (data == null)
            {
                BuildData();
            }

            hostSpots.Clear();
            int ytop    = padding;
            int markerX = 3;
            int lx      = markerX + MarkerWidth + 1;
            int tx      = 250;
            int ty      = ytop;
            int maxx    = lx;
            int maxy    = 0;

            DateTime initialTime = mainValue.TimeStamp;

            Cairo.Context ctx = CairoHelper.Create(GdkWindow);

            using (Gdk.GC gc = new Gdk.GC(GdkWindow)) {
                gc.RgbFgColor = Style.White;
                GdkWindow.DrawRectangle(gc, true, 0, 0, Allocation.Width, Allocation.Height);

                // Draw full time marker

                ctx.NewPath();
                ctx.Rectangle(markerX, ytop + baseTime + 0.5, MarkerWidth / 2, ((mainValue.Duration.TotalMilliseconds * scale) / 1000));
                HslColor hsl = Style.Foreground(Gtk.StateType.Normal);
                hsl.L = 0.8;
                ctx.SetSourceColor(hsl);
                ctx.Fill();

                // Draw values

                foreach (CounterValueInfo val in data)
                {
                    DrawValue(ctx, gc, initialTime, ytop, lx, tx, ref ty, ref maxx, ref maxy, 0, val);
                }

                if (ty > maxy)
                {
                    maxy = ty;
                }

                int totalms = (int)mainValue.Duration.TotalMilliseconds;
                int marks   = (totalms / 1000) + 1;

                ctx.LineWidth = 1;
                gc.RgbFgColor = Style.Foreground(Gtk.StateType.Normal);

                for (int n = 0; n <= marks; n++)
                {
                    ctx.NewPath();
                    int y = ytop + (int)(n * scale) + baseTime;
                    ctx.MoveTo(markerX, y + 0.5);
                    ctx.LineTo(markerX + MarkerWidth, y + 0.5);
                    ctx.SetSourceColor(Style.Foreground(Gtk.StateType.Normal).ToCairoColor());
                    ctx.Stroke();

                    y += 2;
                    layout.SetText(n + "s");
                    GdkWindow.DrawLayout(gc, markerX + 1, y + 2, layout);

                    int tw, th;
                    layout.GetPixelSize(out tw, out th);
                    y += th;

                    if (y > maxy)
                    {
                        maxy = y;
                    }
                }
            }

            ((IDisposable)ctx).Dispose();

            maxy += padding;
            maxx += padding;

            if (lastHeight != maxy || lastWidth != maxx)
            {
                lastWidth  = maxx;
                lastHeight = maxy;
                SetSizeRequest(maxx, maxy);
            }

            return(true);
        }
Exemple #49
0
 public override void Draw(TextEditor editor, Cairo.Context cr, Pango.Layout layout, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
 {
 }
 public static void Line(this Cairo.Context cr, double x1, double y1, double x2, double y2)
 {
     cr.MoveTo(x1, y1);
     cr.LineTo(x2, y2);
 }
 public static void RenderOption(this Gtk.StyleContext style, Cairo.Context cr, RectangleF rect)
 {
     style.RenderOption(cr, rect.X, rect.Y, rect.Width, rect.Height);
 }
 public static void LayoutPath(this Cairo.Context cr, Pango.Layout layout)
 {
     pango_cairo_layout_path(cr == null ? IntPtr.Zero : cr.Handle, layout == null ? IntPtr.Zero : layout.Handle);
 }
        public static Pango.Layout CreateLayout(this Cairo.Context cr)
        {
            IntPtr raw_ret = pango_cairo_create_layout(cr == null ? IntPtr.Zero : cr.Handle);

            return(GLib.Object.GetObject(raw_ret) as Pango.Layout);
        }
 public static void ShowLayout(this Cairo.Context cr, Pango.Layout layout)
 {
     pango_cairo_show_layout(cr == null ? IntPtr.Zero : cr.Handle, layout == null ? IntPtr.Zero : layout.Handle);
 }
 public static void RenderLayout(this Gtk.StyleContext style, Cairo.Context cr, PointF location, Pango.Layout layout)
 {
     style.RenderLayout(cr, location.X, location.Y, layout);
 }
 public static void Dispose(this Cairo.Context cr)
 {
     ((IDisposable)cr).Dispose();
 }
Exemple #57
0
        public override void DrawAfterEol(MonoTextEditor textEditor, Cairo.Context g, EndOfLineMetrics metrics)
        {
            if (!IsVisible)
            {
                return;
            }
            EnsureLayoutCreated(editor);
            int errorCounterWidth = 0, eh = 0;

            if (errorCountLayout != null)
            {
                errorCountLayout.GetPixelSize(out errorCounterWidth, out eh);
                errorCounterWidth = Math.Max(15, Math.Max(errorCounterWidth + 3, (int)(editor.LineHeight * 3 / 4)));
            }

            var  sx = metrics.TextRenderEndPosition;
            var  width      = LayoutWidth + errorCounterWidth + editor.LineHeight;
            var  drawLayout = layouts[0].Layout;
            var  y            = metrics.LineYRenderStartPosition;
            bool customLayout = true;             //sx + width > editor.Allocation.Width;
            bool hideText     = false;

            bubbleIsReduced = customLayout;
            var    showErrorCount = errorCounterWidth > 0 && errorCountLayout != null;
            double roundingRadius = editor.LineHeight / 2 - 1;

            if (customLayout)
            {
                width = editor.Allocation.Width - sx;
                string text = layouts[0].Layout.Text;
                drawLayout = new Pango.Layout(editor.PangoContext);
                drawLayout.FontDescription = cache.fontDescription;
                var paintWidth = (width - errorCounterWidth - editor.LineHeight + 4);
                var minWidth   = Math.Max(25, errorCounterWidth) * editor.Options.Zoom;
                if (paintWidth < minWidth)
                {
                    hideText       = true;
                    showErrorCount = false;
//					drawLayout.SetMarkup ("<span weight='heavy'>···</span>");
                    width = minWidth;
                    //roundingRadius = 10 * editor.Options.Zoom;
                    sx = Math.Min(sx, editor.Allocation.Width - width);
                }
                else
                {
                    drawLayout.Ellipsize = Pango.EllipsizeMode.End;
                    drawLayout.Width     = (int)(paintWidth * Pango.Scale.PangoScale);
                    drawLayout.SetText(text);
                    int w2, h2;
                    drawLayout.GetPixelSize(out w2, out h2);
                    width = w2 + errorCounterWidth + editor.LineHeight - 2;
                }
            }

            bubbleDrawX = sx - editor.TextViewMargin.XOffset;
            bubbleDrawY = y + 2;
            bubbleWidth = width;
            var bubbleHeight = editor.LineHeight;

            g.RoundedRectangle(sx, y, width, bubbleHeight, roundingRadius);
            g.SetSourceColor(TagColor);
            g.Fill();

            // Draw error count icon
            if (showErrorCount)
            {
                var errorCounterHeight = bubbleHeight - 2;
                var errorCounterX      = sx + width - errorCounterWidth - 1;
                var errorCounterY      = Math.Round(y + (bubbleHeight - errorCounterHeight) / 2);

                g.RoundedRectangle(
                    errorCounterX,
                    errorCounterY,
                    errorCounterWidth,
                    errorCounterHeight,
                    editor.LineHeight / 2 - 2
                    );

                // FIXME: VV: Remove gradient features
                using (var lg = new Cairo.LinearGradient(errorCounterX, errorCounterY, errorCounterX, errorCounterY + errorCounterHeight)) {
                    lg.AddColorStop(0, CounterColor);
                    lg.AddColorStop(1, CounterColor.AddLight(-0.1));
                    g.SetSource(lg);
                    g.Fill();
                }

                g.Save();

                int ew;
                errorCountLayout.GetPixelSize(out ew, out eh);

                var tx = Math.Round(errorCounterX + (2 + errorCounterWidth - ew) / 2);
                var ty = Math.Round(errorCounterY + (-1 + errorCounterHeight - eh) / 2);

                g.Translate(tx, ty);
                g.SetSourceColor(CounterColor2);
                g.ShowLayout(errorCountLayout);
                g.Restore();
            }

            if (hideText)
            {
                // Draw dots
                double radius  = 2 * editor.Options.Zoom;
                double spacing = 1 * editor.Options.Zoom;

                sx += 1 * editor.Options.Zoom + Math.Ceiling((bubbleWidth - 3 * (radius * 2) - 2 * spacing) / 2);

                for (int i = 0; i < 3; i++)
                {
                    g.Arc(sx, y + bubbleHeight / 2, radius, 0, Math.PI * 2);
                    g.SetSourceColor(TagColor2);
                    g.Fill();
                    sx += radius * 2 + spacing;
                }
            }
            else
            {
                // Draw label text
                var tx = Math.Round(sx + editor.LineHeight / 2);
                var ty = Math.Round(y + (editor.LineHeight - layouts [0].Height) / 2) - 1;

                g.Save();
                g.Translate(tx, ty);

                g.SetSourceColor(TagColor2);
                g.ShowLayout(drawLayout);
                g.Restore();
            }

            if (customLayout)
            {
                drawLayout.Dispose();
            }
        }
Exemple #58
0
 public static void DrawImage(this Cairo.Context s, Gtk.Widget widget, Xwt.Drawing.Image image, double x, double y)
 {
     GtkToolkit.RenderImage(widget, s, image, x, y);
 }
Exemple #59
0
		public void Start (BaseEffect effect)
		{			
			if (live_preview_enabled)
				throw new InvalidOperationException ("LivePreviewManager.Start() called while live preview is already enabled.");
			
			// Create live preview surface.
			// Start rendering.
			// Listen for changes to effectConfiguration object, and restart render if needed.

			live_preview_enabled = true;
			apply_live_preview_flag = false;
			cancel_live_preview_flag = false;
			
			layer = PintaCore.Layers.CurrentLayer;
			this.effect = effect;

			//TODO Use the current tool layer instead.
			live_preview_surface = new Cairo.ImageSurface (Cairo.Format.Argb32,
			                                  PintaCore.Workspace.ImageSize.Width,
			                                  PintaCore.Workspace.ImageSize.Height);

			// Handle selection path.
			PintaCore.Tools.Commit ();
			selection_path = (PintaCore.Layers.ShowSelection) ? PintaCore.Workspace.ActiveDocument.Selection.SelectionPath : null;
			render_bounds = (selection_path != null) ? selection_path.GetBounds () : live_preview_surface.GetBounds ();
			render_bounds = PintaCore.Workspace.ClampToImageSize (render_bounds);	

			history_item = new SimpleHistoryItem (effect.Icon, effect.Name);
			history_item.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayerIndex);	
			
			// Paint the pre-effect layer surface into into the working surface.
			using (var ctx = new Cairo.Context (live_preview_surface)) {
				layer.Draw(ctx, layer.Surface, 1);
			}
			
			if (effect.EffectData != null)
				effect.EffectData.PropertyChanged += EffectData_PropertyChanged;
			
			if (Started != null) {
				Started (this, new LivePreviewStartedEventArgs());
			}
			
			var settings = new AsyncEffectRenderer.Settings () {
				ThreadCount = PintaCore.System.RenderThreads,
				TileWidth = render_bounds.Width,
				TileHeight = 1,
				ThreadPriority = ThreadPriority.BelowNormal
			};
			
			Debug.WriteLine (DateTime.Now.ToString("HH:mm:ss:ffff") + "Start Live preview.");
			
			renderer = new Renderer (this, settings);
			renderer.Start (effect, layer.Surface, live_preview_surface, render_bounds);
			
			if (effect.IsConfigurable) {		
				if (!effect.LaunchConfiguration ()) {
					PintaCore.Chrome.MainWindowBusy = true;
					Cancel ();
				} else {
					PintaCore.Chrome.MainWindowBusy = true;
					Apply ();
				}
			} else {
				PintaCore.Chrome.MainWindowBusy = true;
				Apply ();
			}
		}
Exemple #60
0
        public override bool DrawBackground(MonoTextEditor editor, Cairo.Context g, LineMetrics metrics)
        {
            if (!IsVisible)
            {
                return(false);
            }
            bool markerShouldDrawnAsHidden = cache.CurrentSelectedTextMarker != null && cache.CurrentSelectedTextMarker != this;

            if (editor.Document.GetTextSegmentMarkersAt(metrics.LineSegment).Any(m => m is DebugTextMarker))
            {
                return(false);
            }

            EnsureLayoutCreated(editor);
            double x                 = editor.TextViewMargin.XOffset;
            int    right             = editor.Allocation.Width;
            bool   isCaretInLine     = metrics.TextStartOffset <= editor.Caret.Offset && editor.Caret.Offset <= metrics.TextEndOffset;
            int    errorCounterWidth = GetErrorCountBounds(metrics).Item1;

            var    min = right - LayoutWidth - border - (ShowIconsInBubble ? MessageBubbleCache.errorPixbuf.Width : 0) - errorCounterWidth;
            var    max = Math.Round(editor.TextViewMargin.XOffset + editor.LineHeight / 2);
            double x2  = Math.Max(min, max);

            bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != MonoDevelop.Ide.Editor.SelectionMode.Block ? editor.SelectionRange.Contains(LineSegment.Offset + LineSegment.Length) : false;

            int  active      = 0;
            bool highlighted = active == 0 && isCaretInLine;
            var  y           = metrics.LineYRenderStartPosition;

            // draw background
            if (!markerShouldDrawnAsHidden)
            {
                DrawRectangle(g, x, y, right, editor.LineHeight);
                g.SetSourceColor(LineColor);
                g.Fill();

                if (metrics.Layout.StartSet || metrics.SelectionStart == metrics.TextEndOffset)
                {
                    double startX;
                    double endX;

                    if (metrics.SelectionStart != metrics.TextEndOffset)
                    {
                        var start = metrics.Layout.IndexToPos((int)metrics.Layout.SelectionStartIndex);
                        startX = (int)(start.X / Pango.Scale.PangoScale);
                        var end = metrics.Layout.IndexToPos((int)metrics.Layout.SelectionEndIndex);
                        endX = (int)(end.X / Pango.Scale.PangoScale);
                    }
                    else
                    {
                        startX = x2;
                        endX   = startX;
                    }

                    if (editor.MainSelection.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block && startX == endX)
                    {
                        endX = startX + 2;
                    }
                    startX += metrics.TextRenderStartPosition;
                    endX   += metrics.TextRenderStartPosition;
                    startX  = Math.Max(editor.TextViewMargin.XOffset, startX);
                    // clip region to textviewmargin start
                    if (isEolSelected)
                    {
                        endX = editor.Allocation.Width + (int)editor.HAdjustment.Value;
                    }
                    if (startX < endX)
                    {
                        DrawRectangle(g, startX, y, endX - startX, editor.LineHeight);
                        g.SetSourceColor(GetLineColor(highlighted, true));
                        g.Fill();
                    }
                }
                DrawErrorMarkers(editor, g, metrics, y);
            }

            double y2         = y + 0.5;
            double y2Bottom   = y2 + editor.LineHeight - 1;
            var    selected   = isEolSelected;
            var    lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + metrics.Layout.Width;

            if (x2 < lineTextPx)
            {
                x2 = lineTextPx;
            }

            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                if (divider >= x2)
                {
                    g.MoveTo(new Cairo.PointD(divider + 0.5, y2));
                    g.LineTo(new Cairo.PointD(divider + 0.5, y2Bottom));
                    g.SetSourceColor(GetLineColorBorder(highlighted, selected));
                    g.Stroke();
                }
            }

            return(true);
        }