ThisGuy
ThisGuy

Reputation: 1415

How to get an aero effect delphi for FMX

How can I get a similar 'aero effect' in OSX/Windows for delphi xe6 using FMX? I see this tutorial but is it is for VLC http://theroadtodelphi.wordpress.com/2009/10/26/glass-effect-in-a-delphi-console-application/

I am looking for an effect that is something similar to aero. More specifically, where the effect blurs the background. Similar to a blurred overlay you would see in iOS.

So my form would need to be transparent, and then blur that image where the form is to make use for the background.

Thanks to @RRUZ this is what I have so far. Compiles, but doesn't quite work yet:

unit test;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls
  {$IFDEF MACOS32}
  ,FMX.Platform.Mac,
  Macapi.CoreFoundation,
  Macapi.CoreGraphics,
  Macapi.AppKit,
  Macapi.CocoaTypes
  {$ENDIF}
  ;

{$IFDEF MACOS32}
type
 CGSConnection = Pointer;

function CGSSetWindowBackgroundBlurRadius(connection: CGSConnection; windowNumber : NSInteger; radius : integer): CGError; cdecl; external libCoreGraphics name _PU + 'CGSSetWindowBackgroundBlurRadius';
function CGSDefaultConnectionForThread : CGSConnection ; cdecl; external libCoreGraphics name _PU + 'CGSDefaultConnectionForThread';
{$ENDIF}


type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    procedure enableBlurForWindow(Handle : TWindowHandle);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

{ TForm1 }

procedure TForm1.enableBlurForWindow(Handle: TWindowHandle);
var
  connection : CGSConnection;
  LNSWindow : NSWindow;
begin
  LNSWindow:= WindowHandleToPlatform(Handle).Wnd;
  LNSWindow.setOpaque(False);
  LNSWindow.setBackgroundColor(TNSColor.Wrap(TNSColor.OCClass.colorWithCalibratedWhite(1.0, 0.5)));
  connection := CGSDefaultConnectionForThread();
  CGSSetWindowBackgroundBlurRadius(connection, LNSWindow.windowNumber, 20);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  enableBlurForWindow(Form1.Handle);
end;

end.

Upvotes: 0

Views: 1295

Answers (1)

Get this effect in FMX application is much simpler than in VCL, FMX brings specific components to apply effects to other components or forms (including the Blur effect).

Just drop the component on the form and activate it.

enter image description here

Upvotes: 1

Related Questions