Skip to content

Commit

Permalink
Add Cocoa launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Apr 10, 2017
1 parent 7c4a07d commit b2a8f24
Show file tree
Hide file tree
Showing 24 changed files with 1,104 additions and 2 deletions.
23 changes: 23 additions & 0 deletions UrhoSharp.Viewer.Cocoa/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using AppKit;
using Foundation;

namespace UrhoSharp.Viewer.Cocoa
{
[Register("AppDelegate")]
public class AppDelegate : NSApplicationDelegate
{
public AppDelegate()
{
}

public override void DidFinishLaunching(NSNotification notification)
{
// Insert code here to initialize your application
}

public override void WillTerminate(NSNotification notification)
{
// Insert code here to tear down your application
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images": [
{
"filename": "AppIcon-16.png",
"size": "16x16",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-16@2x.png",
"size": "16x16",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-32.png",
"size": "32x32",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-32@2x.png",
"size": "32x32",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-128.png",
"size": "128x128",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-128@2x.png",
"size": "128x128",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-256.png",
"size": "256x256",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-256@2x.png",
"size": "256x256",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-512.png",
"size": "512x512",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-512@2x.png",
"size": "512x512",
"scale": "2x",
"idiom": "mac"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
6 changes: 6 additions & 0 deletions UrhoSharp.Viewer.Cocoa/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
6 changes: 6 additions & 0 deletions UrhoSharp.Viewer.Cocoa/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
33 changes: 33 additions & 0 deletions UrhoSharp.Viewer.Cocoa/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>UrhoSharp.Viewer.Mac</string>
<key>CFBundleIdentifier</key>
<string>com.xamarin.urhosharp-viewer-mac</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSHumanReadableCopyright</key>
<string>egorb</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string>

</dict>
</plist>
13 changes: 13 additions & 0 deletions UrhoSharp.Viewer.Cocoa/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using AppKit;

namespace UrhoSharp.Viewer.Cocoa
{
static class MainClass
{
static void Main(string[] args)
{
NSApplication.Init();
NSApplication.Main(args);
}
}
}
703 changes: 703 additions & 0 deletions UrhoSharp.Viewer.Cocoa/Main.storyboard

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions UrhoSharp.Viewer.Cocoa/PreviewerApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace UrhoSharp.Viewer.Cocoa
{
class PreviewerApplication
{
AssetsResolver assetsResolver;

public PreviewerApplication(AssetsResolver assetsResolver)
{
this.assetsResolver = assetsResolver;
}
}
}
107 changes: 107 additions & 0 deletions UrhoSharp.Viewer.Cocoa/UrhoSharp.Viewer.Cocoa.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A28AF950-0D4C-4895-AA1E-AD33B253F9BF}</ProjectGuid>
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>UrhoSharp.Viewer.Cocoa</RootNamespace>
<AssemblyName>UrhoSharp.Viewer.Mac</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<UseXamMacFullFramework>true</UseXamMacFullFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<EnableCodeSigning>false</EnableCodeSigning>
<CodeSigningKey>Mac Developer</CodeSigningKey>
<CreatePackage>false</CreatePackage>
<EnablePackageSigning>false</EnablePackageSigning>
<IncludeMonoRuntime>false</IncludeMonoRuntime>
<UseSGen>true</UseSGen>
<UseRefCounting>true</UseRefCounting>
<HttpClientHandler>HttpClientHandler</HttpClientHandler>
<TlsProvider>Default</TlsProvider>
<LinkMode>None</LinkMode>
<XamMacArch></XamMacArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants></DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<EnableCodeSigning>false</EnableCodeSigning>
<CreatePackage>true</CreatePackage>
<EnablePackageSigning>false</EnablePackageSigning>
<IncludeMonoRuntime>true</IncludeMonoRuntime>
<UseSGen>true</UseSGen>
<UseRefCounting>true</UseRefCounting>
<LinkMode>None</LinkMode>
<HttpClientHandler>HttpClientHandler</HttpClientHandler>
<TlsProvider>Default</TlsProvider>
<XamMacArch></XamMacArch>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.Mac" />
<Reference Include="Urho">
<HintPath>..\packages\UrhoSharp.1.3.0\lib\net45\Urho.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-128.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-128%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-16.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-16%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-256.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-256%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-32.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-32%402x.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-512.png" />
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\AppIcon-512%402x.png" />
<ImageAsset Include="Assets.xcassets\Contents.json" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<None Include="Entitlements.plist" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="ViewController.cs" />
<Compile Include="ViewController.designer.cs">
<DependentUpon>ViewController.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Main.storyboard" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UrhoSharp.Viewer.Core\UrhoSharp.Viewer.Core.csproj">
<Project>{3019D9B3-3926-4BE1-B8F7-E5AA3FB0486A}</Project>
<Name>UrhoSharp.Viewer.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BundleResource Include="..\ViewerAssets\ViewerAssets.pak">
<Link>ViewerAssets.pak</Link>
</BundleResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
<Import Project="..\packages\UrhoSharp.1.3.0\build\net45\UrhoSharp.targets" Condition="Exists('..\packages\UrhoSharp.1.3.0\build\net45\UrhoSharp.targets')" />
</Project>
91 changes: 91 additions & 0 deletions UrhoSharp.Viewer.Cocoa/ViewController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;

using AppKit;
using Foundation;
using Urho;
using UrhoSharp.Viewer.Core;
using System.Threading.Tasks;
using CoreGraphics;

namespace UrhoSharp.Viewer.Cocoa
{
public partial class ViewController : NSViewController
{
PreviewerApplication previewer;
UrhoSurface urhoSurface;

public ViewController(IntPtr handle) : base(handle)
{
}

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

urhoSurface = new UrhoSurface();
urhoSurface.Frame = UrhoSurfacePlaceholder.Frame;
urhoSurface.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
UrhoSurfacePlaceholder.AddSubview(urhoSurface);

previewer = new PreviewerApplication(new AssetsResolver { AssetsImporterFormats = true, AssetsImporterRareFormats = true, Images = true });
previewer.SurfaceRecreationRequested += OnSurfaceRequested;
}

partial void OpenFileButton(Foundation.NSObject sender)
{
var dlg = NSOpenPanel.OpenPanel;
dlg.CanChooseFiles = true;
dlg.CanChooseDirectories = false;
dlg.AllowsMultipleSelection = false;
dlg.Title = "Choose any format Urho3D and Assetimp support";

if (dlg.RunModal() == 1)
{
Run(dlg.Filename);
}
}

async void Run(string file)
{
await Task.Delay(1000);
previewer.Show(file);
}

IntPtr OnSurfaceRequested()
{
return urhoSurface.Handle;
}

public override NSObject RepresentedObject
{
get
{
return base.RepresentedObject;
}
set
{
base.RepresentedObject = value;
// Update the view, if already loaded.
}
}
}



public class UrhoSurface : NSView
{
public override async void ViewDidMoveToWindow()
{
base.ViewDidMoveToWindow();
PostsFrameChangedNotifications = true;
PostsBoundsChangedNotifications = true;
}

public override async void SetFrameSize(CoreGraphics.CGSize newSize)
{
base.SetFrameSize(newSize);
if (Application.HasCurrent)
NSOpenGLContext.CurrentContext?.Update();
}
}
}
Loading

0 comments on commit b2a8f24

Please sign in to comment.