Resolution du dernier(?) problème de Drag And Drop

master
cldupland 5 years ago
parent 9840165d90
commit 16043a30c0

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.uca.thegameextreme" android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.1" package="com.uca.thegameextreme" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="TheGameExtreme.Android" android:icon="@drawable/iconpique"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

@ -68,10 +68,6 @@
HeightRequest="45"
BackgroundColor="{DynamicResource BlackColor}"
Clicked="PlayToHome"/>
<Label Text="↑" TextColor="White"
FontSize="64"
Grid.Column="0" Grid.Row="1" Margin="120,0,0,10"/>
</StackLayout>
@ -88,9 +84,6 @@
BackgroundColor="{DynamicResource SkyBlueColor}"
HeightRequest="35"
Clicked="EndTurn"/>
<Label Text="↓" TextColor="White"
FontSize="64" Grid.Column="2" Grid.Row="1" Margin="0,0,120,10"/>
</StackLayout>

@ -122,6 +122,8 @@ namespace TheGameExtreme.view
if (textDictionary.ContainsKey(args.Id))
{
TouchManipulationBitmap bitmap = textDictionary[args.Id];
point.Y -= 120;
point.X -= 50;
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
canvasView.InvalidateSurface();
}
@ -137,7 +139,8 @@ namespace TheGameExtreme.view
bool find = false;
foreach (TouchManipulationBitmap stack in stackCollection)
{
if (stack.HitTest(point))
SKPoint pointVisuCard = new SKPoint(point.X, point.Y - 120);
if (stack.HitTest(point) || stack.HitTest(pointVisuCard))
{
int indexPile = stackCollection.IndexOf(stack);
if (played(indexPile, decimal.Parse(bitmap.Value)))
@ -190,6 +193,7 @@ namespace TheGameExtreme.view
stackCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.getListOrderedStacks()[i].Peek().Value)
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialPoint = position
});
@ -213,6 +217,7 @@ namespace TheGameExtreme.view
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value)
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialPoint = position
});

@ -16,31 +16,34 @@ namespace TheGameExtreme.view
{
this.textPaint = textPaint;
Value = value.ToString();
if (value < 0 && value > -10)
{
Value = "-0" + Math.Abs(value).ToString();
}
else if (value >= 0 && value < 10 && !(value > 0 && value < 1))
{
Value = "0" + value.ToString();
}
else
if (!Value.Contains(",") && !Value.Contains("."))
{
Value = value.ToString();
if (value < 0 && value > -10)
{
Value = "-0" + Math.Abs(value).ToString();
}
else if (value >= 0 && value < 10)
{
Value = "0" + value.ToString();
}
else
{
Value = value.ToString();
}
}
Matrix = SKMatrix.MakeIdentity();
TouchManager = new TouchManipulationManager
{
Mode = TouchManipulationMode.PanOnly
};
Mode = TouchManipulationMode.PanOnly;
}
public TouchManipulationManager TouchManager { set; get; }
public TouchManipulationMode Mode { set; get; }
public SKMatrix Matrix { set; get; }
public SKMatrix InitialMatrix { set; get; }
public void Paint(SKCanvas canvas, SKColor color)
{
canvas.Save();
@ -119,29 +122,11 @@ namespace TheGameExtreme.view
{
TouchManipulationInfo[] infos = new TouchManipulationInfo[touchDictionary.Count];
touchDictionary.Values.CopyTo(infos, 0);
SKMatrix touchMatrix = SKMatrix.MakeIdentity();
if (infos.Length == 1)
if (Mode == TouchManipulationMode.PanOnly)
{
SKPoint prevPoint = infos[0].PreviousPoint;
SKPoint newPoint = infos[0].NewPoint;
SKPoint pivotPoint = Matrix.MapPoint(textPaint.MeasureText(Value) / 2, textPaint.TextSize / 2);
touchMatrix = TouchManager.OneFingerManipulate(prevPoint, newPoint, pivotPoint);
Matrix = SKMatrix.MakeTranslation(infos[0].NewPoint.X, infos[0].NewPoint.Y);
}
//else if (infos.Length >= 2)
//{
// int pivotIndex = infos[0].NewPoint == infos[0].PreviousPoint ? 0 : 1;
// SKPoint pivotPoint = infos[pivotIndex].NewPoint;
// SKPoint newPoint = infos[1 - pivotIndex].NewPoint;
// SKPoint prevPoint = infos[1 - pivotIndex].PreviousPoint;
// touchMatrix = TouchManager.TwoFingerManipulate(prevPoint, newPoint, pivotPoint);
//}
SKMatrix matrix = Matrix;
SKMatrix.PostConcat(ref matrix, touchMatrix);
Matrix = matrix;
}
}
}

