Browse Source

implement transparency api on osx.

pull/3962/head
Dan Walmsley 6 years ago
parent
commit
0c3f2aa856
  1. 1
      native/Avalonia.Native/inc/avalonia-native.h
  2. 3
      native/Avalonia.Native/src/OSX/window.h
  3. 29
      native/Avalonia.Native/src/OSX/window.mm
  4. 17
      src/Avalonia.Native/WindowImplBase.cs

1
native/Avalonia.Native/inc/avalonia-native.h

@ -258,6 +258,7 @@ AVNCOM(IAvnWindowBase, 02) : IUnknown
virtual HRESULT ObtainNSViewHandleRetained(void** retOut) = 0;
virtual HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point,
IAvnClipboard* clipboard, IAvnDndResultCallback* cb, void* sourceHandle) = 0;
virtual HRESULT SetBlurEnabled (bool enable) = 0;
};
AVNCOM(IAvnPopup, 03) : virtual IAvnWindowBase

3
native/Avalonia.Native/src/OSX/window.h

@ -3,6 +3,9 @@
class WindowBaseImpl;
@interface AutoFitContentVisualEffectView : NSVisualEffectView
@end
@interface AvnView : NSView<NSTextInputClient, NSDraggingDestination>
-(AvnView* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent;
-(NSEvent* _Nonnull) lastMouseDownEvent;

29
native/Avalonia.Native/src/OSX/window.mm

@ -20,6 +20,7 @@ public:
View = NULL;
Window = NULL;
}
NSVisualEffectView* VisualEffect;
AvnView* View;
AvnWindow* Window;
ComPtr<IAvnWindowBaseEvents> BaseEvents;
@ -47,6 +48,12 @@ public:
[Window setStyleMask:NSWindowStyleMaskBorderless];
[Window setBackingType:NSBackingStoreBuffered];
VisualEffect = [AutoFitContentVisualEffectView new];
[VisualEffect setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
[VisualEffect setMaterial:NSVisualEffectMaterialLight];
[VisualEffect setAutoresizesSubviews:true];
[Window setContentView: View];
}
@ -383,6 +390,18 @@ public:
return *ppv == nil ? E_FAIL : S_OK;
}
virtual HRESULT SetBlurEnabled (bool enable) override
{
[Window setContentView: enable ? VisualEffect : View];
if(enable)
{
[VisualEffect addSubview:View];
}
return S_OK;
}
virtual HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point,
IAvnClipboard* clipboard, IAvnDndResultCallback* cb,
void* sourceHandle) override
@ -911,6 +930,16 @@ protected:
NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEventTrackingRunLoopMode, NSModalPanelRunLoopMode, NSRunLoopCommonModes, NSConnectionReplyMode, nil];
@implementation AutoFitContentVisualEffectView
-(void)setFrameSize:(NSSize)newSize
{
[super setFrameSize:newSize];
if([[self subviews] count] == 0)
return;
[[self subviews][0] setFrameSize: newSize];
}
@end
@implementation AvnView
{
ComPtr<WindowBaseImpl> _parent;

17
src/Avalonia.Native/WindowImplBase.cs

@ -391,7 +391,22 @@ namespace Avalonia.Native
_native.BeginDragAndDropOperation(effects, point, clipboard, callback, sourceHandle);
}
public WindowTransparencyLevel TransparencyLevel { get => WindowTransparencyLevel.None; set { } }
private WindowTransparencyLevel _transparencyLevel;
public WindowTransparencyLevel TransparencyLevel
{
get => _transparencyLevel;
set
{
if(_transparencyLevel != value)
{
_transparencyLevel = value;
_native.SetBlurEnabled(_transparencyLevel >= WindowTransparencyLevel.Blur);
TransparencyLevelChanged?.Invoke(_transparencyLevel);
}
}
}
public IPlatformHandle Handle { get; private set; }
}

Loading…
Cancel
Save