From c8ede8d4307769a4f2ccef4bf62905fd37b61e43 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 17 Jul 2020 10:59:38 +0200 Subject: [PATCH 1/3] Fix #include form for a wx header in the sample Use quotes, not angle brackets, for #includes in wx source tree itself. No real changes. --- samples/drawing/drawing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 8a502ad97b..acd2eeaa47 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -2108,7 +2108,7 @@ void MyCanvas::UseGraphicRenderer(wxGraphicsRenderer* renderer) #if wxUSE_DC_TRANSFORM_MATRIX -#include +#include "wx/valnum.h" class TransformDataDialog : public wxDialog { From 130e11688bb665a7291c7fe3c382b0faf2012e30 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 17 Jul 2020 14:24:39 +0200 Subject: [PATCH 2/3] New macOS overlay window implementation Make wxOverlay work on recent macOS versions. Closes #18399. --- src/osx/cocoa/overlay.mm | 104 +++++++++++++++++++++++++++++++++++---- 1 file changed, 94 insertions(+), 10 deletions(-) diff --git a/src/osx/cocoa/overlay.mm b/src/osx/cocoa/overlay.mm index 5e7eac8048..8eda13c50e 100644 --- a/src/osx/cocoa/overlay.mm +++ b/src/osx/cocoa/overlay.mm @@ -39,6 +39,90 @@ // implementation // ============================================================================ +@interface wxOSXOverlayView : NSView +{ +} + +- (instancetype)initWithFrame:(NSRect)frameRect; +- (void)drawRect:(NSRect)dirtyRect; + +@property (retain) NSBitmapImageRep *bitmapImageRep; + +@end + +@interface wxOSXOverlayWindow : NSWindow +{ +} +- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag; + +@property (retain) wxOSXOverlayView *overlayView; + +@end + + +@implementation wxOSXOverlayWindow + +- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag +{ + self = [super initWithContentRect:contentRect styleMask:style backing:backingStoreType defer:flag]; + if ( self ) + { + self.overlayView = [[wxOSXOverlayView alloc] initWithFrame:contentRect]; + [self setContentView:self.overlayView]; + + [self setOpaque:NO]; + [self setIgnoresMouseEvents:YES]; + [self setBackgroundColor:[NSColor clearColor]]; + [self setAlphaValue:1.0]; + } + return self; +} + +@end + +@implementation wxOSXOverlayView + +- (void)drawRect:(NSRect)dirtyRect +{ + [self.bitmapImageRep drawInRect:[self bounds]]; +} + +// from https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + self = [super initWithFrame:frameRect]; + if ( self ) + { + NSRect bounds = [self bounds]; + NSRect backingBounds = [self convertRectToBacking:bounds]; + + NSBitmapImageRep* bmp = [[NSBitmapImageRep alloc] + initWithBitmapDataPlanes:NULL + pixelsWide:backingBounds.size.width + pixelsHigh:backingBounds.size.height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSCalibratedRGBColorSpace + bitmapFormat:NSAlphaFirstBitmapFormat + bytesPerRow:0 + bitsPerPixel:0 + ]; + + // There isn't a colorspace name constant for sRGB so retag + // using the sRGBColorSpace method + self.bitmapImageRep = [bmp bitmapImageRepByRetaggingWithColorSpace: + [NSColorSpace sRGBColorSpace]]; + [bmp release]; + // Setting the user size communicates the dpi + [self.bitmapImageRep setSize:bounds.size]; + } + return self; +} +@end + wxOverlayImpl::wxOverlayImpl() { m_window = NULL ; @@ -73,7 +157,7 @@ void wxOverlayImpl::CreateOverlayWindow( wxDC* dc ) NSRect overlayRect = wxToNSRect(NULL, wxRect(origin, size)); overlayRect = [NSWindow contentRectForFrameRect:overlayRect styleMask:NSBorderlessWindowMask]; - m_overlayWindow = [[NSWindow alloc] initWithContentRect:overlayRect + m_overlayWindow = [[wxOSXOverlayWindow alloc] initWithContentRect:overlayRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]; @@ -85,18 +169,13 @@ void wxOverlayImpl::CreateOverlayWindow( wxDC* dc ) CGRect cgbounds; cgbounds = CGDisplayBounds(CGMainDisplayID()); - m_overlayWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(cgbounds.origin.x, cgbounds.origin.y, + m_overlayWindow = [[wxOSXOverlayWindow alloc] initWithContentRect:NSMakeRect(cgbounds.origin.x, cgbounds.origin.y, cgbounds.size.width, cgbounds.size.height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]; } - [m_overlayWindow setOpaque:NO]; - [m_overlayWindow setIgnoresMouseEvents:YES]; - [m_overlayWindow setBackgroundColor:[NSColor clearColor]]; - [m_overlayWindow setAlphaValue:1.0]; - [m_overlayWindow orderFront:nil]; } @@ -112,9 +191,6 @@ void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height ) CreateOverlayWindow(dc); wxASSERT_MSG(m_overlayWindow != NULL, _("Couldn't create the overlay window")); - m_overlayContext = [[m_overlayWindow graphicsContext] CGContext]; - wxASSERT_MSG( m_overlayContext != NULL , _("Couldn't init the context on the overlay window") ); - [(id)m_overlayContext retain]; } void wxOverlayImpl::BeginDrawing( wxDC* dc) @@ -135,6 +211,11 @@ void wxOverlayImpl::BeginDrawing( wxDC* dc) ySize = cgbounds.size.height; } + wxOSXOverlayWindow* wxoverlay = (wxOSXOverlayWindow*) m_overlayWindow; + NSBitmapImageRep* rep = wxoverlay.overlayView.bitmapImageRep; + m_overlayContext = [[NSGraphicsContext graphicsContextWithBitmapImageRep:rep] CGContext]; + wxASSERT_MSG( m_overlayContext != NULL , _("Couldn't init the context on the overlay window") ); + wxGraphicsContext* ctx = wxGraphicsContext::CreateFromNative( m_overlayContext ); ctx->Translate(0, ySize); ctx->Scale(1,-1); @@ -155,6 +236,9 @@ void wxOverlayImpl::EndDrawing( wxDC* dc) win_impl->SetGraphicsContext(NULL); CGContextFlush( m_overlayContext ); + m_overlayContext = NULL; + wxOSXOverlayWindow* wxoverlay = (wxOSXOverlayWindow*) m_overlayWindow; + [wxoverlay.overlayView setNeedsDisplay:YES]; } void wxOverlayImpl::Clear(wxDC* dc) From b1e168b946d649b4242e5eb9219e99a0405acd8e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 19 Jul 2020 00:19:00 +0200 Subject: [PATCH 3/3] Remove _() macros from assert messages We don't translate those, as they're meant for (presumably English-speaking) developers only. --- src/dfb/overlay.cpp | 2 +- src/osx/cocoa/overlay.mm | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dfb/overlay.cpp b/src/dfb/overlay.cpp index d264ecf4b8..27400ec151 100644 --- a/src/dfb/overlay.cpp +++ b/src/dfb/overlay.cpp @@ -58,7 +58,7 @@ bool wxOverlayImpl::IsOk() void wxOverlayImpl::Init(wxDC *dc, int x, int y, int width, int height) { wxCHECK_RET( dc, "NULL dc pointer" ); - wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") ); + wxASSERT_MSG( !IsOk() , "You cannot Init an overlay twice" ); wxDFBDCImpl * const dcimpl = wxDynamicCast(dc->GetImpl(), wxDFBDCImpl); wxCHECK_RET( dcimpl, "must have a DFB wxDC" ); diff --git a/src/osx/cocoa/overlay.mm b/src/osx/cocoa/overlay.mm index 8eda13c50e..6114d31e0a 100644 --- a/src/osx/cocoa/overlay.mm +++ b/src/osx/cocoa/overlay.mm @@ -181,7 +181,7 @@ void wxOverlayImpl::CreateOverlayWindow( wxDC* dc ) void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height ) { - wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") ); + wxASSERT_MSG( !IsOk() , "You cannot Init an overlay twice" ); m_window = dc->GetWindow(); m_x = x ; @@ -190,7 +190,7 @@ void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height ) m_height = height ; CreateOverlayWindow(dc); - wxASSERT_MSG(m_overlayWindow != NULL, _("Couldn't create the overlay window")); + wxASSERT_MSG(m_overlayWindow != NULL, "Couldn't create the overlay window"); } void wxOverlayImpl::BeginDrawing( wxDC* dc) @@ -214,7 +214,7 @@ void wxOverlayImpl::BeginDrawing( wxDC* dc) wxOSXOverlayWindow* wxoverlay = (wxOSXOverlayWindow*) m_overlayWindow; NSBitmapImageRep* rep = wxoverlay.overlayView.bitmapImageRep; m_overlayContext = [[NSGraphicsContext graphicsContextWithBitmapImageRep:rep] CGContext]; - wxASSERT_MSG( m_overlayContext != NULL , _("Couldn't init the context on the overlay window") ); + wxASSERT_MSG( m_overlayContext != NULL , "Couldn't init the context on the overlay window" ); wxGraphicsContext* ctx = wxGraphicsContext::CreateFromNative( m_overlayContext ); ctx->Translate(0, ySize); @@ -243,7 +243,7 @@ void wxOverlayImpl::EndDrawing( wxDC* dc) void wxOverlayImpl::Clear(wxDC* dc) { - wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") ); + wxASSERT_MSG( IsOk() , "You cannot Clear an overlay that is not inited" ); dc->GetGraphicsContext()->ClearRectangle(m_x - 1, m_y - 1, m_width + 2, m_height + 2); }