Skip to content

Commit

Permalink
a template for refactoring ANIME
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Isakov <[email protected]>
  • Loading branch information
SergeySlice committed Apr 13, 2020
1 parent b828a3b commit 12d9715
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 35 deletions.
67 changes: 49 additions & 18 deletions rEFIt_UEFI/gui/REFIT_MENU_SCREEN.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "../cpp_foundation/XStringWArray.h"
#include "../cpp_foundation/XStringW.h"
#include "../libeg/XPointer.h"
#include "../libeg/XCinema.h"
#include "menu_items/menu_items.h"


Expand Down Expand Up @@ -72,30 +73,38 @@ class REFIT_MENU_SCREEN
static XPointer mPointer;
// XPointer mPointer;
UINTN ID;
XStringW Title;
XImage TitleImage;
XStringW Title;
XImage TitleImage;
XStringWArray InfoLines;

XObjArray<REFIT_ABSTRACT_MENU_ENTRY> Entries;

INTN TimeoutSeconds;
XStringW TimeoutText;
XStringW ThemeName; //?
EG_RECT OldTextBufferRect;
XImage OldTextBufferImage;
BOOLEAN isBootScreen;
XStringW TimeoutText;
XStringW ThemeName; //?
EG_RECT OldTextBufferRect;
XImage OldTextBufferImage;
BOOLEAN isBootScreen;
BOOLEAN AnimeRun;
BOOLEAN Once;
//same for xcinema
UINT64 LastDraw;
INTN CurrentFrame;
INTN Frames;
UINTN FrameTime; //ms
EG_RECT FilmPlace;

#if XCINEMA
FILM *FilmX;
#else
EG_IMAGE **Film;
#endif

ACTION mAction;
UINTN mItemID;
SCROLL_STATE ScrollState;
BOOLEAN ScrollEnabled;
INTN TextStyle;
ACTION mAction;
UINTN mItemID;
SCROLL_STATE ScrollState;
BOOLEAN ScrollEnabled;
INTN TextStyle;
// MENU_STYLE_FUNC StyleFunc;

