protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress) { cr.SetSourceColor(new Color(0, 0, 0)); if (next != null) { double scale = Math.Min((double)width / (double)next.Width, (double)height / (double)next.Height); cr.Save(); cr.Translate(width * (1.0 - progress), 0); cr.Rectangle(0, 0, width, .5 * (height - scale * next.Height)); cr.Fill(); cr.Rectangle(0, height - .5 * (height - scale * next.Height), width, .5 * (height - scale * next.Height)); cr.Fill(); cr.Rectangle(0, 0, .5 * (width - scale * next.Width), height); cr.Fill(); cr.Rectangle(width - .5 * (width - scale * next.Width), 0, .5 * (width - scale * next.Width), height); cr.Fill(); cr.Rectangle(0, 0, width, height); cr.Scale(scale, scale); CairoHelper.SetSourcePixbuf(cr, next, .5 * ((double)width / scale - next.Width), .5 * ((double)height / scale - next.Height)); cr.Paint(); cr.Restore(); } }
static void PrintOperation_DrawPage(object o, DrawPageArgs args) { using (PrintContext context = args.Context) { using (var pixBuf = currentImage.GetPixbuf()) { Cairo.Context cr = context.CairoContext; double scale = 1; if (pixBuf.Height * context.Width / pixBuf.Width <= context.Height) { scale = context.Width / pixBuf.Width; } if (pixBuf.Width * context.Height / pixBuf.Height <= context.Width) { scale = context.Height / pixBuf.Height; } cr.Scale(scale, scale); cr.MoveTo(0, 0); CairoHelper.SetSourcePixbuf(cr, pixBuf, 0, 0); cr.Paint(); ((IDisposable)cr).Dispose(); } } }
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(); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { int width = Allocation.Width; int height = Allocation.Height; var bgColor = Style.Backgrounds[(int)State]; int imgWidth = (int)(pixbuf.Width / DpiScaling.Dialog); int imgHeight = (int)(pixbuf.Height / DpiScaling.Dialog); int x = (width - imgWidth) / 2; int y = (height - imgHeight) / 2; // Have to use Cairo here since i am unable to draw unpixelated bitmaps with Gdk. var ctx = CairoHelper.Create(ev.Window); CairoHelper.SetSourceColor(ctx, bgColor); ctx.Paint(); ctx.Translate(x, y); ctx.Scale(1.0f / DpiScaling.Dialog, 1.0f / DpiScaling.Dialog); CairoHelper.SetSourcePixbuf(ctx, pixbuf, 0, 0); ctx.Paint(); ctx.Target.Dispose(); ctx.Dispose(); return(true); }
public static Surface ScaleSmooth(this Surface source, int width, int height, double zoomX, double zoomY, InterpType interpolation = InterpType.Hyper) { ImageSurface tempSurface = new ImageSurface(Format.ARGB32, width, height); var tempContext = new Context(tempSurface); tempContext.SetSourceSurface(source, 0, 0); tempContext.Paint(); Pixbuf pbSrc = tempSurface.ToPixbuf(); tempContext.DisposeAll(); using (Pixbuf pbDest = new Pixbuf(Colorspace.Rgb, true, 8, (int)(width * zoomX), (int)(height * zoomY))) { pbSrc.Scale(pbDest, 0, 0, pbDest.Width, pbDest.Height, 0, 0, zoomX, zoomY, interpolation); pbSrc.Dispose(); Surface cache = new ImageSurface(Format.ARGB32, pbDest.Width, pbDest.Height); var cacheContext = new Context(cache); CairoHelper.SetSourcePixbuf(cacheContext, pbDest, 0, 0); cacheContext.Paint(); cacheContext.DisposeContext(); return(cache); } }
void DrawShape(Context g, int width, int height) { int inner_x = radius + border + inner; int cx = Center.X; int cy = Center.Y; g.Operator = Operator.Source; g.SetSource(new SolidPattern(new Cairo.Color(0, 0, 0, 0))); g.Rectangle(0, 0, width, height); g.Paint(); g.NewPath(); g.Translate(cx, cy); g.Rotate(angle); g.SetSource(new SolidPattern(new Cairo.Color(0.2, 0.2, 0.2, .6))); g.Operator = Operator.Over; g.Rectangle(0, -(border + inner), inner_x, 2 * (border + inner)); g.Arc(inner_x, 0, inner + border, 0, 2 * Math.PI); g.Arc(0, 0, radius + border, 0, 2 * Math.PI); g.Fill(); g.SetSource(new SolidPattern(new Cairo.Color(0, 0, 0, 1.0))); g.Operator = Operator.DestOut; g.Arc(inner_x, 0, inner, 0, 2 * Math.PI); #if true g.Fill(); #else g.FillPreserve(); g.Operator = Operator.Over; RadialGradient rg = new RadialGradient(inner_x - (inner * 0.3), inner * 0.3, inner * 0.1, inner_x, 0, inner); rg.AddColorStop(0, new Cairo.Color(0.0, 0.2, .8, 0.5)); rg.AddColorStop(0.7, new Cairo.Color(0.0, 0.2, .8, 0.1)); rg.AddColorStop(1.0, new Cairo.Color(0.0, 0.0, 0.0, 0.0)); g.Source = rg; g.Fill(); rg.Destroy(); #endif g.Operator = Operator.Over; g.Matrix = new Matrix(); g.Translate(cx, cy); if (source != null) { CairoHelper.SetSourcePixbuf(g, source, -source.Width / 2, -source.Height / 2); } g.Arc(0, 0, radius, 0, 2 * Math.PI); g.Fill(); if (overlay != null) { CairoHelper.SetSourcePixbuf(g, overlay, -overlay.Width / 2, -overlay.Height / 2); g.Arc(0, 0, radius, angle, angle + Math.PI); g.ClosePath(); g.FillPreserve(); g.SetSource(new SolidPattern(new Cairo.Color(1.0, 1.0, 1.0, 1.0))); g.Stroke(); } }
/// <summary> /// Draws the image. /// </summary> /// <param name="source">The source.</param> /// <param name="srcX">The source executable.</param> /// <param name="srcY">The source asynchronous.</param> /// <param name="srcWidth">Width of the source.</param> /// <param name="srcHeight">Height of the source.</param> /// <param name="x">The executable.</param> /// <param name="y">The asynchronous.</param> /// <param name="w">The forward.</param> /// <param name="h">The authentication.</param> /// <param name="opacity">The opacity.</param> /// <param name="interpolate">Interpolate if set to <c>true</c>.</param> public override void DrawImage( OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double x, double y, double w, double h, double opacity, bool interpolate) { var image = this.GetImage(source); if (image != null) { // TODO: srcX, srcY this.g.Save(); /* * ImageAttributes ia = null; * if (opacity < 1) * { * var cm = new ColorMatrix * { * Matrix00 = 1f, * Matrix11 = 1f, * Matrix22 = 1f, * Matrix33 = 1f, * Matrix44 = (float)opacity * }; * * ia = new ImageAttributes(); * ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); * } * */ var scalex = w / image.Width; var scaley = h / image.Height; var rectw = w / scalex; var recth = h / scaley; this.g.Translate(x, y); this.g.Scale(scalex, scaley); this.g.Rectangle(0, 0, rectw, recth); CairoHelper.SetSourcePixbuf( this.g, image, (rectw - image.Width) / 2.0, (recth - image.Height) / 2.0); this.g.Fill(); // TODO: InterpolationMode // g.InterpolationMode = interpolate ? InterpolationMode.HighQualityBicubic : InterpolationMode.NearestNeighbor; this.g.Restore(); } }
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)); } }
protected override bool OnExposeEvent(EventExpose evnt) { if (pb == null) { return(true); } double sf = 1.0; // pixbuf scale factor // if any image dimension > widget area => calc downscale factor if ((pb.Width > evnt.Area.Width) || (pb.Height > evnt.Area.Height)) { double sfWidth = (double)evnt.Area.Width / pb.Width; double sfHeight = (double)evnt.Area.Height / pb.Height; sf = Math.Min(sfWidth, sfHeight); } // adjust selection area size to that of the pixbuf int width = (int)(pb.Width * sf); int height = (int)(pb.Height * sf); // center in the widget area double x = Math.Floor(evnt.Area.X + (evnt.Area.Width / 2.0) - (width / 2.0)); double y = Math.Floor(evnt.Area.Y + (evnt.Area.Height / 2.0) - (height / 2.0)); using (Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.MoveTo(x, y); if (RoundedCorners && !isIcon && (width > MIN_LEN_FOR_CORNERS) && (height > MIN_LEN_FOR_CORNERS)) { cr.Arc(x + width - RADIUS, y + RADIUS, RADIUS, Math.PI * 1.5, Math.PI * 2); cr.Arc(x + width - RADIUS, y + height - RADIUS, RADIUS, 0, Math.PI * .5); cr.Arc(x + RADIUS, y + height - RADIUS, RADIUS, Math.PI * .5, Math.PI); cr.Arc(x + RADIUS, y + RADIUS, RADIUS, Math.PI, Math.PI * 1.5); cr.Clip(); cr.NewPath(); } // set pixbuf source downscale if (sf < 1.0) { cr.Scale(sf, sf); } // set pixbuf source CairoHelper.SetSourcePixbuf(cr, pb, Math.Floor(x / sf), Math.Floor(y / sf)); // paint pixbuf source cr.Paint(); } return(base.OnExposeEvent(evnt)); }
protected override bool OnExposeEvent(EventExpose evnt) { var ret = base.OnExposeEvent(evnt); if (image.Pixbuf == null) { using (var cr = CairoHelper.Create(evnt.Window)) { cr.Rectangle(evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height); cr.Clip(); var imgAlloc = image.Allocation; cr.Translate(imgAlloc.X, imgAlloc.Y); using (var layout = new Pango.Layout(PangoContext)) { layout.SetText(string.Format("({0}x{1})", RecommendedSize.Width, RecommendedSize.Height)); layout.Width = (int)(imgAlloc.Width * Pango.Scale.PangoScale); layout.Wrap = Pango.WrapMode.WordChar; layout.Alignment = Pango.Alignment.Center; int pw, ph; layout.GetPixelSize(out pw, out ph); cr.MoveTo(0, (imgAlloc.Height - ph) / 2); cr.Color = new Cairo.Color(0.5, 0.5, 0.5); cr.ShowLayout(layout); } CairoExtensions.RoundedRectangle(cr, 5, 5, imgAlloc.Width - 10, imgAlloc.Height - 10, 5); cr.LineWidth = 3; cr.Color = new Cairo.Color(0.8, 0.8, 0.8); cr.SetDash(new double[] { 12, 2 }, 0); cr.Stroke(); } } else if (RecommendedSize != Size.Empty && imageSize != RecommendedSize) { using (var cr = CairoHelper.Create(evnt.Window)) { cr.Rectangle(evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height); cr.Clip(); var imgAlloc = image.Allocation; cr.Translate(imgAlloc.X + displaySize.Width - WarningIcon.Width - 3, imgAlloc.Y + displaySize.Height - WarningIcon.Height); CairoHelper.SetSourcePixbuf(cr, WarningIcon, 0, 0); cr.Rectangle(0, 0, WarningIcon.Width, WarningIcon.Height); cr.Fill(); } } return(ret); }
private void Activated(object sender, EventArgs e) { int delay = PintaCore.Settings.GetSetting <int> ("screenshot-delay", 0); using var dialog = new SpinButtonEntryDialog(Translations.GetString("Take Screenshot"), PintaCore.Chrome.MainWindow, Translations.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); GLib.Timeout.Add((uint)delay * 1000, () => { Screen screen = Screen.Default; var root_window = screen.RootWindow; int width = root_window.Width; int height = root_window.Height; if (width == 0 || height == 0) { // Something went wrong... // This might happen when running under wayland, see bug 1923241 PintaCore.Chrome.ShowErrorDialog(PintaCore.Chrome.MainWindow, Translations.GetString("Failed to take screenshot"), Translations.GetString("Could not obtain the size of display '{0}'", screen.Display.Name)); return(false); } Document doc = PintaCore.Workspace.NewDocument(new Size(width, height), new Cairo.Color(1, 1, 1)); using (var pb = new Pixbuf(root_window, 0, 0, width, height)) { using (Cairo.Context g = new Cairo.Context(doc.Layers.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); }); } }
private void Draw(Cairo.Context context) { CairoHelper.SetSourcePixbuf(context, this.screenshot, 0, 0); context.Paint(); if (this.x0 >= 0 && this.y0 >= 0) { CairoHelpers.DrawInverseSelectionRectangles( context, this.inverseSelectionColor, this.x0, this.y0, this.x1, this.y1, this.windowWidth, this.windowHeight); CairoHelpers.DrawSelectionRectangle( context, SelectionRectangleDashesPattern, this.accentColor, this.x0, this.y0, this.x1, this.y1); CairoHelpers.DrawSizeTooltip( context, this.tooltipBackgroundColor, this.textColor, this.x0, this.y0, this.x1, this.y1, SizeTooltipPaddingInPixels, SizeTooltipMarginInPixels); } else if (this.croppingRectangle != null) { this.Crop(this.croppingRectangle.Value); this.croppingRectangle = null; } else { context.SetSourceRGBA( this.inverseSelectionColor.R, this.inverseSelectionColor.G, this.inverseSelectionColor.B, this.inverseSelectionColor.A); context.Rectangle(0, 0, this.windowWidth, this.windowHeight); context.Fill(); } }
public static Surface CreateSurfaceForPixbuf(Context cr, Pixbuf pixbuf) { Surface surface; using (var t = cr.GetTarget()) { surface = t.CreateSimilar(t.Content, pixbuf.Width, pixbuf.Height); } using (Context surface_cr = new Context(surface)) { CairoHelper.SetSourcePixbuf(surface_cr, pixbuf, 0, 0); surface_cr.Paint(); surface_cr.Dispose(); } return(surface); }
public virtual void Resize(int width, int height) { ImageSurface dest = new ImageSurface(Format.Argb32, width, height); Pixbuf pb = Surface.ToPixbuf(); Pixbuf pbScaled = pb.ScaleSimple(width, height, InterpType.Bilinear); using (Context g = new Context(dest)) { CairoHelper.SetSourcePixbuf(g, pbScaled, 0, 0); g.Paint(); } (Surface as IDisposable).Dispose(); (pb as IDisposable).Dispose(); (pbScaled as IDisposable).Dispose(); Surface = dest; }
protected void DrawIndicator(Cairo.Context cr, Severity severity) { cr.Save(); var pixbuf = GetIndicatorIcon(severity); cr.Translate( 1 + (Allocation.Width - pixbuf.Width) / 2, 1 ); CairoHelper.SetSourcePixbuf( cr, pixbuf, 0, 0 ); cr.Paint(); cr.Restore(); }
private void HandlePintaCoreActionsLayersImportFromFileActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); var fcd = new Gtk.FileChooserDialog(Catalog.GetString("Open Image File"), PintaCore.Chrome.MainWindow, FileChooserAction.Open, Stock.Cancel, ResponseType.Cancel, Stock.Open, ResponseType.Ok); fcd.SetCurrentFolder(PintaCore.System.GetDialogDirectory()); fcd.AlternativeButtonOrder = new int[] { (int)ResponseType.Ok, (int)ResponseType.Cancel }; fcd.AddImagePreview(); int response = fcd.Run(); if (response == (int)Gtk.ResponseType.Ok) { string file = fcd.Filename; PintaCore.System.LastDialogDirectory = fcd.CurrentFolder; // Open the image and add it to the layers Layer layer = doc.AddNewLayer(System.IO.Path.GetFileName(file)); using (var fs = new FileStream(file, FileMode.Open)) using (Pixbuf bg = new Pixbuf(fs)) using (Cairo.Context g = new Cairo.Context(layer.Surface)) { CairoHelper.SetSourcePixbuf(g, bg, 0, 0); g.Paint(); } doc.SetCurrentLayer(layer); AddLayerHistoryItem hist = new AddLayerHistoryItem("Menu.Layers.ImportFromFile.png", Catalog.GetString("Import From File"), doc.Layers.IndexOf(layer)); doc.History.PushNewItem(hist); doc.Workspace.Invalidate(); } fcd.Destroy(); }
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), new Cairo.Color(1, 1, 1)); 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(); }
private void UpdateScaleAndRotation() { if (_image != null && _original != null) { Pixbuf rotated; if (_rotation != 0.0) { ImageSurface surface = new ImageSurface(Format.Argb32, _original.Width, _original.Height); Context ctx = new Context(surface); ctx.Translate(_original.Width / 2.0, _original.Height / 2.0); double radians = _rotation * (Math.PI / 180.0); ctx.Rotate(radians); ctx.Translate(-_original.Width / 2.0, -_original.Height / 2.0); CairoHelper.SetSourcePixbuf(ctx, _original, 0, 0); ctx.Paint(); rotated = GetPixbufFromImageSurface(surface, surface.Width, surface.Height); surface.Dispose(); ctx.GetTarget().Dispose(); ctx.Dispose(); } else { rotated = _original; } if (_scaleX != 0.0 || _scaleY != 0.0) { _image.Pixbuf = rotated.ScaleSimple((int)(rotated.Width * _scale), (int)(rotated.Height * _scale), InterpType.Bilinear); } else { _image.Pixbuf = rotated; } } QueueDraw(); }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { var bgColor = Style.Backgrounds[(int)State]; var fgColor = Style.Foregrounds[(int)State]; int width = Allocation.Width; int height = Allocation.Height; int imgWidth = (int)(pixbuf.Width / GLTheme.DialogScaling); int imgHeight = (int)(pixbuf.Height / GLTheme.DialogScaling); int x = buttonText == null ? (width - imgWidth) / 2 : 5; int y = (height - imgHeight) / 2; int yp = State == Gtk.StateType.Active ? 1 : 0; // Have to use Cairo here since i am unable to draw unpixelated bitmaps with Gdk. var ctx = CairoHelper.Create(ev.Window); CairoHelper.SetSourceColor(ctx, bgColor); ctx.Paint(); ctx.Translate(x, y + yp); ctx.Scale(1.0f / GLTheme.DialogScaling, 1.0f / GLTheme.DialogScaling); CairoHelper.SetSourcePixbuf(ctx, pixbuf, 0, 0); ctx.Paint(); if (buttonText != null) { CairoHelper.SetSourceColor(ctx, fgColor); ctx.Scale(1.0f, 1.0f); ctx.SelectFontFace("Quicksand", FontSlant.Normal, bold ? FontWeight.Bold : FontWeight.Normal); ctx.SetFontSize(14 * GLTheme.DialogScaling); ctx.MoveTo(20 * GLTheme.DialogScaling, 13 * GLTheme.DialogScaling); ctx.ShowText(buttonText); } ctx.Target.Dispose(); ctx.Dispose(); return(true); }
void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y) { if (!heightMeasured) { return; } Pango.Layout layout = new Pango.Layout(PangoContext); TableRow lastCategory = null; Pango.FontDescription defaultFont = new Pango.FontDescription(); Pango.FontDescription changedFont = defaultFont.Copy(); defaultFont.Weight = Pango.Weight.Bold; foreach (var r in rowList) { int w, h; layout.SetText(r.Label); if (r.IsDefaultValue && (r.Expanded || HasDefaultValue(r.ChildRows))) { layout.FontDescription = changedFont; } else { layout.FontDescription = defaultFont; } layout.GetPixelSize(out w, out h); int indent = 0; if (r.IsCategory) { var rh = h + CategoryTopBottomPadding * 2; ctx.Rectangle(0, y, Allocation.Width, rh); using (var gr = new LinearGradient(0, y, 0, rh)) { gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d)); gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d)); ctx.SetSource(gr); ctx.Fill(); } if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand) { ctx.MoveTo(0, y + 0.5); ctx.LineTo(Allocation.Width, y + 0.5); } ctx.MoveTo(0, y + rh - 0.5); ctx.LineTo(Allocation.Width, y + rh - 0.5); ctx.SetSourceColor(DividerColor); ctx.Stroke(); ctx.MoveTo(x, y + CategoryTopBottomPadding); ctx.SetSourceColor(CategoryLabelColor); Pango.CairoHelper.ShowLayout(ctx, layout); var img = r.Expanded ? discloseUp : discloseDown; var area = GetCategoryArrowArea(r); CairoHelper.SetSourcePixbuf(ctx, img, area.X + (area.Width - img.Width) / 2, area.Y + (area.Height - img.Height) / 2); ctx.Paint(); y += rh; lastCategory = r; } else { var cell = GetCell(r); r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject; var state = r.Enabled ? State : Gtk.StateType.Insensitive; ctx.Save(); if (r == lastEditorRow) { ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2); ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1)); ctx.Fill(); //int dividerX = (int)((double)Allocation.Width * dividerPosition); //var cell = GetCell(r); //cell.GetSize(Allocation.Width - dividerX, out w, out eh); //eh = Math.Max(h + PropertyTopBottomPadding * 2, eh); //r.EditorBounds = new Gdk.Rectangle(dividerX + PropertyContentLeftPadding, y, Allocation.Width - dividerX - PropertyContentLeftPadding, eh); //var bounds = new Gdk.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height); //ctx.MoveTo(bounds.Right, bounds.Y+1); //ctx.LineTo(bounds.X, bounds.Y+1); //ctx.MoveTo(bounds.Right, bounds.Bottom); //ctx.LineTo(bounds.X, bounds.Bottom); //ctx.Stroke(); //ctx.Rectangle(dividerX + 1, r.EditorBounds.Y, Allocation.Width - dividerX - 1, r.EditorBounds.Height); //ctx.SetSourceColor(new Cairo.Color(0.8, 0.9, 1.0, 1)); //ctx.Fill(); } if (r.ChildRows != null && r.ChildRows.Count > 0) { var img = r.Expanded ? arrowLeft : arrowRight; CairoHelper.SetSourcePixbuf(ctx, img, 2, y + (h + PropertyTopBottomPadding * 2) / 2 - img.Height / 2); ctx.Paint(); } ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2); ctx.Clip(); ctx.MoveTo(x, y + PropertyTopBottomPadding); ctx.SetSourceColor(Style.Text(state).ToCairoColor()); Pango.CairoHelper.ShowLayout(ctx, layout); ctx.Restore(); if (r != currentEditorRow) { cell.Render(GdkWindow, ctx, r.EditorBounds, state); } y += r.EditorBounds.Height; indent = PropertyIndent; } if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand)) { int py = y; ctx.Save(); if (r.AnimatingExpand) { ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight); } else { ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height); } ctx.Clip(); Draw(ctx, r.ChildRows, dividerX, x + indent, ref y); ctx.Restore(); if (r.AnimatingExpand) { y = py + r.AnimationHeight; // Repaing the background because the cairo clip doesn't work for gdk primitives int dx = (int)((double)Allocation.Width * dividerPosition); ctx.Rectangle(0, y, dx, Allocation.Height - y); ctx.SetSourceColor(LabelBackgroundColor); ctx.Fill(); ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y); ctx.SetSourceRGB(1, 1, 1); ctx.Fill(); } } } }
void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y) { if (!heightMeasured) { return; } Pango.Layout layout = new Pango.Layout(PangoContext); TableRow lastCategory = null; foreach (var r in rowList) { int w, h; layout.SetText(r.Label); layout.GetPixelSize(out w, out h); int indent = 0; if (r.IsCategory) { var rh = h + CategoryTopBottomPadding * 2; ctx.Rectangle(0, y, Allocation.Width, rh); using (var gr = new LinearGradient(0, y, 0, rh)) { gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d)); gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d)); ctx.SetSource(gr); ctx.Fill(); } if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand) { ctx.MoveTo(0, y + 0.5); ctx.LineTo(Allocation.Width, y + 0.5); } ctx.MoveTo(0, y + rh - 0.5); ctx.LineTo(Allocation.Width, y + rh - 0.5); ctx.SetSourceColor(DividerColor); ctx.Stroke(); ctx.MoveTo(x, y + CategoryTopBottomPadding); ctx.SetSourceColor(CategoryLabelColor); Pango.CairoHelper.ShowLayout(ctx, layout); var img = r.Expanded ? discloseUp : discloseDown; CairoHelper.SetSourcePixbuf(ctx, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + (rh - img.Height) / 2); ctx.Paint(); y += rh; lastCategory = r; } else { var cell = GetCell(r); r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject; var state = r.Enabled ? State : Gtk.StateType.Insensitive; ctx.Save(); ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2); ctx.Clip(); ctx.MoveTo(x, y + PropertyTopBottomPadding); ctx.SetSourceColor(Style.Text(state).ToCairoColor()); Pango.CairoHelper.ShowLayout(ctx, layout); ctx.Restore(); if (r != currentEditorRow) { cell.Render(GdkWindow, ctx, r.EditorBounds, state); } y += r.EditorBounds.Height; indent = PropertyIndent; } if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand)) { int py = y; ctx.Save(); if (r.AnimatingExpand) { ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight); } else { ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height); } ctx.Clip(); Draw(ctx, r.ChildRows, dividerX, x + indent, ref y); ctx.Restore(); if (r.AnimatingExpand) { y = py + r.AnimationHeight; // Repaing the background because the cairo clip doesn't work for gdk primitives int dx = (int)((double)Allocation.Width * dividerPosition); ctx.Rectangle(0, y, dx, Allocation.Height - y); ctx.SetSourceColor(LabelBackgroundColor); ctx.Fill(); ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y); ctx.SetSourceRGB(1, 1, 1); ctx.Fill(); } } } }
protected override bool OnExposeEvent(Gdk.EventExpose e) { Gdk.Pixbuf bg; try{ //if(fileName.ToLower().EndsWith (".svg")){ //bg = Rsvg.Pixbuf.FromFile(fileName); // bg = Rsvg.Tool.PixbufFromFileAtSize(fileName,800,600); //} else{ using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open)) bg = new Gdk.Pixbuf(fs); //} }catch (Exception ex) { Tool.Logger.Error(ex.Message, null); return(true); } bg = bg.ApplyEmbeddedOrientation(); this.HeightImage = bg.Height; this.WidthImage = bg.Width; if (this.listPoint == null) { this.listPoint = new List <BarierPoint>(); if (this.shapeListPoint != null) { foreach (BarierPoint bp in this.shapeListPoint) { BarierPoint updateBp = new BarierPoint(); updateBp.X = bp.X + (1 / HeightImage); updateBp.Y = -bp.Y + (1 / WidthImage); listPoint.Add(updateBp); } } } //Size imagesize = new Size (bg.Width, bg.Height); width = (int)(bg.Width * scaling); height = (int)(bg.Height * scaling); int x, y, w, h, d = 0; this.ParentWindow.GetGeometry(out x, out y, out w, out h, out d); drawOffsetX = (w - width) / 2; if (drawOffsetX < 0) { drawOffsetX = 0; } drawOffsetY = (h - height) / 2; if (drawOffsetY < 0) { drawOffsetY = 0; } using (Context cr = Gdk.CairoHelper.Create(e.Window)) { if (!MainClass.Platform.IsMac) { FillChecks(cr, 0, 0, w, h); //w, h); cr.Save(); cr.DrawRectangle(new Cairo.Rectangle(drawOffsetX - 1, drawOffsetY - 1, width + 1, height + 1), new Cairo.Color(0, 0, 0), 1); cr.Rectangle(new Cairo.Rectangle(drawOffsetX - 1, drawOffsetY - 1, width, height)); cr.Clip(); } cr.Scale(scaling, scaling); CairoHelper.SetSourcePixbuf(cr, bg, drawOffsetX / scaling, drawOffsetY / scaling); cr.Paint(); this.WidthRequest = width + 1; this.HeightRequest = height + 1; if (showBarierLayer) { Draw(cr, width, height); } cr.Scale(scaling, scaling); } return(true); /*using (Context cr = Gdk.CairoHelper.Create (e.Window)) { * int w, h; * e.Window.GetSize (out w, out h); * Draw (cr, w, h); * } * return true;*/ }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { int width = Allocation.Width; int height = Allocation.Height; #if FAMISTUDIO_MACOS var bgColor = Style.Backgrounds[(int)State]; var fgColor = Style.Foregrounds[(int)State]; int imgWidth = (int)(pixbuf.Width / GLTheme.DialogScaling); int imgHeight = (int)(pixbuf.Height / GLTheme.DialogScaling); int x = buttonText == null ? (width - imgWidth) / 2 : 5; int y = (height - imgHeight) / 2; int yp = State == Gtk.StateType.Active ? 1 : 0; // Have to use Cairo here since i am unable to draw unpixelated bitmaps with Gdk. var ctx = CairoHelper.Create(ev.Window); CairoHelper.SetSourceColor(ctx, bgColor); ctx.Paint(); ctx.Translate(x, y + yp); ctx.Scale(1.0f / GLTheme.DialogScaling, 1.0f / GLTheme.DialogScaling); CairoHelper.SetSourcePixbuf(ctx, pixbuf, 0, 0); ctx.Paint(); if (buttonText != null) { CairoHelper.SetSourceColor(ctx, fgColor); ctx.Scale(1.0f, 1.0f); ctx.SelectFontFace("Quicksand", FontSlant.Normal, bold ? FontWeight.Bold : FontWeight.Normal); ctx.SetFontSize(14 * GLTheme.DialogScaling); ctx.MoveTo(20 * GLTheme.DialogScaling, 13 * GLTheme.DialogScaling); ctx.ShowText(buttonText); } ctx.Target.Dispose(); ctx.Dispose(); #else using (Gdk.GC gc = new Gdk.GC((Drawable)base.GdkWindow)) { int x = layoutNormal == null ? (width - pixbuf.Width) / 2 : 5; int y = (height - pixbuf.Height) / 2; int yp = State == Gtk.StateType.Active ? 1 : 0; GdkWindow.DrawRectangle(Style.BackgroundGC(State), true, 0, 0, width, height); if (layoutNormal != null) { var layout = bold ? layoutBold : layoutNormal; layout.Width = -1; layout.GetSize(out _, out int layoutHeight); layoutHeight = Pango.Units.ToPixels(layoutHeight); GdkWindow.DrawPixbuf(gc, pixbuf, 0, 0, x, y + yp, pixbuf.Width, pixbuf.Height, RgbDither.None, 0, 0); GdkWindow.DrawLayout(Style.ForegroundGC(State), 10 + pixbuf.Width, (height - layoutHeight) / 2 + yp, layout); } else { GdkWindow.DrawPixbuf(gc, pixbuf, 0, 0, x, y + yp, pixbuf.Width, pixbuf.Height, RgbDither.None, 0, 0); } } #endif return(true); }
public void Import(string fileName, Gtk.Window parent) { ZipFile file = new ZipFile(fileName); XmlDocument stackXml = new XmlDocument(); stackXml.Load(file.GetInputStream(file.GetEntry("stack.xml"))); XmlElement imageElement = stackXml.DocumentElement; int width = int.Parse(imageElement.GetAttribute("w")); int height = int.Parse(imageElement.GetAttribute("h")); Size imagesize = new Size(width, height); Document doc = PintaCore.Workspace.CreateAndActivateDocument(fileName, imagesize); doc.HasFile = true; XmlElement stackElement = (XmlElement)stackXml.GetElementsByTagName("stack")[0]; XmlNodeList layerElements = stackElement.GetElementsByTagName("layer"); if (layerElements.Count == 0) { throw new XmlException("No layers found in OpenRaster file"); } doc.ImageSize = imagesize; doc.Workspace.CanvasSize = imagesize; for (int i = 0; i < layerElements.Count; i++) { XmlElement layerElement = (XmlElement)layerElements[i]; int x = int.Parse(GetAttribute(layerElement, "x", "0")); int y = int.Parse(GetAttribute(layerElement, "y", "0")); string name = GetAttribute(layerElement, "name", string.Format("Layer {0}", i)); try { // Write the file to a temporary file first // Fixes a bug when running on .Net ZipEntry zf = file.GetEntry(layerElement.GetAttribute("src")); Stream s = file.GetInputStream(zf); string tmp_file = System.IO.Path.GetTempFileName(); using (Stream stream_out = File.Open(tmp_file, FileMode.OpenOrCreate)) { byte[] buffer = new byte[2048]; while (true) { int len = s.Read(buffer, 0, buffer.Length); if (len > 0) { stream_out.Write(buffer, 0, len); } else { break; } } } UserLayer layer = doc.CreateLayer(name); doc.Insert(layer, 0); layer.Opacity = double.Parse(GetAttribute(layerElement, "opacity", "1"), GetFormat()); layer.BlendMode = StandardToBlendMode(GetAttribute(layerElement, "composite-op", "svg:src-over")); using (var fs = new FileStream(tmp_file, FileMode.Open)) using (Pixbuf pb = new Pixbuf(fs)) { using (Context g = new Context(layer.Surface)) { CairoHelper.SetSourcePixbuf(g, pb, x, y); g.Paint(); } } try { File.Delete(tmp_file); } catch { } } catch { MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Could not import layer \"{0}\" from {0}", name, file); md.Title = "Error"; md.Run(); md.Destroy(); } } file.Close(); }
private void UpdateImage() { float scale = Math.Min(Allocation.Width / _svgOriginalW, Allocation.Height / _svgOriginalH); int width = (int)(_svgOriginalW * scale); int height = (int)(_svgOriginalH * scale); Context cr = Gdk.CairoHelper.Create(this.GdkWindow); cr.SetSourceRGB(0, 0, 0); cr.Rectangle(0, 0, width, height); cr.Fill(); cr.Save(); using (MemoryStream ms = new MemoryStream()) { _svg.Draw(width, height).Save(ms, ImageFormat.Png); // imageView.Pixbuf = new Pixbuf(ms.ToArray()); CairoHelper.SetSourcePixbuf(cr, new Pixbuf(ms.ToArray()), 0, 0); } cr.Paint(); cr.Restore(); cr.SetSourceRGB(1, 1, 1); foreach (SvgText text in _svgTexts) { if (text.Text == null) { continue; } float dx = text.X[0].Value / _svgOriginalW * width; float dy = text.Y[0].Value / _svgOriginalH * height; cr.MoveTo(dx, dy); if (text.Color == warningColor) { cr.SetSourceColor(cWarningColor); } else if (text.Color == disabledColor) { cr.SetSourceColor(cDisabledColor); } else { cr.SetSourceColor(cNominalColor); } if (text.FontSize.Value is float size) { cr.SetFontSize(size * scale); } FontWeight weight = (text.FontWeight == SvgFontWeight.Bold) ? FontWeight.Bold : FontWeight.Normal; FontSlant slant = (text.FontStyle == SvgFontStyle.Italic) ? FontSlant.Italic : FontSlant.Normal; cr.SelectFontFace("sans serif", slant, weight); if (text.TextAnchor == SvgTextAnchor.Middle) { TextExtents te = cr.TextExtents(text.Text); cr.RelMoveTo(-te.Width / 2.0, 0); } cr.ShowText(text.Text); } // GC from example ((IDisposable)cr.GetTarget()).Dispose(); ((IDisposable)cr).Dispose(); }