forked from aosoft/Xamarin.Forms.WinForms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page1.xaml.cs
61 lines (53 loc) · 1.51 KB
/
Page1.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using SkiaSharp;
using System;
using OpenTK.Graphics.OpenGL;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace WinFormsTestApp
{
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
//openglView.OnDisplay = OpenGLView_OnDisplay;
}
void Button_Clicked(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Clicked!");
}
private void OpenGLView_OnDisplay(Rectangle rect)
{
GL.ClearColor(0.5f, 1.0f, 0.0f, 1.0f);
GL.Clear((ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));
}
private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
{
var w = (float)e.Info.Width / 2;
var h = (float)e.Info.Height / 2;
var r = w < h ? w : h;
var angle = 3.14159 * sliderAngle.Value / 180.0;
var len = new SKPoint((float)Math.Cos(angle) * r, (float)Math.Sin(angle) * r);
e.Surface.Canvas.Clear(SKColors.White);
using (var p = new SKPaint())
using (var shader = SKShader.CreateLinearGradient(
new SKPoint(w + len.X, h + len.Y),
new SKPoint(w - len.X, h - len.Y),
new[] { SKColors.Red, SKColors.Lime },
new[] { 0.0f, 1.0f },
SKShaderTileMode.Clamp))
{
p.Shader = shader;
e.Surface.Canvas.DrawCircle(w, h, r, p);
}
}
private void sliderAngle_ValueChanged(object sender, ValueChangedEventArgs e)
{
skiaView.InvalidateSurface();
}
}
}