Skip to content

Commit

Permalink
fix(Studio): Coordinate-system issues on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Nov 6, 2024
1 parent 8a95136 commit 262ec8b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Studio/CelesteStudio.Mac/SkiaDrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class SkiaDrawableView(SkiaDrawable drawable) : MacPanelView {
public override void DrawRect(CGRect dirtyRect) {
base.DrawRect(dirtyRect);

var bounds = new CGRect(drawable.DrawX, drawable.DrawY, drawable.DrawWidth * Window.BackingScaleFactor, drawable.DrawHeight * Window.BackingScaleFactor);
double scale = Window.BackingScaleFactor;
var bounds = new CGRect(drawable.DrawX * scale, drawable.DrawY * scale, drawable.DrawWidth * scale, drawable.DrawHeight * scale);
var info = new SKImageInfo((int)bounds.Width, (int)bounds.Height, SKColorType.Rgba8888, SKAlphaType.Premul);

// Allocate a memory for the drawing process
Expand Down Expand Up @@ -57,7 +58,8 @@ public override void DrawRect(CGRect dirtyRect) {
dataProvider, null, false, CGColorRenderingIntent.Default);

var ctx = NSGraphicsContext.CurrentContext.GraphicsPort;
ctx.DrawImage(bounds, image);
// NOTE: macOS uses a different coordinate-system
ctx.DrawImage(new CGRect(bounds.X, Bounds.Height - bounds.Height - bounds.Y, bounds.Width, bounds.Height), image);
}

protected override void Dispose(bool disposing) {
Expand Down

0 comments on commit 262ec8b

Please sign in to comment.