-
Notifications
You must be signed in to change notification settings - Fork 642
Add nullable attributes, TimeSpan and overloads to Skottie #2119
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a256766
Add nullable attibutes and overloads to Skottie
mattleibow 5a237d5
Changed Duration to TimeSpan
mattleibow 9c1ec94
Merge remote-tracking branch 'origin/main' into dev/anim-overloads
mattleibow 779957b
Merge branch 'main' into dev/anim-overloads
mattleibow bdd57f0
Update xample to use new APIs
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
@@ -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; | ||
|
|
||
| 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; | ||
| } | ||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the new |
||
|
|
||
| public double Fps | ||
| => SkottieApi.skottie_animation_get_fps (Handle); | ||
|
|
@@ -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 (); | ||
| } | ||
| } | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.