Skip to content

Commit

Permalink
Updated to 3.0.7 version.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Nov 2, 2020
1 parent a8340f6 commit c2ccfc4
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 73 deletions.
41 changes: 33 additions & 8 deletions Src/Noesis/Core/Src/Core/Extend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,13 @@ public static IntPtr RegisterNativeType(Type type, bool registerDP)
PropertyInfo indexerInfo = null;
IndexerAccessor indexer = null;

#if UNITY_5_3_OR_NEWER
if (typeof(UnityEngine.Texture).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
{
nativeType = Noesis.TextureSource.Extend(TypeFullName(type));
}
else
#endif
if (typeof(Noesis.IScrollInfo).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()) &&
typeof(Noesis.VirtualizingPanel).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
{
Expand Down Expand Up @@ -1470,7 +1477,12 @@ private static ExtendTypeData CreateNativeTypeData(System.Type type, IntPtr nati
{
ExtendTypeData typeData = new ExtendTypeData();
typeData.type = nativeType.ToInt64();
typeData.baseType = EnsureNativeType(type.GetTypeInfo().BaseType).ToInt64();
typeData.baseType =
#if UNITY_5_3_OR_NEWER
typeof(UnityEngine.Texture).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()) ?
TryGetNativeType(typeof(Noesis.TextureSource)).ToInt64() :
#endif
EnsureNativeType(type.GetTypeInfo().BaseType).ToInt64();

var typeConverter = type.GetTypeInfo().GetCustomAttribute<System.ComponentModel.TypeConverterAttribute>();
if (typeConverter != null)
Expand Down Expand Up @@ -4612,7 +4624,7 @@ public static IntPtr GetCPtr(BaseComponent instance, Type extendType)
}

////////////////////////////////////////////////////////////////////////////////////////////////
public static IntPtr NewCPtr(System.Type type, object instance)
public static IntPtr NewCPtr(System.Type type)
{
// Ensure native type is registered
IntPtr nativeType = EnsureNativeType(type);
Expand Down Expand Up @@ -4687,10 +4699,7 @@ private static void DeleteInstance(IntPtr cPtr)
{
try
{
if (Initialized)
{
RemoveExtendInfo(cPtr);
}
RemoveExtendInfo(cPtr);
}
catch (Exception e)
{
Expand Down Expand Up @@ -5015,9 +5024,17 @@ public static HandleRef GetInstanceHandle(object instance)
cPtr = FindInstancePtr(instance);
if (cPtr == IntPtr.Zero && Initialized)
{
cPtr = NewCPtr(instance.GetType(), instance);
cPtr = NewCPtr(instance.GetType());
AddExtendInfo(cPtr, instance);
RegisterInterfaces(instance);

#if UNITY_5_3_OR_NEWER
// Automatic conversion from Unity's Texture to a TextureSource proxy
if (instance is UnityEngine.Texture)
{
Noesis.TextureSource.SetTexture(cPtr, (UnityEngine.Texture)instance);
}
#endif
}
}

Expand Down Expand Up @@ -5068,7 +5085,15 @@ private static IntPtr FindWeakInstancePtr(object instance)
WeakInfo info = extends[i];
if (info.weak.Target == instance)
{
cPtr = new IntPtr(info.ptr);
if (!Initialized && !_extends.ContainsKey(info.ptr))
{
// Extend already destroyed
cPtr = IntPtr.Zero;
}
else
{
cPtr = new IntPtr(info.ptr);
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Noesis/Core/Src/Proxies/BaseComponentExtend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected virtual IntPtr CreateCPtr(Type type, out bool registerExtend)
protected IntPtr CreateExtendCPtr(Type type, out bool registerExtend)
{
registerExtend = true;
return Noesis.Extend.NewCPtr(type, this);
return Noesis.Extend.NewCPtr(type);
}

public static IntPtr GetPtr(object instance)
Expand Down
65 changes: 32 additions & 33 deletions Src/Noesis/Core/Src/Proxies/ManipulationDelta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,58 +45,57 @@ public virtual void Dispose() {
}
}

public Point Expansion {
set {
NoesisGUI_PINVOKE.ManipulationDelta_Expansion_set(swigCPtr, ref value);
public Vector Scale {
get {
float scale = GetScaleHelper();
return new Vector(scale, scale);
}
}

public Vector Translation {
get {
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_Expansion_get(swigCPtr);
if (ret != IntPtr.Zero) {
return Marshal.PtrToStructure<Point>(ret);
}
else {
return new Point();
}
Point trans = GetTranslationHelper();
return new Vector(trans.X, trans.Y);
}
}

public Vector Expansion {
get {
Point exp = GetExpansionHelper();
return new Vector(exp.X, exp.Y);
}
}

public float Rotation {
set {
NoesisGUI_PINVOKE.ManipulationDelta_Rotation_set(swigCPtr, value);
}
get {
float ret = NoesisGUI_PINVOKE.ManipulationDelta_Rotation_get(swigCPtr);
return ret;
}
}

public float Scale {
set {
NoesisGUI_PINVOKE.ManipulationDelta_Scale_set(swigCPtr, value);
}
get {
float ret = NoesisGUI_PINVOKE.ManipulationDelta_Scale_get(swigCPtr);
return ret;
}
private float GetScaleHelper() {
float ret = NoesisGUI_PINVOKE.ManipulationDelta_GetScaleHelper(swigCPtr);
return ret;
}

public Point Translation {
set {
NoesisGUI_PINVOKE.ManipulationDelta_Translation_set(swigCPtr, ref value);
private Point GetTranslationHelper() {
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_GetTranslationHelper(swigCPtr);
if (ret != IntPtr.Zero) {
return Marshal.PtrToStructure<Point>(ret);
}

get {
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_Translation_get(swigCPtr);
if (ret != IntPtr.Zero) {
return Marshal.PtrToStructure<Point>(ret);
}
else {
return new Point();
}
else {
return new Point();
}
}

private Point GetExpansionHelper() {
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_GetExpansionHelper(swigCPtr);
if (ret != IntPtr.Zero) {
return Marshal.PtrToStructure<Point>(ret);
}
else {
return new Point();
}
}

public ManipulationDelta() : this(NoesisGUI_PINVOKE.new_ManipulationDelta(), true) {
Expand Down
8 changes: 4 additions & 4 deletions Src/Noesis/Core/Src/Proxies/ManipulationDeltaEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public Point ManipulationOrigin {

}

public ManipulationDelta CumulativeManipulation {
public ManipulationDelta DeltaManipulation {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_CumulativeManipulation_get(swigCPtr);
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_DeltaManipulation_get(swigCPtr);
ManipulationDelta ret = (cPtr == IntPtr.Zero) ? null : new ManipulationDelta(cPtr, false);
return ret;
}
}

public ManipulationDelta DeltaManipulation {
public ManipulationDelta CumulativeManipulation {
get {
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_DeltaManipulation_get(swigCPtr);
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_CumulativeManipulation_get(swigCPtr);
ManipulationDelta ret = (cPtr == IntPtr.Zero) ? null : new ManipulationDelta(cPtr, false);
return ret;
}
Expand Down
5 changes: 5 additions & 0 deletions Src/Noesis/Core/Src/Proxies/Matrix4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ public static Matrix4 Inverse(Matrix4 m, float determinant) {
d30, d31, d32, d33);
}

public Rect TransformBounds(Rect bounds) {
bounds.Transform(this);
return bounds;
}

}

}
Expand Down
22 changes: 5 additions & 17 deletions Src/Noesis/Core/Src/Proxies/NoesisGUI_PINVOKE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3391,29 +3391,17 @@ internal class NoesisGUI_PINVOKE {
[DllImport(Library.Name)]
public static extern void delete_ManipulationStartedEventArgs(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern void ManipulationDelta_Expansion_set(HandleRef jarg1, ref Point jarg2);

[DllImport(Library.Name)]
public static extern IntPtr ManipulationDelta_Expansion_get(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern void ManipulationDelta_Rotation_set(HandleRef jarg1, float jarg2);

[DllImport(Library.Name)]
public static extern float ManipulationDelta_Rotation_get(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern void ManipulationDelta_Scale_set(HandleRef jarg1, float jarg2);
public static extern float ManipulationDelta_GetScaleHelper(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern float ManipulationDelta_Scale_get(HandleRef jarg1);
public static extern IntPtr ManipulationDelta_GetTranslationHelper(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern void ManipulationDelta_Translation_set(HandleRef jarg1, ref Point jarg2);

[DllImport(Library.Name)]
public static extern IntPtr ManipulationDelta_Translation_get(HandleRef jarg1);
public static extern IntPtr ManipulationDelta_GetExpansionHelper(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern IntPtr new_ManipulationDelta();
Expand Down Expand Up @@ -3449,10 +3437,10 @@ internal class NoesisGUI_PINVOKE {
public static extern IntPtr ManipulationDeltaEventArgs_ManipulationOrigin_get(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern IntPtr ManipulationDeltaEventArgs_CumulativeManipulation_get(HandleRef jarg1);
public static extern IntPtr ManipulationDeltaEventArgs_DeltaManipulation_get(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern IntPtr ManipulationDeltaEventArgs_DeltaManipulation_get(HandleRef jarg1);
public static extern IntPtr ManipulationDeltaEventArgs_CumulativeManipulation_get(HandleRef jarg1);

[DllImport(Library.Name)]
public static extern IntPtr ManipulationDeltaEventArgs_Velocities_get(HandleRef jarg1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
ManipulationDelta delta = e.DeltaManipulation;

// Update Scale transform
float scale = delta.Scale * _scale.ScaleX;
scale = Math.Max(Math.Max(0.00001f, MinimumScale), Math.Min(scale, MaximumScale));
_scale.ScaleX = scale;
_scale.ScaleY = scale;
float scaleX = delta.Scale.X * _scale.ScaleX;
_scale.ScaleX = Math.Max(Math.Max(0.00001f, MinimumScale), Math.Min(scaleX, MaximumScale));
float scaleY = delta.Scale.Y * _scale.ScaleY;
_scale.ScaleY = Math.Max(Math.Max(0.00001f, MinimumScale), Math.Min(scaleY, MaximumScale));

// Update Rotate transform
_rotate.Angle += delta.Rotation;
Expand Down
49 changes: 48 additions & 1 deletion Src/NoesisApp/RenderContexts/EGL/Src/RenderContextEGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,40 @@ public override void SetDefaultRenderTarget(int width, int height, bool doClearC

public override ImageCapture CaptureRenderTarget(RenderTarget surface)
{
throw new NotImplementedException();
int[] viewport = new int[4];
glGetIntegerv(GL_VIEWPORT, viewport);

int x = viewport[0];
int y = viewport[1];
int width = viewport[2];
int height = viewport[3];

byte[] src = new byte[width * height * 4];
int srcStride = width * 4;

glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, src);

ImageCapture img = new ImageCapture((uint)width, (uint)height);

byte[] dst = img.Pixels;

for (int i = 0; i < height; ++i)
{
int dstRow = i * (int)img.Stride;
int srcRow = i * srcStride;

for (int j = 0; j < width; ++j)
{
// RGBA -> BGRA
dst[dstRow + 4 * j + 2] = src[srcRow + 4 * j + 0];
dst[dstRow + 4 * j + 1] = src[srcRow + 4 * j + 1];
dst[dstRow + 4 * j + 0] = src[srcRow + 4 * j + 2];
dst[dstRow + 4 * j + 3] = src[srcRow + 4 * j + 3];
}
}

return img;
}

public override void Swap()
Expand Down Expand Up @@ -205,6 +238,10 @@ public override void Resize() { }
private const uint GL_FRAMEBUFFER = 0x8D40;
private const uint GL_STENCIL_BUFFER_BIT = 0x00000400;
private const uint GL_COLOR_BUFFER_BIT = 0x00004000;
private const uint GL_VIEWPORT = 0x00000BA2;
private const uint GL_PACK_ALIGNMENT = 0x00000D05;
private const uint GL_UNSIGNED_BYTE = 0x00001401;
private const uint GL_RGBA = 0x00001908;

[DllImport("GLESv2")]
static extern void glBindFramebuffer(uint target, uint framebuffer);
Expand All @@ -223,5 +260,15 @@ public override void Resize() { }

[DllImport("GLESv2")]
static extern void glClearColor(float r, float g, float b, float a);

[DllImport("GLESv2")]
public static extern void glGetIntegerv(uint pname, int[] param);

[DllImport("GLESv2")]
public static extern void glPixelStorei(uint pname, int param);

[DllImport("GLESv2")]
public static extern void glReadPixels(int x, int y, int width, int height,
uint format, uint type, byte[] pixels);
}
}
Loading

0 comments on commit c2ccfc4

Please sign in to comment.