Brought back all the graphics/finger paint views!
This commit is contained in:
Родитель
f1fff14111
Коммит
522f1c3200
|
@ -1,93 +1,62 @@
|
|||
//using System.Collections.Generic;
|
||||
//
|
||||
//using Comet.Skia;
|
||||
//using SkiaSharp;
|
||||
using System.Collections.Generic;
|
||||
namespace Comet.Samples
|
||||
{
|
||||
public class BindableFingerPaint : SimpleFingerPaint, IDrawable, IGraphicsView
|
||||
{
|
||||
private Binding<double> _strokeWidth = 2;
|
||||
private Binding<Color> _strokeColor = Colors.Black;
|
||||
|
||||
//namespace Comet.Samples.Skia
|
||||
//{
|
||||
// public class BindableFingerPaint : SimpleFingerPaint
|
||||
// {
|
||||
// private readonly List<List<PointF>> _pointsLists = new List<List<PointF>>();
|
||||
// private Binding<float> _strokeWidth = 2f;
|
||||
// private Binding<string> _strokeColor = "#00FF00";
|
||||
public BindableFingerPaint(
|
||||
Binding<double> strokeSize = null,
|
||||
Binding<Color> strokeColor = null)
|
||||
{
|
||||
StrokeWidth = strokeSize;
|
||||
StrokeColor = strokeColor;
|
||||
}
|
||||
|
||||
// public BindableFingerPaint(
|
||||
// Binding<float> strokeSize = null,
|
||||
// Binding<string> strokeColor = null)
|
||||
// {
|
||||
// StrokeWidth = strokeSize;
|
||||
// StrokeColor = strokeColor;
|
||||
// }
|
||||
public Binding<double> StrokeWidth
|
||||
{
|
||||
get => _strokeWidth;
|
||||
private set => this.SetBindingValue(ref _strokeWidth, value);
|
||||
}
|
||||
|
||||
// public Binding<float> StrokeWidth
|
||||
// {
|
||||
// get => _strokeWidth;
|
||||
// private set => SetBindingValue(ref _strokeWidth, value);
|
||||
// }
|
||||
public Binding<Color> StrokeColor
|
||||
{
|
||||
get => _strokeColor;
|
||||
private set => this.SetBindingValue(ref _strokeColor, value);
|
||||
}
|
||||
|
||||
// public Binding<string> StrokeColor
|
||||
// {
|
||||
// get => _strokeColor;
|
||||
// private set => SetBindingValue(ref _strokeColor, value);
|
||||
// }
|
||||
public override void ViewPropertyChanged(string property, object value)
|
||||
{
|
||||
base.ViewPropertyChanged(property, value);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
// public override void Draw(SKCanvas canvas, RectangleF dirtyRect)
|
||||
// {
|
||||
// canvas.Clear(SKColors.White);
|
||||
void IDrawable.Draw(ICanvas canvas, RectF dirtyRect)
|
||||
{
|
||||
//var paint = new SolidPaint(Colors.Blue);
|
||||
canvas.StrokeColor = _strokeColor;
|
||||
canvas.StrokeSize = (float)_strokeWidth.CurrentValue;
|
||||
|
||||
// var color = new Color(_strokeColor);
|
||||
foreach (var pointsList in _pointsLists)
|
||||
{
|
||||
for (var i = 0; i < pointsList.Count; i++)
|
||||
{
|
||||
var point = pointsList[i];
|
||||
if (i > 0)
|
||||
{
|
||||
var lastPoint = pointsList[i - 1];
|
||||
canvas.DrawLine(lastPoint.X, lastPoint.Y, point.X, point.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// var paint = new SKPaint()
|
||||
// {
|
||||
// Color = color.ToSKColor(),
|
||||
// StrokeWidth = StrokeWidth,
|
||||
// Style = SKPaintStyle.Stroke
|
||||
// };
|
||||
|
||||
// foreach (var pointsList in _pointsLists)
|
||||
// {
|
||||
// var path = new SKPath();
|
||||
// for (var i = 0; i < pointsList.Count; i++)
|
||||
// {
|
||||
// var point = pointsList[i];
|
||||
// if (i == 0)
|
||||
// path.MoveTo(point.X, point.Y);
|
||||
// else
|
||||
// path.LineTo(point.X, point.Y);
|
||||
// }
|
||||
// canvas.DrawPath(path, paint);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public override bool StartInteraction(PointF[] points)
|
||||
// {
|
||||
// var pointsList = new List<PointF> { points[0] };
|
||||
// _pointsLists.Add(pointsList);
|
||||
|
||||
// Invalidate();
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public override void DragInteraction(PointF[] points)
|
||||
// {
|
||||
// var pointsList = _pointsLists[_pointsLists.Count - 1];
|
||||
// pointsList.Add(points[0]);
|
||||
|
||||
// Invalidate();
|
||||
// }
|
||||
|
||||
// public override void EndInteraction(PointF[] points)
|
||||
// {
|
||||
// var pointsList = _pointsLists[_pointsLists.Count - 1];
|
||||
// pointsList.Add(points[0]);
|
||||
|
||||
// Invalidate();
|
||||
// }
|
||||
|
||||
// public void Reset()
|
||||
// {
|
||||
// _pointsLists.Clear();
|
||||
// Invalidate();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
public void Reset()
|
||||
{
|
||||
_pointsLists.Clear();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using Comet.Graphics;
|
||||
using Microsoft.Maui.Graphics;
|
||||
|
||||
namespace Comet.Samples.Skia
|
||||
namespace Comet.Samples
|
||||
{
|
||||
public class GraphicsSample5 : View
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Comet.Graphics;
|
||||
using Microsoft.Maui.Graphics;
|
||||
namespace Comet.Samples.Skia
|
||||
namespace Comet.Samples
|
||||
{
|
||||
public class GraphicsSample6 : View
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Comet.Samples
|
|||
{
|
||||
public class SimpleFingerPaint : GraphicsView, IDrawable, IGraphicsView
|
||||
{
|
||||
private readonly List<List<PointF>> _pointsLists = new List<List<PointF>>();
|
||||
protected readonly List<List<PointF>> _pointsLists = new List<List<PointF>>();
|
||||
|
||||
void IDrawable.Draw(ICanvas canvas, RectF dirtyRect)
|
||||
{
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Comet.Skia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
//namespace Comet.Samples.Skia
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// This example shows the cleaner way to use a drawable control. A control delegate can be
|
||||
// /// implicitly converted into a drawable control, so there is no need to wrap it like in
|
||||
// /// SkiaSample1.
|
||||
// /// </summary>
|
||||
// public class SkiaSample2 : View
|
||||
// {
|
||||
// [Body]
|
||||
// View body() => new SimpleFingerPaint();
|
||||
namespace Comet.Samples
|
||||
{
|
||||
/// <summary>
|
||||
/// This example shows the cleaner way to use a drawable control. A control delegate can be
|
||||
/// implicitly converted into a drawable control, so there is no need to wrap it like in
|
||||
/// SkiaSample1.
|
||||
/// </summary>
|
||||
public class SkiaSample2 : View
|
||||
{
|
||||
[Body]
|
||||
View body() => new SimpleFingerPaint();
|
||||
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +1,45 @@
|
|||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Comet.Skia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
//namespace Comet.Samples.Skia
|
||||
//{
|
||||
// public class SkiaSample3 : View
|
||||
// {
|
||||
// readonly State<float> _strokeSize = 2;
|
||||
// readonly State<string> _strokeColor = "#000000";
|
||||
namespace Comet.Samples
|
||||
{
|
||||
public class SkiaSample3 : View
|
||||
{
|
||||
readonly State<double> _strokeSize = 2;
|
||||
readonly State<Color> _strokeColor = Colors.Black;
|
||||
|
||||
// [Body]
|
||||
// View body() => new VStack()
|
||||
// {
|
||||
// new VStack()
|
||||
// {
|
||||
// new HStack()
|
||||
// {
|
||||
// new Text("Stroke Width:"),
|
||||
// new Slider(_strokeSize, 1, 10, 1)
|
||||
// },
|
||||
// new HStack()
|
||||
// {
|
||||
// new Text("Stroke Color!:"),
|
||||
// new TextField(_strokeColor),
|
||||
// },
|
||||
// //new ScrollView{
|
||||
// new HStack
|
||||
// {
|
||||
// new Button("Black", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Black.ToHexString();
|
||||
// }).Color(Colors.Black),
|
||||
// new Button("Blue", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Blue.ToHexString();
|
||||
// }).Color(Colors.Blue),
|
||||
// new Button("Red", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Red.ToHexString();
|
||||
// }).Color(Colors.Red),
|
||||
// },
|
||||
// //},
|
||||
// new BindableFingerPaint(
|
||||
// strokeSize:_strokeSize,
|
||||
// strokeColor:_strokeColor).ToView().Frame(height:400)
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
[Body]
|
||||
View body() =>
|
||||
new VStack()
|
||||
{
|
||||
new HStack()
|
||||
{
|
||||
new Text("Stroke Width:"),
|
||||
new Slider(_strokeSize, 1, 10).FillHorizontal()
|
||||
}.FillHorizontal(),
|
||||
|
||||
new Text("Stroke Color!:").HorizontalTextAlignment(TextAlignment.Center),
|
||||
//new ScrollView{
|
||||
new HStack
|
||||
{
|
||||
new Button("Black", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Black;
|
||||
}).Color(Colors.Black),
|
||||
new Button("Blue", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Blue;
|
||||
}).Color(Colors.Blue),
|
||||
new Button("Red", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Red;
|
||||
}).Color(Colors.Red),
|
||||
}.Alignment(Alignment.Center),
|
||||
//},
|
||||
new BindableFingerPaint(
|
||||
strokeSize:_strokeSize,
|
||||
strokeColor:_strokeColor).Frame(width:400, height:400).RoundedBorder(color:Colors.White)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,76 +1,74 @@
|
|||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Comet.Skia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
//namespace Comet.Samples.Skia
|
||||
//{
|
||||
// public class SkiaSample3WithScrollView : View
|
||||
// {
|
||||
// readonly State<float> _strokeSize = 2;
|
||||
// readonly State<string> _strokeColor = "#000000";
|
||||
namespace Comet.Samples
|
||||
{
|
||||
public class SkiaSample3WithScrollView : View
|
||||
{
|
||||
readonly State<double> _strokeSize = 2;
|
||||
readonly State<Color> _strokeColor = Colors.Black;
|
||||
|
||||
// [Body]
|
||||
// View body() => new VStack()
|
||||
// {
|
||||
// new VStack()
|
||||
// {
|
||||
// new HStack()
|
||||
// {
|
||||
// new Text("Stroke Width:"),
|
||||
// new Slider(_strokeSize, 1, 10, 1)
|
||||
// },
|
||||
// new HStack()
|
||||
// {
|
||||
// new Text("Stroke Color!:"),
|
||||
// new TextField(_strokeColor),
|
||||
// },
|
||||
// new ScrollView(Orientation.Horizontal)
|
||||
// {
|
||||
// new HStack(spacing:8)
|
||||
// {
|
||||
// new Button("Black", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Black.ToHexString();
|
||||
// }),
|
||||
// new Button("Blue", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Blue.ToHexString();
|
||||
// }),
|
||||
// new Button("Red", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Red.ToHexString();
|
||||
// }),
|
||||
// new Button("Green", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Green.ToHexString();
|
||||
// }),
|
||||
// new Button("Orange", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Color.Orange.ToHexString();
|
||||
// }),
|
||||
// new Button("Yellow", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Color.Yellow.ToHexString();
|
||||
// }),
|
||||
// new Button("Brown", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Color.Brown.ToHexString();
|
||||
// }),
|
||||
// new Button("Salmon", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Colors.Salmon.ToHexString();
|
||||
// }),
|
||||
// new Button("Magenta", () =>
|
||||
// {
|
||||
// _strokeColor.Value = Color.Magenta.ToHexString();
|
||||
// })
|
||||
// },
|
||||
// },
|
||||
// new BindableFingerPaint(
|
||||
// strokeSize:_strokeSize,
|
||||
// strokeColor:_strokeColor).ToView().Frame(height:400)
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
[Body]
|
||||
View body() => new VStack()
|
||||
{
|
||||
new VStack()
|
||||
{
|
||||
new HStack()
|
||||
{
|
||||
new Text("Stroke Width:"),
|
||||
new Slider(_strokeSize, 1, 10).FillHorizontal()
|
||||
},
|
||||
new HStack()
|
||||
{
|
||||
new Text("Stroke Color!:"),
|
||||
},
|
||||
new ScrollView(Orientation.Horizontal)
|
||||
{
|
||||
new HStack(spacing:8)
|
||||
{
|
||||
new Button("Black", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Black;
|
||||
}),
|
||||
new Button("Blue", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Blue;
|
||||
}),
|
||||
new Button("Red", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Red;
|
||||
}),
|
||||
new Button("Green", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Green;
|
||||
}),
|
||||
new Button("Orange", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Orange;
|
||||
}),
|
||||
new Button("Yellow", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Yellow;
|
||||
}),
|
||||
new Button("Brown", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Brown;
|
||||
}),
|
||||
new Button("Salmon", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Salmon;
|
||||
}),
|
||||
new Button("Magenta", () =>
|
||||
{
|
||||
_strokeColor.Value = Colors.Magenta;
|
||||
})
|
||||
},
|
||||
},
|
||||
new BindableFingerPaint(
|
||||
strokeSize:_strokeSize,
|
||||
strokeColor:_strokeColor).Frame(height:400).FillHorizontal().Border(new Rectangle().Stroke(Colors.White,2))
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +1,38 @@
|
|||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Comet.Skia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
namespace Comet.Samples
|
||||
{
|
||||
public class SkiaSample4 : View
|
||||
{
|
||||
readonly State<double> _strokeSize = 2;
|
||||
readonly State<Color> _strokeColor = Colors.White ;
|
||||
|
||||
//namespace Comet.Samples.Skia
|
||||
//{
|
||||
// public class SkiaSample4 : View
|
||||
// {
|
||||
// readonly State<float> _strokeSize = 2;
|
||||
// readonly State<string> _strokeColor = "#000000";
|
||||
[Body]
|
||||
View body()
|
||||
{
|
||||
var fingerPaint = new BindableFingerPaint(
|
||||
strokeSize: _strokeSize,
|
||||
strokeColor: _strokeColor);
|
||||
|
||||
// [Body]
|
||||
// View body()
|
||||
// {
|
||||
// var fingerPaint = new BindableFingerPaint(
|
||||
// strokeSize: _strokeSize,
|
||||
// strokeColor: _strokeColor);
|
||||
|
||||
// return new VStack()
|
||||
// {
|
||||
// new VStack()
|
||||
// {
|
||||
// new HStack()
|
||||
// {
|
||||
// new Text("Stroke Width:"),
|
||||
// new Slider(_strokeSize, 1, 10, 1)
|
||||
// },
|
||||
// new HStack()
|
||||
// {
|
||||
// new Text("Stroke Color:"),
|
||||
// new TextField(_strokeColor)
|
||||
// },
|
||||
// new Button("Reset", () => fingerPaint.Reset()),
|
||||
// fingerPaint.ToView().Frame(height: 400)
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
return new VStack()
|
||||
{
|
||||
new VStack()
|
||||
{
|
||||
new HStack()
|
||||
{
|
||||
new Text("Stroke Width:"),
|
||||
new Slider(_strokeSize, 1, 10).FillHorizontal()
|
||||
},
|
||||
new HStack()
|
||||
{
|
||||
new Text("Stroke Color:"),
|
||||
new TextField(new Binding<string>(() => _strokeColor.Value.ToArgbHex(),(s) => _strokeColor.Value = Color.FromArgb(s)))
|
||||
},
|
||||
new Button("Reset", () => fingerPaint.Reset()),
|
||||
fingerPaint.Frame(height: 400)
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ namespace Comet.Samples
|
|||
new MenuItem("TextFieldSample3", ()=> new TextFieldSample3()),
|
||||
new MenuItem("TextFieldSample4", ()=> new TextFieldSample4()),
|
||||
new MenuItem("RadioButtonSample", ()=> new RadioButtonSample()),
|
||||
//new MenuItem("SkiaSample1 (FingerPaint)", ()=> new SkiaSample1()),
|
||||
//new MenuItem("SkiaSample2 (FingerPaint)", ()=> new SkiaSample2()),
|
||||
//new MenuItem("SkiaSample3 (BindableFingerPaint)", ()=> new SkiaSample3()),
|
||||
//new MenuItem("SkiaSample3WithScrollView (BindableFingerPaint)", ()=> new SkiaSample3WithScrollView()),
|
||||
//new MenuItem("SkiaSample4 (BindableFingerPaint)", ()=> new SkiaSample4()),
|
||||
//new MenuItem("SkiaSample5 (Shapes) ",() => new SkiaSample5()),
|
||||
//new MenuItem("SkiaSample6 (Shapes w/ Gradient) ",() => new SkiaSample6()),
|
||||
new MenuItem("Graphics Sample1 (FingerPaint)", ()=> new SkiaSample1()),
|
||||
new MenuItem("Graphics Sample2 (FingerPaint)", ()=> new SkiaSample2()),
|
||||
new MenuItem("Graphics Sample3 (BindableFingerPaint)", ()=> new SkiaSample3()),
|
||||
new MenuItem("Graphics Sample3WithScrollView (BindableFingerPaint)", ()=> new SkiaSample3WithScrollView()),
|
||||
new MenuItem("Graphics Sample4 (BindableFingerPaint)", ()=> new SkiaSample4()),
|
||||
new MenuItem("Graphics Sample5 (Shapes) ",() => new GraphicsSample5()),
|
||||
new MenuItem("Graphics Sample6 (Shapes w/ Gradient) ",() => new GraphicsSample5()),
|
||||
new MenuItem("SwiftUI Tutorial Section 1", ()=> new Section1()),
|
||||
new MenuItem("SwiftUI Tutorial Section 2", ()=> new Section2()),
|
||||
new MenuItem("SwiftUI Tutorial Section 3", ()=> new Section3()),
|
||||
|
|
|
@ -4,6 +4,7 @@ using Comet.Handlers;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Maui;
|
||||
using Microsoft.Maui.Essentials;
|
||||
using Microsoft.Maui.Handlers;
|
||||
using Microsoft.Maui.Hosting;
|
||||
|
||||
|
@ -44,6 +45,7 @@ namespace Comet
|
|||
{ typeof(CometWindow), typeof(WindowHandler) },
|
||||
{ typeof(DatePicker), typeof(DatePickerHandler) },
|
||||
{ typeof(FlyoutView), typeof(FlyoutViewHandler) },
|
||||
{ typeof(GraphicsView), typeof(GraphicsViewHandler) },
|
||||
{ typeof(Image) , typeof(ImageHandler) },
|
||||
//{ typeof(Picker), typeof(PickerHandler) },
|
||||
{ typeof(ProgressBar), typeof(ProgressBarHandler) },
|
||||
|
@ -92,6 +94,7 @@ namespace Comet
|
|||
}
|
||||
|
||||
#endif
|
||||
ThreadHelper.SetFireOnMainThread(MainThread.BeginInvokeOnMainThread);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче