Commit baede058 authored by Bkg2k's avatar Bkg2k

feat(video): new themable video component and video effects

parent 36d6904a
......@@ -4,7 +4,8 @@
#include "components/ScrollableContainer.h"
#include "components/RatingComponent.h"
#include "components/DateTimeComponent.h"
#include "components/ImageVideoComponent.h"
#include "components/ImageComponent.h"
#include "components/VideoComponent.h"
#include "SystemData.h"
class DetailedGameListView : public BasicGameListView
......@@ -25,7 +26,8 @@ private:
void initMDLabels();
void initMDValues();
ImageVideoComponent mImage;
ImageComponent mImage;
VideoComponent mVideo;
std::vector<ImageComponent *> mFolderContent;
TextComponent mLblRating, mLblReleaseDate, mLblDeveloper, mLblPublisher, mLblGenre, mLblPlayers, mLblLastPlayed, mLblPlayCount, mLblFavorite;
......@@ -49,6 +51,8 @@ private:
SystemData* mSystem;
RecalboxConf& mSettings;
bool switchDisplay(bool isGame);
bool switchToFolderScrappedDisplay();
std::vector<GuiComponent*> getFolderComponents();
......
......@@ -45,7 +45,7 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/components/HelpComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/IList.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageVideoComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageGridComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/MenuComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.h
......@@ -121,7 +121,7 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/components/DateTimeComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/HelpComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageVideoComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/MenuComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ScrollableContainer.cpp
......
//
// Created by bkg2k on 16/05/19.
//
#pragma once
#include "platform.h"
......@@ -11,25 +7,37 @@
#include <string>
#include <memory>
#include <util/HighResolutionTimer.h>
#include <RecalboxConf.h>
#include "resources/TextureResource.h"
class ImageVideoComponent : public GuiComponent
class VideoComponent : public GuiComponent
{
private:
enum State
{
DisplayImage,
Uninitialized,
InitializeVideo,
BumpVideo,
StartVideo,
DisplayVideo,
FinalizeVideo,
StopVideo,
};
enum Effect
{
Bump,
Fade,
BreakingNews,
_LastItem,
};
//! Video state
State mState;
//! Video effect
Effect mEffect;
Eigen::Vector2f mTargetSize;
std::string mPath;
std::string mVideoPath;
bool mTargetIsMax;
......@@ -37,63 +45,70 @@ class ImageVideoComponent : public GuiComponent
// Used internally whenever the resizing parameters or texture change.
void resize();
typedef struct Vertex
struct Vertex
{
Eigen::Vector2f pos;
Eigen::Vector2f tex;
} RectangleVertexes[6];
RectangleVertexes mVertices;
} mVertices[6];
GLubyte mColors[6*4];
void updateVertices();
void updateVertices(double bump);
void updateColors();
unsigned int mColorShift;
std::shared_ptr<TextureResource> mTexture;
unsigned char mFadeOpacity;
bool mFading;
bool mForceLoad;
bool mDynamic;
HighResolutionTimer mTimer;
//! Time to vidéo
int mVideoDelay;
//! Effect timeing
int mVideoEffect;
//! Video loop (0 for infinite loop)
int mVideoLoop;
static constexpr int IMAGE_TIMING = 5000;
static constexpr int IMAGE_TO_VIDEO_TIMING = 500;
//! High reolution timer for time computations
HighResolutionTimer mTimer;
/*!
* @brief Decide what to display
* @param video [out] Set if we must display the video
* @param image [out] Set if we must display the image
* @param bumpEffect [out] Set to the video bump value
* @param effect [out] Set to the video bump value
* @return bool if the video frame has to be displayed
*/
void ProcessDisplay(bool& video, bool&image, double& bumpEffect);
bool ProcessDisplay(double& effect);
/*!
* @brief Calculate new bumped vertexes
* @param bump
* @brief Stop video and reset component context
*/
void CalculateVideoVextexes(RectangleVertexes& destinationVertexes, double bump);
void ResetAnimations();
public:
explicit ImageVideoComponent(Window* window, bool dynamic = true);
~ImageVideoComponent() override;
/*!
* @brief Process effect and return a double from 0.0 to 1.0
* @param elapsedms elapsed time in millisecond
* @param in True if the effect is used in starting video phase. False in stopping video phase
* @return 0.0 to 1.0 value.
*/
double ProcessEffect(int elapsedms, bool in);
// Loads the image at the given filepath. Will tile if tile is true (retrieves texture as tiling, creates vertices accordingly).
void setImage(const std::string& path, bool tile = false);
// Loads an image from memory.
void setImage(const char* image, size_t length, bool tile = false);
// Use an already existing texture.
void setImage(const std::shared_ptr<TextureResource>& texture);
//! Pi constant
static constexpr double Pi = 3.1415926535;
// Set video file path
void setVideo(const std::string& path);
public:
explicit VideoComponent(Window* window, bool forceLoad = false, bool dynamic = true);
~VideoComponent() override = default;
void onSizeChanged() override;
void setOpacity(unsigned char opacity) override;
/*!
* @brief Set video
* @param path Path to video file
* @param delay Delay before actually playing the video in milliseconds
* @param loops Number of loops (0 = infinite loops)
*/
void setVideo(const std::string& path, int delay, int loops);
Eigen::Vector2f getTargetSize() const { return mTargetSize; }
void setOpacity(unsigned char opacity) override;
// Resize the image to fit this size. If one axis is zero, scale that axis to maintain aspect ratio.
// If both are non-zero, potentially break the aspect ratio. If both are zero, no resizing.
......@@ -106,23 +121,19 @@ class ImageVideoComponent : public GuiComponent
// Can be set before or after an image is loaded.
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
void setMaxSize(float width, float height);
void setNormalisedMaxSize(float width, float height);
inline void setMaxSize(const Eigen::Vector2f& size) { setMaxSize(size.x(), size.y()); }
// Multiply all pixels in the image by this color when rendering.
void setColorShift(unsigned int color);
void setColor(unsigned int color) override;
// Returns the size of the current texture, or (0, 0) if none is loaded. May be different than drawn size (use getSize() for that).
Eigen::Vector2i getTextureSize() const;
bool hasImage();
void render(const Eigen::Affine3f& parentTrans) override;
void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
std::vector<HelpPrompt> getHelpPrompts() override;
void ResetAnimations();
static constexpr int DEFAULT_VIDEODELAY = 2000;
static constexpr int DEFAULT_VIDEOEFFET = 500;
static constexpr int DEFAULT_VIDEOLOOP = 1;
};
......@@ -35,4 +35,6 @@ void* Thread::StartThread(void* thread_)
thread.Run();
thread.AfterRun();
thread.mIsDone = true;
return nullptr;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment