Skip to content

Commit

Permalink
SVGKLayeredImageView .actor missing Issue #5
Browse files Browse the repository at this point in the history
bgen changes in 15.5 beta
  • Loading branch information
sushihangover committed Oct 13, 2017
1 parent ee8f4ee commit 0796316
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 42 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ Tagged: **`[XAMARIN]`** **`[SVGKit]`** **`[Xamarin.iOS]`** **`[iOS]`**

###Building `SushiHangover.SVGKit.Binding`

#####`xbuild` or `msbuild` based:
#####`msbuild` based:

xbuild /p:SolutionDir=./ /target:Clean /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj
xbuild /p:SolutionDir=./ /target:Build /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj
msbuild /p:SolutionDir=./ /target:Clean /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj
msbuild /p:SolutionDir=./ /target:Build /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj

#####Building `Target:Release` also builds the Nuget package:

Expand Down
113 changes: 81 additions & 32 deletions SVGKit.SampleApp/ViewController.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,88 @@
using System;
using UIKit;
using SushiHangover.SVGKit;
using CoreAnimation;
using CoreGraphics;
using CoreFoundation;
using Foundation;

namespace SVGKit.SampleApp
{
public partial class ViewController : UIViewController
{
protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}

public override void ViewDidLoad()
{
base.ViewDidLoad();

var image = new SVGKImage("Media/Sushi.svg");
var imageView = new SVGKFastImageView(image);
imageView.Frame = View.Frame;
View.Add(imageView);
}

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.LandscapeLeft;
}

public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.LandscapeLeft;
}

public override bool ShouldAutorotate()
{
return false;
}
}
public static class Extension
{
public static UIColor Inverse(this UIColor color)
{
try
{
var cgcolor = color.CGColor;
if (cgcolor.NumberOfComponents == 1)
return color;

var comps = cgcolor.Components;
var newComps = new nfloat[comps.Length];
var i = comps.Length - 1;
newComps[i] = comps[i];
while (i-- > -0)
{
newComps[i] = 1 - comps[i];
}
using (var newCGColor = new CGColor(cgcolor.ColorSpace, newComps))
{
var newUIColor = UIColor.FromCGColor(newCGColor);
return newUIColor;
}
}
catch
{
return UIColor.Black;
}
}
}

public partial class ViewController : UIViewController
{
NSTimer timer;

protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}

public override void ViewDidLoad()
{
base.ViewDidLoad();

void RecurseLayers(CALayer[] layers)
{
foreach (var layer in layers)
{
if (layer is CAShapeLayer && (layer as CAShapeLayer).FillColor != null)
(layer as CAShapeLayer).FillColor = UIColor.FromCGColor((layer as CAShapeLayer).FillColor).Inverse().CGColor;
if (layer.Sublayers != null)
RecurseLayers(layer.Sublayers);
}
}
//var imageView = new SVGKLayeredImageView(new SVGKImage("Media/Sushi.svg"));
var imageView = new SVGKFastImageView(new SVGKImage("Media/Sushi.svg"));
imageView.Frame = View.Bounds;
View.Add(imageView);
//timer = NSTimer.CreateRepeatingScheduledTimer(2, (_) => InvokeOnMainThread(() => RecurseLayers(imageView.Layer.Sublayers)));
}


public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.LandscapeLeft;
}

public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.LandscapeLeft;
}

public override bool ShouldAutorotate()
{
return false;
}
}
}
59 changes: 59 additions & 0 deletions SushiHangover.SVGKit/Additions/SVGKLayeredImageView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System;
using System.Drawing;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using UIKit;
using GLKit;
using Metal;
using MapKit;
using Photos;
using ModelIO;
using SceneKit;
using Contacts;
using Security;
using Messages;
using AudioUnit;
using CoreVideo;
using CoreMedia;
using QuickLook;
using CoreImage;
using SpriteKit;
using Foundation;
using CoreMotion;
using ObjCRuntime;
using AddressBook;
using MediaPlayer;
using GameplayKit;
using CoreGraphics;
using CoreLocation;
using AVFoundation;
using NewsstandKit;
using FileProvider;
using CoreAnimation;
using CoreFoundation;

