Skip to content

Commit

Permalink
Updated to NoesisGUI 3.2.4 version
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Jun 20, 2024
1 parent 41b5c92 commit f0aef3a
Show file tree
Hide file tree
Showing 21 changed files with 484 additions and 134 deletions.
42 changes: 14 additions & 28 deletions Src/Noesis/Core/Src/Core/Extend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,19 +2576,10 @@ private static bool ConverterConvert(IntPtr cPtr,

object obj = converter.Convert(val, targetType, param, CultureInfo.CurrentCulture);

if (AreCompatibleTypes(obj, targetType))
{
HandleRef res = GetInstanceHandle(obj);
BaseComponent.AddReference(res.Handle); // released by native bindings
result = res.Handle;
return true;
}
else
{
Log.Error(string.Format("{0} Convert() expects {1} and {2} is returned",
converter.GetType().FullName, targetType.FullName,
obj != null ? obj.GetType().FullName : "null"));
}
HandleRef res = GetInstanceHandle(obj);
BaseComponent.AddReference(res.Handle); // released by native bindings
result = res.Handle;
return true;
}
}
catch (Exception e)
Expand Down Expand Up @@ -2622,19 +2613,10 @@ private static bool ConverterConvertBack(IntPtr cPtr,

object obj = converter.ConvertBack(val, targetType, param, CultureInfo.CurrentCulture);

if (AreCompatibleTypes(obj, targetType))
{
HandleRef res = GetInstanceHandle(obj);
BaseComponent.AddReference(res.Handle); // released by native bindings
result = res.Handle;
return true;
}
else
{
Log.Error(string.Format("{0} ConvertBack() expects {1} and {2} is returned",
converter.GetType().FullName, targetType.FullName,
obj != null ? obj.GetType().FullName : "null"));
}
HandleRef res = GetInstanceHandle(obj);
BaseComponent.AddReference(res.Handle); // released by native bindings
result = res.Handle;
return true;
}
}
catch (Exception e)
Expand Down Expand Up @@ -5742,11 +5724,12 @@ public static IntPtr NewCPtr(Type type)
}

////////////////////////////////////////////////////////////////////////////////////////////////
private delegate void Callback_CreateInstance(IntPtr nativeType, IntPtr cPtr);
[return: MarshalAs(UnmanagedType.U1)]
private delegate bool Callback_CreateInstance(IntPtr nativeType, IntPtr cPtr);
private static Callback_CreateInstance _createInstance = CreateInstance;

[MonoPInvokeCallback(typeof(Callback_CreateInstance))]
private static void CreateInstance(IntPtr nativeType, IntPtr cPtr)
private static bool CreateInstance(IntPtr nativeType, IntPtr cPtr)
{
try
{
Expand Down Expand Up @@ -5782,10 +5765,13 @@ private static void CreateInstance(IntPtr nativeType, IntPtr cPtr)
BaseComponent.AddReference(cPtr);
RegisterInterfaces(instance);
}

return true;
}
catch (Exception e)
{
Error.UnhandledException(e);
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Noesis/Core/Src/Core/NoesisGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ static extern IntPtr Noesis_LoadStreamXaml(HandleRef stream,
static extern IntPtr Noesis_LoadXaml([MarshalAs(UnmanagedType.LPStr)] string filename);

[DllImport(Library.Name)]
static extern IntPtr Noesis_ParseXaml([MarshalAs(UnmanagedType.LPStr)] string xamlText);
static extern IntPtr Noesis_ParseXaml([MarshalAs(UnmanagedType.LPWStr)] string xamlText);

[DllImport(Library.Name)]
static extern IntPtr Noesis_LoadXamlResource(
Expand Down
21 changes: 21 additions & 0 deletions Src/Noesis/Core/Src/Core/RenderDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,33 @@ public enum TextureFormat
[StructLayout(LayoutKind.Sequential)]
public struct DeviceCaps
{
/// <summary>Offset in pixel units from top-left corner to center of pixel</summary>
[MarshalAs(UnmanagedType.R4)]
public float CenterPixelOffset;

/// <summary>
/// When this flag is enabled the device works in 'Linear' mode. All internal textures and
/// offscreens are created in 'sRGB' format. In this mode, the device also expects colors
/// (like the ones in the vertex buffer) in 'sRGB' format. It also indicates that the device
/// writes to the render target in linear space
/// </summary>
[MarshalAs(UnmanagedType.U1)]
public bool LinearRendering;

/// <summary>
/// This flag is enabled to indicate that the device supports LCD subpixel rendering. Extra
/// shaders and dual source blending are needed for this feature
/// </summary>
[MarshalAs(UnmanagedType.U1)]
public bool SubpixelRendering;

/// <summary>Indicates whether the device clip space depth values range from 0 to 1</summary>
[MarshalAs(UnmanagedType.U1)]
public bool DepthRangeZeroToOne;

/// <summary>Whether the device clip space Y values are inverted (increase from top (-1) to bottom (1))</summary>
[MarshalAs(UnmanagedType.U1)]
public bool ClipSpaceYInverted;
}

/// <summary>
Expand Down
126 changes: 126 additions & 0 deletions Src/Noesis/Core/Src/Core/TypeConverterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,132 @@

namespace Noesis
{
public class SizeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return Size.Parse((string)value);
}

return base.ConvertFrom(context, culture, value);
}
}

public class PointConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return Point.Parse((string)value);
}