//TODO scroll positions should depends on REFIT_SCREEN?
Expand All @@ -120,22 +129,37 @@ class REFIT_MENU_SCREEN
OldTextBufferRect(), OldTextBufferImage(), isBootScreen(false),
AnimeRun(0), Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
#if XCINEMA
FilmX(),
#else
Film(0),
#endif
mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{};
REFIT_MENU_SCREEN(UINTN ID, XStringW TTitle, XStringW TTimeoutText)
: ID(ID), Title(TTitle), TitleImage(),
TimeoutSeconds(0), TimeoutText(TTimeoutText), ThemeName(),
OldTextBufferRect(), OldTextBufferImage(), isBootScreen(false),
AnimeRun(0), Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
#if XCINEMA
FilmX(),
#else
Film(0),
#endif
mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{};
REFIT_MENU_SCREEN(UINTN ID, CONST CHAR16* TitleC, CONST CHAR16* TimeoutTextC)
: ID(ID), Title(), TitleImage(),
TimeoutSeconds(0), TimeoutText(), ThemeName(), AnimeRun(0),
Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
#if XCINEMA
FilmX(),
#else
Film(0),
#endif
mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{
Title.takeValueFrom(TitleC);
TimeoutText.takeValueFrom(TimeoutTextC);
Expand All @@ -147,7 +171,12 @@ class REFIT_MENU_SCREEN
OldTextBufferRect(), OldTextBufferImage(), isBootScreen(false),
AnimeRun(0), Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
#if XCINEMA
FilmX(),
#else
Film(0),
#endif
mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{
Entries.AddReference(entry1, false);
Entries.AddReference(entry2, false);
Expand Down Expand Up @@ -192,9 +221,11 @@ class REFIT_MENU_SCREEN
VOID DrawBCSText(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign);
VOID CountItems();
VOID InitAnime();
BOOLEAN GetAnime();
BOOLEAN GetAnime(); //same for xcinema
VOID UpdateAnime();

#if XCINEMA
VOID UpdateFilm(); // for future use instead of UpdateAnime
#endif

//Style functions

Expand Down
61 changes: 59 additions & 2 deletions rEFIt_UEFI/libeg/XCinema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,66 @@
// Copyright © 2020 Slice. All rights reserved.
//


#include "libegint.h"
#include "XCinema.h"
#include "../gui/REFIT_MENU_SCREEN.h"

//Screen.UpdateAnime(); called from Menu cycle wait for event
//Now = AsmReadTsc();
//if (TimeDiff(LastDraw, Now) < FrameTime) return;
//if (Film[CurrentFrame]) { Draw }
// else skip draw
// CurrentFrame++;
//if (CurrentFrame >= Frames) {
// AnimeRun = !Once;
// CurrentFrame = 0;
//}
//LastDraw = Now;

// object XCinema::Cinema is a part of Theme
// object FILM::FilmX is a part or current Screen. Must be initialized from Cinema somewhere on Screen init
#if XCINEMA
VOID REFIT_MENU_SCREEN::UpdateFilm()
{
// here we propose each screen has own link to a Film
UINT64 Now = AsmReadTsc();

if (LastDraw == 0) {
//save background into last frame
}

if (TimeDiff(LastDraw, Now) < FrameTime) return;
XImage *Frame = nullptr; // a link to frame needed
// EFI_STATUS Status = ThemeX.Cinema.GetFrame(CurrentFrame);
EFI_STATUS Status = FilmX->GetFrame(CurrentFrame, Frame); //get a pointer to existing frame
if (!EFI_ERROR(Status) && Frame != nullptr) {
Frame->Draw(FilmPlace.XPos, FilmPlace.YPos);
}
FilmX->Advance(CurrentFrame); //next frame no matter if previous was not found
if (CurrentFrame == 0) { //first loop finished
AnimeRun = !Once; //will stop anime
}
LastDraw = Now;
}
#endif
FILM* XCinema::GetFilm(INTN Id)
{
for (size_t i = 0; i < Cinema.size(); ++i) {
if (Cinema[i].Id == Id) {
return &Cinema[i];
}
}
return nullptr;
}

void FILM::Advance()
EFI_STATUS FILM::GetFrame(IN INTN Index, OUT XImage *Image)
{
CurrentFrame = ++CurrentFrame % Count;
for (size_t i = 0; i < Frames.size(); ++i) {
if (Frames[i].Index == Index) {
Image = &Frames[i].Image;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
28 changes: 16 additions & 12 deletions rEFIt_UEFI/libeg/XCinema.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,43 @@ class FILM
{
public:
bool RunOnce;
INTN Id; //ScreenID, enumeration value but keep it to be int for extensibility
protected:
INTN Id; //enumeration value but keep it to be int for extensibility

INTN FrameTime; //usually 50, 100, 200 ms
XString Path; //user defined name for folder and files Path/Path_002.png etc
XObjArray<FRAME> Frames; //Frames can be not sorted
INTN LastIndex; // it is not Frames.size(), it is last index inclusive, so frames 0,1,2,5,8 be LastIndex = 8
EG_RECT FilmPlace;
INTN CurrentFrame; // like a static value will be increase between 0..LastIndex
// INTN CurrentFrame; // like a static value will be increased between 0..LastIndex, no it's a part of Screen

public:
FILM();
FILM(): RunOnce(false), Id(0), FrameTime(0), Path(), Frames(), LastIndex(0), FilmPlace()
{}
FILM(INTN Id) : RunOnce(false), Id(Id), FrameTime(0), Path(), Frames(),
LastIndex(0), FilmPlace(), CurrentFrame(0) {};
~FILM();
LastIndex(0), FilmPlace() {}
~FILM() {}

const XImage& GetImage(INTN Index);
void AddFrame(const FRAME& Frame, INTN Index);
size_t Size() { return Frames.size(); }
INTN LastFrame() { return LastIndex; }
void GetFilm(const XStringW& Path); //read from Theme
void SetPlace(const EG_RECT& Rect);
void Advance() { ++CurrentFrame %= (LastIndex + 1); }
void Advance(INTN& Current) { ++Current %= (LastIndex + 1); }
EFI_STATUS GetFrame(IN INTN Index, OUT XImage *Frame); //usually Index=CurrentFrame
EFI_STATUS GetFrame(OUT XImage *Frame);

};

//initially it was supposed to be one anime per one REFIT_SCREEN
// but this leads to large delays switching screens to initialize Film sequence again and again
// otherwise anime depends on theme and should be a member or XTheme
// otherwise anime depends on theme and should be a member of XTheme
// then it should contain Screen->ID for each film
// but for next future we want to have other animated images except screen->titleimage
// but for next future we want to have other animated images in addition to screen->titleimage
// so let it be frames arrays each with own purpose (Id)
// XTheme contains Cinema
// Each Screen contains a pointer to FILM. And moreover titleFilm, or BackgroundFilm or even entryFilm
// XTheme contains Cinema which is an array of FILMs
// Each Screen contains a pointer to a FILM. And moreover titleFilm, or BackgroundFilm or even entryFilm
// Next problem is a timeout between frames.
// A theme contains images with indexes 1,2,5,6 for one Id.
// This Id contains fixed timeout between frames. Then next updateAnime Index will be compared with current tick
Expand All @@ -76,8 +80,8 @@ class XCinema


public:
XCinema();
~XCinema();
XCinema() {}
~XCinema() {}

FILM* GetFilm(INTN Id);
void AddFilm(const FILM& NewFilm, INTN Id);
Expand Down
4 changes: 4 additions & 0 deletions rEFIt_UEFI/libeg/XTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "libeg.h"
//#include "nanosvg.h"
#include "XImage.h"
#include "XCinema.h"


#define INDICATOR_SIZE (52)
Expand Down Expand Up @@ -118,6 +119,9 @@ class XTheme
XImage FontImage;

EG_RECT BannerPlace;
#if XCINEMA
XCinema Cinema;
#endif

//fill the theme
// const XImage& GetIcon(const char* Name);
Expand Down
2 changes: 2 additions & 0 deletions rEFIt_UEFI/libeg/libeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#ifndef __LIBEG_LIBEG_H__
#define __LIBEG_LIBEG_H__

#define XCINEMA 0

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions rEFIt_UEFI/refit.inf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
libeg/XPointer.h
libeg/XTheme.cpp
libeg/XTheme.h
libeg/XCinema.cpp
libeg/XCinema.h
Platform/Posix/posix.h
Platform/Posix/limits.h
Platform/Posix/stdarg.h
Expand Down
7 changes: 5 additions & 2 deletions rEFIt_UEFI/refit/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,11 @@ EFI_STATUS WaitForInputEventPoll(REFIT_MENU_SCREEN* ScreenPtr, UINTN TimeoutDefa
if (Status != EFI_TIMEOUT) {
break;
}

Screen.UpdateAnime(); //should be moved to REFIT_MENU_SCREEN class
#if XCINEMA
Screen.UpdateFilm();
#else
Screen.UpdateAnime();
#endif
if (gSettings.PlayAsync) {
CheckSyncSound();
}
Expand Down
14 changes: 13 additions & 1 deletion rEFIt_UEFI/refit/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ INTN HybridRepositioning(INTN Edge, INTN Value, INTN ImageDimension, INTN Screen
}
return pos;
}
#if XCINEMA
BOOLEAN REFIT_MENU_SCREEN::GetAnime()
{
FilmX = ThemeX.Cinema.GetFilm(ID);
return FilmX != nullptr;
}

VOID REFIT_MENU_SCREEN::InitAnime()
{
//something
}
#else

static EG_IMAGE *AnimeImage = NULL;

Expand Down Expand Up @@ -672,7 +684,7 @@ BOOLEAN REFIT_MENU_SCREEN::GetAnime()

return TRUE;
}

#endif
//
// Sets next/previous available screen resolution, according to specified offset
//
Expand Down

0 comments on commit 12d9715

Please sign in to comment.