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"?> <?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" /> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="TheGameExtreme.Android" android:icon="@drawable/iconpique"></application> <application android:label="TheGameExtreme.Android" android:icon="@drawable/iconpique"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

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

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

@ -16,11 +16,14 @@ namespace TheGameExtreme.view
{ {
this.textPaint = textPaint; this.textPaint = textPaint;
Value = value.ToString(); Value = value.ToString();
if (!Value.Contains(",") && !Value.Contains("."))
{
if (value < 0 && value > -10) if (value < 0 && value > -10)
{ {
Value = "-0" + Math.Abs(value).ToString(); Value = "-0" + Math.Abs(value).ToString();
} }
else if (value >= 0 && value < 10 && !(value > 0 && value < 1)) else if (value >= 0 && value < 10)
{ {
Value = "0" + value.ToString(); Value = "0" + value.ToString();
} }
@ -28,19 +31,19 @@ namespace TheGameExtreme.view
{ {
Value = value.ToString(); Value = value.ToString();
} }
}
Matrix = SKMatrix.MakeIdentity(); 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 Matrix { set; get; }
public SKMatrix InitialMatrix { set; get; }
public void Paint(SKCanvas canvas, SKColor color) public void Paint(SKCanvas canvas, SKColor color)
{ {
canvas.Save(); canvas.Save();
@ -119,29 +122,11 @@ namespace TheGameExtreme.view
{ {
TouchManipulationInfo[] infos = new TouchManipulationInfo[touchDictionary.Count]; TouchManipulationInfo[] infos = new TouchManipulationInfo[touchDictionary.Count];
touchDictionary.Values.CopyTo(infos, 0); touchDictionary.Values.CopyTo(infos, 0);
SKMatrix touchMatrix = SKMatrix.MakeIdentity();
if (infos.Length == 1) if (Mode == TouchManipulationMode.PanOnly)
{ {
SKPoint prevPoint = infos[0].PreviousPoint; Matrix = SKMatrix.MakeTranslation(infos[0].NewPoint.X, infos[0].NewPoint.Y);
SKPoint newPoint = infos[0].NewPoint;
SKPoint pivotPoint = Matrix.MapPoint(textPaint.MeasureText(Value) / 2, textPaint.TextSize / 2);
touchMatrix = TouchManager.OneFingerManipulate(prevPoint, newPoint, pivotPoint);
} }
//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 System;
using SkiaSharp; //using SkiaSharp;
namespace TheGameExtreme.view //namespace TheGameExtreme.view
{ //{
public class TouchManipulationManager // 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) // public TouchManipulationMode Mode { set; get; }
{
if (Mode == TouchManipulationMode.None)
{
return SKMatrix.MakeIdentity();
}
SKMatrix touchMatrix = SKMatrix.MakeIdentity(); // //float Magnitude(SKPoint point)
SKPoint delta = newPoint - prevPoint; // //{
// // return (float)Math.Sqrt(Math.Pow(point.X, 2) + Math.Pow(point.Y, 2));
// //}
//if (Mode == TouchManipulationMode.ScaleDualRotate) // One-finger rotation // public SKMatrix OneFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
// { // {
// SKPoint oldVector = prevPoint - pivotPoint; // if (Mode == TouchManipulationMode.None)
// 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); // return SKMatrix.MakeIdentity();
// float newAngle = (float)Math.Atan2(newVector.Y, newVector.X); // }
// // Calculate rotation matrix // SKMatrix touchMatrix = SKMatrix.MakeIdentity();
// float angle = newAngle - prevAngle; // SKPoint delta = newPoint - prevPoint;
// touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
// // Effectively rotate the old vector // //if (Mode == TouchManipulationMode.ScaleDualRotate) // One-finger rotation
// float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector); // //{
// oldVector.X = magnitudeRatio * newVector.X; // // SKPoint oldVector = prevPoint - pivotPoint;
// oldVector.Y = magnitudeRatio * newVector.Y; // // SKPoint newVector = newPoint - pivotPoint;
// // Recalculate delta // // // Avoid rotation if fingers are too close to center
// delta = newVector - oldVector; // // 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);
// Multiply the rotation matrix by a translation matrix // // // Calculate rotation matrix
SKMatrix.PostConcat(ref touchMatrix, SKMatrix.MakeTranslation(delta.X, delta.Y)); // // float angle = newAngle - prevAngle;
// // touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
return touchMatrix; // // // Effectively rotate the old vector
} // // float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector);
// // oldVector.X = magnitudeRatio * newVector.X;
// // oldVector.Y = magnitudeRatio * newVector.Y;
public SKMatrix TwoFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint) // // // Recalculate delta
{ // // delta = newVector - oldVector;
SKMatrix touchMatrix = SKMatrix.MakeIdentity(); // // }
//SKPoint oldVector = prevPoint - pivotPoint; // //}
//SKPoint newVector = newPoint - pivotPoint;
//if (Mode == TouchManipulationMode.ScaleRotate || // // Multiply the rotation matrix by a translation matrix
// Mode == TouchManipulationMode.ScaleDualRotate) // SKMatrix.PostConcat(ref touchMatrix, SKMatrix.MakeTranslation(delta.X, delta.Y));
//{
// // 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; // return touchMatrix;
float scaleY = 1; // }
//if (Mode == TouchManipulationMode.AnisotropicScale) // public SKMatrix TwoFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
// { // {
// scaleX = newVector.X / oldVector.X; // SKMatrix touchMatrix = SKMatrix.MakeIdentity();
// scaleY = newVector.Y / oldVector.Y; // //SKPoint oldVector = prevPoint - pivotPoint;
// //SKPoint newVector = newPoint - pivotPoint;
//}
//else if (Mode == TouchManipulationMode.IsotropicScale || // //if (Mode == TouchManipulationMode.ScaleRotate ||
// Mode == TouchManipulationMode.ScaleRotate || // // Mode == TouchManipulationMode.ScaleDualRotate)
// 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))
// { // {
// scaleX = scaleY = Magnitude(newVector) / Magnitude(oldVector); // SKMatrix.PostConcat(ref touchMatrix,
// SKMatrix.MakeScale(scaleX, scaleY, pivotPoint.X, pivotPoint.Y));
// } // }
if (!float.IsNaN(scaleX) && !float.IsInfinity(scaleX) && // return touchMatrix;
!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