Removed some bugs
This commit is contained in:
Родитель
d60e7fafa0
Коммит
e1c0178a62
|
@ -14,9 +14,9 @@ namespace SkiaSharp
|
|||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
|
||||
internal delegate IntPtr draw_delegate (IntPtr managedDrawablePtr, IntPtr canvasPtr);
|
||||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
|
||||
internal delegate IntPtr getBounds_delegate (IntPtr managedDrawablePtr, ref SKRect bounds);
|
||||
internal delegate SKRect getBounds_delegate (IntPtr managedDrawablePtr);
|
||||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
|
||||
internal delegate IntPtr newPictureSnapshot_delegate (IntPtr managedDrawablePtr);
|
||||
internal delegate SKPicture newPictureSnapshot_delegate (IntPtr managedDrawablePtr);
|
||||
|
||||
// delegate fields
|
||||
private static readonly draw_delegate fDraw;
|
||||
|
@ -94,16 +94,15 @@ namespace SkiaSharp
|
|||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(getBounds_delegate))]
|
||||
private static IntPtr GetBoundsInternal (IntPtr managedDrawablePtr, ref SKRect bounds)
|
||||
private static SKRect GetBoundsInternal (IntPtr managedDrawablePtr)
|
||||
{
|
||||
bounds = AsManagedDrawable (managedDrawablePtr).OnGetBounds ();
|
||||
return IntPtr.Zero;
|
||||
return AsManagedDrawable (managedDrawablePtr).OnGetBounds ();
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(newPictureSnapshot_delegate))]
|
||||
private static IntPtr NewPictureSnapshotInternal (IntPtr managedDrawablePtr)
|
||||
private static SKPicture NewPictureSnapshotInternal (IntPtr managedDrawablePtr)
|
||||
{
|
||||
return AsManagedDrawable (managedDrawablePtr).OnNewPictureSnapshot ().Handle;
|
||||
return GetObject<SKPicture> (AsManagedDrawable (managedDrawablePtr).OnNewPictureSnapshot ().Handle);
|
||||
}
|
||||
|
||||
private static SKAbstractDrawable AsManagedDrawable (IntPtr ptr)
|
||||
|
|
|
@ -404,6 +404,20 @@ namespace SkiaSharp
|
|||
SkiaApi.sk_canvas_draw_picture (Handle, picture.Handle, IntPtr.Zero, paint == null ? IntPtr.Zero : paint.Handle);
|
||||
}
|
||||
|
||||
public void DrawDrawable (SKDrawable drawable, ref SKMatrix matrix)
|
||||
{
|
||||
if (drawable == null)
|
||||
throw new ArgumentNullException (nameof (drawable));
|
||||
SkiaApi.sk_canvas_draw_drawable (Handle, drawable.Handle, ref matrix);
|
||||
}
|
||||
|
||||
public void DrawDrawable (SKDrawable drawable, float x, float y)
|
||||
{
|
||||
if (drawable == null)
|
||||
throw new ArgumentNullException (nameof (drawable));
|
||||
SkiaApi.sk_canvas_draw_drawable (Handle, drawable.Handle, x, y);
|
||||
}
|
||||
|
||||
public void DrawBitmap (SKBitmap bitmap, SKPoint p, SKPaint paint = null)
|
||||
{
|
||||
DrawBitmap (bitmap, p.X, p.Y, paint);
|
||||
|
|
|
@ -11,6 +11,10 @@ namespace SkiaSharp
|
|||
{
|
||||
}
|
||||
|
||||
public SKDrawable() : base ()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (Handle != IntPtr.Zero && OwnsHandle) {
|
||||
|
@ -24,29 +28,37 @@ namespace SkiaSharp
|
|||
|
||||
public SKRect Bounds {
|
||||
get {
|
||||
SkiaApi.sk_manageddrawable_get_bounds (Handle, out var rect);
|
||||
return rect;
|
||||
return SkiaApi.sk_manageddrawable_get_bounds (Handle);
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw (SKCanvas canvas, ref SKMatrix matrix)
|
||||
{
|
||||
SkiaApi.sk_manageddrawable_draw (canvas.Handle, ref matrix);
|
||||
SkiaApi.sk_manageddrawable_draw (Handle, canvas.Handle, ref matrix);
|
||||
}
|
||||
|
||||
public void Draw (SKCanvas canvas, float x, float y)
|
||||
{
|
||||
SkiaApi.sk_manageddrawable_draw (canvas.Handle, x, y);
|
||||
var matrix = SKMatrix.MakeTranslation (x, y);
|
||||
SkiaApi.sk_manageddrawable_draw (Handle, canvas.Handle, ref matrix);
|
||||
}
|
||||
|
||||
public SKPicture NewPictureSnapshot ()
|
||||
{
|
||||
return GetObject<SKPicture> (SkiaApi.sk_manageddrawable_new_picture_snapshot ());
|
||||
return GetObject<SKPicture> (SkiaApi.sk_manageddrawable_new_picture_snapshot (Handle));
|
||||
}
|
||||
|
||||
public void NotifyDrawingChanged ()
|
||||
{
|
||||
SkiaApi.sk_manageddrawable_notify_drawing_changed ();
|
||||
SkiaApi.sk_manageddrawable_notify_drawing_changed (Handle);
|
||||
}
|
||||
|
||||
protected override SKPicture OnNewPictureSnapshot ()
|
||||
{
|
||||
var recorder = new SKPictureRecorder ();
|
||||
var canvas = recorder.BeginRecording (Bounds);
|
||||
Draw (canvas, 0, 0);
|
||||
return recorder.EndRecording ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -962,15 +962,13 @@ namespace SkiaSharp
|
|||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static uint sk_manageddrawable_get_generation_id (sk_manageddrawable_t d);
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static void sk_manageddrawable_get_bounds (sk_manageddrawable_t d, out SKRect rect);
|
||||
public extern static SKRect sk_manageddrawable_get_bounds (sk_manageddrawable_t d);
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static void sk_manageddrawable_draw (sk_canvas_t c, ref SKMatrix matrix);
|
||||
public extern static void sk_manageddrawable_draw (sk_manageddrawable_t d, sk_canvas_t c, ref SKMatrix matrix);
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static void sk_manageddrawable_draw (sk_canvas_t c, float x, float y);
|
||||
public extern static sk_picture_t sk_manageddrawable_new_picture_snapshot (sk_manageddrawable_t d);
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static sk_picture_t sk_manageddrawable_new_picture_snapshot ();
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
public extern static void sk_manageddrawable_notify_drawing_changed ();
|
||||
public extern static void sk_manageddrawable_notify_drawing_changed (sk_manageddrawable_t d);
|
||||
|
||||
// shader
|
||||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace SkiaSharpSample
|
||||
{
|
||||
public class Class1 : SKDrawable
|
||||
{
|
||||
public Class1()
|
||||
{ }
|
||||
|
||||
protected override void OnDraw(SKCanvas canvas)
|
||||
{
|
||||
var path = new SKPath();
|
||||
var paint = new SKPaint();
|
||||
path.MoveTo(20, 20);
|
||||
path.LineTo(100, 100);
|
||||
path.Close();
|
||||
paint.Color = SKColors.Red;
|
||||
paint.StrokeWidth = 2;
|
||||
paint.Style = SKPaintStyle.Stroke;
|
||||
canvas.DrawPath(path, paint);
|
||||
}
|
||||
|
||||
protected override SKRect OnGetBounds()
|
||||
{
|
||||
return new SKRect(20, 20, 100, 100);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,6 +38,12 @@ namespace SkiaSharpSample
|
|||
};
|
||||
var coord = new SKPoint(scaledSize.Width / 2, (scaledSize.Height + paint.TextSize) / 2);
|
||||
canvas.DrawText("SkiaSharp", coord, paint);
|
||||
var drawable = new Class1();
|
||||
var bounds = drawable.Bounds;
|
||||
canvas.DrawDrawable(drawable, 0, 0);
|
||||
drawable.NewPictureSnapshot();
|
||||
var id = drawable.GenerationID;
|
||||
drawable.NotifyDrawingChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
Загрузка…
Ссылка в новой задаче