Einzelnen Beitrag anzeigen

CHackbart

Registriert seit: 22. Okt 2012
260 Beiträge
 
#5

AW: NSVisualEffectView

  Alt 15. Nov 2021, 09:18
Man kann so etwas machen. Ich hab es aber nicht wirklich getestet.

Delphi-Quellcode:
unit UNSVisualEffectView;

interface

{$IFDEF MACOS}
{$IFNDEF IOS}

uses MacApi.CocoaTypes, MacApi.AppKit, MacApi.ObjectiveC, FMX.Forms;

const
  NSVisualEffectMaterialAppearanceBased = 0;
  NSVisualEffectMaterialLight = 1;
  NSVisualEffectMaterialDark = 2;
  NSVisualEffectMaterialTitlebar = 3;

  NSVisualEffectBlendingModeBehindWindow = 0;
  NSVisualEffectBlendingModeWithinWindow = 1;
  NSVisualEffectStateFollowsWindowActiveState = 0;
  NSVisualEffectStateActive = 1;
  NSVisualEffectStateInactive = 2;

  NSVisualEffectViewMaterialFullScreenUI = 15;

type
  NSVisualEffectMaterial = NSInteger;
  NSVisualEffectMaterialPtr = ^NSVisualEffectMaterial;
  NSVisualEffectBlendingMode = NSInteger;
  NSVisualEffectBlendingModePtr = ^NSVisualEffectBlendingMode;
  NSVisualEffectState = NSInteger;
  NSVisualEffectStatePtr = ^NSVisualEffectState;

  NSVisualEffectViewClass = interface(NSViewClass)
    ['{EF4AB3D6-5620-44CD-82F0-FD80FB79FB9D}']
    { class } procedure setMaterial(newValue: NSVisualEffectMaterial); cdecl;
    { class } function material: NSVisualEffectMaterial; cdecl;
    { class } function interiorBackgroundStyle: NSBackgroundStyle; cdecl;
    { class } procedure setBlendingMode
      (newValue: NSVisualEffectBlendingMode); cdecl;
    { class } function blendingMode: NSVisualEffectBlendingMode; cdecl;
    { class } procedure setState(newValue: NSVisualEffectState); cdecl;
    { class } function state: NSVisualEffectState; cdecl;
    { class } procedure setMaskImage(newValue: NSImage); cdecl;
    { class } function maskImage: NSImage; cdecl;
    { class } procedure viewDidMoveToWindow; cdecl;
    { class } procedure viewWillMoveToWindow(newWindow: NSWindow); cdecl;
  end;

  NSVisualEffectView = interface(NSView)
    procedure setMaterial(newValue: NSVisualEffectMaterial); cdecl;
    function material: NSVisualEffectMaterial; cdecl;
    function interiorBackgroundStyle: NSBackgroundStyle; cdecl;
    procedure setBlendingMode(newValue: NSVisualEffectBlendingMode); cdecl;
    function blendingMode: NSVisualEffectBlendingMode; cdecl;
    procedure setState(newValue: NSVisualEffectState); cdecl;
    function state: NSVisualEffectState; cdecl;
    procedure setMaskImage(newValue: NSImage); cdecl;
    function maskImage: NSImage;cdecl;
    procedure viewDidMoveToWindow;cdecl;
    procedure viewWillMoveToWindow(newWindow: NSWindow);cdecl;
  end;

  TNSVisualEffectView = class(TOCGenericImport<NSVisualEffectViewClass,
    NSVisualEffectView>)
  end;

procedure AppendToForm(const AForm: TCommonCustomForm);
{$ENDIF}
{$ENDIF}

implementation

{$IFDEF MACOS}
{$IFNDEF IOS}

uses FMX.Platform.Mac;

procedure AppendToForm(const AForm: TCommonCustomForm);
var
  NSWin: NSWindow;
  BlurView: NSVisualEffectView;
  ContentView: NSView;
begin
  NSWin := WindowHandleToPlatform(AForm.Handle).Wnd;
  NSWin.setOpaque(false);
  NSWin.setAlphaValue(0.98);

  BlurView := TNSVisualEffectView.Wrap(
   TNSVisualEffectView.Alloc.initWithFrame(
    MakeNSRect(0,0, AForm.Width, AForm.Height)));
  BlurView.setBlendingMode(NSVisualEffectBlendingModeBehindWindow);
  BlurView.setMaterial(NSVisualEffectViewMaterialFullScreenUI);
  BlurView.setState(NSVisualEffectStateActive);

  ContentView := TNSView.Wrap(NSWin.ContentView);
  ContentView.setAutoresizesSubviews(True);
  ContentView.addSubview(BlurView);
end;
{$ENDIF}
{$ENDIF}

end.
Christian
  Mit Zitat antworten Zitat