Drag AND Drop

master
cldupland 6 years ago
parent 5d8aec3ade
commit 426a3ce6f8

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

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

@ -25,9 +25,10 @@ namespace TheGameExtreme.view
List<string> playersNames; List<string> playersNames;
TouchManipulationBitmap bitmap; TouchManipulationBitmap textPaint;
List<TouchManipulationBitmap> bitmapCollection = new List<TouchManipulationBitmap>(); List<TouchManipulationBitmap> textCollection = new List<TouchManipulationBitmap>();
Dictionary<long, TouchManipulationBitmap> bitmapDictionary = new Dictionary<long, TouchManipulationBitmap>(); List<TouchManipulationBitmap> stackCollection = new List<TouchManipulationBitmap>();
Dictionary<long, TouchManipulationBitmap> textDictionary = new Dictionary<long, TouchManipulationBitmap>();
@ -38,32 +39,8 @@ namespace TheGameExtreme.view
InitializeComponent(); InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false); 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.Text = "Retry";
//button.Clicked += retry; //button.Clicked += retry;
@ -71,8 +48,6 @@ namespace TheGameExtreme.view
//viewmodel.BindingChanged += OnBindingChanged; //viewmodel.BindingChanged += OnBindingChanged;
//viewmodel.PlayerChanged += OnPlayerChanged;
viewmodel.AlertChanged += OnAlertChanged; viewmodel.AlertChanged += OnAlertChanged;
pseudo.SetBinding(Label.TextProperty, new Binding("Pseudo", source: viewmodel)); 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; SKCanvas canvas = args.Surface.Canvas;
canvas.Clear(); 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) switch (args.Type)
{ {
case TouchActionType.Pressed: 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 // Move bitmap to end of collection
bitmapCollection.Remove(bitmap); textCollection.Remove(textPaint);
bitmapCollection.Add(bitmap); textCollection.Add(textPaint);
// Do the touch processing // Do the touch processing
bitmapDictionary.Add(args.Id, bitmap); textDictionary.Add(args.Id, textPaint);
bitmap.ProcessTouchEvent(args.Id, args.Type, point); textPaint.ProcessTouchEvent(args.Id, args.Type, point, stackCollection);
canvasView.InvalidateSurface(); canvasView.InvalidateSurface();
break; break;
} }
@ -137,82 +115,78 @@ namespace TheGameExtreme.view
break; break;
case TouchActionType.Moved: case TouchActionType.Moved:
if (bitmapDictionary.ContainsKey(args.Id)) if (textDictionary.ContainsKey(args.Id))
{ {
TouchManipulationBitmap bitmap = bitmapDictionary[args.Id]; TouchManipulationBitmap bitmap = textDictionary[args.Id];
bitmap.ProcessTouchEvent(args.Id, args.Type, point); bitmap.ProcessTouchEvent(args.Id, args.Type, point, stackCollection);
canvasView.InvalidateSurface(); canvasView.InvalidateSurface();
} }
break; break;
case TouchActionType.Released: case TouchActionType.Released:
case TouchActionType.Cancelled: case TouchActionType.Cancelled:
if (bitmapDictionary.ContainsKey(args.Id)) if (textDictionary.ContainsKey(args.Id))
{ {
TouchManipulationBitmap bitmap = bitmapDictionary[args.Id]; TouchManipulationBitmap bitmap = textDictionary[args.Id];
bitmap.ProcessTouchEvent(args.Id, args.Type, point); bitmap.ProcessTouchEvent(args.Id, args.Type, point, stackCollection);
bitmapDictionary.Remove(args.Id); textDictionary.Remove(args.Id);
canvasView.InvalidateSurface(); canvasView.InvalidateSurface();
} }
break; break;
} }
} }
public void OnTouchModePickerSelectedIndexChanged(object sender, EventArgs args) //public void OnTouchModePickerSelectedIndexChanged(object sender, EventArgs args)
{ //{
if (bitmap != null) // if (textPaint != null)
{ // {
Picker picker = (Picker)sender; // Picker picker = (Picker)sender;
bitmap.TouchManager.Mode = (TouchManipulationMode)picker.SelectedItem; // 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) position.X += textPaint.MeasureText("1") + (float)(DeviceDisplay.MainDisplayInfo.Width * 0.15);
//{ }
// inflateHand(); }
//}
private void InflateHand() private void InflateHand()
{ {
//Hand.Children.Clear(); textCollection.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; SKPoint position = new SKPoint(100, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.2));
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 < viewmodel.CurrentHand.Count; i++) for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
{ {
using (Stream stream = assembly.GetManifestResourceStream(resourceID)) SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString());
textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value.ToString())
{ {
SKBitmap bitmap = SKBitmap.Decode(stream).Resize(new SKImageInfo(225, 225), SKFilterQuality.High); Matrix = SKMatrix.MakeTranslation(position.X, position.Y - textPaint.TextSize),
InitialPoint = position
});
bitmapCollection.Add(new TouchManipulationBitmap(bitmap) position.X += textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString()) + 50;
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y - bitmap.Height),
});
position.X += bitmap.Width + 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) private void retry(object sender, EventArgs args)
{ {
viewmodel = new Main(playersNames); viewmodel = new Main(playersNames);
@ -300,12 +256,9 @@ namespace TheGameExtreme.view
pseudo.SetBinding(Label.TextProperty, new Binding("Pseudo", source: viewmodel)); pseudo.SetBinding(Label.TextProperty, new Binding("Pseudo", source: viewmodel));
inflateHand(); InflateStack();
//pile0.Text = "1"; InflateHand();
//pile1.Text = "1";
//pile2.Text = "100";
//pile3.Text = "100";
gameOption.Children.Clear(); gameOption.Children.Clear();
gameOption.Children.Add(button); gameOption.Children.Add(button);
@ -324,7 +277,7 @@ namespace TheGameExtreme.view
} }
else else
{ {
inflateHand(); InflateHand();
} }
} }

