Skip to content

Commit

Permalink
Updated to NoesisGUI 3.2.2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Oct 4, 2023
1 parent 0990dc8 commit 82bf47b
Show file tree
Hide file tree
Showing 30 changed files with 1,815 additions and 253 deletions.
16 changes: 8 additions & 8 deletions Src/Noesis/Core/Src/Core/Extend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public static void Shutdown()

ReleasePending();

Noesis_ClearExtendTypes();
Noesis_EnableExtend(false);
}
catch (Exception)
{
// clear errors generated releasing all C# proxies, throwing during
// assembly unload will close Unity without notifying
}


Noesis_ClearExtendTypes();
Noesis_EnableExtend(false);
ClearTables();
}
}
Expand Down Expand Up @@ -6034,14 +6034,14 @@ public static HandleRef GetInstanceHandle(object instance)
// Automatic conversion from Unity's Sprite to a CroppedBitmap proxy
else if (instance is UnityEngine.Sprite sprite && sprite != null)
{
UnityEngine.Rect spriteRect = sprite.packed && sprite.packingMode == UnityEngine.SpritePackingMode.Rectangle ?
UnityEngine.Rect r = sprite.packed && sprite.packingMode == UnityEngine.SpritePackingMode.Rectangle ?
sprite.textureRect : sprite.rect;

Int32Rect rect = new Int32Rect(
(int)spriteRect.x,
(int)(sprite.texture.height - spriteRect.height - spriteRect.y),
(int)spriteRect.width,
(int)spriteRect.height);
(int)(r.x * sprite.spriteAtlasTextureScale),
sprite.texture.height - (int)((r.height + r.y) * sprite.spriteAtlasTextureScale),
(int)(r.width * sprite.spriteAtlasTextureScale),
(int)(r.height * sprite.spriteAtlasTextureScale));

HandleRef bmp = new HandleRef(instance, cPtr);
NoesisGUI_PINVOKE.CroppedBitmap_Source_set(bmp, GetInstanceHandle(sprite.texture));
Expand Down
27 changes: 23 additions & 4 deletions Src/Noesis/Core/Src/Core/ExtendProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,20 @@ private static ExtendPropertyData AddProperty(NativeTypePropsInfo info, Property

if (p.PropertyType.GetTypeInfo().IsEnum)
{
AddPropertyAccessor<ulong, object>(info, p,
(v) => Convert.ToUInt64(v),
(v) => Enum.ToObject(p.PropertyType, v),
true);
if (IsSignedEnum(p.PropertyType))
{
AddPropertyAccessor<ulong, object>(info, p,
(v) => (ulong)Convert.ToInt64(v),
(v) => Enum.ToObject(p.PropertyType, (long)v),
true);
}
else
{
AddPropertyAccessor<ulong, object>(info, p,
(v) => Convert.ToUInt64(v),
(v) => Enum.ToObject(p.PropertyType, v),
true);
}

return CreatePropertyData(p, NativePropertyType.Enum, propertyType);
}
Expand All @@ -803,6 +813,15 @@ private static ExtendPropertyData AddProperty(NativeTypePropsInfo info, Property
}
}

private static bool IsSignedEnum(Type enumType)
{
Type underlyingType = enumType.GetTypeInfo().GetEnumUnderlyingType();
return underlyingType.Equals(typeof(sbyte)) ||
underlyingType.Equals(typeof(short)) ||
underlyingType.Equals(typeof(int)) ||
underlyingType.Equals(typeof(long));
}

private static void AddPropertyAccessor<PropertyT>(NativeTypePropsInfo info, PropertyInfo p, bool usePropertyInfo)
{
#if !ENABLE_IL2CPP && !UNITY_IOS
Expand Down
2 changes: 1 addition & 1 deletion Src/Noesis/Core/Src/Core/NetCoreAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld)

public static T PtrToStructure<T>(IntPtr ptr)
{
return (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr, typeof(T));
return System.Runtime.InteropServices.Marshal.PtrToStructure<T>(ptr);
}

public static IntPtr StringToHGlobalAnsi(string s)
Expand Down
24 changes: 3 additions & 21 deletions Src/Noesis/Core/Src/Core/RenderDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ public RenderDeviceAGC(bool sRGB, GPUAllocator allocator) :
private static IntPtr CreateDevice(bool sRGB, GPUAllocator allocator)
{
_allocator = allocator;
return Noesis_RenderDeviceAGC_Create(sRGB, _alloc, _free, _registerResource);
return Noesis_RenderDeviceAGC_Create(sRGB, _alloc, _free);
}

/// <summary>
Expand Down Expand Up @@ -1799,37 +1799,19 @@ private static void Free(IntPtr user, IntPtr address)
}
}

