Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
71 changes: 49 additions & 22 deletions binding/SkiaSharp.Skottie/Animation.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
#nullable enable
using System;
using System.IO;
using System.Runtime.InteropServices;
using SkiaSharp.SceneGraph;

namespace SkiaSharp.Skottie
Expand All @@ -22,27 +21,54 @@ void ISKNonVirtualReferenceCounted.UnreferenceNative ()
protected override void DisposeNative ()
=> SkottieApi.skottie_animation_delete (Handle);

public static bool TryParse (string data, out Animation animation)
public static Animation? Parse (string json) =>
TryParse (json, out var animation)
? animation
: null;
Comment on lines +24 to +27

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding "overloads" to return the object, or null on some error that we will never know about.


public static bool TryParse (string json, [System.Diagnostics.CodeAnalysis.NotNullWhen (true)] out Animation? animation)
{
animation = GetObject (SkottieApi.skottie_animation_make_from_string (data, data.Length));
_ = json ?? throw new ArgumentNullException (nameof (json));

animation = GetObject (SkottieApi.skottie_animation_make_from_string (json, json.Length));
return animation != null;
}

public static bool TryCreate (Stream stream, out Animation animation)
public static Animation? Create (Stream stream) =>
TryCreate (stream, out var animation)
? animation
: null;

public static bool TryCreate (Stream stream, [System.Diagnostics.CodeAnalysis.NotNullWhen (true)] out Animation? animation)
{
using (var managed = new SKManagedStream (stream)) {
return TryCreate (managed, out animation);
}
_ = stream ?? throw new ArgumentNullException (nameof (stream));

using var managed = new SKManagedStream (stream);
return TryCreate (managed, out animation);
}

public static bool TryCreate (SKStream stream, out Animation animation)
public static Animation? Create (SKStream stream) =>
TryCreate (stream, out var animation)
? animation
: null;

public static bool TryCreate (SKStream stream, [System.Diagnostics.CodeAnalysis.NotNullWhen (true)] out Animation? animation)
{
_ = stream ?? throw new ArgumentNullException (nameof (stream));

animation = GetObject (SkottieApi.skottie_animation_make_from_stream (stream.Handle));
return animation != null;
}

public static bool TryCreate (string path, out Animation animation)
public static Animation? Create (string path) =>
TryCreate (path, out var animation)
? animation
: null;

public static bool TryCreate (string path, [System.Diagnostics.CodeAnalysis.NotNullWhen (true)] out Animation? animation)
{
_ = path ?? throw new ArgumentNullException (nameof (path));

animation = GetObject (SkottieApi.skottie_animation_make_from_file (path));
return animation != null;
}
Expand All @@ -53,17 +79,20 @@ public unsafe void Render (SKCanvas canvas, SKRect dst)
public void Render (SKCanvas canvas, SKRect dst, AnimationRenderFlags flags)
=> SkottieApi.skottie_animation_render_with_flags (Handle, canvas.Handle, &dst, flags);

public void Seek (double t, InvalidationController ic = null)
=> SkottieApi.skottie_animation_seek (Handle, (float)t, ic?.Handle ?? IntPtr.Zero);
public void Seek (double percent, InvalidationController? ic = null)
=> SkottieApi.skottie_animation_seek (Handle, (float)percent, ic?.Handle ?? IntPtr.Zero);
Comment on lines -56 to +83

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the parameters.


public void SeekFrame (double t, InvalidationController ic = null)
=> SkottieApi.skottie_animation_seek_frame (Handle, (float)t, ic?.Handle ?? IntPtr.Zero);
public void SeekFrame (double frame, InvalidationController? ic = null)
=> SkottieApi.skottie_animation_seek_frame (Handle, (float)frame, ic?.Handle ?? IntPtr.Zero);

public void SeekFrameTime (double t, InvalidationController ic = null)
=> SkottieApi.skottie_animation_seek_frame_time (Handle, (float)t, ic?.Handle ?? IntPtr.Zero);
public void SeekFrameTime (double seconds, InvalidationController? ic = null)
=> SkottieApi.skottie_animation_seek_frame_time (Handle, (float)seconds, ic?.Handle ?? IntPtr.Zero);

public double Duration
=> SkottieApi.skottie_animation_get_duration (Handle);
public void SeekFrameTime (TimeSpan time, InvalidationController? ic = null)
=> SeekFrameTime (time.TotalSeconds, ic);

public TimeSpan Duration
=> TimeSpan.FromSeconds(SkottieApi.skottie_animation_get_duration (Handle));
Comment on lines -65 to +95

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the new SeekFrameTime(TimeSpan) and changed Duration to be a TimeSpan.


public double Fps
=> SkottieApi.skottie_animation_get_fps (Handle);
Expand All @@ -77,9 +106,7 @@ public double OutPoint
public string Version {
get {
using var str = new SKString ();

SkottieApi.skottie_animation_get_version (Handle, str.Handle);

return str.ToString ();
}
}
Expand All @@ -92,7 +119,7 @@ public unsafe SKSize Size {
}
}

internal static Animation GetObject (IntPtr handle) =>
internal static Animation? GetObject (IntPtr handle) =>
handle == IntPtr.Zero ? null : new Animation (handle, true);
}
}
6 changes: 3 additions & 3 deletions source/SkiaSharp.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@

<!-- .NET Standard, .NET FX and .NET 6 -->
<PropertyGroup>
<BasicTargetFrameworks>netstandard1.3;netstandard2.0;net462</BasicTargetFrameworks>
<BasicTargetFrameworks>netstandard1.3;netstandard2.0;netstandard2.1;net462;netcoreapp3.1;net5.0</BasicTargetFrameworks>
<BasicTargetFrameworks Condition="$(BuildingForNet6)">$(BasicTargetFrameworks);net6.0</BasicTargetFrameworks>
Comment thread
mattleibow marked this conversation as resolved.
Outdated
<Net6PlatformTargetFrameworks>net6.0-ios;net6.0-maccatalyst;net6.0-tvos;net6.0-macos;net6.0-android</Net6PlatformTargetFrameworks>
<Net6PlatformTargetFrameworks Condition="$(IsNet6TizenSupported)">$(Net6PlatformTargetFrameworks);net6.0-tizen</Net6PlatformTargetFrameworks>
<Net6TargetFrameworks>net6.0;$(Net6PlatformTargetFrameworks)</Net6TargetFrameworks>
</PropertyGroup>

<!-- Base TFMs for the core parts -->
<PropertyGroup>
<AllTargetFrameworks>$(BasicTargetFrameworks)</AllTargetFrameworks>
<AllTargetFrameworks Condition="$(BuildingForNet6)">$(AllTargetFrameworks);$(Net6TargetFrameworks)</AllTargetFrameworks>
<AllTargetFrameworks Condition="$(BuildingForNet6)">$(AllTargetFrameworks);$(Net6PlatformTargetFrameworks)</AllTargetFrameworks>
</PropertyGroup>

<!-- .NET MAUI -->
Expand Down
4 changes: 4 additions & 0 deletions source/SkiaSharp.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<PackageReference Include="mdoc" Version="5.8.9" PrivateAssets="All" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
</ItemGroup>
Comment thread
mattleibow marked this conversation as resolved.

<!-- HACK: Do not copy the native bootstrap files -->
<Target Name="_RemoveWasdkBootstrapDll" BeforeTargets="ResolveReferences">
<ItemGroup>
Expand Down
Loading