@ -6,17 +6,21 @@ namespace TheGameExtreme.view
{ {
public class TouchManipulationBitmap public class TouchManipulationBitmap
{ {
SKBitmap bitmap; public SKPoint InitialPoint { get; set; }
SKPaint textPaint;
Dictionary<long, TouchManipulationInfo> touchDictionary = new Dictionary<long, TouchManipulationInfo>(); 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(); Matrix = SKMatrix.MakeIdentity();
TouchManager = new TouchManipulationManager TouchManager = new TouchManipulationManager
{ {
Mode = TouchManipulationMode.IsotropicScale Mode = TouchManipulationMode.PanOnly
}; };
} }
@ -26,10 +30,14 @@ namespace TheGameExtreme.view
public void Paint(SKCanvas canvas) public void Paint(SKCanvas canvas)
{ {
this.canvas = canvas;
canvas.Save(); canvas.Save();
SKMatrix matrix = Matrix; SKMatrix matrix = Matrix;
canvas.Concat(ref 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(); canvas.Restore();
} }
@ -44,13 +52,13 @@ 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, bitmap.Width, bitmap.Height); SKRect rect = new SKRect(0, 0, textPaint.MeasureText(value), textPaint.TextSize);
return rect.Contains(transformedPoint); return rect.Contains(transformedPoint);
} }
return false; 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) switch (type)
{ {
@ -70,9 +78,22 @@ namespace TheGameExtreme.view
break; break;
case TouchActionType.Released: case TouchActionType.Released:
touchDictionary[id].NewPoint = location; bool find = false;
Manipulate(); foreach (TouchManipulationBitmap stack in stackCollection)
touchDictionary.Remove(id); {
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; break;
case TouchActionType.Cancelled: case TouchActionType.Cancelled:
@ -91,7 +112,7 @@ namespace TheGameExtreme.view
{ {
SKPoint prevPoint = infos[0].PreviousPoint; SKPoint prevPoint = infos[0].PreviousPoint;
SKPoint newPoint = infos[0].NewPoint; 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); touchMatrix = TouchManager.OneFingerManipulate(prevPoint, newPoint, pivotPoint);
} }

Loading…
Cancel
Save