Resolution d'erreur de drag and drop

master
cldupland 5 years ago
parent 5cf93de6d3
commit 3ddba28071

@ -109,6 +109,7 @@ namespace TheGameExtreme.model.manager
}
else
{
parametreur.GameMode.TestEndGame(currentHand);
EndMessage = parametreur.GameMode.Message;
if (win)
{

@ -144,7 +144,6 @@ namespace TheGameExtreme.view
{
point = stack.InitialPoint;
bitmap.ProcessTouchEvent(args.Id, TouchActionType.Moved, point);
canvasView.InvalidateSurface();
bitmap.InitialPoint = stackCollection[stackCollection.IndexOf(stack)].InitialPoint;
stackCollection[stackCollection.IndexOf(stack)] = bitmap;
textCollection.RemoveAt(textCollection.Count - 1);
@ -157,7 +156,6 @@ namespace TheGameExtreme.view
{
point = bitmap.InitialPoint;
bitmap.ProcessTouchEvent(args.Id, TouchActionType.Moved, point);
canvasView.InvalidateSurface();
}
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
textDictionary.Remove(args.Id);
@ -184,7 +182,7 @@ namespace TheGameExtreme.view
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("001");
float textSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.05) - (textWidth * 0.5)), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01 + 2 * textSize));
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / (viewmodel.getListOrderedStacks().Count * 2)) - textPaint.MeasureText("01"), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01 + 2 * textSize));
for (int i = 0; i < viewmodel.getListOrderedStacks().Count; i++)
{
@ -206,7 +204,7 @@ namespace TheGameExtreme.view
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("001");
float textSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
SKPoint position = new SKPoint((float)(DeviceDisplay.MainDisplayInfo.Width * 0.05), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.2 - textSize));
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / (viewmodel.CurrentHand.Count * 2)) - textPaint.MeasureText("01"), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.2 - textSize));
for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
{

@ -15,14 +15,14 @@ namespace TheGameExtreme.view
{
this.textPaint = textPaint;
Value = value.ToString();
//if (value > 0 && value < 10)
//{
// Value = "0" + value.ToString();
//}
//else
//{
// Value = value.ToString();
//}
if (value > -10 && value < 10)
{
Value = "0" + value.ToString();
}
else
{
Value = value.ToString();
}
Matrix = SKMatrix.MakeIdentity();
@ -50,7 +50,7 @@ namespace TheGameExtreme.view
SKRect textBounds = new SKRect();
textPaint.MeasureText(Value, ref textBounds);
SKRoundRect card = new SKRoundRect(textBounds);
SKRoundRect card = new SKRoundRect(textBounds, 1f, 1f);
card.Inflate(35, 55);
@ -77,7 +77,7 @@ namespace TheGameExtreme.view
SKPoint transformedPoint = inverseMatrix.MapPoint(location);
// Check if it's in the untransformed bitmap rectangle
SKRect rect = new SKRect(0, 0, textPaint.MeasureText(Value), textPaint.TextSize);
SKRect rect = new SKRect(-70, -110, textPaint.MeasureText(Value) + 35, textPaint.TextSize);
return rect.Contains(transformedPoint);
}
return false;
@ -116,14 +116,14 @@ namespace TheGameExtreme.view
touchDictionary.Values.CopyTo(infos, 0);
SKMatrix touchMatrix = SKMatrix.MakeIdentity();
//if (infos.Length == 1)
//{
if (infos.Length == 1)
{
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);
//}
}
//else if (infos.Length >= 2)
//{
// int pivotIndex = infos[0].NewPoint == infos[0].PreviousPoint ? 0 : 1;

@ -8,10 +8,10 @@ namespace TheGameExtreme.view
public TouchManipulationMode Mode { set; get; }
float Magnitude(SKPoint point)
{
return (float)Math.Sqrt(Math.Pow(point.X, 2) + Math.Pow(point.Y, 2));
}
//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)
{
@ -23,30 +23,30 @@ namespace TheGameExtreme.view
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;
}
}
//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));
@ -57,47 +57,47 @@ namespace TheGameExtreme.view
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;
}
//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;
//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);
}
//}
//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));
SKMatrix.MakeScale(scaleX, scaleY, pivotPoint.X, pivotPoint.Y));
}
return touchMatrix;

Loading…
Cancel
Save