Drag AND Drop

master
cldupland 6 years ago
parent 5d8aec3ade
commit 426a3ce6f8

@ -1,11 +1,11 @@
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// Ce code a été généré par un outil.
// Version du runtime :4.0.30319.42000
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
// le code est régénéré.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

@ -11,7 +11,8 @@
mc:Ignorable="d"
x:Class="TheGameExtreme.view.MainPage">
<Grid>
<Grid
x:Name="Display">
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="90*"/>
@ -22,12 +23,6 @@
<ColumnDefinition Width="15*"/>
</Grid.ColumnDefinitions>
<Grid.Effects>
<tt:TouchEffect
Capture="True"
TouchAction="OnTouchEffectAction" />
</Grid.Effects>
@ -42,7 +37,7 @@
VerticalTextAlignment="Center"
TextColor="{DynamicResource WhiteColor}"
FontSize="28"/>
<Picker Title="Touch Mode"
<!--<Picker Title="Touch Mode"
Grid.Row="0"
SelectedIndexChanged="OnTouchModePickerSelectedIndexChanged">
<Picker.ItemsSource>
@ -58,7 +53,7 @@
<Picker.SelectedIndex>
4
</Picker.SelectedIndex>
</Picker>
</Picker>-->
</StackLayout>
@ -148,13 +143,20 @@
</Grid>-->
<Grid
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3">
<Grid.Effects>
<tt:TouchEffect
Capture="True"
TouchAction="OnTouchEffectAction" />
</Grid.Effects>
<skia:SKCanvasView
x:Name="canvasView"
PaintSurface="OnCanvasViewPaintSurface"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Grid.ColumnSpan="3"/>
PaintSurface="OnCanvasViewPaintSurface"/>
</Grid>

