Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to gir.core 0.6.0-preview.1 #1095

Merged
merged 4 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="GirCore.Adw-1" Version="0.5.0" />
<PackageVersion Include="GirCore.Gtk-4.0" Version="0.5.0" />
<PackageVersion Include="GirCore.PangoCairo-1.0" Version="0.5.0" />
<PackageVersion Include="GirCore.Adw-1" Version="0.6.0-preview.1" />
<PackageVersion Include="GirCore.Gtk-4.0" Version="0.6.0-preview.1" />
<PackageVersion Include="GirCore.PangoCairo-1.0" Version="0.6.0-preview.1" />
<!-- Note: at least 1.4.2-alpha3 is required for fixes to uninstalling addins, from https://github.com/mono/mono-addins/pull/198 -->
<PackageVersion Include="Mono.Addins" Version="1.4.2-alpha.4" />
<PackageVersion Include="Mono.Addins.Setup" Version="1.4.2-alpha.4" />
Expand Down
8 changes: 4 additions & 4 deletions Pinta.Core/Actions/EditActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void HandlePintaCoreActionsEditFillSelectionActivated (object sender, Ev

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

Context g = new (doc.Layers.CurrentUserLayer.Surface);
using Context g = new (doc.Layers.CurrentUserLayer.Surface);

g.AppendPath (doc.Selection.SelectionPath);
g.FillRule = FillRule.EvenOdd;
Expand Down Expand Up @@ -247,7 +247,7 @@ private void HandlePintaCoreActionsEditEraseSelectionActivated (object sender, E

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

Context g = new (doc.Layers.CurrentUserLayer.Surface);
using Context g = new (doc.Layers.CurrentUserLayer.Surface);

g.AppendPath (doc.Selection.SelectionPath);
g.FillRule = FillRule.EvenOdd;
Expand Down Expand Up @@ -302,7 +302,7 @@ private void HandlerPintaCoreActionsEditCopyActivated (object sender, EventArgs

ImageSurface dest = CairoExtensions.CreateImageSurface (Format.Argb32, rect.Width, rect.Height);

Context g = new (dest);
using Context g = new (dest);

g.SetSourceSurface (src, -rect.X, -rect.Y);
g.Paint ();
Expand All @@ -324,7 +324,7 @@ private void HandlerPintaCoreActionsEditCopyMergedActivated (object sender, Even
// Copy it to a correctly sized surface
ImageSurface dest = CairoExtensions.CreateImageSurface (Format.Argb32, rect.Width, rect.Height);

Context g = new (dest);
using Context g = new (dest);

g.SetSourceSurface (src, -rect.X, -rect.Y);
g.Paint ();
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Actions/LayerActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void HandlePintaCoreActionsLayersImportFromFileActivated (object sender,
using Gio.FileInputStream fs = file.Read (null);
try {
GdkPixbuf.Pixbuf bg = GdkPixbuf.Pixbuf.NewFromStream (fs, cancellable: null)!; // NRT: only nullable when an error is thrown
Cairo.Context context = new (layer.Surface);
using Cairo.Context context = new (layer.Surface);
context.DrawPixbuf (bg, PointD.Zero);
} finally {
fs.Close (null);
Expand Down
20 changes: 2 additions & 18 deletions Pinta.Core/Classes/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,13 @@ public Context CreateClippedContext ()
return g;
}

public Context CreateClippedContext (bool antialias)
{
Context g = new (Layers.CurrentUserLayer.Surface);
Selection.Clip (g);
g.Antialias = antialias ? Antialias.Subpixel : Antialias.None;
return g;
}

public Context CreateClippedToolContext ()
{
Context g = new (Layers.ToolLayer.Surface);
Selection.Clip (g);
return g;
}

public Context CreateClippedToolContext (bool antialias)
{
Context g = new (Layers.ToolLayer.Surface);
Selection.Clip (g);
g.Antialias = antialias ? Antialias.Subpixel : Antialias.None;
return g;
}

public void FinishSelection ()
{
// We don't have an uncommitted layer, abort
Expand All @@ -232,7 +216,7 @@ public void FinishSelection ()

Layer layer = Layers.SelectionLayer;

Context g = new (Layers.CurrentUserLayer.Surface);
using Context g = new (Layers.CurrentUserLayer.Surface);
selection.Clip (g);
layer.DrawWithOperator (g, Operator.Source, opacity: 1.0, transform: true);

Expand Down Expand Up @@ -270,7 +254,7 @@ public ColorBgra GetComputedPixel (PointI position)
1,
1);

Context g = new (dst);
using Context g = new (dst);

foreach (var layer in Layers.GetLayersToPaint ()) {

Expand Down
8 changes: 4 additions & 4 deletions Pinta.Core/Classes/DocumentLayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public UserLayer DuplicateCurrentLayer ()
// {0} is the name of the source layer. Example: "Layer 3 copy".
UserLayer layer = CreateLayer (Translations.GetString ("{0} copy", source.Name));

Context g = new (layer.Surface);
using Context g = new (layer.Surface);
g.SetSourceSurface (source.Surface, 0, 0);
g.Paint ();

Expand Down Expand Up @@ -254,7 +254,7 @@ public ImageSurface GetClippedLayer (int index)
{
ImageSurface surf = CairoExtensions.CreateImageSurface (Format.Argb32, document.ImageSize.Width, document.ImageSize.Height);

Context g = new (surf);
using Context g = new (surf);
document.Selection.Clip (g);

g.SetSourceSurface (user_layers[index].Surface, 0, 0);
Expand All @@ -271,7 +271,7 @@ internal ImageSurface GetFlattenedImage (bool clip_to_selection = false)
// Create a new image surface
ImageSurface surf = CairoExtensions.CreateImageSurface (Format.Argb32, document.ImageSize.Width, document.ImageSize.Height);

Context g = new (surf);
using Context g = new (surf);

if (clip_to_selection)
document.Selection.Clip (g);
Expand Down Expand Up @@ -350,7 +350,7 @@ public void MergeCurrentLayerDown ()
UserLayer dest = user_layers[CurrentUserLayerIndex - 1];

// Blend the layers
Context g = new (dest.Surface);
using Context g = new (dest.Surface);
source.Draw (g);

DeleteCurrentLayer ();
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Classes/DocumentSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public bool Visible {
public Path SelectionPath {
get {
if (selection_path == null) {
Context g = new (owning_document.Layers.CurrentUserLayer.Surface);
using Context g = new (owning_document.Layers.CurrentUserLayer.Surface);
selection_path = g.CreatePolygonPath (ConvertToPolygonSet (SelectionPolygons));
}

Expand Down
12 changes: 6 additions & 6 deletions Pinta.Core/Classes/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void FlipHorizontal ()
Surface.Width,
Surface.Height);

Context g = new (dest);
using Context g = new (dest);

g.SetMatrix (CairoExtensions.CreateMatrix (-1, 0, 0, 1, Surface.Width, 0));
g.SetSourceSurface (Surface, 0, 0);
Expand All @@ -114,7 +114,7 @@ public void FlipVertical ()
Surface.Width,
Surface.Height);

Context g = new (dest);
using Context g = new (dest);

g.SetMatrix (CairoExtensions.CreateMatrix (1, 0, 0, -1, 0, Surface.Height));
g.SetSourceSurface (Surface, 0, 0);
Expand Down Expand Up @@ -183,7 +183,7 @@ public virtual void ApplyTransform (
new_size.Width,
new_size.Height);

Context g = new (dest);
using Context g = new (dest);

g.Transform (xform);
g.SetSourceSurface (Surface, 0, 0);
Expand Down Expand Up @@ -215,7 +215,7 @@ public virtual void Resize (Size newSize, ResamplingMode resamplingMode)
newSize.Width,
newSize.Height);

Context g = new (dest);
using Context g = new (dest);

g.Scale (newSize.Width / (double) Surface.Width, newSize.Height / (double) Surface.Height);
g.SetSourceSurface (Surface, resamplingMode);
Expand All @@ -238,7 +238,7 @@ public virtual void ResizeCanvas (Size newSize, Anchor anchor)

PointD anchorPoint = GetAnchorPoint (delta, anchor);

Context g = new (dest);
using Context g = new (dest);

g.SetSourceSurface (Surface, anchorPoint.X, anchorPoint.Y);
g.Paint ();
Expand Down Expand Up @@ -267,7 +267,7 @@ public virtual void Crop (RectangleI rect, Path? selection)
rect.Width,
rect.Height);

Context g = new (dest);
using Context g = new (dest);

// Move the selected content to the upper left
g.Translate (-rect.X, -rect.Y);
Expand Down
14 changes: 7 additions & 7 deletions Pinta.Core/Extensions/CairoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public static ImageSurface Clone (this ImageSurface surf)
surf.Width,
surf.Height);

Context g = new (newsurf);
using Context g = new (newsurf);

g.SetSourceSurface (surf, 0, 0);
g.Paint ();
Expand All @@ -639,14 +639,14 @@ public static ImageSurface Clone (this ImageSurface surf)
public static Path Clone (this Path path)
{
Document doc = PintaCore.Workspace.ActiveDocument;
Context g = new (doc.Layers.CurrentUserLayer.Surface);
using Context g = new (doc.Layers.CurrentUserLayer.Surface);
g.AppendPath (path);
return g.CopyPath ();
}

public static void Clear (this ImageSurface surface)
{
Context g = new (surface) { Operator = Operator.Clear };
using Context g = new (surface) { Operator = Operator.Clear };
g.Paint ();
}

Expand Down Expand Up @@ -689,7 +689,7 @@ public static RectangleD PathExtents (this Context context)
public static RectangleI GetBounds (this Path path)
{
Document doc = PintaCore.Workspace.ActiveDocument;
Context g = new (doc.Layers.CurrentUserLayer.Surface);
using Context g = new (doc.Layers.CurrentUserLayer.Surface);
g.AppendPath (path);
return g.PathExtents ().ToInt ();
}
Expand Down Expand Up @@ -1175,7 +1175,7 @@ public static ImageSurface CreateTransparentBackgroundSurface (int size)
ImageSurface surface = CreateImageSurface (Format.Argb32, size, size);

// Draw the checkerboard
Context g = new (surface);
using Context g = new (surface);

// Fill white
g.FillRectangle (new RectangleD (0, 0, size, size), new Color (1, 1, 1));
Expand Down Expand Up @@ -1856,7 +1856,7 @@ public static ImageSurface CreateColorSwatch (
Color color)
{
ImageSurface surf = CreateImageSurface (Cairo.Format.Argb32, size, size);
Context g = new (surf);
using Context g = new (surf);

g.FillRectangle (new RectangleD (0, 0, size, size), color);
g.DrawRectangle (new RectangleD (0, 0, size, size), new Color (0, 0, 0), 1);
Expand All @@ -1867,7 +1867,7 @@ public static ImageSurface CreateColorSwatch (
public static ImageSurface CreateTransparentColorSwatch (int size, bool drawBorder)
{
ImageSurface surface = CreateTransparentBackgroundSurface (size);
Context g = new (surface);
using Context g = new (surface);

if (drawBorder)
g.DrawRectangle (new RectangleD (0, 0, size, size), new Color (0, 0, 0), 1);
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/Extensions/GdkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static Gdk.Texture CreateIconWithShape (
shapeY = imgToShapeY - iconBBox.Top;

var i = CairoExtensions.CreateImageSurface (Cairo.Format.Argb32, iconBBox.Width, iconBBox.Height);
var g = new Cairo.Context (i);
using Cairo.Context g = new (i);
// Don't show shape if shapeWidth less than 3,
if (shapeWidth > 3) {
int diam = Math.Max (1, shapeWidth - 2);
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/HistoryItems/PasteHistoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void Redo ()
doc.Layers.CreateSelectionLayer ();
doc.Layers.ShowSelectionLayer = true;

var g = new Cairo.Context (doc.Layers.SelectionLayer.Surface);
using Cairo.Context g = new (doc.Layers.SelectionLayer.Surface);
g.SetSourceSurface (paste_image, 0, 0);
g.Paint ();

Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/ImageFormats/GdkPixbufFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Document Import (Gio.File file)

Layer layer = newDocument.Layers.AddNewLayer (file.GetDisplayName ());

Cairo.Context g = new (layer.Surface);
using Cairo.Context g = new (layer.Surface);

g.DrawPixbuf (effectiveBuffer, PointD.Zero);

Expand Down
2 changes: 1 addition & 1 deletion Pinta.Core/ImageFormats/OraFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Document Import (Gio.File file)
layer.BlendMode = StandardToBlendMode (GetAttribute (layerElement, "composite-op", "svg:src-over"));

Pixbuf pb = Pixbuf.NewFromFile (tmp_file)!; // NRT: only nullable when an error is thrown
Context g = new (layer.Surface);
using Context g = new (layer.Surface);
g.DrawPixbuf (pb, (PointD) position);

try {
Expand Down
6 changes: 4 additions & 2 deletions Pinta.Core/Managers/ImageConverterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ private static IEnumerable<FormatDescriptor> GetInitialFormats ()

private static FormatDescriptor CreateFormatDescriptor (PixbufFormat format)
{
string formatName = format.GetName ().ToLowerInvariant ();
string formatName = format.GetName ()?.ToLowerInvariant () ??
throw new ArgumentException ($"{nameof (format)} has an empty name");

string formatNameUpperCase = formatName.ToUpperInvariant ();
var extensions = formatName switch {
"jpeg" => new string[] { "jpg", "jpeg", "JPG", "JPEG" },
Expand All @@ -95,7 +97,7 @@ private static FormatDescriptor CreateFormatDescriptor (PixbufFormat format)
FormatDescriptor formatDescriptor = new (
displayPrefix: formatNameUpperCase,
extensions: extensions,
mimes: format.GetMimeTypes (),
mimes: format.GetMimeTypes () ?? Array.Empty<string> (),
importer: importer,
exporter: exporter,
supportsLayers: false);
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Core/Managers/LivePreviewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async void Start (BaseEffect effect)
history_item.TakeSnapshotOfLayer (doc.Layers.CurrentUserLayerIndex);

// Paint the pre-effect layer surface into into the working surface.
Cairo.Context ctx = new (LivePreviewSurface);
using Cairo.Context ctx = new (LivePreviewSurface);
layer.Draw (ctx, layer.Surface, 1);

if (effect.EffectData != null)
Expand Down Expand Up @@ -206,7 +206,7 @@ void HandleApply ()
{
Debug.WriteLine ("LivePreviewManager.HandleApply()");

Cairo.Context ctx = new (layer.Surface);
using Cairo.Context ctx = new (layer.Surface);
ctx.Save ();
workspace.ActiveDocument.Selection.Clip (ctx);

Expand Down
4 changes: 2 additions & 2 deletions Pinta.Core/Managers/WorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static Document NewDocument (
Layer background = doc.Layers.AddNewLayer (Translations.GetString ("Background"));

if (backgroundColor.A != 0) {
Context g = new (background.Surface);
using Context g = new (background.Surface);
g.SetSourceColor (backgroundColor);
g.Paint ();
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public Document NewDocumentFromImage (ActionManager actions, Cairo.ImageSurface
new Size (image.Width, image.Height),
new Color (0, 0, 0, 0));

Context g = new (doc.Layers[0].Surface);
using Context g = new (doc.Layers[0].Surface);
g.SetSourceSurface (image, 0, 0);
g.Paint ();

Expand Down
2 changes: 2 additions & 0 deletions Pinta.Effects/Dialogs/Effects.CurvesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ private void HandleDrawingDrawnEvent (Context g)
DrawGrid (g);
DrawControlPoints (g);

g.Dispose ();

return;

// Methods
Expand Down
4 changes: 3 additions & 1 deletion Pinta.Effects/Dialogs/Effects.LevelsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,9 @@ private void HandleColorPanelButtonPressEvent (
if (args.NPress != 2) // double click
return;

ColorPanelWidget panel = (ColorPanelWidget) controller.GetWidget ();
ColorPanelWidget panel = (ColorPanelWidget?) controller.GetWidget () ??
throw new Exception ("Controller widget should be non-null");

var ccd = Gtk.ColorChooserDialog.New (Translations.GetString ("Choose Color"), chrome.MainWindow);
ccd.UseAlpha = true;
ccd.SetColor (panel.CairoColor);
Expand Down
2 changes: 1 addition & 1 deletion Pinta.Effects/Effects/CloudsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected override void Render (
// Have to lock because effect renderer is multithreaded
lock (render_lock) {

Context g = new (dst);
using Context g = new (dst);

// - Clear any previous render from the destination
// - Copy the source to the destination
Expand Down
2 changes: 2 additions & 0 deletions Pinta.Gui.Widgets/Widgets/AnglePickerGraphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ private void Draw (Context g)
g.DrawEllipse (settings.ellipseOutlineRect, settings.color, 1);
g.FillEllipse (settings.gripEllipseRect, settings.color);
g.DrawLine (settings.center, settings.endPoint, settings.color, 1);

g.Dispose ();
}

public event EventHandler? ValueChanged;
Expand Down
Loading
Loading