View Single Post
  #606  
Old 05-08-2024, 07:17
Fak Eid Fak Eid is offline
Registered User
 
Join Date: Jun 2023
Location: Mars
Posts: 147
Thanks: 98
Thanked 152 Times in 54 Posts
Fak Eid is on a distinguished road
Custom Slideshow and Generic WebView Example

Real life examples are in Epic Games Installer

Generic WebView Example
You can reuse the attached WebView.html like this:

Code:
[Files]
Source: "Files\Web\WebView.html"; DestDir: "{tmp}"; Flags: dontcopy;
Code:
procedure LoadHtmlContent(Width, Height: Integer; SrcURL: WideString);
var
  sHtml, VideoId: Widestring;
  sTemplate: AnsiString;
  Sl: TStringList;
begin
  VideoId := Copy(SrcURL, Pos('v=', SrcURL) + 2, 11);
  LoadStringFromFile(ExtractAndLoad('WebView.html'), sTemplate);
  sHtml := Format(sTemplate, [Width, Height, VideoId]);

  Sl := TStringList.Create;
  try
    Sl.Text := sHtml;
    Sl.SaveToFile(ExpandConstant('{tmp}\WebView.html'));
  finally
    Sl.Free;
  end;
end;
Code:
LoadHtmlContent(680, 384, 'https://www.youtube.com/ watch?v=hS7ZY7oLCS4&ab_channel=RANDOMGAMERTAGS');

TrailerRect.FCreate(FMXForm.Handle);
TrailerRect.SetBounds(250, 145, 680, 383);
TrailerRect.Opacity(0);
TrailerRect.HitTest(False);

TrailerWebView.FCreate(FMXForm.Handle, TrailerRect.Handle, ExpandConstant('{tmp}\WebView.html'));
TrailerWebView.Start;
Custom Image Slideshow
The need for this was because both type of Image Slideshow were dependent on FMXForm and couldn't be overlayed with a different component. Hence, I had to go with creating my own.

Code:
j: Integer;
GameImage: FImage;
SlideShowTimer: FTimer;
Code:
GameImage.FCreate(FMXForm.Handle);
GameImage.SetBounds(250, 145, 680, 383);
GameImage.LoadPicture(ExtractAndLoad('Image0.jpg'), iwStretch);
GameImage.Opacity(1);

SlideShowTimer.FCreate(GameImage.Handle, True);
SlideShowTimer.Interval(100);
SlideShowTimer.OnTimer(@ChangeSlide);
Code:
procedure ChangeSlide(Sender: TObject);
var
  Time: Cardinal;
  SlideOpacity: Single;
begin
  if GameImage.GetOpacity = 1 then Slider := False
  else if GameImage.GetOpacity = 0 then begin
    GameImage.LoadPicture(ExtractAndLoad('Image' + IntToStr(j) +'.jpg'), iwStretch);
    j := j+1;
    Slider := True;
  end;

  if (Slider = False) and not (GameImage.GetOpacity = 0) then SlideOpacity := GameImage.GetOpacity - 0.05
  else if (Slider = True) and not(GameImage.GetOpacity = 1) then SlideOpacity := GameImage.GetOpacity + 0.05;
  GameImage.Opacity(SlideOpacity);

  #ifdef NumberOfSlides
  if j = {#NumberOfSlides} then j := 0;
  #endif
end;
What is NumberOfSlides?
Settings.ini has a parameter as Number of Slides where you need to define the number of Image Files from the folder, to be included in the slideshow.
Attached Images
File Type: gif Fak Eid SlideShow.gif (1.92 MB, 178 views)
Attached Files
File Type: rar WebView.rar (620 Bytes, 16 views)

Last edited by Fak Eid; 05-08-2024 at 07:59.
Reply With Quote