@ -25,9 +25,10 @@ namespace TheGameExtreme.view
List<string> playersNames;
TouchManipulationBitmap bitmap;
List<TouchManipulationBitmap> bitmapCollection = new List<TouchManipulationBitmap>();
Dictionary<long, TouchManipulationBitmap> bitmapDictionary = new Dictionary<long, TouchManipulationBitmap>();
TouchManipulationBitmap textPaint;
List<TouchManipulationBitmap> textCollection = new List<TouchManipulationBitmap>();
List<TouchManipulationBitmap> stackCollection = new List<TouchManipulationBitmap>();
Dictionary<long, TouchManipulationBitmap> textDictionary = new Dictionary<long, TouchManipulationBitmap>();
@ -38,32 +39,8 @@ namespace TheGameExtreme.view
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
//Assembly assembly = GetType().GetTypeInfo().Assembly;
InflateStack();
////string[] resourceIDs = assembly.GetManifestResourceNames();
//string resourceID = "TheGameExtreme.Media.thegame.jpg";
//SKPoint position = new SKPoint(100, (float)(DeviceDisplay.MainDisplayInfo.Height - 0.2 * DeviceDisplay.MainDisplayInfo.Height));
//for (int i = 0; i < 8; i++)
//{
// using (Stream stream = assembly.GetManifestResourceStream(resourceID))
// {
// SKBitmap bitmap = SKBitmap.Decode(stream).Resize(new SKImageInfo(225, 225), SKFilterQuality.High);
// bitmapCollection.Add(new TouchManipulationBitmap(bitmap)
// {
// Matrix = SKMatrix.MakeTranslation(position.X, position.Y - bitmap.Height),
// });
// position.X += bitmap.Width + 50;
// }
//}
//stacks.Add(checkbox0);
//stacks.Add(checkbox1);
//stacks.Add(checkbox2);
//stacks.Add(checkbox3);
//button.Text = "Retry";
//button.Clicked += retry;
@ -71,8 +48,6 @@ namespace TheGameExtreme.view
//viewmodel.BindingChanged += OnBindingChanged;
//viewmodel.PlayerChanged += OnPlayerChanged;
viewmodel.AlertChanged += OnAlertChanged;
pseudo.SetBinding(Label.TextProperty, new Binding("Pseudo", source: viewmodel));
@ -92,17 +67,20 @@ namespace TheGameExtreme.view
public void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) // Faire plusieurs canvas
public void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKCanvas canvas = args.Surface.Canvas;
canvas.Clear();
foreach (TouchManipulationBitmap bitmap in bitmapCollection)
foreach (TouchManipulationBitmap textPaint in stackCollection)
{
bitmap.Paint(canvas);
textPaint.Paint(canvas);
}
foreach (TouchManipulationBitmap textPaint in textCollection)
{
textPaint.Paint(canvas);
}
}
@ -117,19 +95,19 @@ namespace TheGameExtreme.view
switch (args.Type)
{
case TouchActionType.Pressed:
for (int i = bitmapCollection.Count - 1; i >= 0; i--)
for (int i = textCollection.Count - 1; i >= 0; i--)
{
TouchManipulationBitmap bitmap = bitmapCollection[i];
TouchManipulationBitmap textPaint = textCollection[i];
if (bitmap.HitTest(point))
if (textPaint.HitTest(point))
{
// Move bitmap to end of collection
bitmapCollection.Remove(bitmap);
bitmapCollection.Add(bitmap);
textCollection.Remove(textPaint);
textCollection.Add(textPaint);
// Do the touch processing
bitmapDictionary.Add(args.Id, bitmap);
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
textDictionary.Add(args.Id, textPaint);
textPaint.ProcessTouchEvent(args.Id, args.Type, point, stackCollection);
canvasView.InvalidateSurface();
break;
}
@ -137,82 +115,78 @@ namespace TheGameExtreme.view
break;
case TouchActionType.Moved:
if (bitmapDictionary.ContainsKey(args.Id))
if (textDictionary.ContainsKey(args.Id))
{
TouchManipulationBitmap bitmap = bitmapDictionary[args.Id];
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
TouchManipulationBitmap bitmap = textDictionary[args.Id];
bitmap.ProcessTouchEvent(args.Id, args.Type, point, stackCollection);
canvasView.InvalidateSurface();
}
break;
case TouchActionType.Released:
case TouchActionType.Cancelled:
if (bitmapDictionary.ContainsKey(args.Id))
if (textDictionary.ContainsKey(args.Id))
{
TouchManipulationBitmap bitmap = bitmapDictionary[args.Id];
bitmap.ProcessTouchEvent(args.Id, args.Type, point);
bitmapDictionary.Remove(args.Id);
TouchManipulationBitmap bitmap = textDictionary[args.Id];
bitmap.ProcessTouchEvent(args.Id, args.Type, point, stackCollection);
textDictionary.Remove(args.Id);
canvasView.InvalidateSurface();
}
break;
}
}
public void OnTouchModePickerSelectedIndexChanged(object sender, EventArgs args)
{
if (bitmap != null)
{
Picker picker = (Picker)sender;
bitmap.TouchManager.Mode = (TouchManipulationMode)picker.SelectedItem;
}
}
//public void OnTouchModePickerSelectedIndexChanged(object sender, EventArgs args)
//{
// if (textPaint != null)
// {
// Picker picker = (Picker)sender;
// textPaint.TouchManager.Mode = (TouchManipulationMode)picker.SelectedItem;
// }
//}
private void InflateStack()
{
stackCollection.Clear();
SKPoint position = new SKPoint(150, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01));
for (int i = 0; i < 5; i++)
{
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("1");
textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
stackCollection.Add(new TouchManipulationBitmap(textPaint, "1")
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y + textPaint.TextSize),
InitialPoint = position
});
//private void OnPlayerChanged(object sender, PlayerChangedEventArgs args)
//{
// inflateHand();
//}
position.X += textPaint.MeasureText("1") + (float)(DeviceDisplay.MainDisplayInfo.Width * 0.15);
}
}
private void InflateHand()
{
//Hand.Children.Clear();
//for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
//{
// Button card = new Button();
// card.Text = viewmodel.CurrentHand[i].Value.ToString();
// card.Clicked += played;
// Hand.Children.Add(card);
//}
bitmapCollection.Clear();
Assembly assembly = GetType().GetTypeInfo().Assembly;
textCollection.Clear();
string resourceID = "TheGameExtreme.Media.thegame.jpg";
SKPoint position = new SKPoint(100, (float)(DeviceDisplay.MainDisplayInfo.Height - 0.2 * DeviceDisplay.MainDisplayInfo.Height));
SKPoint position = new SKPoint(100, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.2));
for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
{
using (Stream stream = assembly.GetManifestResourceStream(resourceID))
{
SKBitmap bitmap = SKBitmap.Decode(stream).Resize(new SKImageInfo(225, 225), SKFilterQuality.High);
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString());
textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
bitmapCollection.Add(new TouchManipulationBitmap(bitmap)
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value.ToString())
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y - bitmap.Height),
Matrix = SKMatrix.MakeTranslation(position.X, position.Y - textPaint.TextSize),
InitialPoint = position
});
position.X += bitmap.Width + 50;
}
position.X += textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString()) + 50;
}
}
@ -274,24 +248,6 @@ namespace TheGameExtreme.view
}
}
//private void radioButton(object sender, EventArgs args)
//{
// if (isFirst)
// {
// isFirst = false;
// stacks.ForEach(checkbox =>
// {
// if (!checkbox.Equals(sender))
// {
// checkbox.IsChecked = false;
// }
// });
// isFirst = true;
// }
//}
private void retry(object sender, EventArgs args)
{
viewmodel = new Main(playersNames);
@ -300,12 +256,9 @@ namespace TheGameExtreme.view
pseudo.SetBinding(Label.TextProperty, new Binding("Pseudo", source: viewmodel));
inflateHand();
InflateStack();
//pile0.Text = "1";
//pile1.Text = "1";
//pile2.Text = "100";
//pile3.Text = "100";
InflateHand();
gameOption.Children.Clear();
gameOption.Children.Add(button);
@ -324,7 +277,7 @@ namespace TheGameExtreme.view
}
else
{
inflateHand();
InflateHand();
}
}

@ -6,17 +6,21 @@ namespace TheGameExtreme.view
{
public class TouchManipulationBitmap
{
SKBitmap bitmap;
public SKPoint InitialPoint { get; set; }
SKPaint textPaint;
Dictionary<long, TouchManipulationInfo> touchDictionary = new Dictionary<long, TouchManipulationInfo>();
string value;
SKCanvas canvas;
public TouchManipulationBitmap(SKBitmap bitmap)
public TouchManipulationBitmap(SKPaint textPaint, string value)
{
this.bitmap = bitmap;
this.textPaint = textPaint;
this.value = value;
Matrix = SKMatrix.MakeIdentity();
TouchManager = new TouchManipulationManager
{
Mode = TouchManipulationMode.IsotropicScale
Mode = TouchManipulationMode.PanOnly
};
}
@ -26,10 +30,14 @@ namespace TheGameExtreme.view
public void Paint(SKCanvas canvas)
{
this.canvas = canvas;
canvas.Save();
SKMatrix matrix = Matrix;
canvas.Concat(ref matrix);
canvas.DrawBitmap(bitmap, 0, 0);
textPaint.Color = SKColors.Red;
SKRect textBounds = new SKRect();
textPaint.MeasureText(value, ref textBounds);
canvas.DrawText(value, 0, 0, textPaint);
canvas.Restore();
}
@ -44,13 +52,13 @@ namespace TheGameExtreme.view
SKPoint transformedPoint = inverseMatrix.MapPoint(location);
// Check if it's in the untransformed bitmap rectangle
SKRect rect = new SKRect(0, 0, bitmap.Width, bitmap.Height);
SKRect rect = new SKRect(0, 0, textPaint.MeasureText(value), textPaint.TextSize);
return rect.Contains(transformedPoint);
}
return false;
}
public void ProcessTouchEvent(long id, TouchActionType type, SKPoint location)
public void ProcessTouchEvent(long id, TouchActionType type, SKPoint location, List<TouchManipulationBitmap> stackCollection)
{
switch (type)
{
@ -70,9 +78,22 @@ namespace TheGameExtreme.view
break;
case TouchActionType.Released:
touchDictionary[id].NewPoint = location;
bool find = false;
foreach (TouchManipulationBitmap stack in stackCollection)
{
if (stack.HitTest(location))
{
stackCollection[stackCollection.IndexOf(stack)] = this;
break;
}
}
if (!find)
{
touchDictionary[id].NewPoint = InitialPoint;
Manipulate();
touchDictionary[id].PreviousPoint = touchDictionary[id].NewPoint;
touchDictionary.Remove(id);
}
break;
case TouchActionType.Cancelled:
@ -91,7 +112,7 @@ namespace TheGameExtreme.view
{
SKPoint prevPoint = infos[0].PreviousPoint;
SKPoint newPoint = infos[0].NewPoint;
SKPoint pivotPoint = Matrix.MapPoint(bitmap.Width / 2, bitmap.Height / 2);
SKPoint pivotPoint = Matrix.MapPoint(textPaint.MeasureText(value) / 2, textPaint.TextSize / 2);
touchMatrix = TouchManager.OneFingerManipulate(prevPoint, newPoint, pivotPoint);
}

Loading…
Cancel
Save