namespace SushiHangover.SVGKit
{
public unsafe partial class SVGKLayeredImageView : SVGKImageView
{
[Export("initWithSVGKImage:")]
public SVGKLayeredImageView(SVGKImage im) : base (im)
{
if (im == null)
throw new ArgumentNullException("im");
IsDirectBinding = GetType().Assembly == global::ApiDefinitions.Messaging.this_assembly;
if (IsDirectBinding)
{
InitializeHandle(global::ApiDefinitions.Messaging.IntPtr_objc_msgSend_IntPtr(this.Handle, Selector.GetHandle("initWithSVGKImage:"), im.Handle), "initWithSVGKImage:");
}
else
{
InitializeHandle(global::ApiDefinitions.Messaging.IntPtr_objc_msgSendSuper_IntPtr(this.SuperHandle, Selector.GetHandle("initWithSVGKImage:"), im.Handle), "initWithSVGKImage:");
}
}
}
}
6 changes: 3 additions & 3 deletions SushiHangover.SVGKit/ApiDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ interface IDocumentStyle
}

// @protocol DocumentCSS <DocumentStyle>
[Protocol, Model]
[Protocol]
interface IDocumentCSS : IDocumentStyle
{
// @required -(CSSStyleDeclaration *)getOverrideStyle:(Element *)element pseudoElt:(NSString *)pseudoElt;
Expand Down Expand Up @@ -1096,7 +1096,7 @@ interface MediaList
interface NSCharacterSet_SVGKExtensions
{
// +(NSCharacterSet *)SVGWhitespaceCharacterSet;
[Static]
//[Static]
[Export("SVGWhitespaceCharacterSet")]
//[Verify (MethodToProperty)]
NSCharacterSet SVGWhitespaceCharacterSet();
Expand Down Expand Up @@ -2478,7 +2478,7 @@ interface SVGKPattern

// @interface SVGKLayeredImageView : SVGKImageView
[BaseType (typeof(SVGKImageView))]
interface SVGKLayeredImageView
interface SVGKLayeredImageView : SVGKImageView
{
}

Expand Down
4 changes: 2 additions & 2 deletions SushiHangover.SVGKit/SVGKit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<package>
<metadata>
<id>SushiHangover.SVGKit.Binding</id>
<version>1.0.3</version>
<version>1.0.4</version>
<description>
This is a Xamarin.iOS binding project for SVGKit v2.x
</description>
<title>SushiHangover.SVGKit.Binding</title>
<language>en-US</language>
<copyright>2016 - SushiHangover/RobertN</copyright>
<copyright>2016/2017 - SushiHangover/RobertN</copyright>
<authors>SushiHangover</authors>
<projectUrl>https://github.com/sushihangover/SVGKit.Binding</projectUrl>
<iconUrl>https://raw.githubusercontent.com/sushihangover/SVGKit.Binding/master/Media/icon.png</iconUrl>
Expand Down
6 changes: 5 additions & 1 deletion SushiHangover.SVGKit/SushiHangover.SVGKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Additions\SVGKLayeredImageView.cs" />
</ItemGroup>
<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinitions.cs" />
Expand All @@ -45,7 +46,7 @@
<ObjcBindingCoreSource Include="Extras.cs" />
</ItemGroup>
<ItemGroup>
<NativeReference Include="..\SVGKit\DerivedData\SVGKit-iOS\Build\Products\Release-universal\libSVGKit-iOS.2.0.0.a">
<NativeReference Include="..\SVGKit/build/Release-universal/libSVGKit-iOS.2.0.0.a">
<Kind>Static</Kind>
<ForceLoad>True</ForceLoad>
<Frameworks>CocoaLumberjack CoreText CoreImage QuartzCore CoreGraphics</Frameworks>
Expand All @@ -59,6 +60,9 @@
<ItemGroup>
<None Include="SVGKit.nuspec" />
</ItemGroup>
<ItemGroup>
<Folder Include="Additions\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
<Import Project="..\.nuget\NuGet.targets" Condition="Exists('..\.nuget\NuGet.targets')" />
</Project>

0 comments on commit 0796316

Please sign in to comment.