[MonoPInvokeCallback(typeof(Callback_RegisterResource))]
private static void RegisterResource(IntPtr user, IntPtr ptr, uint size, uint type,
IntPtr labelPtr)
{
try
{
string label = Noesis.Extend.StringFromNativeUtf8(labelPtr);
_allocator.RegisterResource(ptr, size, type, label);
}
catch (Exception e)
{
Error.UnhandledException(e);
}
}

private delegate IntPtr Callback_Alloc(IntPtr user, uint size, uint alignment);
private delegate void Callback_Free(IntPtr user, IntPtr address);
private delegate void Callback_RegisterResource(IntPtr user, IntPtr ptr, uint size,
uint type, IntPtr label);

private static Callback_Alloc _alloc = Alloc;
private static Callback_Free _free = Free;
private static Callback_RegisterResource _registerResource = RegisterResource;

private static GPUAllocator _allocator;
#endregion

#region Imports
[DllImport(Library.Name)]
static extern IntPtr Noesis_RenderDeviceAGC_Create(bool sRGB,
Callback_Alloc alloc, Callback_Free free, Callback_RegisterResource registerResource);
static extern IntPtr Noesis_RenderDeviceAGC_Create(bool sRGB, Callback_Alloc alloc,
Callback_Free free);

[DllImport(Library.Name)]
static extern IntPtr Noesis_RenderDeviceAGC_WrapTexture(IntPtr nativePointer,
Expand Down
10 changes: 9 additions & 1 deletion Src/Noesis/Core/Src/Proxies/Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ public override object ProvideValue(IServiceProvider serviceProvider) {
}

internal static IntPtr DoNothingPtr = NoesisGUI_PINVOKE.Binding_GetDoNothing();
public static object DoNothing = new NamedObject("Binding.DoNothing", DoNothingPtr);
private static NamedObject _doNothing;
public static object DoNothing {
get {
if (_doNothing == null || _doNothing.IsDisposed) {
_doNothing = new NamedObject("Binding.DoNothing", DoNothingPtr);
}
return _doNothing;
}
}

public Noesis.IValueConverter Converter {
get {
Expand Down
7 changes: 7 additions & 0 deletions Src/Noesis/Core/Src/Proxies/BindingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public Binding ParentBinding {
}
}

public object ResolvedSource {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.BindingExpression_ResolvedSource_get(swigCPtr);
return Noesis.Extend.GetProxy(cPtr, false);
}
}

}

}
Expand Down
7 changes: 2 additions & 5 deletions Src/Noesis/Core/Src/Proxies/BrushShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,12 @@ protected void SetPixelShader(IntPtr shader, Target target) {
}

#if UNITY_5_3_OR_NEWER
protected NoesisShader CreateShader(int numTextures) {
protected NoesisShader CreateShader() {
string name = GetType().Name.Replace("Brush", ".noesisbrush");
NoesisShader shader = NoesisShaderProvider.instance.GetShader(name);

if (shader != null) {
shader.brush_path = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.Path_Pattern, numTextures, shader.brush_path_bytecode);
shader.brush_path_aa = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.Path_AA_Pattern, numTextures, shader.brush_path_aa_bytecode);
shader.brush_sdf = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.SDF_Pattern, numTextures, shader.brush_sdf_bytecode);
shader.brush_opacity = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.Opacity_Pattern, numTextures, shader.brush_opacity_bytecode);
NoesisRenderer.CreatePixelShader(shader);
return shader;
}

Expand Down
10 changes: 9 additions & 1 deletion Src/Noesis/Core/Src/Proxies/DependencyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ protected DependencyProperty() {
}

internal static IntPtr UnsetValuePtr = NoesisGUI_PINVOKE.DependencyProperty_GetUnsetValue();
public static object UnsetValue = new NamedObject("DependencyProperty.UnsetValue", UnsetValuePtr);
private static NamedObject _unsetValue;
public static object UnsetValue {
get {
if (_unsetValue == null || _unsetValue.IsDisposed) {
_unsetValue = new NamedObject("DependencyProperty.UnsetValue", UnsetValuePtr);
}
return _unsetValue;
}
}

public Type OwnerType {
get {
Expand Down
3 changes: 3 additions & 0 deletions Src/Noesis/Core/Src/Proxies/DispatcherObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public int ThreadId {
}
}

internal new static IntPtr Extend(string typeName) {
return NoesisGUI_PINVOKE.Extend_DispatcherObject(Marshal.StringToHGlobalAnsi(typeName));
}
}

}
Expand Down
73 changes: 73 additions & 0 deletions Src/Noesis/Core/Src/Proxies/FocusManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated />
//
// This file was automatically generated by SWIG (http://www.swig.org).
// Version 3.0.10
//
// Do not make changes to this file unless you know what you are doing--modify
// the SWIG interface file instead.
//------------------------------------------------------------------------------