@ -1,107 +1,107 @@
using System;
using SkiaSharp;
namespace TheGameExtreme.view
{
public class TouchManipulationManager
{
public TouchManipulationMode Mode { set; get; }
//float Magnitude(SKPoint point)
//{
// return (float)Math.Sqrt(Math.Pow(point.X, 2) + Math.Pow(point.Y, 2));
//}
public SKMatrix OneFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
{
if (Mode == TouchManipulationMode.None)
{
return SKMatrix.MakeIdentity();
}
SKMatrix touchMatrix = SKMatrix.MakeIdentity();
SKPoint delta = newPoint - prevPoint;
//if (Mode == TouchManipulationMode.ScaleDualRotate) // One-finger rotation
//{
// SKPoint oldVector = prevPoint - pivotPoint;
// SKPoint newVector = newPoint - pivotPoint;
// // Avoid rotation if fingers are too close to center
// if (Magnitude(newVector) > 25 && Magnitude(oldVector) > 25)
// {
// float prevAngle = (float)Math.Atan2(oldVector.Y, oldVector.X);
// float newAngle = (float)Math.Atan2(newVector.Y, newVector.X);
// // Calculate rotation matrix
// float angle = newAngle - prevAngle;
// touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
// // Effectively rotate the old vector
// float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector);
// oldVector.X = magnitudeRatio * newVector.X;
// oldVector.Y = magnitudeRatio * newVector.Y;
// // Recalculate delta
// delta = newVector - oldVector;
// }
//}
// Multiply the rotation matrix by a translation matrix
SKMatrix.PostConcat(ref touchMatrix, SKMatrix.MakeTranslation(delta.X, delta.Y));
return touchMatrix;
}
public SKMatrix TwoFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
{
SKMatrix touchMatrix = SKMatrix.MakeIdentity();
//SKPoint oldVector = prevPoint - pivotPoint;
//SKPoint newVector = newPoint - pivotPoint;
//if (Mode == TouchManipulationMode.ScaleRotate ||
// Mode == TouchManipulationMode.ScaleDualRotate)
//{
// // Find angles from pivot point to touch points
// float oldAngle = (float)Math.Atan2(oldVector.Y, oldVector.X);
// float newAngle = (float)Math.Atan2(newVector.Y, newVector.X);
// // Calculate rotation matrix
// float angle = newAngle - oldAngle;
// touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
// // Effectively rotate the old vector
// float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector);
// oldVector.X = magnitudeRatio * newVector.X;
// oldVector.Y = magnitudeRatio * newVector.Y;
//}
float scaleX = 1;
float scaleY = 1;
//if (Mode == TouchManipulationMode.AnisotropicScale)
//{
// scaleX = newVector.X / oldVector.X;
// scaleY = newVector.Y / oldVector.Y;
//}
//else if (Mode == TouchManipulationMode.IsotropicScale ||
// Mode == TouchManipulationMode.ScaleRotate ||
// Mode == TouchManipulationMode.ScaleDualRotate)
//{
// scaleX = scaleY = Magnitude(newVector) / Magnitude(oldVector);
//}
if (!float.IsNaN(scaleX) && !float.IsInfinity(scaleX) &&
!float.IsNaN(scaleY) && !float.IsInfinity(scaleY))
{
SKMatrix.PostConcat(ref touchMatrix,
SKMatrix.MakeScale(scaleX, scaleY, pivotPoint.X, pivotPoint.Y));
}
return touchMatrix;
}
}
}
//using System;
//using SkiaSharp;
//namespace TheGameExtreme.view
//{
// public class TouchManipulationManager
// {
// public TouchManipulationMode Mode { set; get; }
// //float Magnitude(SKPoint point)
// //{
// // return (float)Math.Sqrt(Math.Pow(point.X, 2) + Math.Pow(point.Y, 2));
// //}
// public SKMatrix OneFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
// {
// if (Mode == TouchManipulationMode.None)
// {
// return SKMatrix.MakeIdentity();
// }
// SKMatrix touchMatrix = SKMatrix.MakeIdentity();
// SKPoint delta = newPoint - prevPoint;
// //if (Mode == TouchManipulationMode.ScaleDualRotate) // One-finger rotation
// //{
// // SKPoint oldVector = prevPoint - pivotPoint;
// // SKPoint newVector = newPoint - pivotPoint;
// // // Avoid rotation if fingers are too close to center
// // if (Magnitude(newVector) > 25 && Magnitude(oldVector) > 25)
// // {
// // float prevAngle = (float)Math.Atan2(oldVector.Y, oldVector.X);
// // float newAngle = (float)Math.Atan2(newVector.Y, newVector.X);
// // // Calculate rotation matrix
// // float angle = newAngle - prevAngle;
// // touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
// // // Effectively rotate the old vector
// // float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector);
// // oldVector.X = magnitudeRatio * newVector.X;
// // oldVector.Y = magnitudeRatio * newVector.Y;
// // // Recalculate delta
// // delta = newVector - oldVector;
// // }
// //}
// // Multiply the rotation matrix by a translation matrix
// SKMatrix.PostConcat(ref touchMatrix, SKMatrix.MakeTranslation(delta.X, delta.Y));
// return touchMatrix;
// }
// public SKMatrix TwoFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
// {
// SKMatrix touchMatrix = SKMatrix.MakeIdentity();
// //SKPoint oldVector = prevPoint - pivotPoint;
// //SKPoint newVector = newPoint - pivotPoint;
// //if (Mode == TouchManipulationMode.ScaleRotate ||
// // Mode == TouchManipulationMode.ScaleDualRotate)
// //{
// // // Find angles from pivot point to touch points
// // float oldAngle = (float)Math.Atan2(oldVector.Y, oldVector.X);
// // float newAngle = (float)Math.Atan2(newVector.Y, newVector.X);
// // // Calculate rotation matrix
// // float angle = newAngle - oldAngle;
// // touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
// // // Effectively rotate the old vector
// // float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector);
// // oldVector.X = magnitudeRatio * newVector.X;
// // oldVector.Y = magnitudeRatio * newVector.Y;
// //}
// float scaleX = 1;
// float scaleY = 1;
// //if (Mode == TouchManipulationMode.AnisotropicScale)
// //{
// // scaleX = newVector.X / oldVector.X;
// // scaleY = newVector.Y / oldVector.Y;
// //}
// //else if (Mode == TouchManipulationMode.IsotropicScale ||
// // Mode == TouchManipulationMode.ScaleRotate ||
// // Mode == TouchManipulationMode.ScaleDualRotate)
// //{
// // scaleX = scaleY = Magnitude(newVector) / Magnitude(oldVector);
// //}
// if (!float.IsNaN(scaleX) && !float.IsInfinity(scaleX) &&
// !float.IsNaN(scaleY) && !float.IsInfinity(scaleY))
// {
// SKMatrix.PostConcat(ref touchMatrix,
// SKMatrix.MakeScale(scaleX, scaleY, pivotPoint.X, pivotPoint.Y));
// }
// return touchMatrix;
// }
// }
//}

Binary file not shown.
Loading…
Cancel
Save