Skip to content

Commit c2ccfc4

Browse files
committed
Updated to 3.0.7 version.
1 parent a8340f6 commit c2ccfc4

File tree

10 files changed

+231
-73
lines changed

10 files changed

+231
-73
lines changed

Src/Noesis/Core/Src/Core/Extend.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,13 @@ public static IntPtr RegisterNativeType(Type type, bool registerDP)
12891289
PropertyInfo indexerInfo = null;
12901290
IndexerAccessor indexer = null;
12911291

1292+
#if UNITY_5_3_OR_NEWER
1293+
if (typeof(UnityEngine.Texture).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
1294+
{
1295+
nativeType = Noesis.TextureSource.Extend(TypeFullName(type));
1296+
}
1297+
else
1298+
#endif
12921299
if (typeof(Noesis.IScrollInfo).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()) &&
12931300
typeof(Noesis.VirtualizingPanel).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
12941301
{
@@ -1470,7 +1477,12 @@ private static ExtendTypeData CreateNativeTypeData(System.Type type, IntPtr nati
14701477
{
14711478
ExtendTypeData typeData = new ExtendTypeData();
14721479
typeData.type = nativeType.ToInt64();
1473-
typeData.baseType = EnsureNativeType(type.GetTypeInfo().BaseType).ToInt64();
1480+
typeData.baseType =
1481+
#if UNITY_5_3_OR_NEWER
1482+
typeof(UnityEngine.Texture).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()) ?
1483+
TryGetNativeType(typeof(Noesis.TextureSource)).ToInt64() :
1484+
#endif
1485+
EnsureNativeType(type.GetTypeInfo().BaseType).ToInt64();
14741486

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

46144626
////////////////////////////////////////////////////////////////////////////////////////////////
4615-
public static IntPtr NewCPtr(System.Type type, object instance)
4627+
public static IntPtr NewCPtr(System.Type type)
46164628
{
46174629
// Ensure native type is registered
46184630
IntPtr nativeType = EnsureNativeType(type);
@@ -4687,10 +4699,7 @@ private static void DeleteInstance(IntPtr cPtr)
46874699
{
46884700
try
46894701
{
4690-
if (Initialized)
4691-
{
4692-
RemoveExtendInfo(cPtr);
4693-
}
4702+
RemoveExtendInfo(cPtr);
46944703
}
46954704
catch (Exception e)
46964705
{
@@ -5015,9 +5024,17 @@ public static HandleRef GetInstanceHandle(object instance)
50155024
cPtr = FindInstancePtr(instance);
50165025
if (cPtr == IntPtr.Zero && Initialized)
50175026
{
5018-
cPtr = NewCPtr(instance.GetType(), instance);
5027+
cPtr = NewCPtr(instance.GetType());
50195028
AddExtendInfo(cPtr, instance);
50205029
RegisterInterfaces(instance);
5030+
5031+
#if UNITY_5_3_OR_NEWER
5032+
// Automatic conversion from Unity's Texture to a TextureSource proxy
5033+
if (instance is UnityEngine.Texture)
5034+
{
5035+
Noesis.TextureSource.SetTexture(cPtr, (UnityEngine.Texture)instance);
5036+
}
5037+
#endif
50215038
}
50225039
}
50235040

@@ -5068,7 +5085,15 @@ private static IntPtr FindWeakInstancePtr(object instance)
50685085
WeakInfo info = extends[i];
50695086
if (info.weak.Target == instance)
50705087
{
5071-
cPtr = new IntPtr(info.ptr);
5088+
if (!Initialized && !_extends.ContainsKey(info.ptr))
5089+
{
5090+
// Extend already destroyed
5091+
cPtr = IntPtr.Zero;
5092+
}
5093+
else
5094+
{
5095+
cPtr = new IntPtr(info.ptr);
5096+
}
50725097
break;
50735098
}
50745099
}

Src/Noesis/Core/Src/Proxies/BaseComponentExtend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected virtual IntPtr CreateCPtr(Type type, out bool registerExtend)
8282
protected IntPtr CreateExtendCPtr(Type type, out bool registerExtend)
8383
{
8484
registerExtend = true;
85-
return Noesis.Extend.NewCPtr(type, this);
85+
return Noesis.Extend.NewCPtr(type);
8686
}
8787

8888
public static IntPtr GetPtr(object instance)

Src/Noesis/Core/Src/Proxies/ManipulationDelta.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,58 +45,57 @@ public virtual void Dispose() {
4545
}
4646
}
4747

48-
public Point Expansion {
49-
set {
50-
NoesisGUI_PINVOKE.ManipulationDelta_Expansion_set(swigCPtr, ref value);
48+
public Vector Scale {
49+
get {
50+
float scale = GetScaleHelper();
51+
return new Vector(scale, scale);
5152
}
53+
}
5254

55+
public Vector Translation {
5356
get {
54-
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_Expansion_get(swigCPtr);
55-
if (ret != IntPtr.Zero) {
56-
return Marshal.PtrToStructure<Point>(ret);
57-
}
58-
else {
59-
return new Point();
60-
}
57+
Point trans = GetTranslationHelper();
58+
return new Vector(trans.X, trans.Y);
6159
}
60+
}
6261

62+
public Vector Expansion {
63+
get {
64+
Point exp = GetExpansionHelper();
65+
return new Vector(exp.X, exp.Y);
66+
}
6367
}
6468

6569
public float Rotation {
66-
set {
67-
NoesisGUI_PINVOKE.ManipulationDelta_Rotation_set(swigCPtr, value);
68-
}
6970
get {
7071
float ret = NoesisGUI_PINVOKE.ManipulationDelta_Rotation_get(swigCPtr);
7172
return ret;
7273
}
7374
}
7475

75-
public float Scale {
76-
set {
77-
NoesisGUI_PINVOKE.ManipulationDelta_Scale_set(swigCPtr, value);
78-
}
79-
get {
80-
float ret = NoesisGUI_PINVOKE.ManipulationDelta_Scale_get(swigCPtr);
81-
return ret;
82-
}
76+
private float GetScaleHelper() {
77+
float ret = NoesisGUI_PINVOKE.ManipulationDelta_GetScaleHelper(swigCPtr);
78+
return ret;
8379
}
8480

85-
public Point Translation {
86-
set {
87-
NoesisGUI_PINVOKE.ManipulationDelta_Translation_set(swigCPtr, ref value);
81+
private Point GetTranslationHelper() {
82+
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_GetTranslationHelper(swigCPtr);
83+
if (ret != IntPtr.Zero) {
84+
return Marshal.PtrToStructure<Point>(ret);
8885
}
89-
90-
get {
91-
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_Translation_get(swigCPtr);
92-
if (ret != IntPtr.Zero) {
93-
return Marshal.PtrToStructure<Point>(ret);
94-
}
95-
else {
96-
return new Point();
97-
}
86+
else {
87+
return new Point();
9888
}
89+
}
9990

91+
private Point GetExpansionHelper() {
92+
IntPtr ret = NoesisGUI_PINVOKE.ManipulationDelta_GetExpansionHelper(swigCPtr);
93+
if (ret != IntPtr.Zero) {
94+
return Marshal.PtrToStructure<Point>(ret);
95+
}
96+
else {
97+
return new Point();
98+
}
10099
}
101100

102101
public ManipulationDelta() : this(NoesisGUI_PINVOKE.new_ManipulationDelta(), true) {

Src/Noesis/Core/Src/Proxies/ManipulationDeltaEventArgs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ public Point ManipulationOrigin {
7070

7171
}
7272

73-
public ManipulationDelta CumulativeManipulation {
73+
public ManipulationDelta DeltaManipulation {
7474
get {
75-
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_CumulativeManipulation_get(swigCPtr);
75+
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_DeltaManipulation_get(swigCPtr);
7676
ManipulationDelta ret = (cPtr == IntPtr.Zero) ? null : new ManipulationDelta(cPtr, false);
7777
return ret;
7878
}
7979
}
8080

81-
public ManipulationDelta DeltaManipulation {
81+
public ManipulationDelta CumulativeManipulation {
8282
get {
83-
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_DeltaManipulation_get(swigCPtr);
83+
IntPtr cPtr = NoesisGUI_PINVOKE.ManipulationDeltaEventArgs_CumulativeManipulation_get(swigCPtr);
8484
ManipulationDelta ret = (cPtr == IntPtr.Zero) ? null : new ManipulationDelta(cPtr, false);
8585
return ret;
8686
}

Src/Noesis/Core/Src/Proxies/Matrix4.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ public static Matrix4 Inverse(Matrix4 m, float determinant) {
331331
d30, d31, d32, d33);
332332
}
333333

334+
public Rect TransformBounds(Rect bounds) {
335+
bounds.Transform(this);
336+
return bounds;
337+
}
338+
334339
}
335340

336341
}

Src/Noesis/Core/Src/Proxies/NoesisGUI_PINVOKE.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,29 +3391,17 @@ internal class NoesisGUI_PINVOKE {
33913391
[DllImport(Library.Name)]
33923392
public static extern void delete_ManipulationStartedEventArgs(HandleRef jarg1);
33933393

3394-
[DllImport(Library.Name)]
3395-
public static extern void ManipulationDelta_Expansion_set(HandleRef jarg1, ref Point jarg2);
3396-
3397-
[DllImport(Library.Name)]
3398-
public static extern IntPtr ManipulationDelta_Expansion_get(HandleRef jarg1);
3399-
3400-
[DllImport(Library.Name)]
3401-
public static extern void ManipulationDelta_Rotation_set(HandleRef jarg1, float jarg2);
3402-
34033394
[DllImport(Library.Name)]
34043395
public static extern float ManipulationDelta_Rotation_get(HandleRef jarg1);
34053396

34063397
[DllImport(Library.Name)]
3407-
public static extern void ManipulationDelta_Scale_set(HandleRef jarg1, float jarg2);
3398+
public static extern float ManipulationDelta_GetScaleHelper(HandleRef jarg1);
34083399

34093400
[DllImport(Library.Name)]
3410-
public static extern float ManipulationDelta_Scale_get(HandleRef jarg1);
3401+
public static extern IntPtr ManipulationDelta_GetTranslationHelper(HandleRef jarg1);
34113402

34123403
[DllImport(Library.Name)]
3413-
public static extern void ManipulationDelta_Translation_set(HandleRef jarg1, ref Point jarg2);
3414-
3415-
[DllImport(Library.Name)]
3416-
public static extern IntPtr ManipulationDelta_Translation_get(HandleRef jarg1);
3404+
public static extern IntPtr ManipulationDelta_GetExpansionHelper(HandleRef jarg1);
34173405

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

34513439
[DllImport(Library.Name)]
3452-
public static extern IntPtr ManipulationDeltaEventArgs_CumulativeManipulation_get(HandleRef jarg1);
3440+
public static extern IntPtr ManipulationDeltaEventArgs_DeltaManipulation_get(HandleRef jarg1);
34533441

34543442
[DllImport(Library.Name)]
3455-
public static extern IntPtr ManipulationDeltaEventArgs_DeltaManipulation_get(HandleRef jarg1);
3443+
public static extern IntPtr ManipulationDeltaEventArgs_CumulativeManipulation_get(HandleRef jarg1);
34563444

34573445
[DllImport(Library.Name)]
34583446
public static extern IntPtr ManipulationDeltaEventArgs_Velocities_get(HandleRef jarg1);

Src/NoesisApp/Core/Src/Interactivity/TranslateZoomRotateBehavior.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
172172
ManipulationDelta delta = e.DeltaManipulation;
173173

174174
// Update Scale transform
175-
float scale = delta.Scale * _scale.ScaleX;
176-
scale = Math.Max(Math.Max(0.00001f, MinimumScale), Math.Min(scale, MaximumScale));
177-
_scale.ScaleX = scale;
178-
_scale.ScaleY = scale;
175+
float scaleX = delta.Scale.X * _scale.ScaleX;
176+
_scale.ScaleX = Math.Max(Math.Max(0.00001f, MinimumScale), Math.Min(scaleX, MaximumScale));
177+
float scaleY = delta.Scale.Y * _scale.ScaleY;
178+
_scale.ScaleY = Math.Max(Math.Max(0.00001f, MinimumScale), Math.Min(scaleY, MaximumScale));
179179

180180
// Update Rotate transform
181181
_rotate.Angle += delta.Rotation;

Src/NoesisApp/RenderContexts/EGL/Src/RenderContextEGL.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,40 @@ public override void SetDefaultRenderTarget(int width, int height, bool doClearC
126126

127127
public override ImageCapture CaptureRenderTarget(RenderTarget surface)
128128
{
129-
throw new NotImplementedException();
129+
int[] viewport = new int[4];
130+
glGetIntegerv(GL_VIEWPORT, viewport);
131+
132+
int x = viewport[0];
133+
int y = viewport[1];
134+
int width = viewport[2];
135+
int height = viewport[3];
136+
137+
byte[] src = new byte[width * height * 4];
138+
int srcStride = width * 4;
139+
140+
glPixelStorei(GL_PACK_ALIGNMENT, 1);
141+
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, src);
142+
143+
ImageCapture img = new ImageCapture((uint)width, (uint)height);
144+
145+
byte[] dst = img.Pixels;
146+
147+
for (int i = 0; i < height; ++i)
148+
{
149+
int dstRow = i * (int)img.Stride;
150+
int srcRow = i * srcStride;
151+
152+
for (int j = 0; j < width; ++j)
153+
{
154+
// RGBA -> BGRA
155+
dst[dstRow + 4 * j + 2] = src[srcRow + 4 * j + 0];
156+
dst[dstRow + 4 * j + 1] = src[srcRow + 4 * j + 1];
157+
dst[dstRow + 4 * j + 0] = src[srcRow + 4 * j + 2];
158+
dst[dstRow + 4 * j + 3] = src[srcRow + 4 * j + 3];
159+
}
160+
}
161+
162+
return img;
130163
}
131164

132165
public override void Swap()
@@ -205,6 +238,10 @@ public override void Resize() { }
205238
private const uint GL_FRAMEBUFFER = 0x8D40;
206239
private const uint GL_STENCIL_BUFFER_BIT = 0x00000400;
207240
private const uint GL_COLOR_BUFFER_BIT = 0x00004000;
241+
private const uint GL_VIEWPORT = 0x00000BA2;
242+
private const uint GL_PACK_ALIGNMENT = 0x00000D05;
243+
private const uint GL_UNSIGNED_BYTE = 0x00001401;
244+
private const uint GL_RGBA = 0x00001908;
208245

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

224261
[DllImport("GLESv2")]
225262
static extern void glClearColor(float r, float g, float b, float a);
263+
264+
[DllImport("GLESv2")]
265+
public static extern void glGetIntegerv(uint pname, int[] param);
266+
267+
[DllImport("GLESv2")]
268+
public static extern void glPixelStorei(uint pname, int param);
269+
270+
[DllImport("GLESv2")]
271+
public static extern void glReadPixels(int x, int y, int width, int height,
272+
uint format, uint type, byte[] pixels);
226273
}
227274
}

0 commit comments

Comments
 (0)