using System;
using System.Runtime.InteropServices;

namespace Noesis
{

public static class FocusManager {
public static UIElement GetFocusedElement(DependencyObject element) {
IntPtr cPtr = NoesisGUI_PINVOKE.FocusManager_GetFocusedElement(DependencyObject.getCPtr(element));
return (UIElement)Noesis.Extend.GetProxy(cPtr, false);
}

public static void SetFocusedElement(DependencyObject element, UIElement value) {
NoesisGUI_PINVOKE.FocusManager_SetFocusedElement(DependencyObject.getCPtr(element), UIElement.getCPtr(value));
}

public static bool GetIsFocusScope(DependencyObject element) {
bool ret = NoesisGUI_PINVOKE.FocusManager_GetIsFocusScope(DependencyObject.getCPtr(element));
return ret;
}

public static void SetIsFocusScope(DependencyObject element, bool value) {
NoesisGUI_PINVOKE.FocusManager_SetIsFocusScope(DependencyObject.getCPtr(element), value);
}

public static DependencyObject GetFocusScope(DependencyObject element) {
IntPtr cPtr = NoesisGUI_PINVOKE.FocusManager_GetFocusScope(DependencyObject.getCPtr(element));
return (DependencyObject)Noesis.Extend.GetProxy(cPtr, false);
}

public static DependencyProperty FocusedElementProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.FocusManager_FocusedElementProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}

public static DependencyProperty IsFocusScopeProperty {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.FocusManager_IsFocusScopeProperty_get();
return (DependencyProperty)Noesis.Extend.GetProxy(cPtr, false);
}
}

public static RoutedEvent LostFocusEvent {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.FocusManager_LostFocusEvent_get();
return (RoutedEvent)Noesis.Extend.GetProxy(cPtr, false);
}
}

public static RoutedEvent GotFocusEvent {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.FocusManager_GotFocusEvent_get();
return (RoutedEvent)Noesis.Extend.GetProxy(cPtr, false);
}
}

}

}

5 changes: 5 additions & 0 deletions Src/Noesis/Core/Src/Proxies/FrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,11 @@ public static FrameworkElement FindTreeElement(object instance) {
return (FrameworkElement)Noesis.Extend.GetProxy(cPtr, false);
}

public static object FindTreeParent(object instance) {
IntPtr cPtr = NoesisGUI_PINVOKE.FrameworkElement_FindTreeParent(Noesis.Extend.GetInstanceHandle(instance));
return Noesis.Extend.GetProxy(cPtr, false);
}

internal new static IntPtr Extend(string typeName) {
return NoesisGUI_PINVOKE.Extend_FrameworkElement(Marshal.StringToHGlobalAnsi(typeName));
}
Expand Down
57 changes: 11 additions & 46 deletions Src/Noesis/Core/Src/Proxies/HitTest3DResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,25 @@
namespace Noesis
{

public class HitTest3DResult : IDisposable {
private HandleRef swigCPtr;
protected bool swigCMemOwn;
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct HitTest3DResult {
private IntPtr _hit;

internal HitTest3DResult(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}

internal static HandleRef getCPtr(HitTest3DResult obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
[MarshalAs(UnmanagedType.R4)]
private float _x;

~HitTest3DResult() {
Dispose();
}
[MarshalAs(UnmanagedType.R4)]
private float _y;

public virtual void Dispose() {
lock(this) {
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwn) {
swigCMemOwn = false;
NoesisGUI_PINVOKE.delete_HitTest3DResult(swigCPtr);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
}
}
[MarshalAs(UnmanagedType.R4)]
private float _z;

public DependencyObject VisualHit {
get { return GetVisualHit(); }
get { return (DependencyObject)Noesis.Extend.GetProxy(_hit, false); }
}

public Point3D WorldPos {
get { return GetWorldPos(); }
}

public HitTest3DResult() : this(NoesisGUI_PINVOKE.new_HitTest3DResult(), true) {
}

private DependencyObject GetVisualHit() {
IntPtr cPtr = NoesisGUI_PINVOKE.HitTest3DResult_GetVisualHit(swigCPtr);
return (DependencyObject)Noesis.Extend.GetProxy(cPtr, false);
}

private Point3D GetWorldPos() {
IntPtr ret = NoesisGUI_PINVOKE.HitTest3DResult_GetWorldPos(swigCPtr);
if (ret != IntPtr.Zero) {
return Marshal.PtrToStructure<Point3D>(ret);
}
else {
return new Point3D();
}
get { return new Point3D(_x, _y, _z); }
}

}
Expand Down
Loading

0 comments on commit 82bf47b

Please sign in to comment.