unit FMX.Media.Win.Helpers;
interface
uses
FMX.Media,
FMX.Media.Win;
type
TWindowsMediaHelper =
class helper
for TWindowsMedia
procedure Stretch;
end;
implementation
uses
FMX.Controls,
FMX.Forms,
FMX.
Platform.Win,
FMX.Types,
System.Classes,
System.Types,
Winapi.DirectShow9,
Winapi.Windows;
{ TWindowsMediaHelper }
procedure TWindowsMediaHelper.Stretch;
var
P : TPointF;
R : TRect;
Bounds: TRectF;
Form : TCommonCustomForm;
// this is just an updated version of TRecF.Fit to support scaling up
function MyRectFit(
var R: TRectF;
const BoundsRect: TRectF ): Single;
var
ratio: Single;
begin
Result := 1;
if BoundsRect.Width * BoundsRect.Height = 0
then
Exit;
if ( R.Width / BoundsRect.Width ) > ( R.Height / BoundsRect.Height )
then
ratio := R.Width / BoundsRect.Width
else
ratio := R.Height / BoundsRect.Height;
// UPDATED
R := RectF( 0, 0, R.Width / ratio, R.Height / ratio );
Result := ratio;
RectCenter( R, BoundsRect );
end;
var
leFWnd : HWND;
leControl : TControl;
leFVMRWindowlessControl: IVMRWindowlessControl9;
begin
leFWnd := Self.FWnd;
leControl := TControl( FControl );
leFVMRWindowlessControl := Self.FVMRWindowlessControl;
if leFWnd <> 0
then
begin
if ( leControl <>
nil )
and not( csDesigning
in Control.ComponentState )
and ( Control.ParentedVisible )
and ( Control.Root <>
nil )
and
( Control.Root.GetObject
is TCommonCustomForm )
then
begin
Form := TCommonCustomForm( Control.Root.GetObject );
P := Self.GetVideoSize;
Bounds := TRectF.Create( 0, 0, P.X, P.Y );
// UPDATED: Bounds.Fit(RectF(0, 0, Control.AbsoluteWidth, Control.AbsoluteHeight));
MyRectFit( Bounds, RectF( 0, 0, Control.AbsoluteWidth, Control.AbsoluteHeight ) );
Bounds.Offset( Control.AbsoluteRect.Left, Control.AbsoluteRect.Top );
SetParent( leFWnd, FmxHandleToHWND( Form.Handle ) );
SetWindowPos( leFWnd, 0, Bounds.Round.Left, Bounds.Round.Top, Bounds.Round.Width,
Bounds.Round.Height, 0 );
R.Create( 0, 0, Bounds.Round.Width, Bounds.Round.Height );
if leFVMRWindowlessControl <>
nil
then
leFVMRWindowlessControl.SetVideoPosition(
nil, @R );
ShowWindow( leFWnd, SW_SHOW )
end
else
ShowWindow( leFWnd, SW_HIDE )
end;
end;
end.