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 else
{ {
parametreur.GameMode.TestEndGame(currentHand);
EndMessage = parametreur.GameMode.Message; EndMessage = parametreur.GameMode.Message;
if (win) if (win)
{ {

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

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

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

Loading…
Cancel
Save