return base.ConvertFrom(context, culture, value);
}
}

public class RectConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return Rect.Parse((string)value);
}

return base.ConvertFrom(context, culture, value);
}
}

public class Int32RectConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return Int32Rect.Parse((string)value);
}

return base.ConvertFrom(context, culture, value);
}
}

public class ThicknessConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return Thickness.Parse((string)value);
}

return base.ConvertFrom(context, culture, value);
}
}

public class CornerRadiusConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return CornerRadius.Parse((string)value);
}

return base.ConvertFrom(context, culture, value);
}
}

public class ColorConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return Color.Parse((string)value);
}

return base.ConvertFrom(context, culture, value);
}
}

public class BrushConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
Expand Down
13 changes: 13 additions & 0 deletions Src/Noesis/Core/Src/Proxies/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Noesis
{

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.ComponentModel.TypeConverter(typeof(ColorConverter))]
public struct Color {

[MarshalAs(UnmanagedType.R4)]
Expand Down Expand Up @@ -186,6 +187,18 @@ private static bool AreClose(float a, float b) {
return !(l == r);
}

internal static Color Parse(string str) {
if (Color.TryParse(str, out Color color)) {
return color;
}
throw new ArgumentException("Cannot create Color from '" + str + "'");
}

private static bool TryParse(string str, out Color result) {
bool ret = NoesisGUI_PINVOKE.Color_TryParse(str != null ? str : string.Empty, out result);
return ret;
}

}

}
Expand Down
1 change: 1 addition & 0 deletions Src/Noesis/Core/Src/Proxies/CornerRadius.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Noesis
{

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.ComponentModel.TypeConverter(typeof(CornerRadiusConverter))]
public struct CornerRadius {

[MarshalAs(UnmanagedType.R4)]
Expand Down
17 changes: 4 additions & 13 deletions Src/Noesis/Core/Src/Proxies/Inline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
namespace Noesis
{

public class Inline : TextElement {
internal new static Inline CreateProxy(IntPtr cPtr, bool cMemoryOwn) {
return new Inline(cPtr, cMemoryOwn);
}

public abstract class Inline : TextElement {
internal Inline(IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) {
}

internal static HandleRef getCPtr(Inline obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}

protected Inline() {
}

public new FlowDirection FlowDirection {
set {
SetFlowDirection(value);
Expand All @@ -36,14 +35,6 @@ internal static HandleRef getCPtr(Inline obj) {
}
}

public Inline() {
}

protected override IntPtr CreateCPtr(Type type, out bool registerExtend) {
registerExtend = false;
return NoesisGUI_PINVOKE.new_Inline();
}

private FlowDirection GetFlowDirection() {
FlowDirection ret = (FlowDirection)NoesisGUI_PINVOKE.Inline_GetFlowDirection(swigCPtr);
return ret;
Expand Down
1 change: 1 addition & 0 deletions Src/Noesis/Core/Src/Proxies/Int32Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Noesis
{

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.ComponentModel.TypeConverter(typeof(Int32RectConverter))]
public struct Int32Rect {

[MarshalAs(UnmanagedType.I4)]
Expand Down
10 changes: 4 additions & 6 deletions Src/Noesis/Core/Src/Proxies/NoesisGUI_PINVOKE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ internal class NoesisGUI_PINVOKE {
[DllImport(Library.Name)]
public static extern IntPtr Box_Color(ref Color jarg1);

[DllImport(Library.Name)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool Color_TryParse([MarshalAs(UnmanagedType.LPWStr)]string jarg1, out Color jarg2);

[DllImport(Library.Name)]
public static extern IntPtr Matrix_GetStaticType();

Expand Down Expand Up @@ -5782,12 +5786,6 @@ internal class NoesisGUI_PINVOKE {
[DllImport(Library.Name)]
public static extern float TextElement_StrokeThickness_get(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern IntPtr new_TextElement();

[DllImport(Library.Name)]
public static extern IntPtr new_Inline();

[DllImport(Library.Name)]
public static extern int Inline_GetFlowDirection(HandleRef jarg1);

Expand Down
1 change: 1 addition & 0 deletions Src/Noesis/Core/Src/Proxies/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Noesis
{

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.ComponentModel.TypeConverter(typeof(PointConverter))]
public struct Point {

[MarshalAs(UnmanagedType.R4)]
Expand Down
1 change: 1 addition & 0 deletions Src/Noesis/Core/Src/Proxies/Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Noesis
{

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.ComponentModel.TypeConverter(typeof(RectConverter))]
public struct Rect {

[MarshalAs(UnmanagedType.R4)]
Expand Down
1 change: 1 addition & 0 deletions Src/Noesis/Core/Src/Proxies/Size.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Noesis
{

[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[System.ComponentModel.TypeConverter(typeof(SizeConverter))]
public struct Size {

[MarshalAs(UnmanagedType.R4)]
Expand Down
Loading

0 comments on commit f0aef3a

Please sign in to comment.