-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Studio): Drop Eto.SkiaDraw dependency
- Loading branch information
Showing
8 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Eto; | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using SkiaSharp; | ||
using System; | ||
|
||
namespace CelesteStudio.Controls; | ||
|
||
public abstract class SkiaDrawable : Drawable { | ||
private readonly SKColorType colorType = Platform.Instance.IsWinForms || Platform.Instance.IsWpf ? SKColorType.Bgra8888 : SKColorType.Rgba8888; | ||
|
||
private Bitmap? image = null; | ||
private SKImageInfo imageInfo = SKImageInfo.Empty; | ||
|
||
protected abstract void Draw(PaintEventArgs e, SKSurface surface, SKImageInfo info); | ||
|
||
protected override void OnPaint(PaintEventArgs e) | ||
{ | ||
try { | ||
if (Width <= 0 || Height <= 0) { | ||
return; | ||
} | ||
|
||
if (Size != image?.Size) | ||
{ | ||
image?.Dispose(); | ||
image = new Bitmap(Size, PixelFormat.Format32bppRgba); | ||
imageInfo = new SKImageInfo(Width, Height, colorType, SKAlphaType.Unpremul); | ||
} | ||
|
||
using var bmp = image.Lock(); | ||
using var surface = SKSurface.Create(imageInfo, bmp.Data, bmp.ScanWidth); | ||
|
||
Draw(e, surface, imageInfo); | ||
|
||
e.Graphics.DrawImage(image, PointF.Empty); | ||
} | ||
catch (Exception ex) | ||
{ | ||
e.Graphics.DrawText(Fonts.Monospace(12.0f), Colors.Red, PointF.Empty, ex.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters