Further implementation of native overlay on Cocoa

Should work for Caret,  still has a problem with the transformation matrix otherwise, too many things have changed there for me to find a quick solutions.
This commit is contained in:
Stefan Csomor
2017-09-09 11:44:43 +02:00
parent 4d8c1fc890
commit 8ad0039b71
2 changed files with 41 additions and 52 deletions

View File

@@ -38,7 +38,7 @@ public:
void Clear( wxDC* dc);
private:
void CreateOverlayWindow();
void CreateOverlayWindow( wxDC* dc );
WXWindow m_overlayWindow;
WXWindow m_overlayParentWindow;

View File

@@ -56,30 +56,27 @@ bool wxOverlayImpl::IsOk()
return m_overlayWindow != NULL ;
}
void wxOverlayImpl::CreateOverlayWindow()
void wxOverlayImpl::CreateOverlayWindow( wxDC* dc )
{
if (m_window)
{
m_overlayParentWindow = m_window->MacGetTopLevelWindowRef();
[m_overlayParentWindow makeKeyAndOrderFront:nil];
NSView* view = m_window->GetHandle();
wxPoint origin(m_x, m_y);
if (!dc->IsKindOf(CLASSINFO(wxClientDC)))
origin -= m_window->GetClientAreaOrigin();
NSPoint viewOriginBase, viewOriginScreen;
viewOriginBase = [view convertPoint:NSMakePoint(0, 0) toView:nil];
viewOriginScreen = [m_overlayParentWindow convertBaseToScreen:viewOriginBase];
origin = m_window->ClientToScreen(origin);
NSSize viewSize = [view frame].size;
if ( [view isFlipped] )
viewOriginScreen.y -= viewSize.height;
wxSize size(m_width, m_height);
NSRect overlayRect = wxToNSRect(NULL, wxRect(origin, size));
overlayRect = [NSWindow contentRectForFrameRect:overlayRect styleMask:NSBorderlessWindowMask];
m_overlayWindow=[[NSWindow alloc] initWithContentRect:NSMakeRect(viewOriginScreen.x,viewOriginScreen.y,
viewSize.width,
viewSize.height)
m_overlayWindow = [[NSWindow alloc] initWithContentRect:overlayRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES];
[m_overlayParentWindow addChildWindow:m_overlayWindow ordered:NSWindowAbove];
}
else
@@ -97,6 +94,7 @@ void wxOverlayImpl::CreateOverlayWindow()
}
[m_overlayWindow setOpaque:NO];
[m_overlayWindow setIgnoresMouseEvents:YES];
[m_overlayWindow setBackgroundColor:[NSColor clearColor]];
[m_overlayWindow setAlphaValue:1.0];
[m_overlayWindow orderFront:nil];
@@ -109,16 +107,10 @@ void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height )
m_window = dc->GetWindow();
m_x = x ;
m_y = y ;
if ( dc->IsKindOf( CLASSINFO( wxClientDC ) ))
{
wxPoint origin = m_window->GetClientAreaOrigin();
m_x += origin.x;
m_y += origin.y;
}
m_width = width ;
m_height = height ;
CreateOverlayWindow();
CreateOverlayWindow(dc);
wxASSERT_MSG(m_overlayWindow != NULL, _("Couldn't create the overlay window"));
m_overlayContext = (CGContextRef) [[m_overlayWindow graphicsContext] graphicsPort];
wxASSERT_MSG( m_overlayContext != NULL , _("Couldn't init the context on the overlay window") );
@@ -126,22 +118,17 @@ void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height )
int ySize = 0;
if ( m_window )
{
NSView* view = m_window->GetHandle();
NSSize viewSize = [view frame].size;
ySize = viewSize.height;
ySize = m_height;
}
else
{
CGRect cgbounds ;
cgbounds = CGDisplayBounds(CGMainDisplayID());
ySize = cgbounds.size.height;
}
CGContextTranslateCTM(m_overlayContext, 0, ySize);
CGContextScaleCTM(m_overlayContext, 1, -1);
CGContextTranslateCTM( m_overlayContext, -m_x , -m_y );
}
void wxOverlayImpl::BeginDrawing( wxDC* dc)
@@ -151,6 +138,8 @@ void wxOverlayImpl::BeginDrawing( wxDC* dc)
if (win_impl)
{
win_impl->SetGraphicsContext( wxGraphicsContext::CreateFromNative( m_overlayContext ) );
if (m_window)
dc->SetDeviceOrigin(dc->LogicalToDeviceX(-m_x), dc->LogicalToDeviceY(-m_y));
dc->SetClippingRegion(m_x, m_y, m_width, m_height);
}
}
@@ -165,11 +154,11 @@ void wxOverlayImpl::EndDrawing( wxDC* dc)
CGContextFlush( m_overlayContext );
}
void wxOverlayImpl::Clear(wxDC* WXUNUSED(dc))
void wxOverlayImpl::Clear(wxDC* dc)
{
wxASSERT_MSG( IsOk() , _("You cannot Clear an overlay that is not inited") );
CGRect box = CGRectMake( m_x - 1, m_y - 1 , m_width + 2 , m_height + 2 );
CGContextClearRect( m_overlayContext, box );
dc->GetGraphicsContext()->ClearRectangle(m_x - 1, m_y - 1, m_width + 2, m_height + 2);
}
void wxOverlayImpl::Reset()