aboutsummaryrefslogtreecommitdiff
path: root/subprojects/d2tk/pugl/pugl/detail/mac_cairo.m
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/d2tk/pugl/pugl/detail/mac_cairo.m')
-rw-r--r--subprojects/d2tk/pugl/pugl/detail/mac_cairo.m29
1 files changed, 19 insertions, 10 deletions
diff --git a/subprojects/d2tk/pugl/pugl/detail/mac_cairo.m b/subprojects/d2tk/pugl/pugl/detail/mac_cairo.m
index 51c1c13..18209d9 100644
--- a/subprojects/d2tk/pugl/pugl/detail/mac_cairo.m
+++ b/subprojects/d2tk/pugl/pugl/detail/mac_cairo.m
@@ -1,5 +1,5 @@
/*
- Copyright 2019 David Robillard <http://drobilla.net>
+ Copyright 2019-2020 David Robillard <d@drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -15,13 +15,14 @@
*/
/**
- @file mac_cairo.m Cairo graphics backend for MacOS.
+ @file mac_cairo.m
+ @brief Cairo graphics backend for MacOS.
*/
#include "pugl/detail/implementation.h"
#include "pugl/detail/mac.h"
+#include "pugl/detail/stub.h"
#include "pugl/pugl_cairo.h"
-#include "pugl/pugl_stub.h"
#include <cairo-quartz.h>
@@ -30,6 +31,9 @@
#include <assert.h>
@interface PuglCairoView : NSView
+@end
+
+@implementation PuglCairoView
{
@public
PuglView* puglview;
@@ -37,13 +41,11 @@
cairo_t* cr;
}
-@end
-
-@implementation PuglCairoView
-
- (id) initWithFrame:(NSRect)frame
{
- return (self = [super initWithFrame:frame]);
+ self = [super initWithFrame:frame];
+
+ return self;
}
- (void) resizeWithOldSuperviewSize:(NSSize)oldSize
@@ -69,7 +71,7 @@ puglMacCairoCreate(PuglView* view)
PuglCairoView* drawView = [PuglCairoView alloc];
drawView->puglview = view;
- [drawView initWithFrame:NSMakeRect(0, 0, view->frame.width, view->frame.height)];
+ [drawView initWithFrame:[impl->wrapperView bounds]];
if (view->hints[PUGL_RESIZABLE]) {
[drawView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
} else {
@@ -103,10 +105,17 @@ puglMacCairoEnter(PuglView* view, const PuglEventExpose* expose)
assert(!drawView->surface);
assert(!drawView->cr);
+ const double scale = 1.0 / [[NSScreen mainScreen] backingScaleFactor];
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
+ const CGSize sizePx = {view->frame.width, view->frame.height};
+ const CGSize sizePt = CGContextConvertSizeToUserSpace(context, sizePx);
+
+ // Convert coordinates to standard Cairo space
+ CGContextTranslateCTM(context, 0.0, -sizePt.height);
+ CGContextScaleCTM(context, scale, -scale);
drawView->surface = cairo_quartz_surface_create_for_cg_context(
- context, view->frame.width, view->frame.height);
+ context, (unsigned)sizePx.width, (unsigned)sizePx.height);
drawView->cr = cairo_create(drawView->surface);