Skip to content

Commit

Permalink
Updated to NoesisGUI 3.1.5 version
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Jun 27, 2022
1 parent c315b74 commit 7c70ec2
Show file tree
Hide file tree
Showing 39 changed files with 2,015 additions and 158 deletions.
14 changes: 13 additions & 1 deletion Src/Noesis/Core/Src/Core/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SynchronizationContext SynchronizationContext
/// </summary>
public bool CheckAccess()
{
return ThreadId == CurrentThreadId;
return ThreadId == CurrentThreadId && ManagedThreadId == CurrentManagedThreadId;
}

/// <summary>
Expand Down Expand Up @@ -228,10 +228,21 @@ private static int CurrentThreadId
private static extern int Noesis_GetCurrentThreadId();
#endregion

#region Managed Thread Id

private int ManagedThreadId { get => _managedThreadId; }

private static int CurrentManagedThreadId
{
get { return Thread.CurrentThread.ManagedThreadId; }
}
#endregion

#region Private members
private Dispatcher(int threadId)
{
_threadId = threadId;
_managedThreadId = CurrentManagedThreadId;
_operations = new Queue<DispatcherOperation>();
_context = new DispatcherSynchronizationContext(this);
}
Expand All @@ -240,6 +251,7 @@ private Dispatcher(int threadId)
new Dictionary<int, Dispatcher>();

private int _threadId;
private int _managedThreadId;
private Queue<DispatcherOperation> _operations;
private DispatcherSynchronizationContext _context;

Expand Down
130 changes: 96 additions & 34 deletions Src/Noesis/Core/Src/Core/Extend.cs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Src/Noesis/Core/Src/Core/ExtendBoxing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private static Dictionary<Type, BoxDelegate> CreateBoxFunctions()
boxFunctions[typeof(Noesis.GeometryCombineMode)] = (val) => NoesisGUI_.Box_GeometryCombineMode((Noesis.GeometryCombineMode)val);
boxFunctions[typeof(Noesis.GradientSpreadMethod)] = (val) => NoesisGUI_.Box_GradientSpreadMethod((Noesis.GradientSpreadMethod)val);
boxFunctions[typeof(Noesis.HorizontalAlignment)] = (val) => NoesisGUI_.Box_HorizontalAlignment((Noesis.HorizontalAlignment)val);
boxFunctions[typeof(Noesis.MouseAction)] = (val) => NoesisGUI_.Box_MouseAction((Noesis.MouseAction)val);
boxFunctions[typeof(Noesis.Key)] = (val) => NoesisGUI_.Box_Key((Noesis.Key)val);
boxFunctions[typeof(Noesis.ModifierKeys)] = (val) => NoesisGUI_.Box_ModifierKeys((Noesis.ModifierKeys)val);
boxFunctions[typeof(Noesis.KeyboardNavigationMode)] = (val) => NoesisGUI_.Box_KeyboardNavigationMode((Noesis.KeyboardNavigationMode)val);
Expand Down Expand Up @@ -189,6 +190,7 @@ private static Dictionary<Type, UnboxDelegate> CreateUnboxFunctions()
unboxFunctions[typeof(Boxed<Noesis.GeometryCombineMode>)] = (cPtr) => NoesisGUI_.Unbox_GeometryCombineMode(cPtr);
unboxFunctions[typeof(Boxed<Noesis.GradientSpreadMethod>)] = (cPtr) => NoesisGUI_.Unbox_GradientSpreadMethod(cPtr);
unboxFunctions[typeof(Boxed<Noesis.HorizontalAlignment>)] = (cPtr) => NoesisGUI_.Unbox_HorizontalAlignment(cPtr);
unboxFunctions[typeof(Boxed<Noesis.MouseAction>)] = (cPtr) => NoesisGUI_.Unbox_MouseAction(cPtr);
unboxFunctions[typeof(Boxed<Noesis.Key>)] = (cPtr) => NoesisGUI_.Unbox_Key(cPtr);
unboxFunctions[typeof(Boxed<Noesis.ModifierKeys>)] = (cPtr) => NoesisGUI_.Unbox_ModifierKeys(cPtr);
unboxFunctions[typeof(Boxed<Noesis.KeyboardNavigationMode>)] = (cPtr) => NoesisGUI_.Unbox_KeyboardNavigationMode(cPtr);
Expand Down
6 changes: 2 additions & 4 deletions Src/Noesis/Core/Src/Core/ExtendImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ static extern void Noesis_RegisterReflectionCallbacks(
Callback_ProviderTextureInfo callback_ProviderTextureInfo,
Callback_ProviderTextureLoad callback_ProviderTextureLoad,
Callback_ProviderTextureOpen callback_ProviderTextureOpen,
Callback_ProviderMatchFont callback_ProviderMatchFont,
Callback_ProviderFamilyExists callback_ProviderFamilyExists,
Callback_ProviderScanFolder callback_ProviderScanFolder,
Callback_ProviderOpenFont callback_ProviderOpenFont,
Callback_ScrollInfoBringIntoView callback_ScrollInfoBringIntoView,
Expand Down Expand Up @@ -167,10 +169,6 @@ static extern void Noesis_RegisterReflectionCallbacks(
Callback_CreateInstance callback_CreateInstance,
Callback_DeleteInstance callback_DeleteInstance,
Callback_GrabInstance callback_GrabInstance);

////////////////////////////////////////////////////////////////////////////////////////////////
[DllImport(Library.Name)]
static extern void Noesis_SetLoadAssemblyCallback(NoesisLoadAssemblyCallback callback);
}
}

12 changes: 12 additions & 0 deletions Src/Noesis/Core/Src/Core/ExtendProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,12 @@ private static Dictionary<Type, AddPropertyDelegate> AddPropertyFunctions()
return CreatePropertyData(p, NativePropertyType.Rect);
};

addPropFunctions[typeof(Noesis.Int32Rect)] = (info, p, usePropertyInfo) =>
{
AddPropertyAccessor<Noesis.Int32Rect>(info, p, usePropertyInfo);
return CreatePropertyData(p, NativePropertyType.Int32Rect);
};

addPropFunctions[typeof(Noesis.Size)] = (info, p, usePropertyInfo) =>
{
AddPropertyAccessor<Noesis.Size>(info, p, usePropertyInfo);
Expand Down Expand Up @@ -704,6 +710,12 @@ private static Dictionary<Type, AddPropertyDelegate> AddPropertyFunctions()
return CreatePropertyData(p, NativePropertyType.NullableRect);
};

addPropFunctions[typeof(Noesis.Int32Rect?)] = (info, p, usePropertyInfo) =>
{
AddPropertyAccessorNullable<Noesis.Int32Rect?>(info, p, usePropertyInfo);
return CreatePropertyData(p, NativePropertyType.NullableInt32Rect);
};

addPropFunctions[typeof(Noesis.Size?)] = (info, p, usePropertyInfo) =>
{
AddPropertyAccessorNullable<Noesis.Size?>(info, p, usePropertyInfo);
Expand Down
14 changes: 14 additions & 0 deletions Src/Noesis/Core/Src/Core/InputEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ public enum MouseButtonState
Pressed
};

////////////////////////////////////////////////////////////////////////////////////////////////////
[TypeConverter(typeof(MouseActionConverter))]
public enum MouseAction
{
None,
LeftClick,
RightClick,
MiddleClick,
WheelClick,
LeftDoubleClick,
RightDoubleClick,
MiddleDoubleClick
};

////////////////////////////////////////////////////////////////////////////////////////////////////
[TypeConverter(typeof(KeyConverter))]
public enum Key
Expand Down
43 changes: 43 additions & 0 deletions Src/Noesis/Core/Src/Core/NoesisGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace Noesis
public delegate void FontFaceInfoCallback(int index, string familyName, FontWeight weight,
FontStyle style, FontStretch stretch);

/// <summary> Called everytime an assembly is requested by xaml loading</summary>
public delegate void LoadAssemblyCallback(string assembly);

public static class GUI
{
/// <summary>
Expand Down Expand Up @@ -98,6 +101,7 @@ public static void Shutdown()
Noesis_SetOpenUrlCallback(null);
Noesis_SetCursorCallback(null);
Noesis_SetSoftwareKeyboardCallback(null);
Noesis_SetLoadAssemblyCallback(null);

Extend.Shutdown();

Expand Down Expand Up @@ -322,6 +326,19 @@ public static void LoadComponent(object component, string filename)
Noesis_LoadComponent(Extend.GetInstanceHandle(component), filename ?? string.Empty);
}

/// <summary>
/// Callback for assembly loading. It will be called for each assembly referenced in a XAML,
/// for example when a xmlns attribute specifies an assembly:
/// <UserControl xmlns:controls="clr-namespace:Noesis.Controls;assembly=Noesis.GUI.Controls"/>
/// or when a resource Uri specifies an assembly:
/// <Image Source="/SharedResources;component/Images/account.png"/>
/// </summary>
public static void SetLoadAssemblyCallback(LoadAssemblyCallback callback)
{
_loadAssemblyCallback = callback;
Noesis_SetLoadAssemblyCallback(callback != null ? _loadAssembly : null);
}

/// <summary>
/// Creates a View that manages a tree of UI elements.
/// </summary>
Expand Down Expand Up @@ -493,6 +510,29 @@ private static void OnFontFace(int callbackId, int index, IntPtr familyName,
private static Dictionary<int, Faces> _facesCallbacks = new Dictionary<int, Faces>();
#endregion

#region Load Assembly
private static LoadAssemblyCallback _loadAssemblyCallback;

private delegate void NoesisLoadAssemblyCallback(IntPtr assembly);
private static NoesisLoadAssemblyCallback _loadAssembly = OnLoadAssembly;
[MonoPInvokeCallback(typeof(NoesisLoadAssemblyCallback))]
private static void OnLoadAssembly(IntPtr assemblyPtr)
{
try
{
if (_initialized)
{
string assembly = Extend.StringFromNativeUtf8(assemblyPtr);
_loadAssemblyCallback(assembly);
}
}
catch (Exception e)
{
Error.UnhandledException(e);
}
}
#endregion

#region Imports
[DllImport(Library.Name)]
static extern IntPtr Noesis_GetBuildVersion();
Expand Down Expand Up @@ -578,6 +618,9 @@ static extern void Noesis_EnumFontFaces(HandleRef stream, int callbackId,
[DllImport(Library.Name)]
static extern void Noesis_LoadComponent(HandleRef component,
[MarshalAs(UnmanagedType.LPStr)] string filename);

[DllImport(Library.Name)]
static extern void Noesis_SetLoadAssemblyCallback(NoesisLoadAssemblyCallback callback);
#endregion
}
}
5 changes: 5 additions & 0 deletions Src/Noesis/Core/Src/Core/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public enum PlatformID
OSX,
iPhone,
Android,
XboxOne,
XboxSeries,
PlayStation4,
PlayStation5,
Switch
}

public static class Platform
Expand Down
Loading

0 comments on commit 7c70ec2

Please sign in to comment.