2020-04-09 08:04:21 +02:00
|
|
|
//
|
|
|
|
// XCinema.cpp
|
|
|
|
// Clover
|
|
|
|
//
|
|
|
|
// Created by Sergey Isakov on 09/04/2020.
|
|
|
|
// Copyright © 2020 Slice. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2020-04-13 21:01:40 +02:00
|
|
|
|
|
|
|
#include "libegint.h"
|
2020-04-09 08:04:21 +02:00
|
|
|
#include "XCinema.h"
|
2020-04-13 21:01:40 +02:00
|
|
|
#include "../gui/REFIT_MENU_SCREEN.h"
|
|
|
|
|
2020-04-15 11:13:51 +02:00
|
|
|
#ifndef DEBUG_ALL
|
2020-04-15 18:30:39 +02:00
|
|
|
#define DEBUG_CINEMA 0
|
2020-04-15 11:13:51 +02:00
|
|
|
#else
|
|
|
|
#define DEBUG_CINEMA DEBUG_ALL
|
|
|
|
#endif
|
|
|
|
|
2020-04-15 21:18:53 +02:00
|
|
|
#if DEBUG_CINEMA == 0
|
2020-04-15 11:13:51 +02:00
|
|
|
#define DBG(...)
|
|
|
|
#else
|
|
|
|
#define DBG(...) DebugLog(DEBUG_CINEMA, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-04-13 21:01:40 +02:00
|
|
|
//Screen.UpdateAnime(); called from Menu cycle wait for event
|
|
|
|
|
2020-04-15 18:30:39 +02:00
|
|
|
// object XCinema Cinema is a part of Theme
|
|
|
|
// object FILM* FilmC is a part or current Screen. Must be initialized from Cinema somewhere on Screen init
|
2020-04-16 06:45:53 +02:00
|
|
|
|
2020-04-13 21:01:40 +02:00
|
|
|
VOID REFIT_MENU_SCREEN::UpdateFilm()
|
|
|
|
{
|
2020-04-23 10:42:18 +02:00
|
|
|
if (FilmC == nullptr || !FilmC->AnimeRun) {
|
|
|
|
// DBG("no anime -> run=%d\n", FilmC->AnimeRun?1:0);
|
2020-04-15 18:30:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-04-13 21:01:40 +02:00
|
|
|
// here we propose each screen has own link to a Film
|
2020-04-14 18:52:13 +02:00
|
|
|
INT64 Now = AsmReadTsc();
|
2020-04-13 21:01:40 +02:00
|
|
|
|
2020-04-23 10:42:18 +02:00
|
|
|
if (FilmC->LastDraw == 0) {
|
2020-04-15 18:30:39 +02:00
|
|
|
DBG("=== Update Film ===\n");
|
|
|
|
DBG("FilmX=%lld\n", FilmC->FilmX);
|
|
|
|
DBG("ID=%lld\n", FilmC->GetIndex());
|
|
|
|
DBG("RunOnce=%d\n", FilmC->RunOnce?1:0);
|
|
|
|
DBG("NumFrames=%lld\n", FilmC->NumFrames);
|
|
|
|
DBG("FrameTime=%lld\n", FilmC->FrameTime);
|
|
|
|
DBG("Path=%ls\n", FilmC->Path.wc_str());
|
|
|
|
DBG("LastFrame=%lld\n\n", FilmC->LastFrameID());
|
|
|
|
|
2020-04-13 21:01:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-23 10:42:18 +02:00
|
|
|
if (TimeDiff(FilmC->LastDraw, Now) < (UINTN)FilmC->FrameTime) return;
|
2020-04-14 18:52:13 +02:00
|
|
|
|
|
|
|
XImage Frame = FilmC->GetImage(); //take current image
|
|
|
|
if (!Frame.isEmpty()) {
|
2020-04-15 18:30:39 +02:00
|
|
|
Frame.DrawOnBack(FilmC->FilmPlace.XPos, FilmC->FilmPlace.YPos, ThemeX.Background);
|
2020-04-13 21:01:40 +02:00
|
|
|
}
|
2020-04-14 18:52:13 +02:00
|
|
|
FilmC->Advance(); //next frame no matter if previous was not found
|
|
|
|
if (FilmC->Finished()) { //first loop finished
|
2020-04-23 10:42:18 +02:00
|
|
|
FilmC->AnimeRun = !FilmC->RunOnce; //will stop anime if it set as RunOnce
|
2020-04-13 21:01:40 +02:00
|
|
|
}
|
2020-04-23 10:42:18 +02:00
|
|
|
FilmC->LastDraw = Now;
|
2020-04-13 21:01:40 +02:00
|
|
|
}
|
2020-04-16 06:45:53 +02:00
|
|
|
|
2020-04-13 21:01:40 +02:00
|
|
|
FILM* XCinema::GetFilm(INTN Id)
|
|
|
|
{
|
2020-04-15 18:30:39 +02:00
|
|
|
// DBG("ask film %lld from total of %lld\n", Id, Cinema.size());
|
2020-04-13 21:01:40 +02:00
|
|
|
for (size_t i = 0; i < Cinema.size(); ++i) {
|
2020-04-15 18:30:39 +02:00
|
|
|
// DBG("check film# %lld\n", Cinema[i].GetIndex());
|
2020-04-14 21:37:44 +02:00
|
|
|
if (Cinema[i].GetIndex() == Id) {
|
2020-04-15 18:30:39 +02:00
|
|
|
// DBG(" found ID\n");
|
2020-04-13 21:01:40 +02:00
|
|
|
return &Cinema[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-04-09 15:04:12 +02:00
|
|
|
|
2020-04-14 18:52:13 +02:00
|
|
|
void XCinema::AddFilm(FILM* NewFilm)
|
|
|
|
{
|
|
|
|
Cinema.AddReference(NewFilm, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static XImage NullImage;
|
|
|
|
const XImage& FILM::GetImage(INTN Index) const
|
2020-04-09 15:04:12 +02:00
|
|
|
{
|
2020-05-10 11:41:34 +02:00
|
|
|
DBG("ask for frame #%lld from total of %zu\n", Index, Frames.size());
|
2020-04-13 21:01:40 +02:00
|
|
|
for (size_t i = 0; i < Frames.size(); ++i) {
|
2020-04-14 21:37:44 +02:00
|
|
|
if (Frames[i].getIndex() == Index) {
|
2020-04-15 11:13:51 +02:00
|
|
|
DBG("...found\n");
|
2020-04-14 18:52:13 +02:00
|
|
|
return Frames[i].getImage();
|
|
|
|
}
|
|
|
|
}
|
2020-04-15 18:30:39 +02:00
|
|
|
DBG("...not found\n");
|
2020-04-14 18:52:13 +02:00
|
|
|
return NullImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
const XImage& FILM::GetImage() const
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < Frames.size(); ++i) {
|
2020-04-14 21:37:44 +02:00
|
|
|
if (Frames[i].getIndex() == CurrentFrame) {
|
2020-04-14 18:52:13 +02:00
|
|
|
return Frames[i].getImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NullImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FILM::AddFrame(XImage* Frame, INTN Index)
|
|
|
|
{
|
|
|
|
IndexedImage* NewFrame = new IndexedImage(Index);
|
|
|
|
NewFrame->setImage(*Frame);
|
|
|
|
Frames.AddReference(NewFrame, true);
|
2020-04-15 18:30:39 +02:00
|
|
|
DBG("index=%lld last=%lld\n", Index, LastIndex);
|
2020-04-14 18:52:13 +02:00
|
|
|
if (Index > LastIndex) {
|
|
|
|
LastIndex = Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 21:37:44 +02:00
|
|
|
void FILM::GetFrames(XTheme& TheTheme /*, const XStringW& Path*/) // Path already exist as a member. Is it the same ?
|
2020-04-14 18:52:13 +02:00
|
|
|
{
|
|
|
|
EFI_FILE *ThemeDir = TheTheme.ThemeDir;
|
|
|
|
EFI_STATUS Status;
|
2020-04-15 18:30:39 +02:00
|
|
|
LastIndex = 0;
|
2020-04-14 18:52:13 +02:00
|
|
|
for (INTN Index = 0; Index < NumFrames; Index++) {
|
|
|
|
XImage NewImage;
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
if (TheTheme.TypeSVG) {
|
|
|
|
Status = TheTheme.LoadSvgFrame(Index, &NewImage);
|
|
|
|
} else {
|
|
|
|
XStringW Name = SWPrintf("%ls\\%ls_%03lld.png", Path.wc_str(), Path.wc_str(), Index);
|
2020-04-15 11:13:51 +02:00
|
|
|
// DBG("try to load %ls\n", Name.wc_str()); //fine
|
2020-04-27 14:13:09 +02:00
|
|
|
if (FileExists(ThemeDir, Name)) {
|
2020-04-14 18:52:13 +02:00
|
|
|
Status = NewImage.LoadXImage(ThemeDir, Name);
|
|
|
|
}
|
2020-04-15 11:13:51 +02:00
|
|
|
// DBG(" read status=%s\n", strerror(Status));
|
2020-04-14 18:52:13 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
AddFrame(&NewImage, Index);
|
2020-04-13 21:01:40 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-09 15:04:12 +02:00
|
|
|
}
|