Merge branch 'glm-rewrite'

This commit is contained in:
Leon Styhre 2021-08-17 19:00:17 +02:00
commit 85444c0ee6
124 changed files with 2332 additions and 2384 deletions

View file

@ -66,7 +66,7 @@ CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4 ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4 ContinuationIndentWidth: 4
Cpp11BracedListStyle: false Cpp11BracedListStyle: true
DeriveLineEnding: true DeriveLineEnding: true
DerivePointerAlignment: false DerivePointerAlignment: false
DisableFormat: false DisableFormat: false
@ -119,7 +119,7 @@ SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements

View file

@ -196,6 +196,10 @@ if(DEFINED libCEC_FOUND)
add_definitions(-DHAVE_LIBCEC) add_definitions(-DHAVE_LIBCEC)
endif() endif()
# GLM library options.
add_definitions(-DGLM_FORCE_CXX14)
add_definitions(-DGLM_FORCE_XYZW_ONLY)
# For Unix systems, assign the installation prefix. If it's not explicitly set, # For Unix systems, assign the installation prefix. If it's not explicitly set,
# we use /usr on Linux, /usr/pkg on NetBSD and /usr/local on FreeBSD and OpenBSD. # we use /usr on Linux, /usr/pkg on NetBSD and /usr/local on FreeBSD and OpenBSD.
if(NOT WIN32 AND NOT APPLE) if(NOT WIN32 AND NOT APPLE)

View file

@ -52,11 +52,11 @@ CollectionSystemsManager::CollectionSystemsManager(Window* window)
{ {
// clang-format off // clang-format off
CollectionSystemDecl systemDecls[] = { CollectionSystemDecl systemDecls[] = {
// Type Name Long name Theme folder isCustom // Type Name Long name Theme folder isCustom
{ AUTO_ALL_GAMES, "all", "all games", "auto-allgames", false }, {AUTO_ALL_GAMES, "all", "all games", "auto-allgames", false},
{ AUTO_LAST_PLAYED, "recent", "last played", "auto-lastplayed", false }, {AUTO_LAST_PLAYED, "recent", "last played", "auto-lastplayed", false},
{ AUTO_FAVORITES, "favorites", "favorites", "auto-favorites", false }, {AUTO_FAVORITES, "favorites", "favorites", "auto-favorites", false},
{ CUSTOM_COLLECTION, myCollectionsName, "collections", "custom-collections", true } {CUSTOM_COLLECTION, myCollectionsName, "collections", "custom-collections", true }
}; };
// clang-format on // clang-format on
@ -791,7 +791,7 @@ FileData* CollectionSystemsManager::updateCollectionFolderMetadata(SystemData* s
if (gameCount > 1) { if (gameCount > 1) {
std::random_device randDev; std::random_device randDev;
// Mersenne Twister pseudorandom number generator. // Mersenne Twister pseudorandom number generator.
std::mt19937 engine { randDev() }; std::mt19937 engine{randDev()};
unsigned int target; unsigned int target;
for (unsigned int i = 0; i < 3; i++) { for (unsigned int i = 0; i < 3; i++) {

View file

@ -212,7 +212,7 @@ const std::string FileData::getMediaDirectory()
const std::string FileData::getMediafilePath(std::string subdirectory, std::string mediatype) const const std::string FileData::getMediafilePath(std::string subdirectory, std::string mediatype) const
{ {
const std::vector<std::string> extList = { ".png", ".jpg" }; const std::vector<std::string> extList = {".png", ".jpg"};
std::string subFolders; std::string subFolders;
// Extract possible subfolders from the path. // Extract possible subfolders from the path.
@ -287,7 +287,7 @@ const std::string FileData::getThumbnailPath() const
const std::string FileData::getVideoPath() const const std::string FileData::getVideoPath() const
{ {
const std::vector<std::string> extList = { ".avi", ".mkv", ".mov", ".mp4", ".wmv" }; const std::vector<std::string> extList = {".avi", ".mkv", ".mov", ".mp4", ".wmv"};
std::string subFolders; std::string subFolders;
// Extract possible subfolders from the path. // Extract possible subfolders from the path.
@ -1158,7 +1158,7 @@ std::string FileData::findEmulatorPath(std::string& command)
HKEY registryKey; HKEY registryKey;
LSTATUS keyStatus = -1; LSTATUS keyStatus = -1;
LSTATUS pathStatus = -1; LSTATUS pathStatus = -1;
char registryPath[1024] {}; char registryPath[1024]{};
DWORD pathSize = 1024; DWORD pathSize = 1024;
// First look in HKEY_CURRENT_USER. // First look in HKEY_CURRENT_USER.

View file

@ -37,15 +37,15 @@ FileFilterIndex::FileFilterIndex()
// clang-format off // clang-format off
FilterDataDecl filterDecls[] = { FilterDataDecl filterDecls[] = {
//type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel //type //allKeys //filteredBy //filteredKeys //primaryKey //hasSecondaryKey //secondaryKey //menuLabel
{ FAVORITES_FILTER, &mFavoritesIndexAllKeys, &mFilterByFavorites, &mFavoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES" }, {FAVORITES_FILTER, &mFavoritesIndexAllKeys, &mFilterByFavorites, &mFavoritesIndexFilteredKeys, "favorite", false, "", "FAVORITES"},
{ GENRE_FILTER, &mGenreIndexAllKeys, &mFilterByGenre, &mGenreIndexFilteredKeys, "genre", true, "genre", "GENRE" }, {GENRE_FILTER, &mGenreIndexAllKeys, &mFilterByGenre, &mGenreIndexFilteredKeys, "genre", true, "genre", "GENRE"},
{ PLAYER_FILTER, &mPlayersIndexAllKeys, &mFilterByPlayers, &mPlayersIndexFilteredKeys, "players", false, "", "PLAYERS" }, {PLAYER_FILTER, &mPlayersIndexAllKeys, &mFilterByPlayers, &mPlayersIndexFilteredKeys, "players", false, "", "PLAYERS"},
{ PUBDEV_FILTER, &mPubDevIndexAllKeys, &mFilterByPubDev, &mPubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER" }, {PUBDEV_FILTER, &mPubDevIndexAllKeys, &mFilterByPubDev, &mPubDevIndexFilteredKeys, "developer", true, "publisher", "PUBLISHER / DEVELOPER"},
{ RATINGS_FILTER, &mRatingsIndexAllKeys, &mFilterByRatings, &mRatingsIndexFilteredKeys, "rating", false, "", "RATING" }, {RATINGS_FILTER, &mRatingsIndexAllKeys, &mFilterByRatings, &mRatingsIndexFilteredKeys, "rating", false, "", "RATING"},
{ KIDGAME_FILTER, &mKidGameIndexAllKeys, &mFilterByKidGame, &mKidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME" }, {KIDGAME_FILTER, &mKidGameIndexAllKeys, &mFilterByKidGame, &mKidGameIndexFilteredKeys, "kidgame", false, "", "KIDGAME"},
{ COMPLETED_FILTER, &mCompletedIndexAllKeys, &mFilterByCompleted, &mCompletedIndexFilteredKeys, "completed", false, "", "COMPLETED" }, {COMPLETED_FILTER, &mCompletedIndexAllKeys, &mFilterByCompleted, &mCompletedIndexFilteredKeys, "completed", false, "", "COMPLETED"},
{ BROKEN_FILTER, &mBrokenIndexAllKeys, &mFilterByBroken, &mBrokenIndexFilteredKeys, "broken", false, "", "BROKEN" }, {BROKEN_FILTER, &mBrokenIndexAllKeys, &mFilterByBroken, &mBrokenIndexFilteredKeys, "broken", false, "", "BROKEN"},
{ HIDDEN_FILTER, &mHiddenIndexAllKeys, &mFilterByHidden, &mHiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN" } {HIDDEN_FILTER, &mHiddenIndexAllKeys, &mFilterByHidden, &mHiddenIndexFilteredKeys, "hidden", false, "", "HIDDEN"}
}; };
// clang-format on // clang-format on
@ -67,15 +67,15 @@ void FileFilterIndex::importIndex(FileFilterIndex* indexToImport)
}; };
IndexImportStructure indexStructDecls[] = { IndexImportStructure indexStructDecls[] = {
{ &mFavoritesIndexAllKeys, &(indexToImport->mFavoritesIndexAllKeys) }, {&mFavoritesIndexAllKeys, &(indexToImport->mFavoritesIndexAllKeys)},
{ &mGenreIndexAllKeys, &(indexToImport->mGenreIndexAllKeys) }, {&mGenreIndexAllKeys, &(indexToImport->mGenreIndexAllKeys)},
{ &mPlayersIndexAllKeys, &(indexToImport->mPlayersIndexAllKeys) }, {&mPlayersIndexAllKeys, &(indexToImport->mPlayersIndexAllKeys)},
{ &mPubDevIndexAllKeys, &(indexToImport->mPubDevIndexAllKeys) }, {&mPubDevIndexAllKeys, &(indexToImport->mPubDevIndexAllKeys)},
{ &mRatingsIndexAllKeys, &(indexToImport->mRatingsIndexAllKeys) }, {&mRatingsIndexAllKeys, &(indexToImport->mRatingsIndexAllKeys)},
{ &mKidGameIndexAllKeys, &(indexToImport->mKidGameIndexAllKeys) }, {&mKidGameIndexAllKeys, &(indexToImport->mKidGameIndexAllKeys)},
{ &mCompletedIndexAllKeys, &(indexToImport->mCompletedIndexAllKeys) }, {&mCompletedIndexAllKeys, &(indexToImport->mCompletedIndexAllKeys)},
{ &mBrokenIndexAllKeys, &(indexToImport->mBrokenIndexAllKeys) }, {&mBrokenIndexAllKeys, &(indexToImport->mBrokenIndexAllKeys)},
{ &mHiddenIndexAllKeys, &(indexToImport->mHiddenIndexAllKeys) }, {&mHiddenIndexAllKeys, &(indexToImport->mHiddenIndexAllKeys)},
}; };
std::vector<IndexImportStructure> indexImportDecl = std::vector<IndexImportStructure>( std::vector<IndexImportStructure> indexImportDecl = std::vector<IndexImportStructure>(
@ -304,7 +304,7 @@ void FileFilterIndex::setKidModeFilters()
{ {
if (UIModeController::getInstance()->isUIModeKid()) { if (UIModeController::getInstance()->isUIModeKid()) {
mFilterByKidGame = true; mFilterByKidGame = true;
std::vector<std::string> val = { "TRUE" }; std::vector<std::string> val = {"TRUE"};
setFilter(KIDGAME_FILTER, &val); setFilter(KIDGAME_FILTER, &val);
} }
} }
@ -419,14 +419,13 @@ bool FileFilterIndex::isFiltered()
bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type) bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type)
{ {
const FilterIndexType filterTypes[9] = { FAVORITES_FILTER, GENRE_FILTER, PLAYER_FILTER, const FilterIndexType filterTypes[9] = {FAVORITES_FILTER, GENRE_FILTER, PLAYER_FILTER,
PUBDEV_FILTER, RATINGS_FILTER, KIDGAME_FILTER, PUBDEV_FILTER, RATINGS_FILTER, KIDGAME_FILTER,
COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER }; COMPLETED_FILTER, BROKEN_FILTER, HIDDEN_FILTER};
std::vector<std::string> filterKeysList[9] = { std::vector<std::string> filterKeysList[9] = {
mFavoritesIndexFilteredKeys, mGenreIndexFilteredKeys, mPlayersIndexFilteredKeys, mFavoritesIndexFilteredKeys, mGenreIndexFilteredKeys, mPlayersIndexFilteredKeys,
mPubDevIndexFilteredKeys, mRatingsIndexFilteredKeys, mKidGameIndexFilteredKeys, mPubDevIndexFilteredKeys, mRatingsIndexFilteredKeys, mKidGameIndexFilteredKeys,
mCompletedIndexFilteredKeys, mBrokenIndexFilteredKeys, mHiddenIndexFilteredKeys mCompletedIndexFilteredKeys, mBrokenIndexFilteredKeys, mHiddenIndexFilteredKeys};
};
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
if (filterTypes[i] == type) { if (filterTypes[i] == type) {

View file

@ -45,8 +45,7 @@ namespace FileSorts
FileData::SortType(&compareTimesPlayedDescending, "times played, descending"), FileData::SortType(&compareTimesPlayedDescending, "times played, descending"),
FileData::SortType(&compareSystem, "system, ascending"), FileData::SortType(&compareSystem, "system, ascending"),
FileData::SortType(&compareSystemDescending, "system, descending") FileData::SortType(&compareSystemDescending, "system, descending")};
};
const std::vector<FileData::SortType> SortTypes(typesArr, const std::vector<FileData::SortType> SortTypes(typesArr,
typesArr + typesArr +

View file

@ -120,8 +120,8 @@ void parseGamelist(SystemData* system)
std::string relativeTo = system->getStartPath(); std::string relativeTo = system->getStartPath();
bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles"); bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles");
std::vector<std::string> tagList = { "game", "folder" }; std::vector<std::string> tagList = {"game", "folder"};
FileType typeList[2] = { GAME, FOLDER }; FileType typeList[2] = {GAME, FOLDER};
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
std::string tag = tagList[i]; std::string tag = tagList[i];
FileType type = typeList[i]; FileType type = typeList[i];

View file

@ -83,19 +83,19 @@ void MediaViewer::update(int deltaTime)
void MediaViewer::render() void MediaViewer::render()
{ {
Transform4x4f transform = Transform4x4f::Identity(); glm::mat4 trans{Renderer::getIdentity()};
Renderer::setMatrix(transform); Renderer::setMatrix(trans);
// Render a black background below the game media. // Render a black background below the game media.
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()), Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF); static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
if (mVideo && !mDisplayingImage) { if (mVideo && !mDisplayingImage) {
mVideo->render(transform); mVideo->render(trans);
#if defined(USE_OPENGL_21) #if defined(USE_OPENGL_21)
Renderer::shaderParameters videoParameters; Renderer::shaderParameters videoParameters;
unsigned int shaders = 0; unsigned int shaders{0};
if (Settings::getInstance()->getBool("MediaViewerVideoScanlines")) if (Settings::getInstance()->getBool("MediaViewerVideoScanlines"))
shaders = Renderer::SHADER_SCANLINES; shaders = Renderer::SHADER_SCANLINES;
if (Settings::getInstance()->getBool("MediaViewerVideoBlur")) { if (Settings::getInstance()->getBool("MediaViewerVideoBlur")) {
@ -121,8 +121,8 @@ void MediaViewer::render()
Renderer::shaderPostprocessing(shaders, videoParameters); Renderer::shaderPostprocessing(shaders, videoParameters);
#endif #endif
} }
else if (mImage && mImage->hasImage() && mImage->getSize() != 0) { else if (mImage && mImage->hasImage() && mImage->getSize() != glm::vec2{}) {
mImage->render(transform); mImage->render(trans);
#if defined(USE_OPENGL_21) #if defined(USE_OPENGL_21)
if (mCurrentImageIndex == mScreenShotIndex && if (mCurrentImageIndex == mScreenShotIndex &&

View file

@ -472,7 +472,7 @@ bool MiximageGenerator::generateImage()
frameImageAlpha.draw_image(xPosMarquee, yPosMarquee, marqueeImageAlpha); frameImageAlpha.draw_image(xPosMarquee, yPosMarquee, marqueeImageAlpha);
// Set a frame color based on an average of the screenshot contents. // Set a frame color based on an average of the screenshot contents.
unsigned char frameColor[] = { 0, 0, 0, 0 }; unsigned char frameColor[] = {0, 0, 0, 0};
sampleFrameColor(screenshotImage, frameColor); sampleFrameColor(screenshotImage, frameColor);
// Upper / lower frame. // Upper / lower frame.

View file

@ -919,7 +919,7 @@ SystemData* SystemData::getRandomSystem(const SystemData* currentSystem)
// Get a random number in range. // Get a random number in range.
std::random_device randDev; std::random_device randDev;
// Mersenne Twister pseudorandom number generator. // Mersenne Twister pseudorandom number generator.
std::mt19937 engine { randDev() }; std::mt19937 engine{randDev()};
std::uniform_int_distribution<int> uniform_dist(0, total - 1); std::uniform_int_distribution<int> uniform_dist(0, total - 1);
int target = uniform_dist(engine); int target = uniform_dist(engine);
@ -998,7 +998,7 @@ FileData* SystemData::getRandomGame(const FileData* currentGame)
// Get a random number in range. // Get a random number in range.
std::random_device randDev; std::random_device randDev;
// Mersenne Twister pseudorandom number generator. // Mersenne Twister pseudorandom number generator.
std::mt19937 engine { randDev() }; std::mt19937 engine{randDev()};
std::uniform_int_distribution<int> uniform_dist(0, total - 1); std::uniform_int_distribution<int> uniform_dist(0, total - 1);
target = uniform_dist(engine); target = uniform_dist(engine);
} while (currentGame && gameList.at(target) == currentGame); } while (currentGame && gameList.at(target) == currentGame);

View file

@ -248,19 +248,19 @@ void SystemScreensaver::renderScreensaver()
if (mVideoScreensaver && screensaverType == "video") { if (mVideoScreensaver && screensaverType == "video") {
// Render a black background below the video. // Render a black background below the video.
Renderer::setMatrix(Transform4x4f::Identity()); Renderer::setMatrix(Renderer::getIdentity());
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()), Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF); static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
// Only render the video if the state requires it. // Only render the video if the state requires it.
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) { if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
Transform4x4f transform = Transform4x4f::Identity(); glm::mat4 trans{Renderer::getIdentity()};
mVideoScreensaver->render(transform); mVideoScreensaver->render(trans);
} }
} }
else if (mImageScreensaver && screensaverType == "slideshow") { else if (mImageScreensaver && screensaverType == "slideshow") {
// Render a black background below the image. // Render a black background below the image.
Renderer::setMatrix(Transform4x4f::Identity()); Renderer::setMatrix(Renderer::getIdentity());
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()), Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF); static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
@ -268,15 +268,14 @@ void SystemScreensaver::renderScreensaver()
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) { if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
if (mImageScreensaver->hasImage()) { if (mImageScreensaver->hasImage()) {
mImageScreensaver->setOpacity(255 - static_cast<unsigned char>(mOpacity * 255)); mImageScreensaver->setOpacity(255 - static_cast<unsigned char>(mOpacity * 255));
glm::mat4 trans{Renderer::getIdentity()};
Transform4x4f transform = Transform4x4f::Identity(); mImageScreensaver->render(trans);
mImageScreensaver->render(transform);
} }
} }
} }
if (isScreensaverActive()) { if (isScreensaverActive()) {
Renderer::setMatrix(Transform4x4f::Identity()); Renderer::setMatrix(Renderer::getIdentity());
if (Settings::getInstance()->getString("ScreensaverType") == "slideshow") { if (Settings::getInstance()->getString("ScreensaverType") == "slideshow") {
if (mHasMediaFiles) { if (mHasMediaFiles) {
#if defined(USE_OPENGL_21) #if defined(USE_OPENGL_21)
@ -515,7 +514,7 @@ void SystemScreensaver::pickRandomImage(std::string& path)
// Get a random number in range. // Get a random number in range.
std::random_device randDev; std::random_device randDev;
// Mersenne Twister pseudorandom number generator. // Mersenne Twister pseudorandom number generator.
std::mt19937 engine { randDev() }; std::mt19937 engine{randDev()};
std::uniform_int_distribution<int> uniform_dist(0, std::uniform_int_distribution<int> uniform_dist(0,
static_cast<int>(mImageFiles.size()) - 1); static_cast<int>(mImageFiles.size()) - 1);
index = uniform_dist(engine); index = uniform_dist(engine);
@ -549,7 +548,7 @@ void SystemScreensaver::pickRandomVideo(std::string& path)
// Get a random number in range. // Get a random number in range.
std::random_device randDev; std::random_device randDev;
// Mersenne Twister pseudorandom number generator. // Mersenne Twister pseudorandom number generator.
std::mt19937 engine { randDev() }; std::mt19937 engine{randDev()};
std::uniform_int_distribution<int> uniform_dist(0, std::uniform_int_distribution<int> uniform_dist(0,
static_cast<int>(mVideoFiles.size()) - 1); static_cast<int>(mVideoFiles.size()) - 1);
index = uniform_dist(engine); index = uniform_dist(engine);
@ -577,7 +576,7 @@ void SystemScreensaver::pickRandomCustomImage(std::string& path)
// Get a random number in range. // Get a random number in range.
std::random_device randDev; std::random_device randDev;
// Mersenne Twister pseudorandom number generator. // Mersenne Twister pseudorandom number generator.
std::mt19937 engine { randDev() }; std::mt19937 engine{randDev()};
std::uniform_int_distribution<int> uniform_dist( std::uniform_int_distribution<int> uniform_dist(
0, static_cast<int>(mImageCustomFiles.size()) - 1); 0, static_cast<int>(mImageCustomFiles.size()) - 1);
index = uniform_dist(engine); index = uniform_dist(engine);
@ -609,18 +608,18 @@ void SystemScreensaver::generateOverlayInfo()
mGameOverlayFont.at(0)->buildTextCache(overlayText, posX, posY, 0xFFFFFFFF)); mGameOverlayFont.at(0)->buildTextCache(overlayText, posX, posY, 0xFFFFFFFF));
float textSizeX; float textSizeX;
float textSizeY = mGameOverlayFont[0].get()->sizeText(overlayText).y(); float textSizeY = mGameOverlayFont[0].get()->sizeText(overlayText).y;
// There is a weird issue with sizeText() where the X size value is returned // There is a weird issue with sizeText() where the X size value is returned
// as too large if there are two rows in a string and the second row is longer // as too large if there are two rows in a string and the second row is longer
// than the first row. Possibly it's the newline character that is somehow // than the first row. Possibly it's the newline character that is somehow
// injected in the size calculation. Regardless, this workaround is working // injected in the size calculation. Regardless, this workaround is working
// fine for the time being. // fine for the time being.
if (mGameOverlayFont[0].get()->sizeText(gameName).x() > if (mGameOverlayFont[0].get()->sizeText(gameName).x >
mGameOverlayFont[0].get()->sizeText(systemName).x()) mGameOverlayFont[0].get()->sizeText(systemName).x)
textSizeX = mGameOverlayFont[0].get()->sizeText(gameName).x(); textSizeX = mGameOverlayFont[0].get()->sizeText(gameName).x;
else else
textSizeX = mGameOverlayFont[0].get()->sizeText(systemName).x(); textSizeX = mGameOverlayFont[0].get()->sizeText(systemName).x;
float marginX = Renderer::getWindowWidth() * 0.01f; float marginX = Renderer::getWindowWidth() * 0.01f;

View file

@ -10,14 +10,15 @@
#define ES_APP_ANIMATIONS_MOVE_CAMERA_ANIMATION_H #define ES_APP_ANIMATIONS_MOVE_CAMERA_ANIMATION_H
#include "animations/Animation.h" #include "animations/Animation.h"
#include "math/Misc.h"
class MoveCameraAnimation : public Animation class MoveCameraAnimation : public Animation
{ {
public: public:
MoveCameraAnimation(Transform4x4f& camera, const Vector3f& target) MoveCameraAnimation(glm::mat4& camera, const glm::vec3& target)
: mCameraStart(camera) : mCameraStart(camera)
, mTarget(target) , mTarget(target)
, cameraOut(camera) , cameraPosition(camera)
{ {
} }
@ -25,17 +26,16 @@ public:
void apply(float t) override void apply(float t) override
{ {
// Cubic ease out.
t -= 1; t -= 1;
cameraOut.translation() = cameraPosition[3].x = -Math::lerp(-mCameraStart[3].x, mTarget.x, t * t * t + 1);
-Vector3f().lerp(-mCameraStart.translation(), mTarget, t * t * t + 1); cameraPosition[3].y = -Math::lerp(-mCameraStart[3].y, mTarget.y, t * t * t + 1);
cameraPosition[3].z = -Math::lerp(-mCameraStart[3].z, mTarget.z, t * t * t + 1);
} }
private: private:
Transform4x4f mCameraStart; glm::mat4 mCameraStart;
Vector3f mTarget; glm::mat4& cameraPosition;
glm::vec3 mTarget;
Transform4x4f& cameraOut;
}; };
#endif // ES_APP_ANIMATIONS_MOVE_CAMERA_ANIMATION_H #endif // ES_APP_ANIMATIONS_MOVE_CAMERA_ANIMATION_H

View file

@ -158,7 +158,7 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window, std::st
auto bracketThemeCollection = std::make_shared<ImageComponent>(mWindow); auto bracketThemeCollection = std::make_shared<ImageComponent>(mWindow);
bracketThemeCollection->setImage(":/graphics/arrow.svg"); bracketThemeCollection->setImage(":/graphics/arrow.svg");
bracketThemeCollection->setResize( bracketThemeCollection->setResize(
Vector2f(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); glm::vec2{0.0f, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()});
row.addElement(themeCollection, true); row.addElement(themeCollection, true);
row.addElement(bracketThemeCollection, false); row.addElement(bracketThemeCollection, false);
row.makeAcceptInputHandler([this, unusedFolders] { row.makeAcceptInputHandler([this, unusedFolders] {
@ -195,7 +195,8 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window, std::st
Font::get(FONT_SIZE_MEDIUM), 0x777777FF); Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
auto bracketNewCollection = std::make_shared<ImageComponent>(mWindow); auto bracketNewCollection = std::make_shared<ImageComponent>(mWindow);
bracketNewCollection->setImage(":/graphics/arrow.svg"); bracketNewCollection->setImage(":/graphics/arrow.svg");
bracketNewCollection->setResize(Vector2f(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); bracketNewCollection->setResize(
glm::vec2{0.0f, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()});
row.addElement(newCollection, true); row.addElement(newCollection, true);
row.addElement(bracketNewCollection, false); row.addElement(bracketNewCollection, false);
auto createCollectionCall = [this](const std::string& newVal) { auto createCollectionCall = [this](const std::string& newVal) {
@ -219,7 +220,8 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(Window* window, std::st
mWindow, "DELETE CUSTOM COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF); mWindow, "DELETE CUSTOM COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
auto bracketDeleteCollection = std::make_shared<ImageComponent>(mWindow); auto bracketDeleteCollection = std::make_shared<ImageComponent>(mWindow);
bracketDeleteCollection->setImage(":/graphics/arrow.svg"); bracketDeleteCollection->setImage(":/graphics/arrow.svg");
bracketDeleteCollection->setResize(Vector2f(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); bracketDeleteCollection->setResize(
glm::vec2{0.0f, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()});
row.addElement(deleteCollection, true); row.addElement(deleteCollection, true);
row.addElement(bracketDeleteCollection, false); row.addElement(bracketDeleteCollection, false);
row.makeAcceptInputHandler([this, customSystems] { row.makeAcceptInputHandler([this, customSystems] {

View file

@ -22,7 +22,7 @@ GuiGameScraper::GuiGameScraper(Window* window,
ScraperSearchParams params, ScraperSearchParams params,
std::function<void(const ScraperSearchResult&)> doneFunc) std::function<void(const ScraperSearchResult&)> doneFunc)
: GuiComponent(window) : GuiComponent(window)
, mGrid(window, Vector2i(1, 7)) , mGrid(window, glm::ivec2{1, 7})
, mBox(window, ":/graphics/frame.svg") , mBox(window, ":/graphics/frame.svg")
, mSearchParams(params) , mSearchParams(params)
, mClose(false) , mClose(false)
@ -52,20 +52,20 @@ GuiGameScraper::GuiGameScraper(Window* window,
scrapeName + scrapeName +
((mSearchParams.game->getType() == FOLDER) ? " " + ViewController::FOLDER_CHAR : ""), ((mSearchParams.game->getType() == FOLDER) ? " " + ViewController::FOLDER_CHAR : ""),
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER); Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
mGrid.setEntry(mGameName, Vector2i(0, 1), false, true); mGrid.setEntry(mGameName, glm::ivec2{0, 1}, false, true);
// Row 2 is a spacer. // Row 2 is a spacer.
mSystemName = std::make_shared<TextComponent>( mSystemName = std::make_shared<TextComponent>(
mWindow, Utils::String::toUpper(mSearchParams.system->getFullName()), mWindow, Utils::String::toUpper(mSearchParams.system->getFullName()),
Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER); Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER);
mGrid.setEntry(mSystemName, Vector2i(0, 3), false, true); mGrid.setEntry(mSystemName, glm::ivec2{0, 3}, false, true);
// Row 4 is a spacer. // Row 4 is a spacer.
// GuiScraperSearch. // GuiScraperSearch.
mSearch = std::make_shared<GuiScraperSearch>(window, GuiScraperSearch::NEVER_AUTO_ACCEPT, 1); mSearch = std::make_shared<GuiScraperSearch>(window, GuiScraperSearch::NEVER_AUTO_ACCEPT, 1);
mGrid.setEntry(mSearch, Vector2i(0, 5), true); mGrid.setEntry(mSearch, glm::ivec2{0, 5}, true);
// Buttons // Buttons
std::vector<std::shared_ptr<ButtonComponent>> buttons; std::vector<std::shared_ptr<ButtonComponent>> buttons;
@ -92,7 +92,7 @@ GuiGameScraper::GuiGameScraper(Window* window,
})); }));
mButtonGrid = makeButtonGrid(mWindow, buttons); mButtonGrid = makeButtonGrid(mWindow, buttons);
mGrid.setEntry(mButtonGrid, Vector2i(0, 6), true, false); mGrid.setEntry(mButtonGrid, glm::ivec2{0, 6}, true, false);
mSearch->setAcceptCallback([this, doneFunc](const ScraperSearchResult& result) { mSearch->setAcceptCallback([this, doneFunc](const ScraperSearchResult& result) {
doneFunc(result); doneFunc(result);
@ -106,8 +106,8 @@ GuiGameScraper::GuiGameScraper(Window* window,
float width = Math::clamp(0.95f * aspectValue, 0.70f, 0.95f) * Renderer::getScreenWidth(); float width = Math::clamp(0.95f * aspectValue, 0.70f, 0.95f) * Renderer::getScreenWidth();
setSize(width, Renderer::getScreenHeight() * 0.747f); setSize(width, Renderer::getScreenHeight() * 0.747f);
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f,
(Renderer::getScreenHeight() - mSize.y()) / 2.0f); (Renderer::getScreenHeight() - mSize.y) / 2.0f);
mGrid.resetCursor(); mGrid.resetCursor();
mSearch->search(params); // Start the search. mSearch->search(params); // Start the search.
@ -115,16 +115,14 @@ GuiGameScraper::GuiGameScraper(Window* window,
void GuiGameScraper::onSizeChanged() void GuiGameScraper::onSizeChanged()
{ {
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mBox.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
mGrid.setRowHeightPerc(0, 0.04f, false); mGrid.setRowHeightPerc(0, 0.04f, false);
mGrid.setRowHeightPerc(1, mGameName->getFont()->getLetterHeight() / mSize.y(), mGrid.setRowHeightPerc(1, mGameName->getFont()->getLetterHeight() / mSize.y, false);
false); // Game name.
mGrid.setRowHeightPerc(2, 0.04f, false); mGrid.setRowHeightPerc(2, 0.04f, false);
mGrid.setRowHeightPerc(3, mSystemName->getFont()->getLetterHeight() / mSize.y(), mGrid.setRowHeightPerc(3, mSystemName->getFont()->getLetterHeight() / mSize.y, false);
false); // System name.
mGrid.setRowHeightPerc(4, 0.04f, false); mGrid.setRowHeightPerc(4, 0.04f, false);
mGrid.setRowHeightPerc(6, mButtonGrid->getSize().y() / mSize.y(), false); // Buttons. mGrid.setRowHeightPerc(6, mButtonGrid->getSize().y / mSize.y, false);
mGrid.setSize(mSize); mGrid.setSize(mSize);
} }

View file

@ -50,7 +50,7 @@ void GuiGamelistFilter::initializeMenu()
mMenu.addButton("BACK", "back", std::bind(&GuiGamelistFilter::applyFilters, this)); mMenu.addButton("BACK", "back", std::bind(&GuiGamelistFilter::applyFilters, this));
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2.0f, mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x) / 2.0f,
Renderer::getScreenHeight() * 0.13f); Renderer::getScreenHeight() * 0.13f);
// Save the initial filter values to be able to check later if any changes were made. // Save the initial filter values to be able to check later if any changes were made.
@ -101,12 +101,12 @@ void GuiGamelistFilter::addFiltersToMenu()
row.addElement(mTextFilterField, true); row.addElement(mTextFilterField, true);
auto spacer = std::make_shared<GuiComponent>(mWindow); auto spacer = std::make_shared<GuiComponent>(mWindow);
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0); spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f);
row.addElement(spacer, false); row.addElement(spacer, false);
auto bracket = std::make_shared<ImageComponent>(mWindow); auto bracket = std::make_shared<ImageComponent>(mWindow);
bracket->setImage(":/graphics/arrow.svg"); bracket->setImage(":/graphics/arrow.svg");
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight())); bracket->setResize(glm::vec2{0.0f, lbl->getFont()->getLetterHeight()});
row.addElement(bracket, false); row.addElement(bracket, false);
mTextFilterField->setValue(mFilterIndex->getTextFilter()); mTextFilterField->setValue(mFilterIndex->getTextFilter());

View file

@ -240,8 +240,7 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system)
// Center the menu. // Center the menu.
setSize(static_cast<float>(Renderer::getScreenWidth()), setSize(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight()));
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2.0f, mMenu.setPosition((mSize.x - mMenu.getSize().x) / 2.0f, (mSize.y - mMenu.getSize().y) / 2.0f);
(mSize.y() - mMenu.getSize().y()) / 2.0f);
} }
GuiGamelistOptions::~GuiGamelistOptions() GuiGamelistOptions::~GuiGamelistOptions()

View file

@ -33,36 +33,36 @@ GuiInfoPopup::GuiInfoPopup(Window* window, std::string message, int duration)
mSize = s->getSize(); mSize = s->getSize();
// Confirm that the size isn't larger than the screen width, otherwise cap it. // Confirm that the size isn't larger than the screen width, otherwise cap it.
if (mSize.x() > maxWidth) { if (mSize.x > maxWidth) {
s->setSize(maxWidth, mSize[1]); s->setSize(maxWidth, mSize.y);
mSize[0] = maxWidth; mSize.x = maxWidth;
} }
if (mSize.y() > maxHeight) { if (mSize.y > maxHeight) {
s->setSize(mSize[0], maxHeight); s->setSize(mSize.x, maxHeight);
mSize[1] = maxHeight; mSize.y = maxHeight;
} }
// Add a padding to the box. // Add a padding to the box.
int paddingX = static_cast<int>(Renderer::getScreenWidth() * 0.03f); int paddingX = static_cast<int>(Renderer::getScreenWidth() * 0.03f);
int paddingY = static_cast<int>(Renderer::getScreenHeight() * 0.02f); int paddingY = static_cast<int>(Renderer::getScreenHeight() * 0.02f);
mSize[0] = mSize.x() + paddingX; mSize.x = mSize.x + paddingX;
mSize[1] = mSize.y() + paddingY; mSize.y = mSize.y + paddingY;
float posX = Renderer::getScreenWidth() * 0.5f - mSize.x() * 0.5f; float posX = Renderer::getScreenWidth() * 0.5f - mSize.x * 0.5f;
float posY = Renderer::getScreenHeight() * 0.02f; float posY = Renderer::getScreenHeight() * 0.02f;
setPosition(posX, posY, 0); setPosition(posX, posY, 0);
mFrame->setImagePath(":/graphics/frame.svg"); mFrame->setImagePath(":/graphics/frame.svg");
mFrame->fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mFrame->fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
addChild(mFrame); addChild(mFrame);
// We only initialize the actual time when we first start to render. // We only initialize the actual time when we first start to render.
mStartTime = 0; mStartTime = 0;
mGrid = new ComponentGrid(window, Vector2i(1, 3)); mGrid = new ComponentGrid(window, glm::ivec2{1, 3});
mGrid->setSize(mSize); mGrid->setSize(mSize);
mGrid->setEntry(s, Vector2i(0, 1), false, true); mGrid->setEntry(s, glm::ivec2{0, 1}, false, true);
addChild(mGrid); addChild(mGrid);
} }
@ -72,10 +72,10 @@ GuiInfoPopup::~GuiInfoPopup()
delete mFrame; delete mFrame;
} }
void GuiInfoPopup::render(const Transform4x4f& /*parentTrans*/) void GuiInfoPopup::render(const glm::mat4& /*parentTrans*/)
{ {
// We use Identity() as we want to render on a specific window position, not on the view. // We use getIdentity() as we want to render on a specific window position, not on the view.
Transform4x4f trans = getTransform() * Transform4x4f::Identity(); glm::mat4 trans{getTransform() * Renderer::getIdentity()};
if (mRunning && updateState()) { if (mRunning && updateState()) {
// If we're still supposed to be rendering it. // If we're still supposed to be rendering it.
Renderer::setMatrix(trans); Renderer::setMatrix(trans);

View file

@ -21,7 +21,7 @@ public:
GuiInfoPopup(Window* window, std::string message, int duration); GuiInfoPopup(Window* window, std::string message, int duration);
~GuiInfoPopup(); ~GuiInfoPopup();
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void stop() override { mRunning = false; } void stop() override { mRunning = false; }
private: private:

View file

@ -34,7 +34,7 @@ GuiLaunchScreen::~GuiLaunchScreen()
void GuiLaunchScreen::displayLaunchScreen(FileData* game) void GuiLaunchScreen::displayLaunchScreen(FileData* game)
{ {
mGrid = new ComponentGrid(mWindow, Vector2i(3, 8)); mGrid = new ComponentGrid(mWindow, glm::ivec2{3, 8});
addChild(mGrid); addChild(mGrid);
mImagePath = game->getMarqueePath(); mImagePath = game->getMarqueePath();
@ -51,8 +51,8 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
const float gameNameFontSize = 0.073f; const float gameNameFontSize = 0.073f;
// Spacer row. // Spacer row.
mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(1, 0), false, false, mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{1, 0}, false, false,
Vector2i(1, 1)); glm::ivec2{1, 1});
// Title. // Title.
mTitle = std::make_shared<TextComponent>( mTitle = std::make_shared<TextComponent>(
@ -60,19 +60,19 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
Font::get(static_cast<int>( Font::get(static_cast<int>(
titleFontSize * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()))), titleFontSize * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()))),
0x666666FF, ALIGN_CENTER); 0x666666FF, ALIGN_CENTER);
mGrid->setEntry(mTitle, Vector2i(1, 1), false, true, Vector2i(1, 1)); mGrid->setEntry(mTitle, glm::ivec2{1, 1}, false, true, glm::ivec2{1, 1});
// Spacer row. // Spacer row.
mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(1, 2), false, false, mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{1, 2}, false, false,
Vector2i(1, 1)); glm::ivec2{1, 1});
// Row for the marquee. // Row for the marquee.
mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(1, 3), false, false, mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{1, 3}, false, false,
Vector2i(1, 1)); glm::ivec2{1, 1});
// Spacer row. // Spacer row.
mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(1, 4), false, false, mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{1, 4}, false, false,
Vector2i(1, 1)); glm::ivec2{1, 1});
// Game name. // Game name.
mGameName = std::make_shared<TextComponent>( mGameName = std::make_shared<TextComponent>(
@ -80,24 +80,24 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
Font::get(static_cast<int>( Font::get(static_cast<int>(
gameNameFontSize * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()))), gameNameFontSize * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()))),
0x444444FF, ALIGN_CENTER); 0x444444FF, ALIGN_CENTER);
mGrid->setEntry(mGameName, Vector2i(1, 5), false, true, Vector2i(1, 1)); mGrid->setEntry(mGameName, glm::ivec2{1, 5}, false, true, glm::ivec2{1, 1});
// System name. // System name.
mSystemName = std::make_shared<TextComponent>( mSystemName = std::make_shared<TextComponent>(
mWindow, "SYSTEM NAME", Font::get(FONT_SIZE_MEDIUM), 0x666666FF, ALIGN_CENTER); mWindow, "SYSTEM NAME", Font::get(FONT_SIZE_MEDIUM), 0x666666FF, ALIGN_CENTER);
mGrid->setEntry(mSystemName, Vector2i(1, 6), false, true, Vector2i(1, 1)); mGrid->setEntry(mSystemName, glm::ivec2{1, 6}, false, true, glm::ivec2{1, 1});
// Spacer row. // Spacer row.
mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(1, 7), false, false, mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{1, 7}, false, false,
Vector2i(1, 1)); glm::ivec2{1, 1});
// Left spacer. // Left spacer.
mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 0), false, false, mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{0, 0}, false, false,
Vector2i(1, 8)); glm::ivec2{1, 8});
// Right spacer. // Right spacer.
mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(2, 0), false, false, mGrid->setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{2, 0}, false, false,
Vector2i(1, 8)); glm::ivec2{1, 8});
// Adjust the width depending on the aspect ratio of the screen, to make the screen look // Adjust the width depending on the aspect ratio of the screen, to make the screen look
// somewhat coherent regardless of screen type. The 1.778 aspect ratio value is the 16:9 // somewhat coherent regardless of screen type. The 1.778 aspect ratio value is the 16:9
@ -114,7 +114,7 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
Font::get(static_cast<int>(gameNameFontSize * std::min(Renderer::getScreenHeight(), Font::get(static_cast<int>(gameNameFontSize * std::min(Renderer::getScreenHeight(),
Renderer::getScreenWidth()))) Renderer::getScreenWidth())))
->sizeText(Utils::String::toUpper(game->getName())) ->sizeText(Utils::String::toUpper(game->getName()))
.x(); .x;
// Add a bit of width to compensate for the left and right spacers. // Add a bit of width to compensate for the left and right spacers.
fontWidth += static_cast<float>(Renderer::getScreenWidth()) * 0.05f; fontWidth += static_cast<float>(Renderer::getScreenWidth()) * 0.05f;
@ -131,15 +131,15 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
mGrid->setRowHeightPerc(0, 0.09f, false); mGrid->setRowHeightPerc(0, 0.09f, false);
else else
mGrid->setRowHeightPerc(0, 0.15f, false); mGrid->setRowHeightPerc(0, 0.15f, false);
mGrid->setRowHeightPerc(1, mTitle->getFont()->getLetterHeight() * 1.70f / mSize.y(), false); mGrid->setRowHeightPerc(1, mTitle->getFont()->getLetterHeight() * 1.70f / mSize.y, false);
mGrid->setRowHeightPerc(2, 0.05f, false); mGrid->setRowHeightPerc(2, 0.05f, false);
if (mImagePath != "") if (mImagePath != "")
mGrid->setRowHeightPerc(3, 0.35f, false); mGrid->setRowHeightPerc(3, 0.35f, false);
else else
mGrid->setRowHeightPerc(3, 0.01f, false); mGrid->setRowHeightPerc(3, 0.01f, false);
mGrid->setRowHeightPerc(4, 0.05f, false); mGrid->setRowHeightPerc(4, 0.05f, false);
mGrid->setRowHeightPerc(5, mGameName->getFont()->getHeight() * 0.80f / mSize.y(), false); mGrid->setRowHeightPerc(5, mGameName->getFont()->getHeight() * 0.80f / mSize.y, false);
mGrid->setRowHeightPerc(6, mSystemName->getFont()->getHeight() * 0.90f / mSize.y(), false); mGrid->setRowHeightPerc(6, mSystemName->getFont()->getHeight() * 0.90f / mSize.y, false);
// Set left and right spacers column widths. // Set left and right spacers column widths.
mGrid->setColWidthPerc(0, 0.025f); mGrid->setColWidthPerc(0, 0.025f);
@ -153,7 +153,7 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
for (int i = 0; i < 7; i++) for (int i = 0; i < 7; i++)
totalRowHeight += mGrid->getRowHeight(i); totalRowHeight += mGrid->getRowHeight(i);
setSize(mSize.x(), totalRowHeight); setSize(mSize.x, totalRowHeight);
mGameName->setText(Utils::String::toUpper(game->getName())); mGameName->setText(Utils::String::toUpper(game->getName()));
mSystemName->setText(Utils::String::toUpper(game->getSystem()->getFullName())); mSystemName->setText(Utils::String::toUpper(game->getSystem()->getFullName()));
@ -169,23 +169,23 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
mGrid->getRowHeight(3)); mGrid->getRowHeight(3));
mMarquee->setOrigin(0.5f, 0.5f); mMarquee->setOrigin(0.5f, 0.5f);
Vector3f currentPos = mMarquee->getPosition(); glm::vec3 currentPos{mMarquee->getPosition()};
Vector2f currentSize = mMarquee->getSize(); glm::vec2 currentSize{mMarquee->getSize()};
// Position the image in the middle of row four. // Position the image in the middle of row four.
currentPos.x() = mSize.x() / 2.0f; currentPos.x = mSize.x / 2.0f;
currentPos.y() = mGrid->getRowHeight(0) + mGrid->getRowHeight(1) + mGrid->getRowHeight(2) + currentPos.y = mGrid->getRowHeight(0) + mGrid->getRowHeight(1) + mGrid->getRowHeight(2) +
mGrid->getRowHeight(3) / 2.0f; mGrid->getRowHeight(3) / 2.0f;
mMarquee->setPosition(currentPos); mMarquee->setPosition(currentPos);
} }
setOrigin({ 0.5f, 0.5f }); setOrigin({0.5f, 0.5f});
// Center on the X axis and keep slightly off-center on the Y axis. // Center on the X axis and keep slightly off-center on the Y axis.
setPosition(static_cast<float>(Renderer::getScreenWidth()) / 2.0f, setPosition(static_cast<float>(Renderer::getScreenWidth()) / 2.0f,
static_cast<float>(Renderer::getScreenHeight()) / 2.25f); static_cast<float>(Renderer::getScreenHeight()) / 2.25f);
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
mBackground.setEdgeColor(0xEEEEEEFF); mBackground.setEdgeColor(0xEEEEEEFF);
} }
@ -228,7 +228,7 @@ void GuiLaunchScreen::render()
if (mScaleUp < 1.0f) if (mScaleUp < 1.0f)
setScale(mScaleUp); setScale(mScaleUp);
Transform4x4f trans = Transform4x4f::Identity() * getTransform(); glm::mat4 trans{Renderer::getIdentity() * getTransform()};
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
GuiComponent::renderChildren(trans); GuiComponent::renderChildren(trans);

View file

@ -75,8 +75,7 @@ GuiMenu::GuiMenu(Window* window)
addChild(&mMenu); addChild(&mMenu);
addVersionInfo(); addVersionInfo();
setSize(mMenu.getSize()); setSize(mMenu.getSize());
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, Renderer::getScreenHeight() * 0.13f);
Renderer::getScreenHeight() * 0.13f);
} }
GuiMenu::~GuiMenu() GuiMenu::~GuiMenu()
@ -97,17 +96,16 @@ void GuiMenu::openUIOptions()
auto startup_system = std::make_shared<OptionListComponent<std::string>>( auto startup_system = std::make_shared<OptionListComponent<std::string>>(
mWindow, getHelpStyle(), "GAMELIST ON STARTUP", false); mWindow, getHelpStyle(), "GAMELIST ON STARTUP", false);
startup_system->add("NONE", "", Settings::getInstance()->getString("StartupSystem") == ""); startup_system->add("NONE", "", Settings::getInstance()->getString("StartupSystem") == "");
float dotsSize = Font::get(FONT_SIZE_MEDIUM)->sizeText("...").x(); float dotsSize = Font::get(FONT_SIZE_MEDIUM)->sizeText("...").x;
for (auto it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend(); for (auto it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend();
it++) { it++) {
if ((*it)->getName() != "retropie") { if ((*it)->getName() != "retropie") {
// If required, abbreviate the system name so it doesn't overlap the setting name. // If required, abbreviate the system name so it doesn't overlap the setting name.
std::string abbreviatedString = std::string abbreviatedString =
Font::get(FONT_SIZE_MEDIUM) Font::get(FONT_SIZE_MEDIUM)->getTextMaxWidth((*it)->getFullName(), mSize.x * 0.47f);
->getTextMaxWidth((*it)->getFullName(), mSize.x() * 0.47f); float sizeDifference = Font::get(FONT_SIZE_MEDIUM)->sizeText((*it)->getFullName()).x -
float sizeDifference = Font::get(FONT_SIZE_MEDIUM)->sizeText((*it)->getFullName()).x() - Font::get(FONT_SIZE_MEDIUM)->sizeText(abbreviatedString).x;
Font::get(FONT_SIZE_MEDIUM)->sizeText(abbreviatedString).x(); if (sizeDifference > 0.0f) {
if (sizeDifference > 0) {
// It doesn't make sense to abbreviate if the number of pixels removed by // It doesn't make sense to abbreviate if the number of pixels removed by
// the abbreviation is less or equal to the size of the three dots that // the abbreviation is less or equal to the size of the three dots that
// would be appended to the string. // would be appended to the string.
@ -899,7 +897,8 @@ void GuiMenu::openOtherOptions()
Font::get(FONT_SIZE_MEDIUM), 0x777777FF); Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
auto bracketMediaDirectory = std::make_shared<ImageComponent>(mWindow); auto bracketMediaDirectory = std::make_shared<ImageComponent>(mWindow);
bracketMediaDirectory->setImage(":/graphics/arrow.svg"); bracketMediaDirectory->setImage(":/graphics/arrow.svg");
bracketMediaDirectory->setResize(Vector2f(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight())); bracketMediaDirectory->setResize(
glm::vec2{0.0f, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()});
rowMediaDir.addElement(media_directory, true); rowMediaDir.addElement(media_directory, true);
rowMediaDir.addElement(bracketMediaDirectory, false); rowMediaDir.addElement(bracketMediaDirectory, false);
std::string titleMediaDir = "ENTER GAME MEDIA DIRECTORY"; std::string titleMediaDir = "ENTER GAME MEDIA DIRECTORY";
@ -1259,8 +1258,8 @@ void GuiMenu::openCollectionSystemOptions()
void GuiMenu::onSizeChanged() void GuiMenu::onSizeChanged()
{ {
mVersion.setSize(mSize.x(), 0); mVersion.setSize(mSize.x, 0.0f);
mVersion.setPosition(0, mSize.y() - mVersion.getSize().y()); mVersion.setPosition(0.0f, mSize.y - mVersion.getSize().y);
} }
void GuiMenu::addEntry(const std::string& name, void GuiMenu::addEntry(const std::string& name,

View file

@ -42,7 +42,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
: GuiComponent(window) : GuiComponent(window)
, mScraperParams(scraperParams) , mScraperParams(scraperParams)
, mBackground(window, ":/graphics/frame.svg") , mBackground(window, ":/graphics/frame.svg")
, mGrid(window, Vector2i(1, 3)) , mGrid(window, glm::ivec2{1, 3})
, mMetaDataDecl(mdd) , mMetaDataDecl(mdd)
, mMetaData(md) , mMetaData(md)
, mSavedCallback(saveCallback) , mSavedCallback(saveCallback)
@ -53,7 +53,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);
mHeaderGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(1, 5)); mHeaderGrid = std::make_shared<ComponentGrid>(mWindow, glm::ivec2{1, 5});
mTitle = std::make_shared<TextComponent>(mWindow, "EDIT METADATA", Font::get(FONT_SIZE_LARGE), mTitle = std::make_shared<TextComponent>(mWindow, "EDIT METADATA", Font::get(FONT_SIZE_LARGE),
0x555555FF, ALIGN_CENTER); 0x555555FF, ALIGN_CENTER);
@ -78,15 +78,15 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
folderPath + Utils::FileSystem::getFileName(scraperParams.game->getPath()) + " [" + folderPath + Utils::FileSystem::getFileName(scraperParams.game->getPath()) + " [" +
Utils::String::toUpper(scraperParams.system->getName()) + "]" + Utils::String::toUpper(scraperParams.system->getName()) + "]" +
(scraperParams.game->getType() == FOLDER ? " " + ViewController::FOLDER_CHAR : ""), (scraperParams.game->getType() == FOLDER ? " " + ViewController::FOLDER_CHAR : ""),
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER, Vector3f(0.0f, 0.0f, 0.0f), Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER, glm::vec3{}, glm::vec2{}, 0x00000000,
Vector2f(0.0f, 0.0f), 0x00000000, 0.05f); 0.05f);
mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true); mHeaderGrid->setEntry(mTitle, glm::ivec2{0, 1}, false, true);
mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true); mHeaderGrid->setEntry(mSubtitle, glm::ivec2{0, 3}, false, true);
mGrid.setEntry(mHeaderGrid, Vector2i(0, 0), false, true); mGrid.setEntry(mHeaderGrid, glm::ivec2{0, 0}, false, true);
mList = std::make_shared<ComponentList>(mWindow); mList = std::make_shared<ComponentList>(mWindow);
mGrid.setEntry(mList, Vector2i(0, 1), true, true); mGrid.setEntry(mList, glm::ivec2{0, 1}, true, true);
// Populate list. // Populate list.
for (auto iter = mdd.cbegin(); iter != mdd.cend(); iter++) { for (auto iter = mdd.cbegin(); iter != mdd.cend(); iter++) {
@ -123,8 +123,8 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
case MD_BOOL: { case MD_BOOL: {
ed = std::make_shared<SwitchComponent>(window); ed = std::make_shared<SwitchComponent>(window);
// Make the switches slightly smaller. // Make the switches slightly smaller.
auto switchSize = ed->getSize() * 0.9f; glm::vec2 switchSize{ed->getSize() * 0.9f};
ed->setResize(switchSize.x(), switchSize.y()); ed->setResize(switchSize.x, switchSize.y);
ed->setOrigin(-0.05f, -0.09f); ed->setOrigin(-0.05f, -0.09f);
ed->setChangedColor(ICONCOLOR_USERMARKED); ed->setChangedColor(ICONCOLOR_USERMARKED);
@ -138,8 +138,8 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
ed = std::make_shared<RatingComponent>(window, true); ed = std::make_shared<RatingComponent>(window, true);
ed->setChangedColor(ICONCOLOR_USERMARKED); ed->setChangedColor(ICONCOLOR_USERMARKED);
const float height = lbl->getSize().y() * 0.71f; const float height = lbl->getSize().y * 0.71f;
ed->setSize(0, height); ed->setSize(0.0f, height);
row.addElement(ed, false, true); row.addElement(ed, false, true);
auto ratingSpacer = std::make_shared<GuiComponent>(mWindow); auto ratingSpacer = std::make_shared<GuiComponent>(mWindow);
@ -182,7 +182,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
auto bracket = std::make_shared<ImageComponent>(mWindow); auto bracket = std::make_shared<ImageComponent>(mWindow);
bracket->setImage(":/graphics/arrow.svg"); bracket->setImage(":/graphics/arrow.svg");
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight())); bracket->setResize(glm::vec2{0.0f, lbl->getFont()->getLetterHeight()});
row.addElement(bracket, false); row.addElement(bracket, false);
bool multiLine = false; bool multiLine = false;
@ -223,7 +223,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
auto bracket = std::make_shared<ImageComponent>(mWindow); auto bracket = std::make_shared<ImageComponent>(mWindow);
bracket->setImage(":/graphics/arrow.svg"); bracket->setImage(":/graphics/arrow.svg");
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight())); bracket->setResize(glm::vec2{0.0f, lbl->getFont()->getLetterHeight()});
row.addElement(bracket, false); row.addElement(bracket, false);
bool multiLine = iter->type == MD_MULTILINE_STRING; bool multiLine = iter->type == MD_MULTILINE_STRING;
@ -346,15 +346,15 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
} }
mButtons = makeButtonGrid(mWindow, buttons); mButtons = makeButtonGrid(mWindow, buttons);
mGrid.setEntry(mButtons, Vector2i(0, 2), true, false); mGrid.setEntry(mButtons, glm::ivec2{0, 2}, true, false);
// Resize + center. // Resize + center.
float width = float width =
static_cast<float>(std::min(static_cast<int>(Renderer::getScreenHeight() * 1.05f), static_cast<float>(std::min(static_cast<int>(Renderer::getScreenHeight() * 1.05f),
static_cast<int>(Renderer::getScreenWidth() * 0.90f))); static_cast<int>(Renderer::getScreenWidth() * 0.90f)));
setSize(width, Renderer::getScreenHeight() * 0.83f); setSize(width, Renderer::getScreenHeight() * 0.83f);
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f,
(Renderer::getScreenHeight() - mSize.y()) / 2.0f); (Renderer::getScreenHeight() - mSize.y) / 2.0f);
} }
void GuiMetaDataEd::onSizeChanged() void GuiMetaDataEd::onSizeChanged()
@ -363,19 +363,19 @@ void GuiMetaDataEd::onSizeChanged()
const float titleHeight = mTitle->getFont()->getLetterHeight(); const float titleHeight = mTitle->getFont()->getLetterHeight();
const float subtitleHeight = mSubtitle->getFont()->getLetterHeight(); const float subtitleHeight = mSubtitle->getFont()->getLetterHeight();
const float titleSubtitleSpacing = mSize.y() * 0.03f; const float titleSubtitleSpacing = mSize.y * 0.03f;
mGrid.setRowHeightPerc( mGrid.setRowHeightPerc(
0, (titleHeight + titleSubtitleSpacing + subtitleHeight + TITLE_VERT_PADDING) / mSize.y()); 0, (titleHeight + titleSubtitleSpacing + subtitleHeight + TITLE_VERT_PADDING) / mSize.y);
mGrid.setRowHeightPerc(2, mButtons->getSize().y() / mSize.y()); mGrid.setRowHeightPerc(2, mButtons->getSize().y / mSize.y);
// Snap list size to the row height to prevent a fraction of a row from being displayed. // Snap list size to the row height to prevent a fraction of a row from being displayed.
float listHeight = 0; float listHeight = 0.0f;
float listSize = mList->getSize().y(); float listSize = mList->getSize().y;
int i = 0; int i = 0;
while (i < mList->size()) { while (i < mList->size()) {
// Add the separator height to the row height so that it also gets properly rendered. // Add the separator height to the row height so that it also gets properly rendered.
float rowHeight = mList->getRowHeight(i) + (1 * Renderer::getScreenHeightModifier()); float rowHeight = mList->getRowHeight(i) + Renderer::getScreenHeightModifier();
if (listHeight + rowHeight < listSize) if (listHeight + rowHeight < listSize)
listHeight += rowHeight; listHeight += rowHeight;
else else
@ -385,19 +385,19 @@ void GuiMetaDataEd::onSizeChanged()
// Adjust the size of the list and window. // Adjust the size of the list and window.
float heightAdjustment = listSize - listHeight; float heightAdjustment = listSize - listHeight;
mList->setSize(mList->getSize().x(), listHeight); mList->setSize(mList->getSize().x, listHeight);
Vector2f newWindowSize = mSize; glm::vec2 newWindowSize{mSize};
newWindowSize.y() -= heightAdjustment; newWindowSize.y -= heightAdjustment;
mBackground.fitTo(newWindowSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mBackground.fitTo(newWindowSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
// Move the buttons up as well to make the layout align correctly after the resize. // Move the buttons up as well to make the layout align correctly after the resize.
Vector3f newButtonPos = mButtons->getPosition(); glm::vec3 newButtonPos{mButtons->getPosition()};
newButtonPos.y() -= heightAdjustment; newButtonPos.y -= heightAdjustment;
mButtons->setPosition(newButtonPos); mButtons->setPosition(newButtonPos);
mHeaderGrid->setRowHeightPerc(1, titleHeight / mHeaderGrid->getSize().y()); mHeaderGrid->setRowHeightPerc(1, titleHeight / mHeaderGrid->getSize().y);
mHeaderGrid->setRowHeightPerc(2, titleSubtitleSpacing / mHeaderGrid->getSize().y()); mHeaderGrid->setRowHeightPerc(2, titleSubtitleSpacing / mHeaderGrid->getSize().y);
mHeaderGrid->setRowHeightPerc(3, subtitleHeight / mHeaderGrid->getSize().y()); mHeaderGrid->setRowHeightPerc(3, subtitleHeight / mHeaderGrid->getSize().y);
} }
void GuiMetaDataEd::save() void GuiMetaDataEd::save()

View file

@ -16,7 +16,7 @@
GuiOfflineGenerator::GuiOfflineGenerator(Window* window, const std::queue<FileData*>& gameQueue) GuiOfflineGenerator::GuiOfflineGenerator(Window* window, const std::queue<FileData*>& gameQueue)
: GuiComponent(window) : GuiComponent(window)
, mBackground(window, ":/graphics/frame.svg") , mBackground(window, ":/graphics/frame.svg")
, mGrid(window, Vector2i(6, 13)) , mGrid(window, glm::ivec2{6, 13})
, mGameQueue(gameQueue) , mGameQueue(gameQueue)
{ {
addChild(&mBackground); addChild(&mBackground);
@ -38,100 +38,100 @@ GuiOfflineGenerator::GuiOfflineGenerator(Window* window, const std::queue<FileDa
// Header. // Header.
mTitle = std::make_shared<TextComponent>(mWindow, "MIXIMAGE OFFLINE GENERATOR", mTitle = std::make_shared<TextComponent>(mWindow, "MIXIMAGE OFFLINE GENERATOR",
Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER); Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER);
mGrid.setEntry(mTitle, Vector2i(0, 0), false, true, Vector2i(6, 1)); mGrid.setEntry(mTitle, glm::ivec2{0, 0}, false, true, glm::ivec2{6, 1});
mStatus = std::make_shared<TextComponent>(mWindow, "NOT STARTED", Font::get(FONT_SIZE_MEDIUM), mStatus = std::make_shared<TextComponent>(mWindow, "NOT STARTED", Font::get(FONT_SIZE_MEDIUM),
0x777777FF, ALIGN_CENTER); 0x777777FF, ALIGN_CENTER);
mGrid.setEntry(mStatus, Vector2i(0, 1), false, true, Vector2i(6, 1)); mGrid.setEntry(mStatus, glm::ivec2{0, 1}, false, true, glm::ivec2{6, 1});
mGameCounter = std::make_shared<TextComponent>( mGameCounter = std::make_shared<TextComponent>(
mWindow, mWindow,
std::to_string(mGamesProcessed) + " OF " + std::to_string(mTotalGames) + std::to_string(mGamesProcessed) + " OF " + std::to_string(mTotalGames) +
(mTotalGames == 1 ? " GAME " : " GAMES ") + "PROCESSED", (mTotalGames == 1 ? " GAME " : " GAMES ") + "PROCESSED",
Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER); Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER);
mGrid.setEntry(mGameCounter, Vector2i(0, 2), false, true, Vector2i(6, 1)); mGrid.setEntry(mGameCounter, glm::ivec2{0, 2}, false, true, glm::ivec2{6, 1});
// Spacer row with top border. // Spacer row with top border.
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 3), false, false, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{0, 3}, false, false,
Vector2i(6, 1), GridFlags::BORDER_TOP); glm::ivec2{6, 1}, GridFlags::BORDER_TOP);
// Left spacer. // Left spacer.
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 4), false, false, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{0, 4}, false, false,
Vector2i(1, 7)); glm::ivec2{1, 7});
// Generated label. // Generated label.
mGeneratedLbl = std::make_shared<TextComponent>( mGeneratedLbl = std::make_shared<TextComponent>(
mWindow, "Generated:", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); mWindow, "Generated:", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mGeneratedLbl, Vector2i(1, 4), false, true, Vector2i(1, 1)); mGrid.setEntry(mGeneratedLbl, glm::ivec2{1, 4}, false, true, glm::ivec2{1, 1});
// Generated value/counter. // Generated value/counter.
mGeneratedVal = mGeneratedVal =
std::make_shared<TextComponent>(mWindow, std::to_string(mGamesProcessed), std::make_shared<TextComponent>(mWindow, std::to_string(mGamesProcessed),
Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mGeneratedVal, Vector2i(2, 4), false, true, Vector2i(1, 1)); mGrid.setEntry(mGeneratedVal, glm::ivec2{2, 4}, false, true, glm::ivec2{1, 1});
// Overwritten label. // Overwritten label.
mOverwrittenLbl = std::make_shared<TextComponent>( mOverwrittenLbl = std::make_shared<TextComponent>(
mWindow, "Overwritten:", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); mWindow, "Overwritten:", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mOverwrittenLbl, Vector2i(1, 5), false, true, Vector2i(1, 1)); mGrid.setEntry(mOverwrittenLbl, glm::ivec2{1, 5}, false, true, glm::ivec2{1, 1});
// Overwritten value/counter. // Overwritten value/counter.
mOverwrittenVal = mOverwrittenVal =
std::make_shared<TextComponent>(mWindow, std::to_string(mImagesOverwritten), std::make_shared<TextComponent>(mWindow, std::to_string(mImagesOverwritten),
Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mOverwrittenVal, Vector2i(2, 5), false, true, Vector2i(1, 1)); mGrid.setEntry(mOverwrittenVal, glm::ivec2{2, 5}, false, true, glm::ivec2{1, 1});
// Skipping label. // Skipping label.
mSkippedLbl = std::make_shared<TextComponent>( mSkippedLbl = std::make_shared<TextComponent>(
mWindow, "Skipped (existing):", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); mWindow, "Skipped (existing):", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mSkippedLbl, Vector2i(1, 6), false, true, Vector2i(1, 1)); mGrid.setEntry(mSkippedLbl, glm::ivec2{1, 6}, false, true, glm::ivec2{1, 1});
// Skipping value/counter. // Skipping value/counter.
mSkippedVal = std::make_shared<TextComponent>( mSkippedVal = std::make_shared<TextComponent>(
mWindow, std::to_string(mGamesSkipped), Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); mWindow, std::to_string(mGamesSkipped), Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mSkippedVal, Vector2i(2, 6), false, true, Vector2i(1, 1)); mGrid.setEntry(mSkippedVal, glm::ivec2{2, 6}, false, true, glm::ivec2{1, 1});
// Failed label. // Failed label.
mFailedLbl = std::make_shared<TextComponent>(mWindow, "Failed:", Font::get(FONT_SIZE_SMALL), mFailedLbl = std::make_shared<TextComponent>(mWindow, "Failed:", Font::get(FONT_SIZE_SMALL),
0x888888FF, ALIGN_LEFT); 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mFailedLbl, Vector2i(1, 7), false, true, Vector2i(1, 1)); mGrid.setEntry(mFailedLbl, glm::ivec2{1, 7}, false, true, glm::ivec2{1, 1});
// Failed value/counter. // Failed value/counter.
mFailedVal = std::make_shared<TextComponent>( mFailedVal = std::make_shared<TextComponent>(
mWindow, std::to_string(mGamesFailed), Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); mWindow, std::to_string(mGamesFailed), Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mFailedVal, Vector2i(2, 7), false, true, Vector2i(1, 1)); mGrid.setEntry(mFailedVal, glm::ivec2{2, 7}, false, true, glm::ivec2{1, 1});
// Processing label. // Processing label.
mProcessingLbl = std::make_shared<TextComponent>( mProcessingLbl = std::make_shared<TextComponent>(
mWindow, "Processing: ", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); mWindow, "Processing: ", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mProcessingLbl, Vector2i(3, 4), false, true, Vector2i(1, 1)); mGrid.setEntry(mProcessingLbl, glm::ivec2{3, 4}, false, true, glm::ivec2{1, 1});
// Processing value. // Processing value.
mProcessingVal = std::make_shared<TextComponent>(mWindow, "", Font::get(FONT_SIZE_SMALL), mProcessingVal = std::make_shared<TextComponent>(mWindow, "", Font::get(FONT_SIZE_SMALL),
0x888888FF, ALIGN_LEFT); 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mProcessingVal, Vector2i(4, 4), false, true, Vector2i(1, 1)); mGrid.setEntry(mProcessingVal, glm::ivec2{4, 4}, false, true, glm::ivec2{1, 1});
// Spacer row. // Spacer row.
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(1, 8), false, false, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{1, 8}, false, false,
Vector2i(4, 1)); glm::ivec2{4, 1});
// Last error message label. // Last error message label.
mLastErrorLbl = std::make_shared<TextComponent>( mLastErrorLbl = std::make_shared<TextComponent>(
mWindow, "Last error message:", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT); mWindow, "Last error message:", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mLastErrorLbl, Vector2i(1, 9), false, true, Vector2i(4, 1)); mGrid.setEntry(mLastErrorLbl, glm::ivec2{1, 9}, false, true, glm::ivec2{4, 1});
// Last error message value. // Last error message value.
mLastErrorVal = std::make_shared<TextComponent>(mWindow, "", Font::get(FONT_SIZE_SMALL), mLastErrorVal = std::make_shared<TextComponent>(mWindow, "", Font::get(FONT_SIZE_SMALL),
0x888888FF, ALIGN_LEFT); 0x888888FF, ALIGN_LEFT);
mGrid.setEntry(mLastErrorVal, Vector2i(1, 10), false, true, Vector2i(4, 1)); mGrid.setEntry(mLastErrorVal, glm::ivec2{1, 10}, false, true, glm::ivec2{4, 1});
// Right spacer. // Right spacer.
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(5, 4), false, false, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{5, 4}, false, false,
Vector2i(1, 7)); glm::ivec2{1, 7});
// Spacer row with bottom border. // Spacer row with bottom border.
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 11), false, false, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{0, 11}, false, false,
Vector2i(6, 1), GridFlags::BORDER_BOTTOM); glm::ivec2{6, 1}, GridFlags::BORDER_BOTTOM);
// Buttons. // Buttons.
std::vector<std::shared_ptr<ButtonComponent>> buttons; std::vector<std::shared_ptr<ButtonComponent>> buttons;
@ -177,7 +177,7 @@ GuiOfflineGenerator::GuiOfflineGenerator(Window* window, const std::queue<FileDa
buttons.push_back(mCloseButton); buttons.push_back(mCloseButton);
mButtonGrid = makeButtonGrid(mWindow, buttons); mButtonGrid = makeButtonGrid(mWindow, buttons);
mGrid.setEntry(mButtonGrid, Vector2i(0, 12), true, false, Vector2i(6, 1)); mGrid.setEntry(mButtonGrid, glm::ivec2{0, 12}, true, false, glm::ivec2{6, 1});
// For narrower displays (e.g. in 4:3 ratio), allow the window to fill 95% of the screen // For narrower displays (e.g. in 4:3 ratio), allow the window to fill 95% of the screen
// width rather than the 85% allowed for wider displays. // width rather than the 85% allowed for wider displays.
@ -185,8 +185,8 @@ GuiOfflineGenerator::GuiOfflineGenerator(Window* window, const std::queue<FileDa
Renderer::getScreenWidth() * ((Renderer::getScreenAspectRatio() < 1.4f) ? 0.95f : 0.85f); Renderer::getScreenWidth() * ((Renderer::getScreenAspectRatio() < 1.4f) ? 0.95f : 0.85f);
setSize(width, Renderer::getScreenHeight() * 0.75f); setSize(width, Renderer::getScreenHeight() * 0.75f);
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f,
(Renderer::getScreenHeight() - mSize.y()) / 2.0f); (Renderer::getScreenHeight() - mSize.y) / 2.0f);
} }
GuiOfflineGenerator::~GuiOfflineGenerator() GuiOfflineGenerator::~GuiOfflineGenerator()
@ -203,13 +203,13 @@ GuiOfflineGenerator::~GuiOfflineGenerator()
void GuiOfflineGenerator::onSizeChanged() void GuiOfflineGenerator::onSizeChanged()
{ {
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
// Set row heights. // Set row heights.
mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y(), false); mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y, false);
mGrid.setRowHeightPerc(1, (mStatus->getFont()->getLetterHeight() + 2.0f) / mSize.y(), false); mGrid.setRowHeightPerc(1, (mStatus->getFont()->getLetterHeight() + 2.0f) / mSize.y, false);
mGrid.setRowHeightPerc(2, mGameCounter->getFont()->getHeight() * 1.75f / mSize.y(), false); mGrid.setRowHeightPerc(2, mGameCounter->getFont()->getHeight() * 1.75f / mSize.y, false);
mGrid.setRowHeightPerc(3, (mStatus->getFont()->getLetterHeight() + 3.0f) / mSize.y(), false); mGrid.setRowHeightPerc(3, (mStatus->getFont()->getLetterHeight() + 3.0f) / mSize.y, false);
mGrid.setRowHeightPerc(4, 0.07f, false); mGrid.setRowHeightPerc(4, 0.07f, false);
mGrid.setRowHeightPerc(5, 0.07f, false); mGrid.setRowHeightPerc(5, 0.07f, false);
mGrid.setRowHeightPerc(6, 0.07f, false); mGrid.setRowHeightPerc(6, 0.07f, false);
@ -217,7 +217,7 @@ void GuiOfflineGenerator::onSizeChanged()
mGrid.setRowHeightPerc(8, 0.02f, false); mGrid.setRowHeightPerc(8, 0.02f, false);
mGrid.setRowHeightPerc(9, 0.07f, false); mGrid.setRowHeightPerc(9, 0.07f, false);
mGrid.setRowHeightPerc(10, 0.07f, false); mGrid.setRowHeightPerc(10, 0.07f, false);
mGrid.setRowHeightPerc(12, mButtonGrid->getSize().y() / mSize.y(), false); mGrid.setRowHeightPerc(12, mButtonGrid->getSize().y / mSize.y, false);
// Set column widths. // Set column widths.
mGrid.setColWidthPerc(0, 0.03f); mGrid.setColWidthPerc(0, 0.03f);

View file

@ -140,8 +140,7 @@ GuiScraperMenu::GuiScraperMenu(Window* window, std::string title)
setSize(mMenu.getSize()); setSize(mMenu.getSize());
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, Renderer::getScreenHeight() * 0.13f);
Renderer::getScreenHeight() * 0.13f);
} }
GuiScraperMenu::~GuiScraperMenu() GuiScraperMenu::~GuiScraperMenu()

View file

@ -28,7 +28,7 @@ GuiScraperMulti::GuiScraperMulti(Window* window,
bool approveResults) bool approveResults)
: GuiComponent(window) : GuiComponent(window)
, mBackground(window, ":/graphics/frame.svg") , mBackground(window, ":/graphics/frame.svg")
, mGrid(window, Vector2i(1, 5)) , mGrid(window, glm::ivec2{1, 5})
, mSearchQueue(searches) , mSearchQueue(searches)
, mApproveResults(approveResults) , mApproveResults(approveResults)
{ {
@ -47,15 +47,15 @@ GuiScraperMulti::GuiScraperMulti(Window* window,
// Set up grid. // Set up grid.
mTitle = std::make_shared<TextComponent>(mWindow, "SCRAPING IN PROGRESS", mTitle = std::make_shared<TextComponent>(mWindow, "SCRAPING IN PROGRESS",
Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER); Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER);
mGrid.setEntry(mTitle, Vector2i(0, 0), false, true); mGrid.setEntry(mTitle, glm::ivec2{0, 0}, false, true);
mSystem = std::make_shared<TextComponent>(mWindow, "SYSTEM", Font::get(FONT_SIZE_MEDIUM), mSystem = std::make_shared<TextComponent>(mWindow, "SYSTEM", Font::get(FONT_SIZE_MEDIUM),
0x777777FF, ALIGN_CENTER); 0x777777FF, ALIGN_CENTER);
mGrid.setEntry(mSystem, Vector2i(0, 1), false, true); mGrid.setEntry(mSystem, glm::ivec2{0, 1}, false, true);
mSubtitle = std::make_shared<TextComponent>( mSubtitle = std::make_shared<TextComponent>(
mWindow, "subtitle text", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER); mWindow, "subtitle text", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER);
mGrid.setEntry(mSubtitle, Vector2i(0, 2), false, true); mGrid.setEntry(mSubtitle, glm::ivec2{0, 2}, false, true);
if (mApproveResults && !Settings::getInstance()->getBool("ScraperSemiautomatic")) if (mApproveResults && !Settings::getInstance()->getBool("ScraperSemiautomatic"))
mSearchComp = std::make_shared<GuiScraperSearch>( mSearchComp = std::make_shared<GuiScraperSearch>(
@ -70,7 +70,7 @@ GuiScraperMulti::GuiScraperMulti(Window* window,
std::bind(&GuiScraperMulti::acceptResult, this, std::placeholders::_1)); std::bind(&GuiScraperMulti::acceptResult, this, std::placeholders::_1));
mSearchComp->setSkipCallback(std::bind(&GuiScraperMulti::skip, this)); mSearchComp->setSkipCallback(std::bind(&GuiScraperMulti::skip, this));
mSearchComp->setCancelCallback(std::bind(&GuiScraperMulti::finish, this)); mSearchComp->setCancelCallback(std::bind(&GuiScraperMulti::finish, this));
mGrid.setEntry(mSearchComp, Vector2i(0, 3), mGrid.setEntry(mSearchComp, glm::ivec2{0, 3},
mSearchComp->getSearchType() != GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT, mSearchComp->getSearchType() != GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT,
true); true);
@ -102,7 +102,7 @@ GuiScraperMulti::GuiScraperMulti(Window* window,
std::bind(&GuiScraperMulti::finish, this))); std::bind(&GuiScraperMulti::finish, this)));
mButtonGrid = makeButtonGrid(mWindow, buttons); mButtonGrid = makeButtonGrid(mWindow, buttons);
mGrid.setEntry(mButtonGrid, Vector2i(0, 4), true, false); mGrid.setEntry(mButtonGrid, glm::ivec2{0, 4}, true, false);
// Limit the width of the GUI on ultrawide monitors. The 1.778 aspect ratio value is // Limit the width of the GUI on ultrawide monitors. The 1.778 aspect ratio value is
// the 16:9 reference. // the 16:9 reference.
@ -110,8 +110,8 @@ GuiScraperMulti::GuiScraperMulti(Window* window,
float width = Math::clamp(0.95f * aspectValue, 0.70f, 0.95f) * Renderer::getScreenWidth(); float width = Math::clamp(0.95f * aspectValue, 0.70f, 0.95f) * Renderer::getScreenWidth();
setSize(width, Renderer::getScreenHeight() * 0.849f); setSize(width, Renderer::getScreenHeight() * 0.849f);
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f,
(Renderer::getScreenHeight() - mSize.y()) / 2.0f); (Renderer::getScreenHeight() - mSize.y) / 2.0f);
doNextSearch(); doNextSearch();
} }
@ -130,12 +130,12 @@ GuiScraperMulti::~GuiScraperMulti()
void GuiScraperMulti::onSizeChanged() void GuiScraperMulti::onSizeChanged()
{ {
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y(), false); mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y, false);
mGrid.setRowHeightPerc(1, (mSystem->getFont()->getLetterHeight() + 2.0f) / mSize.y(), false); mGrid.setRowHeightPerc(1, (mSystem->getFont()->getLetterHeight() + 2.0f) / mSize.y, false);
mGrid.setRowHeightPerc(2, mSubtitle->getFont()->getHeight() * 1.75f / mSize.y(), false); mGrid.setRowHeightPerc(2, mSubtitle->getFont()->getHeight() * 1.75f / mSize.y, false);
mGrid.setRowHeightPerc(4, mButtonGrid->getSize().y() / mSize.y(), false); mGrid.setRowHeightPerc(4, mButtonGrid->getSize().y / mSize.y, false);
mGrid.setSize(mSize); mGrid.setSize(mSize);
} }

View file

@ -38,7 +38,7 @@
GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int scrapeCount) GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int scrapeCount)
: GuiComponent(window) : GuiComponent(window)
, mGrid(window, Vector2i(4, 3)) , mGrid(window, glm::ivec2{4, 3})
, mBusyAnim(window) , mBusyAnim(window)
, mSearchType(type) , mSearchType(type)
, mScrapeCount(scrapeCount) , mScrapeCount(scrapeCount)
@ -54,8 +54,8 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int
mRetryCount = 0; mRetryCount = 0;
// Left spacer (empty component, needed for borders). // Left spacer (empty component, needed for borders).
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 0), false, false, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{0, 0}, false, false,
Vector2i(1, 3), GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM); glm::ivec2{1, 3}, GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM);
// Selected result name. // Selected result name.
mResultName = std::make_shared<TextComponent>(mWindow, "Result name", mResultName = std::make_shared<TextComponent>(mWindow, "Result name",
@ -63,7 +63,7 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int
// Selected result thumbnail. // Selected result thumbnail.
mResultThumbnail = std::make_shared<ImageComponent>(mWindow); mResultThumbnail = std::make_shared<ImageComponent>(mWindow);
mGrid.setEntry(mResultThumbnail, Vector2i(1, 1), false, false, Vector2i(1, 1)); mGrid.setEntry(mResultThumbnail, glm::ivec2{1, 1}, false, false, glm::ivec2{1, 1});
// Selected result description and container. // Selected result description and container.
mDescContainer = std::make_shared<ScrollableContainer>(mWindow); mDescContainer = std::make_shared<ScrollableContainer>(mWindow);
@ -87,18 +87,14 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int
mMD_ReleaseDate = std::make_shared<DateTimeEditComponent>(mWindow); mMD_ReleaseDate = std::make_shared<DateTimeEditComponent>(mWindow);
mMD_ReleaseDate->setColor(mdColor); mMD_ReleaseDate->setColor(mdColor);
mMD_ReleaseDate->setUppercase(true); mMD_ReleaseDate->setUppercase(true);
mMD_Developer = mMD_Developer = std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT,
std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(), glm::vec3{}, glm::vec2{}, 0x00000000, 0.02f);
Vector2f::Zero(), 0x00000000, 0.02f); mMD_Publisher = std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT,
mMD_Publisher = glm::vec3{}, glm::vec2{}, 0x00000000, 0.02f);
std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(), mMD_Genre = std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3{},
Vector2f::Zero(), 0x00000000, 0.02f); glm::vec2{}, 0x00000000, 0.02f);
mMD_Genre = mMD_Players = std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT,
std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(), glm::vec3{}, glm::vec2{}, 0x00000000, 0.02f);
Vector2f::Zero(), 0x00000000, 0.02f);
mMD_Players =
std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT, Vector3f::Zero(),
Vector2f::Zero(), 0x00000000, 0.02f);
mMD_Filler = std::make_shared<TextComponent>(mWindow, "", font, mdColor); mMD_Filler = std::make_shared<TextComponent>(mWindow, "", font, mdColor);
if (Settings::getInstance()->getString("Scraper") != "thegamesdb") if (Settings::getInstance()->getString("Scraper") != "thegamesdb")
@ -127,15 +123,15 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int
std::make_shared<TextComponent>(mWindow, "", font, mdLblColor), mMD_Filler)); std::make_shared<TextComponent>(mWindow, "", font, mdLblColor), mMD_Filler));
mMD_Grid = std::make_shared<ComponentGrid>( mMD_Grid = std::make_shared<ComponentGrid>(
mWindow, Vector2i(2, static_cast<int>(mMD_Pairs.size() * 2 - 1))); mWindow, glm::ivec2{2, static_cast<int>(mMD_Pairs.size() * 2 - 1)});
unsigned int i = 0; unsigned int i = 0;
for (auto it = mMD_Pairs.cbegin(); it != mMD_Pairs.cend(); it++) { for (auto it = mMD_Pairs.cbegin(); it != mMD_Pairs.cend(); it++) {
mMD_Grid->setEntry(it->first, Vector2i(0, i), false, true); mMD_Grid->setEntry(it->first, glm::ivec2{0, i}, false, true);
mMD_Grid->setEntry(it->second, Vector2i(1, i), false, it->resize); mMD_Grid->setEntry(it->second, glm::ivec2{1, i}, false, it->resize);
i += 2; i += 2;
} }
mGrid.setEntry(mMD_Grid, Vector2i(2, 1), false, false); mGrid.setEntry(mMD_Grid, glm::ivec2{2, 1}, false, false);
// Result list. // Result list.
mResultList = std::make_shared<ComponentList>(mWindow); mResultList = std::make_shared<ComponentList>(mWindow);
@ -184,7 +180,7 @@ void GuiScraperSearch::onSizeChanged()
{ {
mGrid.setSize(mSize); mGrid.setSize(mSize);
if (mSize.x() == 0 || mSize.y() == 0) if (mSize.x == 0 || mSize.y == 0)
return; return;
// Column widths. // Column widths.
@ -203,7 +199,7 @@ void GuiScraperSearch::onSizeChanged()
// Row heights. // Row heights.
if (mSearchType == ALWAYS_ACCEPT_FIRST_RESULT) // Show name. if (mSearchType == ALWAYS_ACCEPT_FIRST_RESULT) // Show name.
mGrid.setRowHeightPerc(0, (mResultName->getFont()->getHeight() * 1.6f) / mGrid.setRowHeightPerc(0, (mResultName->getFont()->getHeight() * 1.6f) /
mGrid.getSize().y()); // Result name. mGrid.getSize().y); // Result name.
else else
mGrid.setRowHeightPerc(0, 0.0825f); // Hide name but do padding. mGrid.setRowHeightPerc(0, 0.0825f); // Hide name but do padding.
@ -230,11 +226,11 @@ void GuiScraperSearch::onSizeChanged()
mResultDesc->getFont()->getHeight() * 6.0f); mResultDesc->getFont()->getHeight() * 6.0f);
// Make description text wrap at edge of container. // Make description text wrap at edge of container.
mResultDesc->setSize(mDescContainer->getSize().x(), 0); mResultDesc->setSize(mDescContainer->getSize().x, 0.0f);
// Set the width of mResultName to the cell width so that text abbreviation will work correctly. // Set the width of mResultName to the cell width so that text abbreviation will work correctly.
Vector2f resultNameSize = mResultName->getSize(); glm::vec2 resultNameSize{mResultName->getSize()};
mResultName->setSize(mGrid.getColWidth(3), resultNameSize.y()); mResultName->setSize(mGrid.getColWidth(3), resultNameSize.y);
mGrid.onSizeChanged(); mGrid.onSizeChanged();
mBusyAnim.setSize(mSize); mBusyAnim.setSize(mSize);
@ -243,8 +239,8 @@ void GuiScraperSearch::onSizeChanged()
void GuiScraperSearch::resizeMetadata() void GuiScraperSearch::resizeMetadata()
{ {
mMD_Grid->setSize(mGrid.getColWidth(2), mGrid.getRowHeight(1)); mMD_Grid->setSize(mGrid.getColWidth(2), mGrid.getRowHeight(1));
if (mMD_Grid->getSize().y() > mMD_Pairs.size()) { if (mMD_Grid->getSize().y > mMD_Pairs.size()) {
const int fontHeight = static_cast<int>(mMD_Grid->getSize().y() / mMD_Pairs.size() * 0.8f); const int fontHeight = static_cast<int>(mMD_Grid->getSize().y / mMD_Pairs.size() * 0.8f);
auto fontLbl = Font::get(fontHeight, FONT_PATH_REGULAR); auto fontLbl = Font::get(fontHeight, FONT_PATH_REGULAR);
auto fontComp = Font::get(fontHeight, FONT_PATH_LIGHT); auto fontComp = Font::get(fontHeight, FONT_PATH_LIGHT);
@ -253,15 +249,14 @@ void GuiScraperSearch::resizeMetadata()
for (auto it = mMD_Pairs.cbegin(); it != mMD_Pairs.cend(); it++) { for (auto it = mMD_Pairs.cbegin(); it != mMD_Pairs.cend(); it++) {
it->first->setFont(fontLbl); it->first->setFont(fontLbl);
it->first->setSize(0, 0); it->first->setSize(0, 0);
if (it->first->getSize().x() > maxLblWidth) if (it->first->getSize().x > maxLblWidth)
maxLblWidth = maxLblWidth = it->first->getSize().x + (16.0f * Renderer::getScreenWidthModifier());
it->first->getSize().x() + (16.0f * Renderer::getScreenWidthModifier());
} }
for (unsigned int i = 0; i < mMD_Pairs.size(); i++) for (unsigned int i = 0; i < mMD_Pairs.size(); i++)
mMD_Grid->setRowHeightPerc( mMD_Grid->setRowHeightPerc(
i * 2, (fontLbl->getLetterHeight() + (2.0f * Renderer::getScreenHeightModifier())) / i * 2, (fontLbl->getLetterHeight() + (2.0f * Renderer::getScreenHeightModifier())) /
mMD_Grid->getSize().y()); mMD_Grid->getSize().y);
// Update component fonts. // Update component fonts.
mMD_ReleaseDate->setFont(fontComp); mMD_ReleaseDate->setFont(fontComp);
@ -270,7 +265,7 @@ void GuiScraperSearch::resizeMetadata()
mMD_Genre->setFont(fontComp); mMD_Genre->setFont(fontComp);
mMD_Players->setFont(fontComp); mMD_Players->setFont(fontComp);
mMD_Grid->setColWidthPerc(0, maxLblWidth / mMD_Grid->getSize().x()); mMD_Grid->setColWidthPerc(0, maxLblWidth / mMD_Grid->getSize().x);
if (mScrapeRatings) { if (mScrapeRatings) {
// Rating is manually sized. // Rating is manually sized.
@ -293,33 +288,33 @@ void GuiScraperSearch::updateViewStyle()
// Add them back depending on search type. // Add them back depending on search type.
if (mSearchType == ALWAYS_ACCEPT_FIRST_RESULT) { if (mSearchType == ALWAYS_ACCEPT_FIRST_RESULT) {
// Show name. // Show name.
mGrid.setEntry(mResultName, Vector2i(1, 0), false, false, Vector2i(2, 1), mGrid.setEntry(mResultName, glm::ivec2{1, 0}, false, false, glm::ivec2{2, 1},
GridFlags::BORDER_TOP); GridFlags::BORDER_TOP);
// Need a border on the bottom left. // Need a border on the bottom left.
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(0, 2), false, false, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{0, 2}, false, false,
Vector2i(3, 1), GridFlags::BORDER_BOTTOM); glm::ivec2{3, 1}, GridFlags::BORDER_BOTTOM);
// Show description on the right. // Show description on the right.
mGrid.setEntry(mDescContainer, Vector2i(3, 0), false, false, Vector2i(1, 3), mGrid.setEntry(mDescContainer, glm::ivec2{3, 0}, false, false, glm::ivec2{1, 3},
GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM); GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM);
// Make description text wrap at edge of container. // Make description text wrap at edge of container.
mResultDesc->setSize(mDescContainer->getSize().x(), 0.0f); mResultDesc->setSize(mDescContainer->getSize().x, 0.0f);
} }
else { else {
// Fake row where name would be. // Fake row where name would be.
mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), Vector2i(1, 0), false, true, mGrid.setEntry(std::make_shared<GuiComponent>(mWindow), glm::ivec2{1, 0}, false, true,
Vector2i(2, 1), GridFlags::BORDER_TOP); glm::ivec2{2, 1}, GridFlags::BORDER_TOP);
// Show result list on the right. // Show result list on the right.
mGrid.setEntry(mResultList, Vector2i(3, 0), true, true, Vector2i(1, 3), mGrid.setEntry(mResultList, glm::ivec2{3, 0}, true, true, glm::ivec2{1, 3},
GridFlags::BORDER_LEFT | GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM); GridFlags::BORDER_LEFT | GridFlags::BORDER_TOP | GridFlags::BORDER_BOTTOM);
// Show description under image/info. // Show description under image/info.
mGrid.setEntry(mDescContainer, Vector2i(1, 2), false, false, Vector2i(2, 1), mGrid.setEntry(mDescContainer, glm::ivec2{1, 2}, false, false, glm::ivec2{2, 1},
GridFlags::BORDER_BOTTOM); GridFlags::BORDER_BOTTOM);
// Make description text wrap at edge of container. // Make description text wrap at edge of container.
mResultDesc->setSize(mDescContainer->getSize().x(), 0); mResultDesc->setSize(mDescContainer->getSize().x, 0);
} }
} }
@ -565,12 +560,12 @@ bool GuiScraperSearch::input(InputConfig* config, Input input)
return GuiComponent::input(config, input); return GuiComponent::input(config, input);
} }
void GuiScraperSearch::render(const Transform4x4f& parentTrans) void GuiScraperSearch::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
renderChildren(trans); renderChildren(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x00000009, 0x00000009); Renderer::drawRect(0.0f, 0.0f, mSize.x, mSize.y, 0x00000009, 0x00000009);
if (mBlockAccept) { if (mBlockAccept) {
Renderer::setMatrix(trans); Renderer::setMatrix(trans);

View file

@ -75,7 +75,7 @@ public:
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
std::vector<HelpPrompt> getHelpPrompts() override; std::vector<HelpPrompt> getHelpPrompts() override;
HelpStyle getHelpStyle() override; HelpStyle getHelpStyle() override;
void onSizeChanged() override; void onSizeChanged() override;

View file

@ -41,8 +41,7 @@ GuiSettings::GuiSettings(Window* window, std::string title)
setSize(static_cast<float>(Renderer::getScreenWidth()), setSize(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight()));
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2.0f, mMenu.setPosition((mSize.x - mMenu.getSize().x) / 2.0f, Renderer::getScreenHeight() * 0.13f);
Renderer::getScreenHeight() * 0.13f);
} }
GuiSettings::~GuiSettings() GuiSettings::~GuiSettings()
@ -171,7 +170,7 @@ void GuiSettings::addEditableTextComponent(const std::string label,
auto bracket = std::make_shared<ImageComponent>(mWindow); auto bracket = std::make_shared<ImageComponent>(mWindow);
bracket->setImage(":/graphics/arrow.svg"); bracket->setImage(":/graphics/arrow.svg");
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight())); bracket->setResize(glm::vec2{0.0f, lbl->getFont()->getLetterHeight()});
row.addElement(bracket, false); row.addElement(bracket, false);
// OK callback (apply new value to ed). // OK callback (apply new value to ed).

View file

@ -572,7 +572,7 @@ int main(int argc, char* argv[])
bool splashScreen = Settings::getInstance()->getBool("SplashScreen"); bool splashScreen = Settings::getInstance()->getBool("SplashScreen");
bool splashScreenProgress = Settings::getInstance()->getBool("SplashScreenProgress"); bool splashScreenProgress = Settings::getInstance()->getBool("SplashScreenProgress");
SDL_Event event {}; SDL_Event event{};
if (!window.init()) { if (!window.init()) {
LOG(LogError) << "Window failed to initialize"; LOG(LogError) << "Window failed to initialize";

View file

@ -33,90 +33,90 @@ namespace
TheGamesDBJSONRequestResources resources; TheGamesDBJSONRequestResources resources;
} }
const std::map<PlatformId, std::string> gamesdb_new_platformid_map { const std::map<PlatformId, std::string> gamesdb_new_platformid_map{
{ THREEDO, "25" }, {THREEDO, "25"},
{ COMMODORE_AMIGA, "4911" }, {COMMODORE_AMIGA, "4911"},
{ COMMODORE_AMIGA_CD32, "4947" }, {COMMODORE_AMIGA_CD32, "4947"},
{ AMSTRAD_CPC, "4914" }, {AMSTRAD_CPC, "4914"},
{ APPLE_II, "4942" }, {APPLE_II, "4942"},
{ ARCADE, "23" }, {ARCADE, "23"},
{ ATARI_800, "4943" }, {ATARI_800, "4943"},
{ ATARI_2600, "22" }, {ATARI_2600, "22"},
{ ATARI_5200, "26" }, {ATARI_5200, "26"},
{ ATARI_7800, "27" }, {ATARI_7800, "27"},
{ ATARI_JAGUAR, "28" }, {ATARI_JAGUAR, "28"},
{ ATARI_JAGUAR_CD, "29" }, {ATARI_JAGUAR_CD, "29"},
{ ATARI_LYNX, "4924" }, {ATARI_LYNX, "4924"},
{ ATARI_ST, "4937" }, {ATARI_ST, "4937"},
{ ATARI_XE, "30" }, {ATARI_XE, "30"},
{ CAVESTORY, "1" }, {CAVESTORY, "1"},
{ COLECOVISION, "31" }, {COLECOVISION, "31"},
{ COMMODORE_64, "40" }, {COMMODORE_64, "40"},
{ DAPHNE, "23" }, {DAPHNE, "23"},
{ INTELLIVISION, "32" }, {INTELLIVISION, "32"},
{ APPLE_MACINTOSH, "37" }, {APPLE_MACINTOSH, "37"},
{ MICROSOFT_XBOX, "14" }, {MICROSOFT_XBOX, "14"},
{ MICROSOFT_XBOX_360, "15" }, {MICROSOFT_XBOX_360, "15"},
{ MOONLIGHT, "1" }, {MOONLIGHT, "1"},
{ MSX, "4929" }, {MSX, "4929"},
{ MSX2, "4929" }, {MSX2, "4929"},
{ MSX_TURBO_R, "4929" }, {MSX_TURBO_R, "4929"},
{ SNK_NEO_GEO, "24" }, {SNK_NEO_GEO, "24"},
{ SNK_NEO_GEO_CD, "24" }, {SNK_NEO_GEO_CD, "24"},
{ SNK_NEO_GEO_POCKET, "4922" }, {SNK_NEO_GEO_POCKET, "4922"},
{ SNK_NEO_GEO_POCKET_COLOR, "4923" }, {SNK_NEO_GEO_POCKET_COLOR, "4923"},
{ NINTENDO_3DS, "4912" }, {NINTENDO_3DS, "4912"},
{ NINTENDO_64, "3" }, {NINTENDO_64, "3"},
{ NINTENDO_DS, "8" }, {NINTENDO_DS, "8"},
{ NINTENDO_FAMICOM, "7" }, {NINTENDO_FAMICOM, "7"},
{ NINTENDO_FAMICOM_DISK_SYSTEM, "4936" }, {NINTENDO_FAMICOM_DISK_SYSTEM, "4936"},
{ NINTENDO_ENTERTAINMENT_SYSTEM, "7" }, {NINTENDO_ENTERTAINMENT_SYSTEM, "7"},
{ NINTENDO_GAME_BOY, "4" }, {NINTENDO_GAME_BOY, "4"},
{ NINTENDO_GAME_BOY_ADVANCE, "5" }, {NINTENDO_GAME_BOY_ADVANCE, "5"},
{ NINTENDO_GAME_BOY_COLOR, "41" }, {NINTENDO_GAME_BOY_COLOR, "41"},
{ NINTENDO_GAMECUBE, "2" }, {NINTENDO_GAMECUBE, "2"},
{ NINTENDO_WII, "9" }, {NINTENDO_WII, "9"},
{ NINTENDO_WII_U, "38" }, {NINTENDO_WII_U, "38"},
{ NINTENDO_VIRTUAL_BOY, "4918" }, {NINTENDO_VIRTUAL_BOY, "4918"},
{ NINTENDO_GAME_AND_WATCH, "4950" }, {NINTENDO_GAME_AND_WATCH, "4950"},
{ NINTENDO_POKEMON_MINI, "4957" }, {NINTENDO_POKEMON_MINI, "4957"},
{ NINTENDO_SATELLAVIEW, "6" }, {NINTENDO_SATELLAVIEW, "6"},
{ NINTENDO_SWITCH, "4971" }, {NINTENDO_SWITCH, "4971"},
{ BANDAI_SUFAMI_TURBO, "6" }, {BANDAI_SUFAMI_TURBO, "6"},
{ DOS, "1" }, {DOS, "1"},
{ PC, "1" }, {PC, "1"},
{ VALVE_STEAM, "1" }, {VALVE_STEAM, "1"},
{ NEC_PCFX, "4930" }, {NEC_PCFX, "4930"},
{ SEGA_32X, "33" }, {SEGA_32X, "33"},
{ SEGA_CD, "21" }, {SEGA_CD, "21"},
{ SEGA_DREAMCAST, "16" }, {SEGA_DREAMCAST, "16"},
{ SEGA_GAME_GEAR, "20" }, {SEGA_GAME_GEAR, "20"},
{ SEGA_GENESIS, "18" }, {SEGA_GENESIS, "18"},
{ SEGA_MASTER_SYSTEM, "35" }, {SEGA_MASTER_SYSTEM, "35"},
{ SEGA_MEGA_DRIVE, "36" }, {SEGA_MEGA_DRIVE, "36"},
{ SEGA_SATURN, "17" }, {SEGA_SATURN, "17"},
{ SEGA_SG1000, "4949" }, {SEGA_SG1000, "4949"},
{ SONY_PLAYSTATION, "10" }, {SONY_PLAYSTATION, "10"},
{ SONY_PLAYSTATION_2, "11" }, {SONY_PLAYSTATION_2, "11"},
{ SONY_PLAYSTATION_3, "12" }, {SONY_PLAYSTATION_3, "12"},
{ SONY_PLAYSTATION_4, "4919" }, {SONY_PLAYSTATION_4, "4919"},
{ SONY_PLAYSTATION_VITA, "39" }, {SONY_PLAYSTATION_VITA, "39"},
{ SONY_PLAYSTATION_PORTABLE, "13" }, {SONY_PLAYSTATION_PORTABLE, "13"},
{ SUPER_NINTENDO, "6" }, {SUPER_NINTENDO, "6"},
{ SHARP_X1, "4977" }, {SHARP_X1, "4977"},
{ SHARP_X68000, "4931" }, {SHARP_X68000, "4931"},
{ NEC_SUPERGRAFX, "34" }, {NEC_SUPERGRAFX, "34"},
{ NEC_PC_8800, "4933" }, {NEC_PC_8800, "4933"},
{ NEC_PC_9800, "4934" }, {NEC_PC_9800, "4934"},
{ NEC_PC_ENGINE, "34" }, {NEC_PC_ENGINE, "34"},
{ NEC_PC_ENGINE_CD, "4955" }, {NEC_PC_ENGINE_CD, "4955"},
{ BANDAI_WONDERSWAN, "4925" }, {BANDAI_WONDERSWAN, "4925"},
{ BANDAI_WONDERSWAN_COLOR, "4926" }, {BANDAI_WONDERSWAN_COLOR, "4926"},
{ SINCLAIR_ZX_SPECTRUM, "4913" }, {SINCLAIR_ZX_SPECTRUM, "4913"},
{ VIDEOPAC_ODYSSEY2, "4927" }, {VIDEOPAC_ODYSSEY2, "4927"},
{ VECTREX, "4939" }, {VECTREX, "4939"},
{ TANDY_COLOR_COMPUTER, "4941" }, {TANDY_COLOR_COMPUTER, "4941"},
{ TANDY_TRS80, "4941" }, {TANDY_TRS80, "4941"},
}; };
void thegamesdb_generate_json_scraper_requests( void thegamesdb_generate_json_scraper_requests(

View file

@ -26,10 +26,9 @@
#include <cmath> #include <cmath>
#include <fstream> #include <fstream>
const std::map<std::string, generate_scraper_requests_func> scraper_request_funcs { const std::map<std::string, generate_scraper_requests_func> scraper_request_funcs{
{ "thegamesdb", &thegamesdb_generate_json_scraper_requests }, {"thegamesdb", &thegamesdb_generate_json_scraper_requests},
{ "screenscraper", &screenscraper_generate_scraper_requests } {"screenscraper", &screenscraper_generate_scraper_requests}};
};
std::unique_ptr<ScraperSearchHandle> startScraperSearch(const ScraperSearchParams& params) std::unique_ptr<ScraperSearchHandle> startScraperSearch(const ScraperSearchParams& params)
{ {

View file

@ -26,109 +26,108 @@ using namespace PlatformIds;
// List of systems and their IDs from: // List of systems and their IDs from:
// https://www.screenscraper.fr/api/systemesListe.php?devid=xxx&devpassword=yyy&softname=zzz&output=XML // https://www.screenscraper.fr/api/systemesListe.php?devid=xxx&devpassword=yyy&softname=zzz&output=XML
const std::map<PlatformId, unsigned short> screenscraper_platformid_map { const std::map<PlatformId, unsigned short> screenscraper_platformid_map{
{ THREEDO, 29 }, {THREEDO, 29},
{ COMMODORE_AMIGA, 64 }, {COMMODORE_AMIGA, 64},
{ COMMODORE_AMIGA_CD32, 130 }, {COMMODORE_AMIGA_CD32, 130},
{ AMSTRAD_CPC, 65 }, {AMSTRAD_CPC, 65},
{ AMSTRAD_GX4000, 87 }, {AMSTRAD_GX4000, 87},
{ APPLE_II, 86 }, {APPLE_II, 86},
{ APPLE_IIGS, 217 }, {APPLE_IIGS, 217},
{ ARCADE, 75 }, {ARCADE, 75},
{ ATARI_800, 43 }, {ATARI_800, 43},
{ ATARI_2600, 26 }, {ATARI_2600, 26},
{ ATARI_5200, 40 }, {ATARI_5200, 40},
{ ATARI_7800, 41 }, {ATARI_7800, 41},
{ ATARI_JAGUAR, 27 }, {ATARI_JAGUAR, 27},
{ ATARI_JAGUAR_CD, 171 }, {ATARI_JAGUAR_CD, 171},
{ ATARI_LYNX, 28 }, {ATARI_LYNX, 28},
{ ATARI_ST, 42 }, {ATARI_ST, 42},
{ ATARI_XE, 43 }, {ATARI_XE, 43},
{ ATOMISWAVE, 53 }, {ATOMISWAVE, 53},
{ BBC_MICRO, 37 }, {BBC_MICRO, 37},
{ CAVESTORY, 135 }, {CAVESTORY, 135},
{ COLECOVISION, 48 }, {COLECOVISION, 48},
{ COMMODORE_64, 66 }, {COMMODORE_64, 66},
{ COMMODORE_CDTV, 129 }, {COMMODORE_CDTV, 129},
{ DAPHNE, 49 }, {DAPHNE, 49},
{ INTELLIVISION, 115 }, {INTELLIVISION, 115},
{ GAMEENGINE_LUTRO, 206 }, {GAMEENGINE_LUTRO, 206},
{ APPLE_MACINTOSH, 146 }, {APPLE_MACINTOSH, 146},
{ MICROSOFT_XBOX, 32 }, {MICROSOFT_XBOX, 32},
{ MICROSOFT_XBOX_360, 33 }, {MICROSOFT_XBOX_360, 33},
{ MOONLIGHT, 138 }, {MOONLIGHT, 138},
{ MSX, 113 }, {MSX, 113},
{ MSX2, 116 }, {MSX2, 116},
{ MSX_TURBO_R, 118 }, {MSX_TURBO_R, 118},
{ SNK_NEO_GEO, 142 }, {SNK_NEO_GEO, 142},
{ SNK_NEO_GEO_CD, 142 }, {SNK_NEO_GEO_CD, 142},
{ SNK_NEO_GEO_POCKET, 25 }, {SNK_NEO_GEO_POCKET, 25},
{ SNK_NEO_GEO_POCKET_COLOR, 82 }, {SNK_NEO_GEO_POCKET_COLOR, 82},
{ NINTENDO_3DS, 17 }, {NINTENDO_3DS, 17},
{ NINTENDO_64, 14 }, {NINTENDO_64, 14},
{ NINTENDO_DS, 15 }, {NINTENDO_DS, 15},
{ NINTENDO_FAMICOM, 3 }, {NINTENDO_FAMICOM, 3},
{ NINTENDO_FAMICOM_DISK_SYSTEM, 106 }, {NINTENDO_FAMICOM_DISK_SYSTEM, 106},
{ NINTENDO_ENTERTAINMENT_SYSTEM, 3 }, {NINTENDO_ENTERTAINMENT_SYSTEM, 3},
{ FAIRCHILD_CHANNELF, 80 }, {FAIRCHILD_CHANNELF, 80},
{ NINTENDO_GAME_BOY, 9 }, {NINTENDO_GAME_BOY, 9},
{ NINTENDO_GAME_BOY_ADVANCE, 12 }, {NINTENDO_GAME_BOY_ADVANCE, 12},
{ NINTENDO_GAME_BOY_COLOR, 10 }, {NINTENDO_GAME_BOY_COLOR, 10},
{ NINTENDO_GAMECUBE, 13 }, {NINTENDO_GAMECUBE, 13},
{ NINTENDO_WII, 16 }, {NINTENDO_WII, 16},
{ NINTENDO_WII_U, 18 }, {NINTENDO_WII_U, 18},
{ NINTENDO_VIRTUAL_BOY, 11 }, {NINTENDO_VIRTUAL_BOY, 11},
{ NINTENDO_GAME_AND_WATCH, 52 }, {NINTENDO_GAME_AND_WATCH, 52},
{ NINTENDO_POKEMON_MINI, 211 }, {NINTENDO_POKEMON_MINI, 211},
{ NINTENDO_SATELLAVIEW, 107 }, {NINTENDO_SATELLAVIEW, 107},
{ NINTENDO_SWITCH, 225 }, {NINTENDO_SWITCH, 225},
{ BANDAI_SUFAMI_TURBO, 108 }, {BANDAI_SUFAMI_TURBO, 108},
{ DOS, 135 }, {DOS, 135},
{ PC, 135 }, {PC, 135},
{ VALVE_STEAM, 135 }, {VALVE_STEAM, 135},
{ NEC_PCFX, 72 }, {NEC_PCFX, 72},
{ GAMEENGINE_OPENBOR, 214 }, {GAMEENGINE_OPENBOR, 214},
{ TANGERINE_ORIC, 131 }, {TANGERINE_ORIC, 131},
{ GAMEENGINE_SCUMMVM, 123 }, {GAMEENGINE_SCUMMVM, 123},
{ SEGA_32X, 19 }, {SEGA_32X, 19},
{ SEGA_CD, 20 }, {SEGA_CD, 20},
{ SEGA_DREAMCAST, 23 }, {SEGA_DREAMCAST, 23},
{ SEGA_GAME_GEAR, 21 }, {SEGA_GAME_GEAR, 21},
{ SEGA_GENESIS, 1 }, {SEGA_GENESIS, 1},
{ SEGA_MASTER_SYSTEM, 2 }, {SEGA_MASTER_SYSTEM, 2},
{ SEGA_MEGA_DRIVE, 1 }, {SEGA_MEGA_DRIVE, 1},
{ SEGA_SATURN, 22 }, {SEGA_SATURN, 22},
{ SEGA_SG1000, 109 }, {SEGA_SG1000, 109},
{ SHARP_X1, 220 }, {SHARP_X1, 220},
{ SHARP_X68000, 79 }, {SHARP_X68000, 79},
{ GAMEENGINE_SOLARUS, 223 }, {GAMEENGINE_SOLARUS, 223},
{ SONY_PLAYSTATION, 57 }, {SONY_PLAYSTATION, 57},
{ SONY_PLAYSTATION_2, 58 }, {SONY_PLAYSTATION_2, 58},
{ SONY_PLAYSTATION_3, 59 }, {SONY_PLAYSTATION_3, 59},
{ SONY_PLAYSTATION_VITA, 62 }, {SONY_PLAYSTATION_VITA, 62},
{ SONY_PLAYSTATION_PORTABLE, 61 }, {SONY_PLAYSTATION_PORTABLE, 61},
{ SAMCOUPE, 213 }, {SAMCOUPE, 213},
{ SUPER_NINTENDO, 4 }, {SUPER_NINTENDO, 4},
{ NEC_SUPERGRAFX, 105 }, {NEC_SUPERGRAFX, 105},
{ GAMEENGINE_TIC80, 222 }, {GAMEENGINE_TIC80, 222},
{ NEC_PC_8800, 221 }, {NEC_PC_8800, 221},
{ NEC_PC_9800, 208 }, {NEC_PC_9800, 208},
{ NEC_PC_ENGINE, 31 }, {NEC_PC_ENGINE, 31},
{ NEC_PC_ENGINE_CD, 114 }, {NEC_PC_ENGINE_CD, 114},
{ BANDAI_WONDERSWAN, 45 }, {BANDAI_WONDERSWAN, 45},
{ BANDAI_WONDERSWAN_COLOR, 46 }, {BANDAI_WONDERSWAN_COLOR, 46},
{ SINCLAIR_ZX_SPECTRUM, 76 }, {SINCLAIR_ZX_SPECTRUM, 76},
{ SINCLAIR_ZX81_SINCLAR, 77 }, {SINCLAIR_ZX81_SINCLAR, 77},
{ VIDEOPAC_ODYSSEY2, 104 }, {VIDEOPAC_ODYSSEY2, 104},
{ VECTREX, 102 }, {VECTREX, 102},
{ TANDY_TRS80, 144 }, {TANDY_TRS80, 144},
{ TANDY_COLOR_COMPUTER, 144 }, {TANDY_COLOR_COMPUTER, 144},
{ SEGA_NAOMI, 56 }, {SEGA_NAOMI, 56},
{ THOMSON_MOTO, 141 }, {THOMSON_MOTO, 141},
{ UZEBOX, 216 }, {UZEBOX, 216},
{ SPECTRAVIDEO, 218 }, {SPECTRAVIDEO, 218},
{ PALM_OS, 219 } {PALM_OS, 219}};
};
// Helper XML parsing method, finding a node-by-name recursively. // Helper XML parsing method, finding a node-by-name recursively.
pugi::xml_node find_node_by_name_re(const pugi::xml_node& node, pugi::xml_node find_node_by_name_re(const pugi::xml_node& node,
@ -333,11 +332,10 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
Utils::String::toLower(Settings::getInstance()->getString("ScraperLanguage")); Utils::String::toLower(Settings::getInstance()->getString("ScraperLanguage"));
// Name fallback: US, WOR(LD). (Xpath: Data/jeu[0]/noms/nom[*]). // Name fallback: US, WOR(LD). (Xpath: Data/jeu[0]/noms/nom[*]).
result.mdl.set("name", result.mdl.set("name", find_child_by_attribute_list(game.child("noms"), "nom", "region",
find_child_by_attribute_list(game.child("noms"), "nom", "region", {region, "wor", "us", "ss", "eu", "jp"})
{ region, "wor", "us", "ss", "eu", "jp" }) .text()
.text() .get());
.get());
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Name: " << result.mdl.get("name"); LOG(LogDebug) << "ScreenScraperRequest::processGame(): Name: " << result.mdl.get("name");
// Validate rating. // Validate rating.
@ -360,7 +358,7 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
// Description fallback language: EN, WOR(LD). // Description fallback language: EN, WOR(LD).
std::string description = find_child_by_attribute_list(game.child("synopsis"), "synopsis", std::string description = find_child_by_attribute_list(game.child("synopsis"), "synopsis",
"langue", { language, "en", "wor" }) "langue", {language, "en", "wor"})
.text() .text()
.get(); .get();
@ -373,7 +371,7 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
// Get the date proper. The API returns multiple 'date' children nodes to the 'dates' // Get the date proper. The API returns multiple 'date' children nodes to the 'dates'
// main child of 'jeu'. Date fallback: WOR(LD), US, SS, JP, EU. // main child of 'jeu'. Date fallback: WOR(LD), US, SS, JP, EU.
std::string _date = find_child_by_attribute_list(game.child("dates"), "date", "region", std::string _date = find_child_by_attribute_list(game.child("dates"), "date", "region",
{ region, "wor", "us", "ss", "jp", "eu" }) {region, "wor", "us", "ss", "jp", "eu"})
.text() .text()
.get(); .get();
@ -411,10 +409,10 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
} }
// Genre fallback language: EN. (Xpath: Data/jeu[0]/genres/genre[*]). // Genre fallback language: EN. (Xpath: Data/jeu[0]/genres/genre[*]).
std::string genre = find_child_by_attribute_list(game.child("genres"), "genre", "langue", std::string genre =
{ language, "en" }) find_child_by_attribute_list(game.child("genres"), "genre", "langue", {language, "en"})
.text() .text()
.get(); .get();
if (!genre.empty()) { if (!genre.empty()) {
result.mdl.set("genre", genre); result.mdl.set("genre", genre);
LOG(LogDebug) << "ScreenScraperRequest::processGame(): Genre: " LOG(LogDebug) << "ScreenScraperRequest::processGame(): Genre: "
@ -482,8 +480,7 @@ void ScreenScraperRequest::processMedia(ScraperSearchResult& result,
} }
else { else {
// Region fallback: WOR(LD), US, CUS(TOM?), JP, EU. // Region fallback: WOR(LD), US, CUS(TOM?), JP, EU.
for (auto _region : for (auto _region : std::vector<std::string>{region, "wor", "us", "cus", "jp", "eu"}) {
std::vector<std::string> { region, "wor", "us", "cus", "jp", "eu" }) {
if (art) if (art)
break; break;

View file

@ -46,10 +46,10 @@ public:
std::string getGameSearchUrl(const std::string gameName) const; std::string getGameSearchUrl(const std::string gameName) const;
// Access to the API. // Access to the API.
const std::string API_DEV_U = { 15, 21, 39, 22, 42, 40 }; const std::string API_DEV_U = {15, 21, 39, 22, 42, 40};
const std::string API_DEV_P = { 32, 70, 46, 54, 12, 5, 13, 120, 50, 66, 25 }; const std::string API_DEV_P = {32, 70, 46, 54, 12, 5, 13, 120, 50, 66, 25};
const std::string API_DEV_KEY = { 67, 112, 72, 120, 121, 77, 119, 74, 84, 56, const std::string API_DEV_KEY = {67, 112, 72, 120, 121, 77, 119, 74, 84, 56,
75, 122, 78, 98, 69, 86, 56, 120, 120, 49 }; 75, 122, 78, 98, 69, 86, 56, 120, 120, 49};
const std::string API_URL_BASE = "https://www.screenscraper.fr/api2"; const std::string API_URL_BASE = "https://www.screenscraper.fr/api2";
const std::string API_SOFT_NAME = const std::string API_SOFT_NAME =
"EmulationStation-DE " + static_cast<std::string>(PROGRAM_VERSION_STRING); "EmulationStation-DE " + static_cast<std::string>(PROGRAM_VERSION_STRING);

View file

@ -23,8 +23,8 @@
#endif #endif
// Buffer values for scrolling velocity (left, stopped, right). // Buffer values for scrolling velocity (left, stopped, right).
const int logoBuffersLeft[] = { -5, -2, -1 }; const int logoBuffersLeft[] = {-5, -2, -1};
const int logoBuffersRight[] = { 1, 2, 5 }; const int logoBuffersRight[] = {1, 2, 5};
SystemView::SystemView(Window* window) SystemView::SystemView(Window* window)
: IList<SystemViewData, SystemData*>(window, LIST_SCROLL_STYLE_SLOW, LIST_ALWAYS_LOOP) : IList<SystemViewData, SystemData*>(window, LIST_SCROLL_STYLE_SLOW, LIST_ALWAYS_LOOP)
@ -123,8 +123,8 @@ void SystemView::populate()
e.data.logo->setOrigin(0.5, 0.5); e.data.logo->setOrigin(0.5, 0.5);
} }
Vector2f denormalized = mCarousel.logoSize * e.data.logo->getOrigin(); glm::vec2 denormalized{mCarousel.logoSize * e.data.logo->getOrigin()};
e.data.logo->setPosition(denormalized.x(), denormalized.y(), 0.0); e.data.logo->setPosition(denormalized.x, denormalized.y, 0.0f);
// Make background extras. // Make background extras.
e.data.backgroundExtras = ThemeData::makeExtras((*it)->getTheme(), "system", mWindow); e.data.backgroundExtras = ThemeData::makeExtras((*it)->getTheme(), "system", mWindow);
@ -396,12 +396,12 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
setAnimation(anim, 0, nullptr, false, 0); setAnimation(anim, 0, nullptr, false, 0);
} }
void SystemView::render(const Transform4x4f& parentTrans) void SystemView::render(const glm::mat4& parentTrans)
{ {
if (size() == 0) if (size() == 0)
return; // Nothing to render. return; // Nothing to render.
Transform4x4f trans = getTransform() * parentTrans; glm::mat4 trans{getTransform() * parentTrans};
renderExtras(trans, INT16_MIN, INT16_MAX); renderExtras(trans, INT16_MIN, INT16_MAX);
@ -449,7 +449,6 @@ void SystemView::onThemeChanged(const std::shared_ptr<ThemeData>& /*theme*/)
populate(); populate();
} }
// Get the ThemeElements that make up the SystemView.
void SystemView::getViewElements(const std::shared_ptr<ThemeData>& theme) void SystemView::getViewElements(const std::shared_ptr<ThemeData>& theme)
{ {
LOG(LogDebug) << "SystemView::getViewElements()"; LOG(LogDebug) << "SystemView::getViewElements()";
@ -473,83 +472,78 @@ void SystemView::getViewElements(const std::shared_ptr<ThemeData>& theme)
mViewNeedsReload = false; mViewNeedsReload = false;
} }
// Render system carousel. void SystemView::renderCarousel(const glm::mat4& trans)
void SystemView::renderCarousel(const Transform4x4f& trans)
{ {
// Background box behind logos. // Background box behind logos.
Transform4x4f carouselTrans = trans; glm::mat4 carouselTrans{trans};
carouselTrans.translate(Vector3f(mCarousel.pos.x(), mCarousel.pos.y(), 0.0)); carouselTrans =
carouselTrans.translate(Vector3f(mCarousel.origin.x() * mCarousel.size.x() * -1.0f, glm::translate(carouselTrans, glm::vec3{mCarousel.pos.x, mCarousel.pos.y, 0.0f});
mCarousel.origin.y() * mCarousel.size.y() * -1.0f, 0.0f)); carouselTrans = glm::translate(carouselTrans,
glm::vec3{mCarousel.origin.x * mCarousel.size.x * -1.0f,
mCarousel.origin.y * mCarousel.size.y * -1.0f, 0.0f});
Vector2f clipPos(carouselTrans.translation().x(), carouselTrans.translation().y()); glm::vec2 clipPos{carouselTrans[3].x, carouselTrans[3].y};
Renderer::pushClipRect( Renderer::pushClipRect(
Vector2i(static_cast<int>(clipPos.x()), static_cast<int>(clipPos.y())), glm::ivec2{static_cast<int>(clipPos.x), static_cast<int>(clipPos.y)},
Vector2i(static_cast<int>(mCarousel.size.x()), static_cast<int>(mCarousel.size.y()))); glm::ivec2{static_cast<int>(mCarousel.size.x), static_cast<int>(mCarousel.size.y)});
Renderer::setMatrix(carouselTrans); Renderer::setMatrix(carouselTrans);
Renderer::drawRect(0.0f, 0.0f, mCarousel.size.x(), mCarousel.size.y(), mCarousel.color, Renderer::drawRect(0.0f, 0.0f, mCarousel.size.x, mCarousel.size.y, mCarousel.color,
mCarousel.colorEnd, mCarousel.colorGradientHorizontal); mCarousel.colorEnd, mCarousel.colorGradientHorizontal);
// Draw logos. // Draw logos.
// Note: logoSpacing will also include the size of the logo itself. // Note: logoSpacing will also include the size of the logo itself.
Vector2f logoSpacing(0.0f, 0.0f); glm::vec2 logoSpacing{};
float xOff = 0.0f; float xOff = 0.0f;
float yOff = 0.0f; float yOff = 0.0f;
switch (mCarousel.type) { switch (mCarousel.type) {
case VERTICAL_WHEEL: { case VERTICAL_WHEEL: {
yOff = (mCarousel.size.y() - mCarousel.logoSize.y()) / 2.0f - yOff = (mCarousel.size.y - mCarousel.logoSize.y) / 2.0f - (mCamOffset * logoSpacing.y);
(mCamOffset * logoSpacing[1]);
if (mCarousel.logoAlignment == ALIGN_LEFT) if (mCarousel.logoAlignment == ALIGN_LEFT)
xOff = mCarousel.logoSize.x() / 10.0f; xOff = mCarousel.logoSize.x / 10.0f;
else if (mCarousel.logoAlignment == ALIGN_RIGHT) else if (mCarousel.logoAlignment == ALIGN_RIGHT)
xOff = mCarousel.size.x() - (mCarousel.logoSize.x() * 1.1f); xOff = mCarousel.size.x - (mCarousel.logoSize.x * 1.1f);
else else
xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2.0f; xOff = (mCarousel.size.x - mCarousel.logoSize.x) / 2.0f;
break; break;
} }
case VERTICAL: { case VERTICAL: {
logoSpacing[1] = logoSpacing.y = ((mCarousel.size.y - (mCarousel.logoSize.y * mCarousel.maxLogoCount)) /
((mCarousel.size.y() - (mCarousel.logoSize.y() * mCarousel.maxLogoCount)) / (mCarousel.maxLogoCount)) +
(mCarousel.maxLogoCount)) + mCarousel.logoSize.y;
mCarousel.logoSize.y(); yOff = (mCarousel.size.y - mCarousel.logoSize.y) / 2.0f - (mCamOffset * logoSpacing.y);
yOff = (mCarousel.size.y() - mCarousel.logoSize.y()) / 2.0f -
(mCamOffset * logoSpacing[1]);
if (mCarousel.logoAlignment == ALIGN_LEFT) if (mCarousel.logoAlignment == ALIGN_LEFT)
xOff = mCarousel.logoSize.x() / 10.0f; xOff = mCarousel.logoSize.x / 10.0f;
else if (mCarousel.logoAlignment == ALIGN_RIGHT) else if (mCarousel.logoAlignment == ALIGN_RIGHT)
xOff = mCarousel.size.x() - (mCarousel.logoSize.x() * 1.1f); xOff = mCarousel.size.x - (mCarousel.logoSize.x * 1.1f);
else else
xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2.0f; xOff = (mCarousel.size.x - mCarousel.logoSize.x) / 2.0f;
break; break;
} }
case HORIZONTAL_WHEEL: { case HORIZONTAL_WHEEL: {
xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2.0f - xOff = (mCarousel.size.x - mCarousel.logoSize.x) / 2.0f - (mCamOffset * logoSpacing.y);
(mCamOffset * logoSpacing[1]);
if (mCarousel.logoAlignment == ALIGN_TOP) if (mCarousel.logoAlignment == ALIGN_TOP)
yOff = mCarousel.logoSize.y() / 10.0f; yOff = mCarousel.logoSize.y / 10.0f;
else if (mCarousel.logoAlignment == ALIGN_BOTTOM) else if (mCarousel.logoAlignment == ALIGN_BOTTOM)
yOff = mCarousel.size.y() - (mCarousel.logoSize.y() * 1.1f); yOff = mCarousel.size.y - (mCarousel.logoSize.y * 1.1f);
else else
yOff = (mCarousel.size.y() - mCarousel.logoSize.y()) / 2.0f; yOff = (mCarousel.size.y - mCarousel.logoSize.y) / 2.0f;
break; break;
} }
case HORIZONTAL: { case HORIZONTAL: {
} }
default: { default: {
logoSpacing[0] = logoSpacing.x = ((mCarousel.size.x - (mCarousel.logoSize.x * mCarousel.maxLogoCount)) /
((mCarousel.size.x() - (mCarousel.logoSize.x() * mCarousel.maxLogoCount)) / (mCarousel.maxLogoCount)) +
(mCarousel.maxLogoCount)) + mCarousel.logoSize.x;
mCarousel.logoSize.x(); xOff = (mCarousel.size.x - mCarousel.logoSize.x) / 2.0f - (mCamOffset * logoSpacing.x);
xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2.0f -
(mCamOffset * logoSpacing[0]);
if (mCarousel.logoAlignment == ALIGN_TOP) if (mCarousel.logoAlignment == ALIGN_TOP)
yOff = mCarousel.logoSize.y() / 10.0f; yOff = mCarousel.logoSize.y / 10.0f;
else if (mCarousel.logoAlignment == ALIGN_BOTTOM) else if (mCarousel.logoAlignment == ALIGN_BOTTOM)
yOff = mCarousel.size.y() - (mCarousel.logoSize.y() * 1.1f); yOff = mCarousel.size.y - (mCarousel.logoSize.y * 1.1f);
else else
yOff = (mCarousel.size.y() - mCarousel.logoSize.y()) / 2.0f; yOff = (mCarousel.size.y - mCarousel.logoSize.y) / 2.0f;
break; break;
} }
} }
@ -575,8 +569,9 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
while (index >= static_cast<int>(mEntries.size())) while (index >= static_cast<int>(mEntries.size()))
index -= static_cast<int>(mEntries.size()); index -= static_cast<int>(mEntries.size());
Transform4x4f logoTrans = carouselTrans; glm::mat4 logoTrans{carouselTrans};
logoTrans.translate(Vector3f(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0)); logoTrans = glm::translate(
logoTrans, glm::vec3{i * logoSpacing.x + xOff, i * logoSpacing.y + yOff, 0.0f});
float distance = i - mCamOffset; float distance = i - mCamOffset;
@ -600,16 +595,15 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
Renderer::popClipRect(); Renderer::popClipRect();
} }
// Draw background extras. void SystemView::renderExtras(const glm::mat4& trans, float lower, float upper)
void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upper)
{ {
int extrasCenter = static_cast<int>(mExtrasCamOffset); int extrasCenter = static_cast<int>(mExtrasCamOffset);
// Adding texture loading buffers depending on scrolling speed and status. // Adding texture loading buffers depending on scrolling speed and status.
int bufferIndex = getScrollingVelocity() + 1; int bufferIndex{getScrollingVelocity() + 1};
Renderer::pushClipRect(Vector2i::Zero(), Renderer::pushClipRect(glm::ivec2{},
Vector2i(static_cast<int>(mSize.x()), static_cast<int>(mSize.y()))); glm::ivec2{static_cast<int>(mSize.x), static_cast<int>(mSize.y)});
for (int i = extrasCenter + logoBuffersLeft[bufferIndex]; for (int i = extrasCenter + logoBuffersLeft[bufferIndex];
i <= extrasCenter + logoBuffersRight[bufferIndex]; i++) { i <= extrasCenter + logoBuffersRight[bufferIndex]; i++) {
@ -621,16 +615,17 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp
// Only render selected system when not showing. // Only render selected system when not showing.
if (mShowing || index == mCursor) { if (mShowing || index == mCursor) {
Transform4x4f extrasTrans = trans; glm::mat4 extrasTrans{trans};
if (mCarousel.type == HORIZONTAL || mCarousel.type == HORIZONTAL_WHEEL) if (mCarousel.type == HORIZONTAL || mCarousel.type == HORIZONTAL_WHEEL)
extrasTrans.translate(Vector3f((i - mExtrasCamOffset) * mSize.x(), 0, 0)); extrasTrans = glm::translate(
extrasTrans, glm::vec3{(i - mExtrasCamOffset) * mSize.x, 0.0f, 0.0f});
else else
extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0)); extrasTrans = glm::translate(
extrasTrans, glm::vec3{0.0f, (i - mExtrasCamOffset) * mSize.y, 0.0f});
Renderer::pushClipRect( Renderer::pushClipRect(
Vector2i(static_cast<int>(extrasTrans.translation()[0]), glm::ivec2{static_cast<int>(extrasTrans[3].x), static_cast<int>(extrasTrans[3].y)},
static_cast<int>(extrasTrans.translation()[1])), glm::ivec2{static_cast<int>(mSize.x), static_cast<int>(mSize.y)});
Vector2i(static_cast<int>(mSize.x()), static_cast<int>(mSize.y())));
SystemViewData data = mEntries.at(index).data; SystemViewData data = mEntries.at(index).data;
for (unsigned int j = 0; j < data.backgroundExtras.size(); j++) { for (unsigned int j = 0; j < data.backgroundExtras.size(); j++) {
GuiComponent* extra = data.backgroundExtras[j]; GuiComponent* extra = data.backgroundExtras[j];
@ -644,46 +639,45 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp
Renderer::popClipRect(); Renderer::popClipRect();
} }
void SystemView::renderFade(const Transform4x4f& trans) void SystemView::renderFade(const glm::mat4& trans)
{ {
unsigned int fadeColor = 0x00000000 | static_cast<unsigned char>(mExtrasFadeOpacity * 255.0f); unsigned int fadeColor = 0x00000000 | static_cast<unsigned char>(mExtrasFadeOpacity * 255.0f);
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), fadeColor, fadeColor); Renderer::drawRect(0.0f, 0.0f, mSize.x, mSize.y, fadeColor, fadeColor);
} }
// Populate the system carousel with the legacy values.
void SystemView::getDefaultElements(void) void SystemView::getDefaultElements(void)
{ {
// Carousel. // Carousel.
mCarousel.type = HORIZONTAL; mCarousel.type = HORIZONTAL;
mCarousel.logoAlignment = ALIGN_CENTER; mCarousel.logoAlignment = ALIGN_CENTER;
mCarousel.size.x() = mSize.x(); mCarousel.size.x = mSize.x;
mCarousel.size.y() = floorf(0.2325f * mSize.y()); mCarousel.size.y = floorf(0.2325f * mSize.y);
mCarousel.pos.x() = 0.0f; mCarousel.pos.x = 0.0f;
mCarousel.pos.y() = floorf(0.5f * (mSize.y() - mCarousel.size.y())); mCarousel.pos.y = floorf(0.5f * (mSize.y - mCarousel.size.y));
mCarousel.origin.x() = 0.0f; mCarousel.origin.x = 0.0f;
mCarousel.origin.y() = 0.0f; mCarousel.origin.y = 0.0f;
mCarousel.color = 0xFFFFFFD8; mCarousel.color = 0xFFFFFFD8;
mCarousel.colorEnd = 0xFFFFFFD8; mCarousel.colorEnd = 0xFFFFFFD8;
mCarousel.colorGradientHorizontal = true; mCarousel.colorGradientHorizontal = true;
mCarousel.logoScale = 1.2f; mCarousel.logoScale = 1.2f;
mCarousel.logoRotation = 7.5f; mCarousel.logoRotation = 7.5f;
mCarousel.logoRotationOrigin.x() = -5.0f; mCarousel.logoRotationOrigin.x = -5.0f;
mCarousel.logoRotationOrigin.y() = 0.5f; mCarousel.logoRotationOrigin.y = 0.5f;
mCarousel.logoSize.x() = 0.25f * mSize.x(); mCarousel.logoSize.x = 0.25f * mSize.x;
mCarousel.logoSize.y() = 0.155f * mSize.y(); mCarousel.logoSize.y = 0.155f * mSize.y;
mCarousel.maxLogoCount = 3; mCarousel.maxLogoCount = 3;
mCarousel.zIndex = 40.0f; mCarousel.zIndex = 40.0f;
// System info bar. // System info bar.
mSystemInfo.setSize(mSize.x(), mSystemInfo.getFont()->getLetterHeight() * 2.2f); mSystemInfo.setSize(mSize.x, mSystemInfo.getFont()->getLetterHeight() * 2.2f);
mSystemInfo.setPosition(0, mCarousel.pos.y() + mCarousel.size.y()); mSystemInfo.setPosition(0.0f, mCarousel.pos.y + mCarousel.size.y);
mSystemInfo.setBackgroundColor(0xDDDDDDD8); mSystemInfo.setBackgroundColor(0xDDDDDDD8);
mSystemInfo.setRenderBackground(true); mSystemInfo.setRenderBackground(true);
mSystemInfo.setFont(Font::get(static_cast<int>(0.035f * mSize.y()), Font::getDefaultPath())); mSystemInfo.setFont(Font::get(static_cast<int>(0.035f * mSize.y), Font::getDefaultPath()));
mSystemInfo.setColor(0x000000FF); mSystemInfo.setColor(0x000000FF);
mSystemInfo.setZIndex(50); mSystemInfo.setZIndex(50.0f);
mSystemInfo.setDefaultZIndex(50); mSystemInfo.setDefaultZIndex(50.0f);
} }
void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem) void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
@ -699,11 +693,11 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
mCarousel.type = HORIZONTAL; mCarousel.type = HORIZONTAL;
} }
if (elem->has("size")) if (elem->has("size"))
mCarousel.size = elem->get<Vector2f>("size") * mSize; mCarousel.size = elem->get<glm::vec2>("size") * mSize;
if (elem->has("pos")) if (elem->has("pos"))
mCarousel.pos = elem->get<Vector2f>("pos") * mSize; mCarousel.pos = elem->get<glm::vec2>("pos") * mSize;
if (elem->has("origin")) if (elem->has("origin"))
mCarousel.origin = elem->get<Vector2f>("origin"); mCarousel.origin = elem->get<glm::vec2>("origin");
if (elem->has("color")) { if (elem->has("color")) {
mCarousel.color = elem->get<unsigned int>("color"); mCarousel.color = elem->get<unsigned int>("color");
mCarousel.colorEnd = mCarousel.color; mCarousel.colorEnd = mCarousel.color;
@ -716,7 +710,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
if (elem->has("logoScale")) if (elem->has("logoScale"))
mCarousel.logoScale = elem->get<float>("logoScale"); mCarousel.logoScale = elem->get<float>("logoScale");
if (elem->has("logoSize")) if (elem->has("logoSize"))
mCarousel.logoSize = elem->get<Vector2f>("logoSize") * mSize; mCarousel.logoSize = elem->get<glm::vec2>("logoSize") * mSize;
if (elem->has("maxLogoCount")) if (elem->has("maxLogoCount"))
mCarousel.maxLogoCount = static_cast<int>(std::round(elem->get<float>("maxLogoCount"))); mCarousel.maxLogoCount = static_cast<int>(std::round(elem->get<float>("maxLogoCount")));
if (elem->has("zIndex")) if (elem->has("zIndex"))
@ -724,7 +718,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
if (elem->has("logoRotation")) if (elem->has("logoRotation"))
mCarousel.logoRotation = elem->get<float>("logoRotation"); mCarousel.logoRotation = elem->get<float>("logoRotation");
if (elem->has("logoRotationOrigin")) if (elem->has("logoRotationOrigin"))
mCarousel.logoRotationOrigin = elem->get<Vector2f>("logoRotationOrigin"); mCarousel.logoRotationOrigin = elem->get<glm::vec2>("logoRotationOrigin");
if (elem->has("logoAlignment")) { if (elem->has("logoAlignment")) {
if (!(elem->get<std::string>("logoAlignment").compare("left"))) if (!(elem->get<std::string>("logoAlignment").compare("left")))
mCarousel.logoAlignment = ALIGN_LEFT; mCarousel.logoAlignment = ALIGN_LEFT;

View file

@ -34,18 +34,18 @@ struct SystemViewData {
struct SystemViewCarousel { struct SystemViewCarousel {
CarouselType type; CarouselType type;
Vector2f pos; glm::vec2 pos;
Vector2f size; glm::vec2 size;
Vector2f origin; glm::vec2 origin;
float logoScale; float logoScale;
float logoRotation; float logoRotation;
Vector2f logoRotationOrigin; glm::vec2 logoRotationOrigin;
Alignment logoAlignment; Alignment logoAlignment;
unsigned int color; unsigned int color;
unsigned int colorEnd; unsigned int colorEnd;
bool colorGradientHorizontal; bool colorGradientHorizontal;
int maxLogoCount; // Number of logos shown on the carousel. int maxLogoCount; // Number of logos shown on the carousel.
Vector2f logoSize; glm::vec2 logoSize;
float zIndex; float zIndex;
}; };
@ -62,7 +62,7 @@ public:
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onThemeChanged(const std::shared_ptr<ThemeData>& theme); void onThemeChanged(const std::shared_ptr<ThemeData>& theme);
@ -81,13 +81,17 @@ protected:
private: private:
void populate(); void populate();
void updateGameCount(); void updateGameCount();
// Get the ThemeElements that make up the SystemView.
void getViewElements(const std::shared_ptr<ThemeData>& theme); void getViewElements(const std::shared_ptr<ThemeData>& theme);
// Populate the system carousel with the legacy values.
void getDefaultElements(void); void getDefaultElements(void);
void getCarouselFromTheme(const ThemeData::ThemeElement* elem); void getCarouselFromTheme(const ThemeData::ThemeElement* elem);
void renderCarousel(const Transform4x4f& parentTrans); // Render system carousel.
void renderExtras(const Transform4x4f& parentTrans, float lower, float upper); void renderCarousel(const glm::mat4& parentTrans);
void renderFade(const Transform4x4f& trans); // Draw background extras.
void renderExtras(const glm::mat4& parentTrans, float lower, float upper);
void renderFade(const glm::mat4& trans);
SystemViewCarousel mCarousel; SystemViewCarousel mCarousel;
TextComponent mSystemInfo; TextComponent mSystemInfo;

View file

@ -58,9 +58,7 @@ private:
int mPassKeyCounter; int mPassKeyCounter;
// These are Xbox button names, so they may be different in pracise on non-Xbox controllers. // These are Xbox button names, so they may be different in pracise on non-Xbox controllers.
const std::vector<std::string> mInputVals = { const std::vector<std::string> mInputVals = {"up", "down", "left", "right", "a", "b", "x", "y"};
"up", "down", "left", "right", "a", "b", "x", "y"
};
}; };
#endif // ES_APP_VIEWS_UI_MODE_CONTROLLER_H #endif // ES_APP_VIEWS_UI_MODE_CONTROLLER_H

View file

@ -66,7 +66,7 @@ ViewController::ViewController(Window* window)
, mCurrentView(nullptr) , mCurrentView(nullptr)
, mPreviousView(nullptr) , mPreviousView(nullptr)
, mSkipView(nullptr) , mSkipView(nullptr)
, mCamera(Transform4x4f::Identity()) , mCamera(Renderer::getIdentity())
, mSystemViewTransition(false) , mSystemViewTransition(false)
, mWrappedViews(false) , mWrappedViews(false)
, mFadeOpacity(0) , mFadeOpacity(0)
@ -234,8 +234,8 @@ void ViewController::ReloadAndGoToStart()
bool ViewController::isCameraMoving() bool ViewController::isCameraMoving()
{ {
if (mCurrentView) { if (mCurrentView) {
if (mCamera.r3().x() - -mCurrentView->getPosition().x() != 0 || if (mCamera[3].x - -mCurrentView->getPosition().x != 0.0f ||
mCamera.r3().y() - -mCurrentView->getPosition().y() != 0) mCamera[3].y - -mCurrentView->getPosition().y != 0.0f)
return true; return true;
} }
return false; return false;
@ -245,8 +245,8 @@ void ViewController::cancelViewTransitions()
{ {
if (Settings::getInstance()->getString("TransitionStyle") == "slide") { if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
if (isCameraMoving()) { if (isCameraMoving()) {
mCamera.r3().x() = -mCurrentView->getPosition().x(); mCamera[3].x = -mCurrentView->getPosition().x;
mCamera.r3().y() = -mCurrentView->getPosition().y(); mCamera[3].y = -mCurrentView->getPosition().y;
stopAllAnimations(); stopAllAnimations();
} }
// mSkipView is used when skipping through the gamelists in quick succession. // mSkipView is used when skipping through the gamelists in quick succession.
@ -285,8 +285,8 @@ int ViewController::getSystemId(SystemData* system)
void ViewController::restoreViewPosition() void ViewController::restoreViewPosition()
{ {
if (mPreviousView) { if (mPreviousView) {
Vector3f restorePosition = mPreviousView->getPosition(); glm::vec3 restorePosition{mPreviousView->getPosition()};
restorePosition.x() = mWrapPreviousPositionX; restorePosition.x = mWrapPreviousPositionX;
mPreviousView->setPosition(restorePosition); mPreviousView->setPosition(restorePosition);
mWrapPreviousPositionX = 0; mWrapPreviousPositionX = 0;
mWrappedViews = false; mWrappedViews = false;
@ -320,7 +320,7 @@ void ViewController::goToSystemView(SystemData* system, bool playTransition)
auto systemList = getSystemListView(); auto systemList = getSystemListView();
systemList->setPosition(getSystemId(system) * static_cast<float>(Renderer::getScreenWidth()), systemList->setPosition(getSystemId(system) * static_cast<float>(Renderer::getScreenWidth()),
systemList->getPosition().y()); systemList->getPosition().y);
systemList->goToSystem(system, false); systemList->goToSystem(system, false);
mCurrentView = systemList; mCurrentView = systemList;
@ -328,21 +328,21 @@ void ViewController::goToSystemView(SystemData* system, bool playTransition)
// Application startup animation. // Application startup animation.
if (applicationStartup) { if (applicationStartup) {
mCamera.translation() = -mCurrentView->getPosition(); mCamera = glm::translate(mCamera, -mCurrentView->getPosition());
if (Settings::getInstance()->getString("TransitionStyle") == "slide") { if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL || if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL ||
getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL) getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL)
mCamera.translation().y() += Renderer::getScreenHeight(); mCamera[3].y += static_cast<float>(Renderer::getScreenHeight());
else else
mCamera.translation().x() -= Renderer::getScreenWidth(); mCamera[3].x -= static_cast<float>(Renderer::getScreenWidth());
updateHelpPrompts(); updateHelpPrompts();
} }
else if (Settings::getInstance()->getString("TransitionStyle") == "fade") { else if (Settings::getInstance()->getString("TransitionStyle") == "fade") {
if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL || if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL ||
getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL) getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL)
mCamera.translation().y() += Renderer::getScreenHeight(); mCamera[3].y += static_cast<float>(Renderer::getScreenHeight());
else else
mCamera.translation().x() += Renderer::getScreenWidth(); mCamera[3].x += static_cast<float>(Renderer::getScreenWidth());
} }
else { else {
updateHelpPrompts(); updateHelpPrompts();
@ -444,13 +444,13 @@ void ViewController::goToGameList(SystemData* system)
if (mState.viewing == SYSTEM_SELECT) { if (mState.viewing == SYSTEM_SELECT) {
// Move the system list. // Move the system list.
auto sysList = getSystemListView(); auto sysList = getSystemListView();
float offsetX = sysList->getPosition().x(); float offsetX = sysList->getPosition().x;
int sysId = getSystemId(system); int sysId = getSystemId(system);
sysList->setPosition(sysId * static_cast<float>(Renderer::getScreenWidth()), sysList->setPosition(sysId * static_cast<float>(Renderer::getScreenWidth()),
sysList->getPosition().y()); sysList->getPosition().y);
offsetX = sysList->getPosition().x() - offsetX; offsetX = sysList->getPosition().x - offsetX;
mCamera.translation().x() -= offsetX; mCamera[3].x -= offsetX;
} }
// If we are wrapping around, either from the first to last system, or the other way // If we are wrapping around, either from the first to last system, or the other way
@ -458,30 +458,30 @@ void ViewController::goToGameList(SystemData* system)
// movements will be correct. This is accomplished by simply offsetting the X position // movements will be correct. This is accomplished by simply offsetting the X position
// with the position of the first or last system plus the screen width. // with the position of the first or last system plus the screen width.
if (wrapFirstToLast) { if (wrapFirstToLast) {
Vector3f currentPosition = mCurrentView->getPosition(); glm::vec3 currentPosition{mCurrentView->getPosition()};
mWrapPreviousPositionX = currentPosition.x(); mWrapPreviousPositionX = currentPosition.x;
float offsetX = getGameListView(system)->getPosition().x(); float offsetX{getGameListView(system)->getPosition().x};
// This is needed to move the camera in the correct direction if there are only two systems. // This is needed to move the camera in the correct direction if there are only two systems.
if (SystemData::sSystemVector.size() == 2 && mNextSystem) if (SystemData::sSystemVector.size() == 2 && mNextSystem)
offsetX -= Renderer::getScreenWidth(); offsetX -= Renderer::getScreenWidth();
else else
offsetX += Renderer::getScreenWidth(); offsetX += Renderer::getScreenWidth();
currentPosition.x() = offsetX; currentPosition.x = offsetX;
mCurrentView->setPosition(currentPosition); mCurrentView->setPosition(currentPosition);
mCamera.translation().x() -= offsetX; mCamera[3].x -= offsetX;
mWrappedViews = true; mWrappedViews = true;
} }
else if (wrapLastToFirst) { else if (wrapLastToFirst) {
Vector3f currentPosition = mCurrentView->getPosition(); glm::vec3 currentPosition{mCurrentView->getPosition()};
mWrapPreviousPositionX = currentPosition.x(); mWrapPreviousPositionX = currentPosition.x;
float offsetX = getGameListView(system)->getPosition().x(); float offsetX{getGameListView(system)->getPosition().x};
if (SystemData::sSystemVector.size() == 2 && !mNextSystem) if (SystemData::sSystemVector.size() == 2 && !mNextSystem)
offsetX += Renderer::getScreenWidth(); offsetX += Renderer::getScreenWidth();
else else
offsetX -= Renderer::getScreenWidth(); offsetX -= Renderer::getScreenWidth();
currentPosition.x() = offsetX; currentPosition.x = offsetX;
mCurrentView->setPosition(currentPosition); mCurrentView->setPosition(currentPosition);
mCamera.translation().x() = -offsetX; mCamera[3].x = -offsetX;
mWrappedViews = true; mWrappedViews = true;
} }
@ -489,13 +489,13 @@ void ViewController::goToGameList(SystemData* system)
// Application startup animation, if starting in a gamelist rather than in the system view. // Application startup animation, if starting in a gamelist rather than in the system view.
if (mState.viewing == NOTHING) { if (mState.viewing == NOTHING) {
mCamera.translation() = -mCurrentView->getPosition(); mCamera = glm::translate(mCamera, -mCurrentView->getPosition());
if (Settings::getInstance()->getString("TransitionStyle") == "slide") { if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
mCamera.translation().y() -= Renderer::getScreenHeight(); mCamera[3].y -= static_cast<float>(Renderer::getScreenHeight());
updateHelpPrompts(); updateHelpPrompts();
} }
else if (Settings::getInstance()->getString("TransitionStyle") == "fade") { else if (Settings::getInstance()->getString("TransitionStyle") == "fade") {
mCamera.translation().y() += Renderer::getScreenHeight() * 2; mCamera[3].y += static_cast<float>(Renderer::getScreenHeight() * 2);
} }
else { else {
updateHelpPrompts(); updateHelpPrompts();
@ -528,21 +528,23 @@ void ViewController::playViewTransition(bool instant)
{ {
mCancelledTransition = false; mCancelledTransition = false;
Vector3f target(Vector3f::Zero()); glm::vec3 target{};
if (mCurrentView) if (mCurrentView)
target = mCurrentView->getPosition(); target = mCurrentView->getPosition();
// No need to animate, we're not going anywhere (probably due to goToNextGamelist() // No need to animate, we're not going anywhere (probably due to goToNextGamelist()
// or goToPrevGamelist() being called when there's only 1 system). // or goToPrevGamelist() being called when there's only 1 system).
if (target == -mCamera.translation() && !isAnimationPlaying(0)) if (target == static_cast<glm::vec3>(-mCamera[3]) && !isAnimationPlaying(0))
return; return;
std::string transition_style = Settings::getInstance()->getString("TransitionStyle"); std::string transition_style{Settings::getInstance()->getString("TransitionStyle")};
if (instant || transition_style == "instant") { if (instant || transition_style == "instant") {
setAnimation(new LambdaAnimation( setAnimation(new LambdaAnimation(
[this, target](float /*t*/) { [this, target](float /*t*/) {
this->mCamera.translation() = -target; this->mCamera[3].x = -target.x;
this->mCamera[3].y = -target.y;
this->mCamera[3].z = -target.z;
if (mPreviousView) if (mPreviousView)
mPreviousView->onHide(); mPreviousView->onHide();
}, },
@ -571,14 +573,16 @@ void ViewController::playViewTransition(bool instant)
const static int FADE_WAIT = 200; // Time to wait between in/out. const static int FADE_WAIT = 200; // Time to wait between in/out.
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), 0, setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), 0,
[this, fadeFunc, fadeCallback, target] { [this, fadeFunc, fadeCallback, target] {
this->mCamera.translation() = -target; this->mCamera[3].x = -target.x;
this->mCamera[3].y = -target.y;
this->mCamera[3].z = -target.z;
updateHelpPrompts(); updateHelpPrompts();
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), FADE_WAIT, setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), FADE_WAIT,
fadeCallback, true); fadeCallback, true);
}); });
// Fast-forward animation if we're partway faded. // Fast-forward animation if we're partway faded.
if (target == -mCamera.translation()) { if (target == static_cast<glm::vec3>(-mCamera[3])) {
// Not changing screens, so cancel the first half entirely. // Not changing screens, so cancel the first half entirely.
advanceAnimation(0, FADE_DURATION); advanceAnimation(0, FADE_DURATION);
advanceAnimation(0, FADE_WAIT); advanceAnimation(0, FADE_WAIT);
@ -848,16 +852,16 @@ void ViewController::update(int deltaTime)
} }
} }
void ViewController::render(const Transform4x4f& parentTrans) void ViewController::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = mCamera * parentTrans; glm::mat4 trans{mCamera * parentTrans};
Transform4x4f transInverse; glm::mat4 transInverse{glm::inverse(trans)};
transInverse.invert(trans);
// Camera position, position + size. // Camera position, position + size.
Vector3f viewStart = transInverse.translation(); glm::vec3 viewStart{transInverse[3]};
Vector3f viewEnd = transInverse * Vector3f(static_cast<float>(Renderer::getScreenWidth()), glm::vec3 viewEnd{std::fabs(trans[3].x) + static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight(), 0)); std::fabs(trans[3].y) + static_cast<float>(Renderer::getScreenHeight()),
0.0f};
// Keep track of UI mode changes. // Keep track of UI mode changes.
UIModeController::getInstance()->monitorUIMode(); UIModeController::getInstance()->monitorUIMode();
@ -872,12 +876,12 @@ void ViewController::render(const Transform4x4f& parentTrans)
// Same thing as for the system view, limit the rendering only to what needs to be drawn. // Same thing as for the system view, limit the rendering only to what needs to be drawn.
if (it->second == mCurrentView || (it->second == mPreviousView && isCameraMoving())) { if (it->second == mCurrentView || (it->second == mPreviousView && isCameraMoving())) {
// Clipping. // Clipping.
Vector3f guiStart = it->second->getPosition(); glm::vec3 guiStart{it->second->getPosition()};
Vector3f guiEnd = it->second->getPosition() + glm::vec3 guiEnd{it->second->getPosition() +
Vector3f(it->second->getSize().x(), it->second->getSize().y(), 0); glm::vec3{it->second->getSize().x, it->second->getSize().y, 0.0f}};
if (guiEnd.x() >= viewStart.x() && guiEnd.y() >= viewStart.y() && if (guiEnd.x >= viewStart.x && guiEnd.y >= viewStart.y && guiStart.x <= viewEnd.x &&
guiStart.x() <= viewEnd.x() && guiStart.y() <= viewEnd.y()) guiStart.y <= viewEnd.y)
it->second->render(trans); it->second->render(trans);
} }
} }
@ -1000,7 +1004,7 @@ void ViewController::reloadAll()
SystemData* system = mState.getSystem(); SystemData* system = mState.getSystem();
mSystemListView->goToSystem(system, false); mSystemListView->goToSystem(system, false);
mCurrentView = mSystemListView; mCurrentView = mSystemListView;
mCamera.r3().x() = 0; mCamera[3].x = 0.0f;
} }
else { else {
goToSystemView(SystemData::sSystemVector.front(), false); goToSystemView(SystemData::sSystemVector.front(), false);

View file

@ -78,7 +78,7 @@ public:
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
enum ViewMode { enum ViewMode {
NOTHING, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0). NOTHING, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
@ -152,7 +152,7 @@ private:
FileData* mGameToLaunch; FileData* mGameToLaunch;
State mState; State mState;
Transform4x4f mCamera; glm::mat4 mCamera;
bool mSystemViewTransition; bool mSystemViewTransition;
bool mWrappedViews; bool mWrappedViews;
float mWrapPreviousPositionX; float mWrapPreviousPositionX;

View file

@ -19,9 +19,9 @@ BasicGameListView::BasicGameListView(Window* window, FileData* root)
: ISimpleGameListView(window, root) : ISimpleGameListView(window, root)
, mList(window) , mList(window)
{ {
mList.setSize(mSize.x(), mSize.y() * 0.8f); mList.setSize(mSize.x, mSize.y * 0.8f);
mList.setPosition(0, mSize.y() * 0.2f); mList.setPosition(0.0f, mSize.y * 0.2f);
mList.setDefaultZIndex(20); mList.setDefaultZIndex(20.0f);
addChild(&mList); addChild(&mList);
populateList(root->getChildrenListToDisplay(), root); populateList(root->getChildrenListToDisplay(), root);

View file

@ -45,8 +45,8 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
{ {
const float padding = 0.01f; const float padding = 0.01f;
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y()); mList.setPosition(mSize.x * (0.50f + padding), mList.getPosition().y);
mList.setSize(mSize.x() * (0.50f - padding), mList.getSize().y()); mList.setSize(mSize.x * (0.50f - padding), mList.getSize().y);
mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT); mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT);
mList.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); }); mList.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); });
@ -54,8 +54,8 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
mThumbnail.setOrigin(0.5f, 0.5f); mThumbnail.setOrigin(0.5f, 0.5f);
mThumbnail.setPosition(2.0f, 2.0f); mThumbnail.setPosition(2.0f, 2.0f);
mThumbnail.setVisible(false); mThumbnail.setVisible(false);
mThumbnail.setMaxSize(mSize.x() * (0.25f - 2 * padding), mSize.y() * 0.10f); mThumbnail.setMaxSize(mSize.x * (0.25f - 2.0f * padding), mSize.y * 0.10f);
mThumbnail.setDefaultZIndex(25); mThumbnail.setDefaultZIndex(25.0f);
addChild(&mThumbnail); addChild(&mThumbnail);
// Marquee. // Marquee.
@ -63,15 +63,15 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
// Default to off the screen. // Default to off the screen.
mMarquee.setPosition(2.0f, 2.0f); mMarquee.setPosition(2.0f, 2.0f);
mMarquee.setVisible(false); mMarquee.setVisible(false);
mMarquee.setMaxSize(mSize.x() * (0.5f - 2 * padding), mSize.y() * 0.18f); mMarquee.setMaxSize(mSize.x * (0.5f - 2.0f * padding), mSize.y * 0.18f);
mMarquee.setDefaultZIndex(35); mMarquee.setDefaultZIndex(35.0f);
addChild(&mMarquee); addChild(&mMarquee);
// Image. // Image.
mImage.setOrigin(0.5f, 0.5f); mImage.setOrigin(0.5f, 0.5f);
mImage.setPosition(mSize.x() * 0.25f, mList.getPosition().y() + mSize.y() * 0.2125f); mImage.setPosition(mSize.x * 0.25f, mList.getPosition().y + mSize.y * 0.2125f);
mImage.setMaxSize(mSize.x() * (0.50f - 2 * padding), mSize.y() * 0.4f); mImage.setMaxSize(mSize.x * (0.50f - 2.0f * padding), mSize.y * 0.4f);
mImage.setDefaultZIndex(30); mImage.setDefaultZIndex(30.0f);
addChild(&mImage); addChild(&mImage);
// Metadata labels + values. // Metadata labels + values.
@ -101,27 +101,27 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root)
addChild(&mLblPlayCount); addChild(&mLblPlayCount);
addChild(&mPlayCount); addChild(&mPlayCount);
mName.setPosition(mSize.x(), mSize.y()); mName.setPosition(mSize.x, mSize.y);
mName.setDefaultZIndex(40); mName.setDefaultZIndex(40.0f);
mName.setColor(0xAAAAAAFF); mName.setColor(0xAAAAAAFF);
mName.setFont(Font::get(FONT_SIZE_MEDIUM)); mName.setFont(Font::get(FONT_SIZE_MEDIUM));
mName.setHorizontalAlignment(ALIGN_CENTER); mName.setHorizontalAlignment(ALIGN_CENTER);
addChild(&mName); addChild(&mName);
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f); mDescContainer.setPosition(mSize.x * padding, mSize.y * 0.65f);
mDescContainer.setSize(mSize.x() * (0.50f - 2.0f * padding), mDescContainer.setSize(mSize.x * (0.50f - 2.0f * padding),
mSize.y() - mDescContainer.getPosition().y()); mSize.y - mDescContainer.getPosition().y);
mDescContainer.setAutoScroll(true); mDescContainer.setAutoScroll(true);
mDescContainer.setDefaultZIndex(40); mDescContainer.setDefaultZIndex(40.0f);
addChild(&mDescContainer); addChild(&mDescContainer);
mDescription.setFont(Font::get(FONT_SIZE_SMALL)); mDescription.setFont(Font::get(FONT_SIZE_SMALL));
mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.setSize(mDescContainer.getSize().x, 0.0f);
mDescContainer.addChild(&mDescription); mDescContainer.addChild(&mDescription);
mGamelistInfo.setOrigin(0.5f, 0.5f); mGamelistInfo.setOrigin(0.5f, 0.5f);
mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL)); mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL));
mGamelistInfo.setDefaultZIndex(50); mGamelistInfo.setDefaultZIndex(50.0f);
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
addChild(&mGamelistInfo); addChild(&mGamelistInfo);
@ -145,10 +145,9 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
initMDLabels(); initMDLabels();
std::vector<TextComponent*> labels = getMDLabels(); std::vector<TextComponent*> labels = getMDLabels();
assert(labels.size() == 8); assert(labels.size() == 8);
std::vector<std::string> lblElements = { "md_lbl_rating", "md_lbl_releasedate", std::vector<std::string> lblElements = {
"md_lbl_developer", "md_lbl_publisher", "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher",
"md_lbl_genre", "md_lbl_players", "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount"};
"md_lbl_lastplayed", "md_lbl_playcount" };
for (unsigned int i = 0; i < labels.size(); i++) for (unsigned int i = 0; i < labels.size(); i++)
labels[i]->applyTheme(theme, getName(), lblElements[i], ALL); labels[i]->applyTheme(theme, getName(), lblElements[i], ALL);
@ -156,23 +155,23 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
initMDValues(); initMDValues();
std::vector<GuiComponent*> values = getMDValues(); std::vector<GuiComponent*> values = getMDValues();
assert(values.size() == 8); assert(values.size() == 8);
std::vector<std::string> valElements = { "md_rating", "md_releasedate", "md_developer", std::vector<std::string> valElements = {"md_rating", "md_releasedate", "md_developer",
"md_publisher", "md_genre", "md_players", "md_publisher", "md_genre", "md_players",
"md_lastplayed", "md_playcount" }; "md_lastplayed", "md_playcount"};
for (unsigned int i = 0; i < values.size(); i++) for (unsigned int i = 0; i < values.size(); i++)
values[i]->applyTheme(theme, getName(), valElements[i], ALL ^ ThemeFlags::TEXT); values[i]->applyTheme(theme, getName(), valElements[i], ALL ^ ThemeFlags::TEXT);
mDescContainer.applyTheme(theme, getName(), "md_description", mDescContainer.applyTheme(theme, getName(), "md_description",
POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE); POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE);
mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.setSize(mDescContainer.getSize().x, 0.0f);
mDescription.applyTheme( mDescription.applyTheme(
theme, getName(), "md_description", theme, getName(), "md_description",
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION)); ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT); mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
// If there is no position defined in the theme for gamelistInfo, then hide it. // If there is no position defined in the theme for gamelistInfo, then hide it.
if (mGamelistInfo.getPosition() == 0) if (mGamelistInfo.getPosition() == glm::vec3{})
mGamelistInfo.setVisible(false); mGamelistInfo.setVisible(false);
else else
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
@ -187,26 +186,26 @@ void DetailedGameListView::initMDLabels()
const unsigned int colCount = 2; const unsigned int colCount = 2;
const unsigned int rowCount = static_cast<int>(components.size() / 2); const unsigned int rowCount = static_cast<int>(components.size() / 2);
Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f); glm::vec3 start{mSize.x * 0.01f, mSize.y * 0.625f, 0.0f};
const float colSize = (mSize.x() * 0.48f) / colCount; const float colSize = (mSize.x * 0.48f) / colCount;
const float rowPadding = 0.01f * mSize.y(); const float rowPadding = 0.01f * mSize.y;
for (unsigned int i = 0; i < components.size(); i++) { for (unsigned int i = 0; i < components.size(); i++) {
const unsigned int row = i % rowCount; const unsigned int row = i % rowCount;
Vector3f pos(0.0f, 0.0f, 0.0f); glm::vec3 pos{};
if (row == 0) { if (row == 0) {
pos = start + Vector3f(colSize * (i / rowCount), 0, 0); pos = start + glm::vec3{colSize * (i / rowCount), 0.0f, 0.0f};
} }
else { else {
// Work from the last component. // Work from the last component.
GuiComponent* lc = components[i - 1]; GuiComponent* lc = components[i - 1];
pos = lc->getPosition() + Vector3f(0, lc->getSize().y() + rowPadding, 0); pos = lc->getPosition() + glm::vec3{0.0f, lc->getSize().y + rowPadding, 0.0f};
} }
components[i]->setFont(Font::get(FONT_SIZE_SMALL)); components[i]->setFont(Font::get(FONT_SIZE_SMALL));
components[i]->setPosition(pos); components[i]->setPosition(pos);
components[i]->setDefaultZIndex(40); components[i]->setDefaultZIndex(40.0f);
} }
} }
@ -227,23 +226,22 @@ void DetailedGameListView::initMDValues()
float bottom = 0.0f; float bottom = 0.0f;
const float colSize = (mSize.x() * 0.48f) / 2.0f; const float colSize = (mSize.x * 0.48f) / 2.0f;
for (unsigned int i = 0; i < labels.size(); i++) { for (unsigned int i = 0; i < labels.size(); i++) {
const float heightDiff = (labels[i]->getSize().y() - values[i]->getSize().y()) / 2.0f; const float heightDiff = (labels[i]->getSize().y - values[i]->getSize().y) / 2.0f;
values[i]->setPosition(labels[i]->getPosition() + values[i]->setPosition(labels[i]->getPosition() +
Vector3f(labels[i]->getSize().x(), heightDiff, 0)); glm::vec3{labels[i]->getSize().x, heightDiff, 0.0f});
values[i]->setSize(colSize - labels[i]->getSize().x(), values[i]->getSize().y()); values[i]->setSize(colSize - labels[i]->getSize().x, values[i]->getSize().y);
values[i]->setDefaultZIndex(40.0f); values[i]->setDefaultZIndex(40.0f);
float testBot = values[i]->getPosition().y() + values[i]->getSize().y(); float testBot = values[i]->getPosition().y + values[i]->getSize().y;
if (testBot > bottom) if (testBot > bottom)
bottom = testBot; bottom = testBot;
} }
mDescContainer.setPosition(mDescContainer.getPosition().x(), bottom + mSize.y() * 0.01f); mDescContainer.setPosition(mDescContainer.getPosition().x, bottom + mSize.y * 0.01f);
mDescContainer.setSize(mDescContainer.getSize().x(), mDescContainer.setSize(mDescContainer.getSize().x, mSize.y - mDescContainer.getPosition().y);
mSize.y() - mDescContainer.getPosition().y());
} }
void DetailedGameListView::updateInfoPanel() void DetailedGameListView::updateInfoPanel()

View file

@ -47,8 +47,8 @@ GridGameListView::GridGameListView(Window* window, FileData* root)
{ {
const float padding = 0.01f; const float padding = 0.01f;
mGrid.setPosition(mSize.x() * 0.1f, mSize.y() * 0.1f); mGrid.setPosition(mSize.x * 0.1f, mSize.y * 0.1f);
mGrid.setDefaultZIndex(20); mGrid.setDefaultZIndex(20.0f);
mGrid.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); }); mGrid.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); });
addChild(&mGrid); addChild(&mGrid);
@ -81,41 +81,41 @@ GridGameListView::GridGameListView(Window* window, FileData* root)
addChild(&mLblPlayCount); addChild(&mLblPlayCount);
addChild(&mPlayCount); addChild(&mPlayCount);
mName.setPosition(mSize.x(), mSize.y()); mName.setPosition(mSize.x, mSize.y);
mName.setDefaultZIndex(40); mName.setDefaultZIndex(40.0f);
mName.setColor(0xAAAAAAFF); mName.setColor(0xAAAAAAFF);
mName.setFont(Font::get(FONT_SIZE_MEDIUM)); mName.setFont(Font::get(FONT_SIZE_MEDIUM));
mName.setHorizontalAlignment(ALIGN_CENTER); mName.setHorizontalAlignment(ALIGN_CENTER);
addChild(&mName); addChild(&mName);
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f); mDescContainer.setPosition(mSize.x * padding, mSize.y * 0.65f);
mDescContainer.setSize(mSize.x() * (0.50f - 2.0f * padding), mDescContainer.setSize(mSize.x * (0.50f - 2.0f * padding),
mSize.y() - mDescContainer.getPosition().y()); mSize.y - mDescContainer.getPosition().y);
mDescContainer.setAutoScroll(true); mDescContainer.setAutoScroll(true);
mDescContainer.setDefaultZIndex(40); mDescContainer.setDefaultZIndex(40.0f);
addChild(&mDescContainer); addChild(&mDescContainer);
mDescription.setFont(Font::get(FONT_SIZE_SMALL)); mDescription.setFont(Font::get(FONT_SIZE_SMALL));
mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.setSize(mDescContainer.getSize().x, 0.0f);
mDescContainer.addChild(&mDescription); mDescContainer.addChild(&mDescription);
mMarquee.setOrigin(0.5f, 0.5f); mMarquee.setOrigin(0.5f, 0.5f);
mMarquee.setPosition(mSize.x() * 0.25f, mSize.y() * 0.10f); mMarquee.setPosition(mSize.x * 0.25f, mSize.y * 0.10f);
mMarquee.setMaxSize(mSize.x() * (0.5f - 2.0f * padding), mSize.y() * 0.18f); mMarquee.setMaxSize(mSize.x * (0.5f - 2.0f * padding), mSize.y * 0.18f);
mMarquee.setDefaultZIndex(35); mMarquee.setDefaultZIndex(35.0f);
mMarquee.setVisible(false); mMarquee.setVisible(false);
addChild(&mMarquee); addChild(&mMarquee);
mImage.setOrigin(0.5f, 0.5f); mImage.setOrigin(0.5f, 0.5f);
mImage.setPosition(2.0f, 2.0f); mImage.setPosition(2.0f, 2.0f);
mImage.setMaxSize(mSize.x() * (0.50f - 2 * padding), mSize.y() * 0.4f); mImage.setMaxSize(mSize.x * (0.50f - 2.0f * padding), mSize.y * 0.4f);
mImage.setDefaultZIndex(10); mImage.setDefaultZIndex(10.0f);
mImage.setVisible(false); mImage.setVisible(false);
addChild(&mImage); addChild(&mImage);
mGamelistInfo.setOrigin(0.5f, 0.5f); mGamelistInfo.setOrigin(0.5f, 0.5f);
mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL)); mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL));
mGamelistInfo.setDefaultZIndex(50); mGamelistInfo.setDefaultZIndex(50.0f);
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
addChild(&mGamelistInfo); addChild(&mGamelistInfo);
@ -244,10 +244,9 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDLabels(); initMDLabels();
std::vector<TextComponent*> labels = getMDLabels(); std::vector<TextComponent*> labels = getMDLabels();
assert(labels.size() == 8); assert(labels.size() == 8);
std::vector<std::string> lblElements = { "md_lbl_rating", "md_lbl_releasedate", std::vector<std::string> lblElements = {
"md_lbl_developer", "md_lbl_publisher", "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher",
"md_lbl_genre", "md_lbl_players", "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount"};
"md_lbl_lastplayed", "md_lbl_playcount" };
for (unsigned int i = 0; i < labels.size(); i++) for (unsigned int i = 0; i < labels.size(); i++)
labels[i]->applyTheme(theme, getName(), lblElements[i], ALL); labels[i]->applyTheme(theme, getName(), lblElements[i], ALL);
@ -255,16 +254,16 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDValues(); initMDValues();
std::vector<GuiComponent*> values = getMDValues(); std::vector<GuiComponent*> values = getMDValues();
assert(values.size() == 8); assert(values.size() == 8);
std::vector<std::string> valElements = { "md_rating", "md_releasedate", "md_developer", std::vector<std::string> valElements = {"md_rating", "md_releasedate", "md_developer",
"md_publisher", "md_genre", "md_players", "md_publisher", "md_genre", "md_players",
"md_lastplayed", "md_playcount" }; "md_lastplayed", "md_playcount"};
for (unsigned int i = 0; i < values.size(); i++) for (unsigned int i = 0; i < values.size(); i++)
values[i]->applyTheme(theme, getName(), valElements[i], ALL ^ ThemeFlags::TEXT); values[i]->applyTheme(theme, getName(), valElements[i], ALL ^ ThemeFlags::TEXT);
mDescContainer.applyTheme(theme, getName(), "md_description", mDescContainer.applyTheme(theme, getName(), "md_description",
POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE); POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE);
mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.setSize(mDescContainer.getSize().x, 0.0f);
mDescription.applyTheme( mDescription.applyTheme(
theme, getName(), "md_description", theme, getName(), "md_description",
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION)); ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
@ -277,7 +276,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT); mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
// If there is no position defined in the theme for gamelistInfo, then hide it. // If there is no position defined in the theme for gamelistInfo, then hide it.
if (mGamelistInfo.getPosition() == 0) if (mGamelistInfo.getPosition() == glm::vec3{})
mGamelistInfo.setVisible(false); mGamelistInfo.setVisible(false);
else else
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
@ -298,26 +297,26 @@ void GridGameListView::initMDLabels()
const unsigned int colCount = 2; const unsigned int colCount = 2;
const unsigned int rowCount = static_cast<int>(components.size() / 2); const unsigned int rowCount = static_cast<int>(components.size() / 2);
Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f); glm::vec3 start{mSize.x * 0.01f, mSize.y * 0.625f, 0.0f};
const float colSize = (mSize.x() * 0.48f) / colCount; const float colSize = (mSize.x * 0.48f) / colCount;
const float rowPadding = 0.01f * mSize.y(); const float rowPadding = 0.01f * mSize.y;
for (unsigned int i = 0; i < components.size(); i++) { for (unsigned int i = 0; i < components.size(); i++) {
const unsigned int row = i % rowCount; const unsigned int row = i % rowCount;
Vector3f pos(0.0f, 0.0f, 0.0f); glm::vec3 pos{};
if (row == 0) { if (row == 0) {
pos = start + Vector3f(colSize * (i / rowCount), 0, 0); pos = start + glm::vec3{colSize * (i / rowCount), 0.0f, 0.0f};
} }
else { else {
// Work from the last component. // Work from the last component.
GuiComponent* lc = components[i - 1]; GuiComponent* lc = components[i - 1];
pos = lc->getPosition() + Vector3f(0, lc->getSize().y() + rowPadding, 0); pos = lc->getPosition() + glm::vec3{0.0f, lc->getSize().y + rowPadding, 0.0f};
} }
components[i]->setFont(Font::get(FONT_SIZE_SMALL)); components[i]->setFont(Font::get(FONT_SIZE_SMALL));
components[i]->setPosition(pos); components[i]->setPosition(pos);
components[i]->setDefaultZIndex(40); components[i]->setDefaultZIndex(40.0f);
} }
} }
@ -338,22 +337,21 @@ void GridGameListView::initMDValues()
float bottom = 0.0f; float bottom = 0.0f;
const float colSize = (mSize.x() * 0.48f) / 2.0f; const float colSize = (mSize.x * 0.48f) / 2.0f;
for (unsigned int i = 0; i < labels.size(); i++) { for (unsigned int i = 0; i < labels.size(); i++) {
const float heightDiff = (labels[i]->getSize().y() - values[i]->getSize().y()) / 2.0f; const float heightDiff = (labels[i]->getSize().y - values[i]->getSize().y) / 2.0f;
values[i]->setPosition(labels[i]->getPosition() + values[i]->setPosition(labels[i]->getPosition() +
Vector3f(labels[i]->getSize().x(), heightDiff, 0)); glm::vec3{labels[i]->getSize().x, heightDiff, 0.0f});
values[i]->setSize(colSize - labels[i]->getSize().x(), values[i]->getSize().y()); values[i]->setSize(colSize - labels[i]->getSize().x, values[i]->getSize().y);
values[i]->setDefaultZIndex(40); values[i]->setDefaultZIndex(40.0f);
float testBot = values[i]->getPosition().y() + values[i]->getSize().y(); float testBot = values[i]->getPosition().y + values[i]->getSize().y;
if (testBot > bottom) if (testBot > bottom)
bottom = testBot; bottom = testBot;
} }
mDescContainer.setPosition(mDescContainer.getPosition().x(), bottom + mSize.y() * 0.01f); mDescContainer.setPosition(mDescContainer.getPosition().x, bottom + mSize.y * 0.01f);
mDescContainer.setSize(mDescContainer.getSize().x(), mDescContainer.setSize(mDescContainer.getSize().x, mSize.y - mDescContainer.getPosition().y);
mSize.y() - mDescContainer.getPosition().y());
} }
void GridGameListView::updateInfoPanel() void GridGameListView::updateInfoPanel()

View file

@ -60,17 +60,17 @@ HelpStyle IGameListView::getHelpStyle()
return style; return style;
} }
void IGameListView::render(const Transform4x4f& parentTrans) void IGameListView::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
float scaleX = trans.r0().x(); float scaleX = trans[0].x;
float scaleY = trans.r1().y(); float scaleY = trans[1].y;
Vector2i pos(static_cast<int>(std::round(trans.translation()[0])), glm::ivec2 pos{static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans.translation()[1]))); static_cast<int>(std::round(trans[3].y))};
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)), glm::ivec2 size{static_cast<int>(std::round(mSize.x * scaleX)),
static_cast<int>(std::round(mSize.y() * scaleY))); static_cast<int>(std::round(mSize.y * scaleY))};
Renderer::pushClipRect(pos, size); Renderer::pushClipRect(pos, size);
renderChildren(trans); renderChildren(trans);

View file

@ -54,7 +54,7 @@ public:
virtual HelpStyle getHelpStyle() override; virtual HelpStyle getHelpStyle() override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
protected: protected:
FileData* mRoot; FileData* mRoot;

View file

@ -28,18 +28,18 @@ ISimpleGameListView::ISimpleGameListView(Window* window, FileData* root)
, mRandomGame(nullptr) , mRandomGame(nullptr)
{ {
mHeaderText.setText("Logo Text"); mHeaderText.setText("Logo Text");
mHeaderText.setSize(mSize.x(), 0); mHeaderText.setSize(mSize.x, 0.0f);
mHeaderText.setPosition(0, 0); mHeaderText.setPosition(0.0f, 0.0f);
mHeaderText.setHorizontalAlignment(ALIGN_CENTER); mHeaderText.setHorizontalAlignment(ALIGN_CENTER);
mHeaderText.setDefaultZIndex(50); mHeaderText.setDefaultZIndex(50.0f);
mHeaderImage.setResize(0, mSize.y() * 0.185f); mHeaderImage.setResize(0.0f, mSize.y * 0.185f);
mHeaderImage.setOrigin(0.5f, 0.0f); mHeaderImage.setOrigin(0.5f, 0.0f);
mHeaderImage.setPosition(mSize.x() / 2, 0); mHeaderImage.setPosition(mSize.x / 2.0f, 0.0f);
mHeaderImage.setDefaultZIndex(50); mHeaderImage.setDefaultZIndex(50.0f);
mBackground.setResize(mSize.x(), mSize.y()); mBackground.setResize(mSize.x, mSize.y);
mBackground.setDefaultZIndex(0); mBackground.setDefaultZIndex(0.0f);
addChild(&mHeaderText); addChild(&mHeaderText);
addChild(&mBackground); addChild(&mBackground);

View file

@ -64,8 +64,8 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root)
mVideo = new VideoFFmpegComponent(window); mVideo = new VideoFFmpegComponent(window);
#endif #endif
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y()); mList.setPosition(mSize.x * (0.50f + padding), mList.getPosition().y);
mList.setSize(mSize.x() * (0.50f - padding), mList.getSize().y()); mList.setSize(mSize.x * (0.50f - padding), mList.getSize().y);
mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT); mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT);
mList.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); }); mList.setCursorChangedCallback([&](const CursorState& /*state*/) { updateInfoPanel(); });
@ -73,22 +73,22 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root)
mThumbnail.setOrigin(0.5f, 0.5f); mThumbnail.setOrigin(0.5f, 0.5f);
mThumbnail.setPosition(2.0f, 2.0f); mThumbnail.setPosition(2.0f, 2.0f);
mThumbnail.setVisible(false); mThumbnail.setVisible(false);
mThumbnail.setMaxSize(mSize.x() * (0.25f - 2.0f * padding), mSize.y() * 0.10f); mThumbnail.setMaxSize(mSize.x * (0.25f - 2.0f * padding), mSize.y * 0.10f);
mThumbnail.setDefaultZIndex(35); mThumbnail.setDefaultZIndex(35.0f);
addChild(&mThumbnail); addChild(&mThumbnail);
// Marquee. // Marquee.
mMarquee.setOrigin(0.5f, 0.5f); mMarquee.setOrigin(0.5f, 0.5f);
mMarquee.setPosition(mSize.x() * 0.25f, mSize.y() * 0.10f); mMarquee.setPosition(mSize.x * 0.25f, mSize.y * 0.10f);
mMarquee.setMaxSize(mSize.x() * (0.5f - 2.0f * padding), mSize.y() * 0.18f); mMarquee.setMaxSize(mSize.x * (0.5f - 2.0f * padding), mSize.y * 0.18f);
mMarquee.setDefaultZIndex(35); mMarquee.setDefaultZIndex(35.0f);
addChild(&mMarquee); addChild(&mMarquee);
// Video. // Video.
mVideo->setOrigin(0.5f, 0.5f); mVideo->setOrigin(0.5f, 0.5f);
mVideo->setPosition(mSize.x() * 0.25f, mSize.y() * 0.4f); mVideo->setPosition(mSize.x * 0.25f, mSize.y * 0.4f);
mVideo->setSize(mSize.x() * (0.5f - 2.0f * padding), mSize.y() * 0.4f); mVideo->setSize(mSize.x * (0.5f - 2.0f * padding), mSize.y * 0.4f);
mVideo->setDefaultZIndex(30); mVideo->setDefaultZIndex(30.0f);
addChild(mVideo); addChild(mVideo);
// Metadata labels + values. // Metadata labels + values.
@ -118,27 +118,27 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root)
addChild(&mLblPlayCount); addChild(&mLblPlayCount);
addChild(&mPlayCount); addChild(&mPlayCount);
mName.setPosition(mSize.x(), mSize.y()); mName.setPosition(mSize.x, mSize.y);
mName.setDefaultZIndex(40); mName.setDefaultZIndex(40.0f);
mName.setColor(0xAAAAAAFF); mName.setColor(0xAAAAAAFF);
mName.setFont(Font::get(FONT_SIZE_MEDIUM)); mName.setFont(Font::get(FONT_SIZE_MEDIUM));
mName.setHorizontalAlignment(ALIGN_CENTER); mName.setHorizontalAlignment(ALIGN_CENTER);
addChild(&mName); addChild(&mName);
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f); mDescContainer.setPosition(mSize.x * padding, mSize.y * 0.65f);
mDescContainer.setSize(mSize.x() * (0.50f - 2.0f * padding), mDescContainer.setSize(mSize.x * (0.50f - 2.0f * padding),
mSize.y() - mDescContainer.getPosition().y()); mSize.y - mDescContainer.getPosition().y);
mDescContainer.setAutoScroll(true); mDescContainer.setAutoScroll(true);
mDescContainer.setDefaultZIndex(40); mDescContainer.setDefaultZIndex(40.0f);
addChild(&mDescContainer); addChild(&mDescContainer);
mDescription.setFont(Font::get(FONT_SIZE_SMALL)); mDescription.setFont(Font::get(FONT_SIZE_SMALL));
mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.setSize(mDescContainer.getSize().x, 0.0f);
mDescContainer.addChild(&mDescription); mDescContainer.addChild(&mDescription);
mGamelistInfo.setOrigin(0.5f, 0.5f); mGamelistInfo.setOrigin(0.5f, 0.5f);
mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL)); mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL));
mGamelistInfo.setDefaultZIndex(50); mGamelistInfo.setDefaultZIndex(50.0f);
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
addChild(&mGamelistInfo); addChild(&mGamelistInfo);
@ -167,10 +167,9 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDLabels(); initMDLabels();
std::vector<TextComponent*> labels = getMDLabels(); std::vector<TextComponent*> labels = getMDLabels();
assert(labels.size() == 8); assert(labels.size() == 8);
std::vector<std::string> lblElements = { "md_lbl_rating", "md_lbl_releasedate", std::vector<std::string> lblElements = {
"md_lbl_developer", "md_lbl_publisher", "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher",
"md_lbl_genre", "md_lbl_players", "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount"};
"md_lbl_lastplayed", "md_lbl_playcount" };
for (unsigned int i = 0; i < labels.size(); i++) for (unsigned int i = 0; i < labels.size(); i++)
labels[i]->applyTheme(theme, getName(), lblElements[i], ALL); labels[i]->applyTheme(theme, getName(), lblElements[i], ALL);
@ -178,23 +177,23 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
initMDValues(); initMDValues();
std::vector<GuiComponent*> values = getMDValues(); std::vector<GuiComponent*> values = getMDValues();
assert(values.size() == 8); assert(values.size() == 8);
std::vector<std::string> valElements = { "md_rating", "md_releasedate", "md_developer", std::vector<std::string> valElements = {"md_rating", "md_releasedate", "md_developer",
"md_publisher", "md_genre", "md_players", "md_publisher", "md_genre", "md_players",
"md_lastplayed", "md_playcount" }; "md_lastplayed", "md_playcount"};
for (unsigned int i = 0; i < values.size(); i++) for (unsigned int i = 0; i < values.size(); i++)
values[i]->applyTheme(theme, getName(), valElements[i], ALL ^ ThemeFlags::TEXT); values[i]->applyTheme(theme, getName(), valElements[i], ALL ^ ThemeFlags::TEXT);
mDescContainer.applyTheme(theme, getName(), "md_description", mDescContainer.applyTheme(theme, getName(), "md_description",
POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE); POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE);
mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.setSize(mDescContainer.getSize().x, 0.0f);
mDescription.applyTheme( mDescription.applyTheme(
theme, getName(), "md_description", theme, getName(), "md_description",
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION)); ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT); mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
// If there is no position defined in the theme for gamelistInfo, then hide it. // If there is no position defined in the theme for gamelistInfo, then hide it.
if (mGamelistInfo.getPosition() == 0) if (mGamelistInfo.getPosition() == glm::vec3{})
mGamelistInfo.setVisible(false); mGamelistInfo.setVisible(false);
else else
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
@ -209,26 +208,26 @@ void VideoGameListView::initMDLabels()
const unsigned int colCount = 2; const unsigned int colCount = 2;
const unsigned int rowCount = static_cast<int>(components.size() / 2); const unsigned int rowCount = static_cast<int>(components.size() / 2);
Vector3f start(mSize.x() * 0.01f, mSize.y() * 0.625f, 0.0f); glm::vec3 start{mSize.x * 0.01f, mSize.y * 0.625f, 0.0f};
const float colSize = (mSize.x() * 0.48f) / colCount; const float colSize = (mSize.x * 0.48f) / colCount;
const float rowPadding = 0.01f * mSize.y(); const float rowPadding = 0.01f * mSize.y;
for (unsigned int i = 0; i < components.size(); i++) { for (unsigned int i = 0; i < components.size(); i++) {
const unsigned int row = i % rowCount; const unsigned int row = i % rowCount;
Vector3f pos(0.0f, 0.0f, 0.0f); glm::vec3 pos{};
if (row == 0) { if (row == 0) {
pos = start + Vector3f(colSize * (i / rowCount), 0, 0); pos = start + glm::vec3{colSize * (i / rowCount), 0.0f, 0.0f};
} }
else { else {
// Work from the last component. // Work from the last component.
GuiComponent* lc = components[i - 1]; GuiComponent* lc = components[i - 1];
pos = lc->getPosition() + Vector3f(0, lc->getSize().y() + rowPadding, 0); pos = lc->getPosition() + glm::vec3{0.0f, lc->getSize().y + rowPadding, 0.0f};
} }
components[i]->setFont(Font::get(FONT_SIZE_SMALL)); components[i]->setFont(Font::get(FONT_SIZE_SMALL));
components[i]->setPosition(pos); components[i]->setPosition(pos);
components[i]->setDefaultZIndex(40); components[i]->setDefaultZIndex(40.0f);
} }
} }
@ -249,23 +248,22 @@ void VideoGameListView::initMDValues()
float bottom = 0.0f; float bottom = 0.0f;
const float colSize = (mSize.x() * 0.48f) / 2.0f; const float colSize = (mSize.x * 0.48f) / 2.0f;
for (unsigned int i = 0; i < labels.size(); i++) { for (unsigned int i = 0; i < labels.size(); i++) {
const float heightDiff = (labels[i]->getSize().y() - values[i]->getSize().y()) / 2.0f; const float heightDiff = (labels[i]->getSize().y - values[i]->getSize().y) / 2.0f;
values[i]->setPosition(labels[i]->getPosition() + values[i]->setPosition(labels[i]->getPosition() +
Vector3f(labels[i]->getSize().x(), heightDiff, 0)); glm::vec3{labels[i]->getSize().x, heightDiff, 0.0f});
values[i]->setSize(colSize - labels[i]->getSize().x(), values[i]->getSize().y()); values[i]->setSize(colSize - labels[i]->getSize().x, values[i]->getSize().y);
values[i]->setDefaultZIndex(40); values[i]->setDefaultZIndex(40.0f);
float testBot = values[i]->getPosition().y() + values[i]->getSize().y(); float testBot = values[i]->getPosition().y + values[i]->getSize().y;
if (testBot > bottom) if (testBot > bottom)
bottom = testBot; bottom = testBot;
} }
mDescContainer.setPosition(mDescContainer.getPosition().x(), bottom + mSize.y() * 0.01f); mDescContainer.setPosition(mDescContainer.getPosition().x, bottom + mSize.y * 0.01f);
mDescContainer.setSize(mDescContainer.getSize().x(), mDescContainer.setSize(mDescContainer.getSize().x, mSize.y - mDescContainer.getPosition().y);
mSize.y() - mDescContainer.getPosition().y());
} }
void VideoGameListView::updateInfoPanel() void VideoGameListView::updateInfoPanel()

View file

@ -24,11 +24,11 @@ GuiComponent::GuiComponent(Window* window)
, mColorShiftEnd(0) , mColorShiftEnd(0)
, mOpacity(255) , mOpacity(255)
, mSaturation(1.0f) , mSaturation(1.0f)
, mPosition(Vector3f::Zero()) , mPosition({})
, mOrigin(Vector2f::Zero()) , mOrigin({})
, mRotationOrigin(0.5f, 0.5f) , mRotationOrigin(0.5f, 0.5f)
, mSize(Vector2f::Zero()) , mSize({})
, mTransform(Transform4x4f::Identity()) , mTransform(Renderer::getIdentity())
, mIsProcessing(false) , mIsProcessing(false)
, mVisible(true) , mVisible(true)
, mEnabled(true) , mEnabled(true)
@ -78,16 +78,16 @@ void GuiComponent::update(int deltaTime)
updateChildren(deltaTime); updateChildren(deltaTime);
} }
void GuiComponent::render(const Transform4x4f& parentTrans) void GuiComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible()) if (!isVisible())
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
renderChildren(trans); renderChildren(trans);
} }
void GuiComponent::renderChildren(const Transform4x4f& transform) const void GuiComponent::renderChildren(const glm::mat4& transform) const
{ {
for (unsigned int i = 0; i < getChildCount(); i++) for (unsigned int i = 0; i < getChildCount(); i++)
getChild(i)->render(transform); getChild(i)->render(transform);
@ -95,26 +95,26 @@ void GuiComponent::renderChildren(const Transform4x4f& transform) const
void GuiComponent::setPosition(float x, float y, float z) void GuiComponent::setPosition(float x, float y, float z)
{ {
mPosition = Vector3f(x, y, z); mPosition = glm::vec3{x, y, z};
onPositionChanged(); onPositionChanged();
} }
void GuiComponent::setOrigin(float x, float y) void GuiComponent::setOrigin(float x, float y)
{ {
mOrigin = Vector2f(x, y); mOrigin = glm::vec2{x, y};
onOriginChanged(); onOriginChanged();
} }
void GuiComponent::setSize(float w, float h) void GuiComponent::setSize(float w, float h)
{ {
mSize = Vector2f(w, h); mSize = glm::vec2{w, h};
onSizeChanged(); onSizeChanged();
} }
Vector2f GuiComponent::getCenter() const glm::vec2 GuiComponent::getCenter() const
{ {
return Vector2f(mPosition.x() - (getSize().x() * mOrigin.x()) + getSize().x() / 2.0f, return glm::vec2{mPosition.x - (getSize().x * mOrigin.x) + getSize().x / 2.0f,
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2.0f); mPosition.y - (getSize().y * mOrigin.y) + getSize().y / 2.0f};
} }
void GuiComponent::addChild(GuiComponent* cmp) void GuiComponent::addChild(GuiComponent* cmp)
@ -171,33 +171,34 @@ void GuiComponent::setOpacity(unsigned char opacity)
(*it)->setOpacity(opacity); (*it)->setOpacity(opacity);
} }
const Transform4x4f& GuiComponent::getTransform() const glm::mat4& GuiComponent::getTransform()
{ {
mTransform = Transform4x4f::Identity(); mTransform = Renderer::getIdentity();
mTransform.translate(mPosition); mTransform = glm::translate(mTransform, mPosition);
if (mScale != 1.0f) if (mScale != 1.0f)
mTransform.scale(mScale); mTransform = glm::scale(mTransform, glm::vec3{mScale});
if (mRotation != 0.0f) { if (mRotation != 0.0f) {
// Calculate offset as difference between origin and rotation origin. // Calculate offset as difference between origin and rotation origin.
Vector2f rotationSize = getRotationSize(); glm::vec2 rotationSize{getRotationSize()};
float xOff = (mOrigin.x() - mRotationOrigin.x()) * rotationSize.x(); float xOff{(mOrigin.x - mRotationOrigin.x) * rotationSize.x};
float yOff = (mOrigin.y() - mRotationOrigin.y()) * rotationSize.y(); float yOff{(mOrigin.y - mRotationOrigin.y) * rotationSize.y};
// Transform to offset point. // Transform to offset point.
if (xOff != 0.0f || yOff != 0.0f) if (xOff != 0.0f || yOff != 0.0f)
mTransform.translate(Vector3f(xOff * -1.0f, yOff * -1.0f, 0.0f)); mTransform = glm::translate(mTransform, glm::vec3{xOff * -1.0f, yOff * -1.0f, 0.0f});
// Apply rotation transform. // Apply rotation transform.
mTransform.rotateZ(mRotation); mTransform = glm::rotate(mTransform, mRotation, glm::vec3{0.0f, 0.0f, 1.0f});
// Transform back to original point. // Transform back to original point.
if (xOff != 0.0f || yOff != 0.0f) if (xOff != 0.0f || yOff != 0.0f)
mTransform.translate(Vector3f(xOff, yOff, 0.0f)); mTransform = glm::translate(mTransform, glm::vec3{xOff, yOff, 0.0f});
} }
mTransform.translate( mTransform = glm::translate(
Vector3f(mOrigin.x() * mSize.x() * -1.0f, mOrigin.y() * mSize.y() * -1.0f, 0.0f)); mTransform, glm::vec3{mOrigin.x * mSize.x * -1.0f, mOrigin.y * mSize.y * -1.0f, 0.0f});
return mTransform; return mTransform;
} }
@ -301,9 +302,9 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& element, const std::string& element,
unsigned int properties) unsigned int properties)
{ {
Vector2f scale = getParent() ? getParent()->getSize() : glm::vec2 scale{getParent() ? getParent()->getSize() :
Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2{static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight())}};
const ThemeData::ThemeElement* elem = theme->getElement(view, element, ""); const ThemeData::ThemeElement* elem = theme->getElement(view, element, "");
if (!elem) if (!elem)
@ -311,24 +312,24 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
using namespace ThemeFlags; using namespace ThemeFlags;
if (properties & POSITION && elem->has("pos")) { if (properties & POSITION && elem->has("pos")) {
Vector2f denormalized = elem->get<Vector2f>("pos") * scale; glm::vec2 denormalized{elem->get<glm::vec2>("pos") * scale};
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0)); setPosition(glm::vec3{denormalized.x, denormalized.y, 0.0f});
} }
if (properties & ThemeFlags::SIZE && elem->has("size")) if (properties & ThemeFlags::SIZE && elem->has("size"))
setSize(elem->get<Vector2f>("size") * scale); setSize(elem->get<glm::vec2>("size") * scale);
// Position + size also implies origin. // Position + size also implies origin.
if ((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && if ((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) &&
elem->has("origin")) { elem->has("origin")) {
setOrigin(elem->get<Vector2f>("origin")); setOrigin(elem->get<glm::vec2>("origin"));
} }
if (properties & ThemeFlags::ROTATION) { if (properties & ThemeFlags::ROTATION) {
if (elem->has("rotation")) if (elem->has("rotation"))
setRotationDegrees(elem->get<float>("rotation")); setRotationDegrees(elem->get<float>("rotation"));
if (elem->has("rotationOrigin")) if (elem->has("rotationOrigin"))
setRotationOrigin(elem->get<Vector2f>("rotationOrigin")); setRotationOrigin(elem->get<glm::vec2>("rotationOrigin"));
} }
if (properties & ThemeFlags::Z_INDEX && elem->has("zIndex")) if (properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))

View file

@ -14,7 +14,6 @@
#include "InputConfig.h" #include "InputConfig.h"
#include "animations/AnimationController.h" #include "animations/AnimationController.h"
#include "math/Misc.h" #include "math/Misc.h"
#include "math/Transform4x4f.h"
#include <functional> #include <functional>
#include <memory> #include <memory>
@ -45,8 +44,8 @@ public:
virtual void textInput(const std::string& text); virtual void textInput(const std::string& text);
// Called when input is received. // Called when input is received.
// Return true if the input is consumed, false if // Return true if the input is consumed, false if it should continue to be passed
// it should continue to be passed to other children. // to other children.
virtual bool input(InputConfig* config, Input input); virtual bool input(InputConfig* config, Input input);
// Called when time passes. // Called when time passes.
@ -56,49 +55,50 @@ public:
virtual void update(int deltaTime); virtual void update(int deltaTime);
// Called when it's time to render. // Called when it's time to render.
// By default, just calls renderChildren(parentTrans * getTransform()). // By default, just calls renderChildren(parentTrans * getTransform())
// You probably want to override this like so: // Normally the following steps are required:
// 1. Calculate the new transform that your control will draw at with // 1. Calculate the new transform that your component will draw at
// Transform4x4f t = parentTrans * getTransform(). // glm::mat4 trans {parentTrans * getTransform()};
// 2. Set the renderer to use that new transform as the model matrix // 2. Set the renderer to use that new transform as the model matrix
// Renderer::setMatrix(t); // Renderer::setMatrix(trans);
// 3. Draw your component. // 3. Draw your component
// 4. Tell your children to render, based on your component's transform - renderChildren(t). // 4. Tell your children to render, based on your component's transform
virtual void render(const Transform4x4f& parentTrans); // renderChildren(trans);
virtual void render(const glm::mat4& parentTrans);
Vector3f getPosition() const { return mPosition; } glm::vec3 getPosition() const { return mPosition; }
void setPosition(const Vector3f& offset) { setPosition(offset.x(), offset.y(), offset.z()); } void setPosition(const glm::vec3& offset) { setPosition(offset.x, offset.y, offset.z); }
void setPosition(float x, float y, float z = 0.0f); void setPosition(float x, float y, float z = 0.0f);
virtual void onPositionChanged() {} virtual void onPositionChanged() {}
Vector2f getOrigin() const { return mOrigin; } glm::vec2 getOrigin() const { return mOrigin; }
// Sets the origin as a percentage of this image. // Sets the origin as a percentage of this image.
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center.) // (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
void setOrigin(float originX, float originY); void setOrigin(float originX, float originY);
void setOrigin(Vector2f origin) { setOrigin(origin.x(), origin.y()); } void setOrigin(glm::vec2 origin) { setOrigin(origin.x, origin.y); }
virtual void onOriginChanged() {} virtual void onOriginChanged() {}
Vector2f getRotationOrigin() const { return mRotationOrigin; } glm::vec2 getRotationOrigin() const { return mRotationOrigin; }
// Sets the rotation origin as a percentage of this image. // Sets the rotation origin as a percentage of this image.
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center.) // (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
void setRotationOrigin(float originX, float originY) void setRotationOrigin(float originX, float originY)
{ {
mRotationOrigin = Vector2f(originX, originY); mRotationOrigin = glm::vec2{originX, originY};
} }
void setRotationOrigin(Vector2f origin) { setRotationOrigin(origin.x(), origin.y()); } void setRotationOrigin(glm::vec2 origin) { setRotationOrigin(origin.x, origin.y); }
virtual Vector2f getSize() const { return mSize; } virtual glm::vec2 getSize() const { return mSize; }
void setSize(const Vector2f& size) { setSize(size.x(), size.y()); } void setSize(const glm::vec2& size) { setSize(size.x, size.y); }
void setSize(float w, float h); void setSize(float w, float h);
virtual void setResize(float width, float height) {} virtual void setResize(float width, float height) {}
virtual void onSizeChanged() {} virtual void onSizeChanged() {}
virtual Vector2f getRotationSize() const { return getSize(); } virtual glm::vec2 getRotationSize() const { return getSize(); }
float getRotation() const { return mRotation; } float getRotation() const { return mRotation; }
void setRotation(float rotation) { mRotation = rotation; } void setRotation(float rotation) { mRotation = rotation; }
void setRotationDegrees(float rotation) void setRotationDegrees(float rotation)
{ {
setRotation(static_cast<float>(ES_DEG_TO_RAD(rotation))); setRotation(static_cast<float>(glm::radians(rotation)));
} }
float getScale() const { return mScale; } float getScale() const { return mScale; }
@ -114,7 +114,7 @@ public:
void setVisible(bool visible) { mVisible = visible; } void setVisible(bool visible) { mVisible = visible; }
// Returns the center point of the image (takes origin into account). // Returns the center point of the image (takes origin into account).
Vector2f getCenter() const; glm::vec2 getCenter() const;
void setParent(GuiComponent* parent) { mParent = parent; } void setParent(GuiComponent* parent) { mParent = parent; }
GuiComponent* getParent() const { return mParent; } GuiComponent* getParent() const { return mParent; }
@ -183,7 +183,7 @@ public:
virtual std::shared_ptr<Font> getFont() const { return nullptr; } virtual std::shared_ptr<Font> getFont() const { return nullptr; }
const Transform4x4f& getTransform(); const glm::mat4& getTransform();
virtual std::string getValue() const { return ""; } virtual std::string getValue() const { return ""; }
virtual void setValue(const std::string& value) {} virtual void setValue(const std::string& value) {}
@ -231,7 +231,7 @@ public:
const static unsigned char MAX_ANIMATIONS = 4; const static unsigned char MAX_ANIMATIONS = 4;
protected: protected:
void renderChildren(const Transform4x4f& transform) const; void renderChildren(const glm::mat4& transform) const;
void updateSelf(int deltaTime); // Updates animations. void updateSelf(int deltaTime); // Updates animations.
void updateChildren(int deltaTime); // Updates animations. void updateChildren(int deltaTime); // Updates animations.
@ -249,10 +249,10 @@ protected:
GuiComponent* mParent; GuiComponent* mParent;
std::vector<GuiComponent*> mChildren; std::vector<GuiComponent*> mChildren;
Vector3f mPosition; glm::vec3 mPosition;
Vector2f mOrigin; glm::vec2 mOrigin;
Vector2f mRotationOrigin; glm::vec2 mRotationOrigin;
Vector2f mSize; glm::vec2 mSize;
float mRotation = 0.0; float mRotation = 0.0;
float mScale = 1.0; float mScale = 1.0;
@ -265,8 +265,8 @@ protected:
bool mEnabled; bool mEnabled;
private: private:
// Don't access this directly! Use getTransform()! // Don't access this directly, instead use getTransform().
Transform4x4f mTransform; glm::mat4 mTransform;
AnimationController* mAnimationMap[MAX_ANIMATIONS]; AnimationController* mAnimationMap[MAX_ANIMATIONS];
}; };

View file

@ -13,8 +13,9 @@
HelpStyle::HelpStyle() HelpStyle::HelpStyle()
{ {
position = Vector2f(Renderer::getScreenWidth() * 0.012f, Renderer::getScreenHeight() * 0.9515f); position =
origin = Vector2f(0.0f, 0.0f); glm::vec2{Renderer::getScreenWidth() * 0.012f, Renderer::getScreenHeight() * 0.9515f};
origin = glm::vec2{};
iconColor = 0x777777FF; iconColor = 0x777777FF;
textColor = 0x777777FF; textColor = 0x777777FF;
@ -31,12 +32,12 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
return; return;
if (elem->has("pos")) if (elem->has("pos"))
position = position = elem->get<glm::vec2>("pos") *
elem->get<Vector2f>("pos") * Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2{static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight())};
if (elem->has("origin")) if (elem->has("origin"))
origin = elem->get<Vector2f>("origin"); origin = elem->get<glm::vec2>("origin");
if (elem->has("textColor")) if (elem->has("textColor"))
textColor = elem->get<unsigned int>("textColor"); textColor = elem->get<unsigned int>("textColor");

View file

@ -10,7 +10,7 @@
#ifndef ES_CORE_HELP_STYLE_H #ifndef ES_CORE_HELP_STYLE_H
#define ES_CORE_HELP_STYLE_H #define ES_CORE_HELP_STYLE_H
#include "math/Vector2f.h" #include "math/Misc.h"
#include <memory> #include <memory>
#include <string> #include <string>
@ -19,8 +19,8 @@ class Font;
class ThemeData; class ThemeData;
struct HelpStyle { struct HelpStyle {
Vector2f position; glm::vec2 position;
Vector2f origin; glm::vec2 origin;
unsigned int iconColor; unsigned int iconColor;
unsigned int textColor; unsigned int textColor;
std::shared_ptr<Font> font; std::shared_ptr<Font> font;

View file

@ -49,12 +49,11 @@ protected:
std::ostringstream os; std::ostringstream os;
private: private:
std::map<LogLevel, std::string> logLevelMap { // Log level indicators. std::map<LogLevel, std::string> logLevelMap{// Log level indicators.
{ LogError, "Error" }, {LogError, "Error"},
{ LogWarning, "Warn" }, {LogWarning, "Warn"},
{ LogInfo, "Info" }, {LogInfo, "Info"},
{ LogDebug, "Debug" } {LogDebug, "Debug"}};
};
static LogLevel reportingLevel; static LogLevel reportingLevel;
LogLevel messageLevel; LogLevel messageLevel;

View file

@ -68,8 +68,8 @@ MameNames::MameNames()
for (pugi::xml_node gameNode = doc.child("game"); gameNode; for (pugi::xml_node gameNode = doc.child("game"); gameNode;
gameNode = gameNode.next_sibling("game")) { gameNode = gameNode.next_sibling("game")) {
NamePair namePair = { gameNode.child("mamename").text().get(), NamePair namePair = {gameNode.child("mamename").text().get(),
gameNode.child("realname").text().get() }; gameNode.child("realname").text().get()};
mNamePairs.push_back(namePair); mNamePairs.push_back(namePair);
} }

View file

@ -139,7 +139,7 @@ int launchGameUnix(const std::string& cmd_utf8, bool runInBackground)
int launchGameWindows(const std::wstring& cmd_utf16, bool runInBackground, bool hideWindow) int launchGameWindows(const std::wstring& cmd_utf16, bool runInBackground, bool hideWindow)
{ {
#if defined(_WIN64) #if defined(_WIN64)
STARTUPINFOW si {}; STARTUPINFOW si{};
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
si.cb = sizeof(si); si.cb = sizeof(si);

View file

@ -97,161 +97,161 @@ void Settings::setDefaults()
// //
// Scraper. // Scraper.
mStringMap["Scraper"] = { "screenscraper", "screenscraper" }; mStringMap["Scraper"] = {"screenscraper", "screenscraper"};
mBoolMap["ScraperUseAccountScreenScraper"] = { false, false }; mBoolMap["ScraperUseAccountScreenScraper"] = {false, false};
mStringMap["ScraperUsernameScreenScraper"] = { "", "" }; mStringMap["ScraperUsernameScreenScraper"] = {"", ""};
mStringMap["ScraperPasswordScreenScraper"] = { "", "" }; mStringMap["ScraperPasswordScreenScraper"] = {"", ""};
mBoolMap["ScrapeGameNames"] = { true, true }; mBoolMap["ScrapeGameNames"] = {true, true};
mBoolMap["ScrapeRatings"] = { true, true }; mBoolMap["ScrapeRatings"] = {true, true};
mBoolMap["ScrapeMetadata"] = { true, true }; mBoolMap["ScrapeMetadata"] = {true, true};
mBoolMap["ScrapeVideos"] = { true, true }; mBoolMap["ScrapeVideos"] = {true, true};
mBoolMap["ScrapeScreenshots"] = { true, true }; mBoolMap["ScrapeScreenshots"] = {true, true};
mBoolMap["ScrapeCovers"] = { true, true }; mBoolMap["ScrapeCovers"] = {true, true};
mBoolMap["ScrapeMarquees"] = { true, true }; mBoolMap["ScrapeMarquees"] = {true, true};
mBoolMap["Scrape3DBoxes"] = { true, true }; mBoolMap["Scrape3DBoxes"] = {true, true};
mStringMap["MiximageResolution"] = { "1280x960", "1280x960" }; mStringMap["MiximageResolution"] = {"1280x960", "1280x960"};
mStringMap["MiximageScreenshotScaling"] = { "sharp", "sharp" }; mStringMap["MiximageScreenshotScaling"] = {"sharp", "sharp"};
mBoolMap["MiximageGenerate"] = { true, true }; mBoolMap["MiximageGenerate"] = {true, true};
mBoolMap["MiximageOverwrite"] = { true, true }; mBoolMap["MiximageOverwrite"] = {true, true};
mBoolMap["MiximageRemoveLetterboxes"] = { true, true }; mBoolMap["MiximageRemoveLetterboxes"] = {true, true};
mBoolMap["MiximageRemovePillarboxes"] = { true, true }; mBoolMap["MiximageRemovePillarboxes"] = {true, true};
mBoolMap["MiximageIncludeMarquee"] = { true, true }; mBoolMap["MiximageIncludeMarquee"] = {true, true};
mBoolMap["MiximageIncludeBox"] = { true, true }; mBoolMap["MiximageIncludeBox"] = {true, true};
mBoolMap["MiximageCoverFallback"] = { true, true }; mBoolMap["MiximageCoverFallback"] = {true, true};
mStringMap["ScraperRegion"] = { "eu", "eu" }; mStringMap["ScraperRegion"] = {"eu", "eu"};
mStringMap["ScraperLanguage"] = { "en", "en" }; mStringMap["ScraperLanguage"] = {"en", "en"};
mBoolMap["ScraperOverwriteData"] = { true, true }; mBoolMap["ScraperOverwriteData"] = {true, true};
mBoolMap["ScraperHaltOnInvalidMedia"] = { true, true }; mBoolMap["ScraperHaltOnInvalidMedia"] = {true, true};
mBoolMap["ScraperSearchMetadataName"] = { true, true }; mBoolMap["ScraperSearchMetadataName"] = {true, true};
mBoolMap["ScraperInteractive"] = { true, true }; mBoolMap["ScraperInteractive"] = {true, true};
mBoolMap["ScraperSemiautomatic"] = { true, true }; mBoolMap["ScraperSemiautomatic"] = {true, true};
mBoolMap["ScraperRespectExclusions"] = { true, true }; mBoolMap["ScraperRespectExclusions"] = {true, true};
mBoolMap["ScraperExcludeRecursively"] = { true, true }; mBoolMap["ScraperExcludeRecursively"] = {true, true};
mBoolMap["ScraperIncludeFolders"] = { false, false }; mBoolMap["ScraperIncludeFolders"] = {false, false};
mBoolMap["ScraperRetryPeerVerification"] = { false, false }; mBoolMap["ScraperRetryPeerVerification"] = {false, false};
// UI settings. // UI settings.
mStringMap["StartupSystem"] = { "", "" }; mStringMap["StartupSystem"] = {"", ""};
mStringMap["GamelistViewStyle"] = { "automatic", "automatic" }; mStringMap["GamelistViewStyle"] = {"automatic", "automatic"};
mStringMap["TransitionStyle"] = { "slide", "slide" }; mStringMap["TransitionStyle"] = {"slide", "slide"};
mStringMap["ThemeSet"] = { "rbsimple-DE", "rbsimple-DE" }; mStringMap["ThemeSet"] = {"rbsimple-DE", "rbsimple-DE"};
mStringMap["UIMode"] = { "full", "full" }; mStringMap["UIMode"] = {"full", "full"};
mStringMap["DefaultSortOrder"] = { "filename, ascending", "filename, ascending" }; mStringMap["DefaultSortOrder"] = {"filename, ascending", "filename, ascending"};
mStringMap["MenuOpeningEffect"] = { "scale-up", "scale-up" }; mStringMap["MenuOpeningEffect"] = {"scale-up", "scale-up"};
mStringMap["LaunchScreenDuration"] = { "normal", "normal" }; mStringMap["LaunchScreenDuration"] = {"normal", "normal"};
mBoolMap["MenuBlurBackground"] = { true, true }; mBoolMap["MenuBlurBackground"] = {true, true};
mBoolMap["GamelistVideoPillarbox"] = { true, true }; mBoolMap["GamelistVideoPillarbox"] = {true, true};
mBoolMap["GamelistVideoScanlines"] = { false, false }; mBoolMap["GamelistVideoScanlines"] = {false, false};
mBoolMap["FoldersOnTop"] = { true, true }; mBoolMap["FoldersOnTop"] = {true, true};
mBoolMap["FavoritesFirst"] = { true, true }; mBoolMap["FavoritesFirst"] = {true, true};
mBoolMap["FavoritesStar"] = { true, true }; mBoolMap["FavoritesStar"] = {true, true};
mBoolMap["SpecialCharsASCII"] = { false, false }; mBoolMap["SpecialCharsASCII"] = {false, false};
mBoolMap["ListScrollOverlay"] = { false, false }; mBoolMap["ListScrollOverlay"] = {false, false};
mBoolMap["FavoritesAddButton"] = { true, true }; mBoolMap["FavoritesAddButton"] = {true, true};
mBoolMap["RandomAddButton"] = { false, false }; mBoolMap["RandomAddButton"] = {false, false};
mBoolMap["GamelistFilters"] = { true, true }; mBoolMap["GamelistFilters"] = {true, true};
mBoolMap["QuickSystemSelect"] = { true, true }; mBoolMap["QuickSystemSelect"] = {true, true};
mBoolMap["ShowHelpPrompts"] = { true, true }; mBoolMap["ShowHelpPrompts"] = {true, true};
mBoolMap["PlayVideosImmediately"] = { false, false }; mBoolMap["PlayVideosImmediately"] = {false, false};
mBoolMap["EnableMenuKidMode"] = { false, false }; mBoolMap["EnableMenuKidMode"] = {false, false};
// UI settings -> media viewer settings. // UI settings -> media viewer settings.
mBoolMap["MediaViewerKeepVideoRunning"] = { true, true }; mBoolMap["MediaViewerKeepVideoRunning"] = {true, true};
mBoolMap["MediaViewerStretchVideos"] = { false, false }; mBoolMap["MediaViewerStretchVideos"] = {false, false};
mBoolMap["MediaViewerVideoScanlines"] = { true, true }; mBoolMap["MediaViewerVideoScanlines"] = {true, true};
mBoolMap["MediaViewerVideoBlur"] = { false, false }; mBoolMap["MediaViewerVideoBlur"] = {false, false};
mBoolMap["MediaViewerScreenshotScanlines"] = { true, true }; mBoolMap["MediaViewerScreenshotScanlines"] = {true, true};
// UI settings -> screensaver settings. // UI settings -> screensaver settings.
mIntMap["ScreensaverTimer"] = { 5 * 60 * 1000, 5 * 60 * 1000 }; // 5 minutes. mIntMap["ScreensaverTimer"] = {5 * 60 * 1000, 5 * 60 * 1000}; // 5 minutes.
mStringMap["ScreensaverType"] = { "video", "video" }; mStringMap["ScreensaverType"] = {"video", "video"};
mBoolMap["ScreensaverControls"] = { true, true }; mBoolMap["ScreensaverControls"] = {true, true};
// UI settings -> screensaver settings -> slideshow screensaver settings. // UI settings -> screensaver settings -> slideshow screensaver settings.
mIntMap["ScreensaverSwapImageTimeout"] = { 10000, 10000 }; mIntMap["ScreensaverSwapImageTimeout"] = {10000, 10000};
mBoolMap["ScreensaverStretchImages"] = { false, false }; mBoolMap["ScreensaverStretchImages"] = {false, false};
mBoolMap["ScreensaverSlideshowGameInfo"] = { true, true }; mBoolMap["ScreensaverSlideshowGameInfo"] = {true, true};
mBoolMap["ScreensaverSlideshowScanlines"] = { true, true }; mBoolMap["ScreensaverSlideshowScanlines"] = {true, true};
mBoolMap["ScreensaverSlideshowCustomImages"] = { false, false }; mBoolMap["ScreensaverSlideshowCustomImages"] = {false, false};
mBoolMap["ScreensaverSlideshowRecurse"] = { false, false }; mBoolMap["ScreensaverSlideshowRecurse"] = {false, false};
mStringMap["ScreensaverSlideshowImageDir"] = { "~/.emulationstation/slideshow/custom_images", mStringMap["ScreensaverSlideshowImageDir"] = {"~/.emulationstation/slideshow/custom_images",
"~/.emulationstation/slideshow/custom_images" }; "~/.emulationstation/slideshow/custom_images"};
// UI settings -> screensaver settings -> video screensaver settings. // UI settings -> screensaver settings -> video screensaver settings.
mIntMap["ScreensaverSwapVideoTimeout"] = { 0, 0 }; mIntMap["ScreensaverSwapVideoTimeout"] = {0, 0};
mBoolMap["ScreensaverStretchVideos"] = { false, false }; mBoolMap["ScreensaverStretchVideos"] = {false, false};
mBoolMap["ScreensaverVideoGameInfo"] = { true, true }; mBoolMap["ScreensaverVideoGameInfo"] = {true, true};
mBoolMap["ScreensaverVideoScanlines"] = { true, true }; mBoolMap["ScreensaverVideoScanlines"] = {true, true};
mBoolMap["ScreensaverVideoBlur"] = { false, false }; mBoolMap["ScreensaverVideoBlur"] = {false, false};
// Sound settings. // Sound settings.
mIntMap["SoundVolumeNavigation"] = { 80, 80 }; mIntMap["SoundVolumeNavigation"] = {80, 80};
mIntMap["SoundVolumeVideos"] = { 100, 100 }; mIntMap["SoundVolumeVideos"] = {100, 100};
mBoolMap["GamelistVideoAudio"] = { true, true }; mBoolMap["GamelistVideoAudio"] = {true, true};
mBoolMap["MediaViewerVideoAudio"] = { true, true }; mBoolMap["MediaViewerVideoAudio"] = {true, true};
mBoolMap["ScreensaverVideoAudio"] = { false, false }; mBoolMap["ScreensaverVideoAudio"] = {false, false};
mBoolMap["NavigationSounds"] = { true, true }; mBoolMap["NavigationSounds"] = {true, true};
// Input device settings. // Input device settings.
mStringMap["InputControllerType"] = { "xbox", "xbox" }; mStringMap["InputControllerType"] = {"xbox", "xbox"};
mBoolMap["InputOnlyFirstController"] = { false, false }; mBoolMap["InputOnlyFirstController"] = {false, false};
// Game collection settings. // Game collection settings.
mStringMap["CollectionSystemsAuto"] = { "", "" }; mStringMap["CollectionSystemsAuto"] = {"", ""};
mStringMap["CollectionSystemsCustom"] = { "", "" }; mStringMap["CollectionSystemsCustom"] = {"", ""};
mBoolMap["FavFirstCustom"] = { false, false }; mBoolMap["FavFirstCustom"] = {false, false};
mBoolMap["FavStarCustom"] = { false, false }; mBoolMap["FavStarCustom"] = {false, false};
mBoolMap["UseCustomCollectionsSystem"] = { true, true }; mBoolMap["UseCustomCollectionsSystem"] = {true, true};
mBoolMap["CollectionShowSystemInfo"] = { true, true }; mBoolMap["CollectionShowSystemInfo"] = {true, true};
// Other settings. // Other settings.
#if defined(_RPI_) #if defined(_RPI_)
mIntMap["MaxVRAM"] = { 80, 80 }; mIntMap["MaxVRAM"] = {80, 80};
#else #else
mIntMap["MaxVRAM"] = { 256, 256 }; mIntMap["MaxVRAM"] = {256, 256};
#endif #endif
mIntMap["DisplayIndex"] = { 1, 1 }; mIntMap["DisplayIndex"] = {1, 1};
#if defined(__unix__) #if defined(__unix__)
mStringMap["FullscreenMode"] = { "normal", "normal" }; mStringMap["FullscreenMode"] = {"normal", "normal"};
#endif #endif
#if defined(BUILD_VLC_PLAYER) #if defined(BUILD_VLC_PLAYER)
#if defined(_RPI_) #if defined(_RPI_)
// As the FFmpeg video player is not HW accelerated, use VLC as default on this weak device. // As the FFmpeg video player is not HW accelerated, use VLC as default on this weak device.
mStringMap["VideoPlayer"] = { "vlc", "vlc" }; mStringMap["VideoPlayer"] = {"vlc", "vlc"};
#else #else
mStringMap["VideoPlayer"] = { "ffmpeg", "ffmpeg" }; mStringMap["VideoPlayer"] = {"ffmpeg", "ffmpeg"};
#endif #endif
#endif #endif
mStringMap["ExitButtonCombo"] = { "F4", "F4" }; mStringMap["ExitButtonCombo"] = {"F4", "F4"};
mStringMap["SaveGamelistsMode"] = { "always", "always" }; mStringMap["SaveGamelistsMode"] = {"always", "always"};
#if defined(_WIN64) #if defined(_WIN64)
mBoolMap["HideTaskbar"] = { false, false }; mBoolMap["HideTaskbar"] = {false, false};
#endif #endif
mBoolMap["RunInBackground"] = { false, false }; mBoolMap["RunInBackground"] = {false, false};
#if defined(_WIN64) #if defined(_WIN64)
mBoolMap["LaunchWorkaround"] = { true, true }; mBoolMap["LaunchWorkaround"] = {true, true};
#endif #endif
mStringMap["MediaDirectory"] = { "", "" }; mStringMap["MediaDirectory"] = {"", ""};
#if !defined(_RPI_) #if !defined(_RPI_)
mBoolMap["VideoHardwareDecoding"] = { false, false }; mBoolMap["VideoHardwareDecoding"] = {false, false};
#endif #endif
mBoolMap["VideoUpscaleFrameRate"] = { false, false }; mBoolMap["VideoUpscaleFrameRate"] = {false, false};
mBoolMap["LaunchCommandOverride"] = { true, true }; mBoolMap["LaunchCommandOverride"] = {true, true};
mBoolMap["ShowHiddenFiles"] = { true, true }; mBoolMap["ShowHiddenFiles"] = {true, true};
mBoolMap["ShowHiddenGames"] = { true, true }; mBoolMap["ShowHiddenGames"] = {true, true};
mBoolMap["CustomEventScripts"] = { false, false }; mBoolMap["CustomEventScripts"] = {false, false};
mBoolMap["ParseGamelistOnly"] = { false, false }; mBoolMap["ParseGamelistOnly"] = {false, false};
#if defined(__unix__) #if defined(__unix__)
mBoolMap["DisableComposition"] = { true, true }; mBoolMap["DisableComposition"] = {true, true};
#endif #endif
mBoolMap["DisplayGPUStatistics"] = { false, false }; mBoolMap["DisplayGPUStatistics"] = {false, false};
// macOS requires root privileges to reboot and power off so it doesn't make much // macOS requires root privileges to reboot and power off so it doesn't make much
// sense to enable this setting and menu entry for that operating system. // sense to enable this setting and menu entry for that operating system.
#if !defined(__APPLE__) #if !defined(__APPLE__)
mBoolMap["ShowQuitMenu"] = { false, false }; mBoolMap["ShowQuitMenu"] = {false, false};
#endif #endif
// //
@ -259,45 +259,45 @@ void Settings::setDefaults()
// //
// Options listed using --help // Options listed using --help
mBoolMap["Debug"] = { false, false }; mBoolMap["Debug"] = {false, false};
mBoolMap["ForceFull"] = { false, false }; mBoolMap["ForceFull"] = {false, false};
mBoolMap["ForceKid"] = { false, false }; mBoolMap["ForceKid"] = {false, false};
mBoolMap["ForceKiosk"] = { false, false }; mBoolMap["ForceKiosk"] = {false, false};
mBoolMap["IgnoreGamelist"] = { false, false }; mBoolMap["IgnoreGamelist"] = {false, false};
mBoolMap["SplashScreen"] = { true, true }; mBoolMap["SplashScreen"] = {true, true};
mBoolMap["VSync"] = { true, true }; mBoolMap["VSync"] = {true, true};
#if !defined(_WIN64) #if !defined(_WIN64)
mBoolMap["Windowed"] = { false, false }; mBoolMap["Windowed"] = {false, false};
#endif #endif
mIntMap["WindowWidth"] = { 0, 0 }; mIntMap["WindowWidth"] = {0, 0};
mIntMap["WindowHeight"] = { 0, 0 }; mIntMap["WindowHeight"] = {0, 0};
mIntMap["ScreenWidth"] = { 0, 0 }; mIntMap["ScreenWidth"] = {0, 0};
// Undocumented options. // Undocumented options.
mIntMap["ScreenHeight"] = { 0, 0 }; mIntMap["ScreenHeight"] = {0, 0};
mIntMap["ScreenOffsetX"] = { 0, 0 }; mIntMap["ScreenOffsetX"] = {0, 0};
mIntMap["ScreenOffsetY"] = { 0, 0 }; mIntMap["ScreenOffsetY"] = {0, 0};
mIntMap["ScreenRotate"] = { 0, 0 }; mIntMap["ScreenRotate"] = {0, 0};
// //
// Settings that can be changed in es_settings.xml // Settings that can be changed in es_settings.xml
// but that are not configurable via the GUI. // but that are not configurable via the GUI.
// //
mBoolMap["DebugSkipInputLogging"] = { false, false }; mBoolMap["DebugSkipInputLogging"] = {false, false};
mStringMap["ROMDirectory"] = { "", "" }; mStringMap["ROMDirectory"] = {"", ""};
mStringMap["UIMode_passkey"] = { "uuddlrlrba", "uuddlrlrba" }; mStringMap["UIMode_passkey"] = {"uuddlrlrba", "uuddlrlrba"};
// //
// Hardcoded or program-internal settings. // Hardcoded or program-internal settings.
// //
mStringMap["ApplicationVersion"] = { "", "" }; mStringMap["ApplicationVersion"] = {"", ""};
mBoolMap["DebugGrid"] = { false, false }; mBoolMap["DebugGrid"] = {false, false};
mBoolMap["DebugText"] = { false, false }; mBoolMap["DebugText"] = {false, false};
mBoolMap["DebugImage"] = { false, false }; mBoolMap["DebugImage"] = {false, false};
mBoolMap["SplashScreenProgress"] = { true, true }; mBoolMap["SplashScreenProgress"] = {true, true};
mIntMap["ScraperFilter"] = { 0, 0 }; mIntMap["ScraperFilter"] = {0, 0};
} }
template <typename K, typename V> template <typename K, typename V>

View file

@ -21,178 +21,175 @@
#include <algorithm> #include <algorithm>
#include <pugixml.hpp> #include <pugixml.hpp>
std::vector<std::string> ThemeData::sSupportedViews { { "all" }, { "system" }, { "basic" }, std::vector<std::string> ThemeData::sSupportedViews{{"all"}, {"system"}, {"basic"},
{ "detailed" }, { "grid" }, { "video" } }; {"detailed"}, {"grid"}, {"video"}};
std::vector<std::string> ThemeData::sSupportedFeatures { std::vector<std::string> ThemeData::sSupportedFeatures{
{ "navigationsounds" }, { "video" }, { "carousel" }, { "z-index" }, { "visible" } {"navigationsounds"}, {"video"}, {"carousel"}, {"z-index"}, {"visible"}};
};
std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>> std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>> ThemeData::sElementMap{
ThemeData::sElementMap { {"image",
{ "image", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"maxSize", NORMALIZED_PAIR},
{ "maxSize", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"rotation", FLOAT},
{ "rotation", FLOAT }, {"rotationOrigin", NORMALIZED_PAIR},
{ "rotationOrigin", NORMALIZED_PAIR }, {"path", PATH},
{ "path", PATH }, {"default", PATH},
{ "default", PATH }, {"tile", BOOLEAN},
{ "tile", BOOLEAN }, {"color", COLOR},
{ "color", COLOR }, {"colorEnd", COLOR},
{ "colorEnd", COLOR }, {"gradientType", STRING},
{ "gradientType", STRING }, {"visible", BOOLEAN},
{ "visible", BOOLEAN }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"imagegrid",
{ "imagegrid", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"margin", NORMALIZED_PAIR},
{ "margin", NORMALIZED_PAIR }, {"padding", NORMALIZED_RECT},
{ "padding", NORMALIZED_RECT }, {"autoLayout", NORMALIZED_PAIR},
{ "autoLayout", NORMALIZED_PAIR }, {"autoLayoutSelectedZoom", FLOAT},
{ "autoLayoutSelectedZoom", FLOAT }, {"gameImage", PATH},
{ "gameImage", PATH }, {"folderImage", PATH},
{ "folderImage", PATH }, {"imageSource", STRING},
{ "imageSource", STRING }, {"scrollDirection", STRING},
{ "scrollDirection", STRING }, {"centerSelection", BOOLEAN},
{ "centerSelection", BOOLEAN }, {"scrollLoop", BOOLEAN},
{ "scrollLoop", BOOLEAN }, {"animate", BOOLEAN},
{ "animate", BOOLEAN }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"gridtile",
{ "gridtile", {{"size", NORMALIZED_PAIR},
{ { "size", NORMALIZED_PAIR }, {"padding", NORMALIZED_PAIR},
{ "padding", NORMALIZED_PAIR }, {"imageColor", COLOR},
{ "imageColor", COLOR }, {"backgroundImage", PATH},
{ "backgroundImage", PATH }, {"backgroundCornerSize", NORMALIZED_PAIR},
{ "backgroundCornerSize", NORMALIZED_PAIR }, {"backgroundColor", COLOR},
{ "backgroundColor", COLOR }, {"backgroundCenterColor", COLOR},
{ "backgroundCenterColor", COLOR }, {"backgroundEdgeColor", COLOR}}},
{ "backgroundEdgeColor", COLOR } } }, {"text",
{ "text", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"rotation", FLOAT},
{ "rotation", FLOAT }, {"rotationOrigin", NORMALIZED_PAIR},
{ "rotationOrigin", NORMALIZED_PAIR }, {"text", STRING},
{ "text", STRING }, {"backgroundColor", COLOR},
{ "backgroundColor", COLOR }, {"fontPath", PATH},
{ "fontPath", PATH }, {"fontSize", FLOAT},
{ "fontSize", FLOAT }, {"color", COLOR},
{ "color", COLOR }, {"alignment", STRING},
{ "alignment", STRING }, {"forceUppercase", BOOLEAN},
{ "forceUppercase", BOOLEAN }, {"lineSpacing", FLOAT},
{ "lineSpacing", FLOAT }, {"value", STRING},
{ "value", STRING }, {"visible", BOOLEAN},
{ "visible", BOOLEAN }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"textlist",
{ "textlist", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"selectorHeight", FLOAT},
{ "selectorHeight", FLOAT }, {"selectorOffsetY", FLOAT},
{ "selectorOffsetY", FLOAT }, {"selectorColor", COLOR},
{ "selectorColor", COLOR }, {"selectorColorEnd", COLOR},
{ "selectorColorEnd", COLOR }, {"selectorGradientType", STRING},
{ "selectorGradientType", STRING }, {"selectorImagePath", PATH},
{ "selectorImagePath", PATH }, {"selectorImageTile", BOOLEAN},
{ "selectorImageTile", BOOLEAN }, {"selectedColor", COLOR},
{ "selectedColor", COLOR }, {"primaryColor", COLOR},
{ "primaryColor", COLOR }, {"secondaryColor", COLOR},
{ "secondaryColor", COLOR }, {"fontPath", PATH},
{ "fontPath", PATH }, {"fontSize", FLOAT},
{ "fontSize", FLOAT }, {"scrollSound", PATH}, // For backward compatibility with old themes.
{ "scrollSound", PATH }, // For backward compatibility with old themes. {"alignment", STRING},
{ "alignment", STRING }, {"horizontalMargin", FLOAT},
{ "horizontalMargin", FLOAT }, {"forceUppercase", BOOLEAN},
{ "forceUppercase", BOOLEAN }, {"lineSpacing", FLOAT},
{ "lineSpacing", FLOAT }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"container",
{ "container", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"visible", BOOLEAN},
{ "visible", BOOLEAN }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"ninepatch",
{ "ninepatch", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"path", PATH},
{ "path", PATH }, {"visible", BOOLEAN},
{ "visible", BOOLEAN }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"datetime",
{ "datetime", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"rotation", FLOAT},
{ "rotation", FLOAT }, {"rotationOrigin", NORMALIZED_PAIR},
{ "rotationOrigin", NORMALIZED_PAIR }, {"backgroundColor", COLOR},
{ "backgroundColor", COLOR }, {"fontPath", PATH},
{ "fontPath", PATH }, {"fontSize", FLOAT},
{ "fontSize", FLOAT }, {"color", COLOR},
{ "color", COLOR }, {"alignment", STRING},
{ "alignment", STRING }, {"forceUppercase", BOOLEAN},
{ "forceUppercase", BOOLEAN }, {"lineSpacing", FLOAT},
{ "lineSpacing", FLOAT }, {"value", STRING},
{ "value", STRING }, {"format", STRING},
{ "format", STRING }, {"displayRelative", BOOLEAN},
{ "displayRelative", BOOLEAN }, {"visible", BOOLEAN},
{ "visible", BOOLEAN }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"rating",
{ "rating", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"rotation", FLOAT},
{ "rotation", FLOAT }, {"rotationOrigin", NORMALIZED_PAIR},
{ "rotationOrigin", NORMALIZED_PAIR }, {"color", COLOR},
{ "color", COLOR }, {"filledPath", PATH},
{ "filledPath", PATH }, {"unfilledPath", PATH},
{ "unfilledPath", PATH }, {"visible", BOOLEAN},
{ "visible", BOOLEAN }, {"zIndex", FLOAT}}},
{ "zIndex", FLOAT } } }, {"sound", {{"path", PATH}}},
{ "sound", { { "path", PATH } } }, {"helpsystem",
{ "helpsystem", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"textColor", COLOR},
{ "textColor", COLOR }, {"iconColor", COLOR},
{ "iconColor", COLOR }, {"fontPath", PATH},
{ "fontPath", PATH }, {"fontSize", FLOAT}}},
{ "fontSize", FLOAT } } }, {"navigationsounds",
{ "navigationsounds", {{"systembrowseSound", PATH},
{ { "systembrowseSound", PATH }, {"quicksysselectSound", PATH},
{ "quicksysselectSound", PATH }, {"selectSound", PATH},
{ "selectSound", PATH }, {"backSound", PATH},
{ "backSound", PATH }, {"scrollSound", PATH},
{ "scrollSound", PATH }, {"favoriteSound", PATH},
{ "favoriteSound", PATH }, {"launchSound", PATH}}},
{ "launchSound", PATH } } }, {"video",
{ "video", {{"pos", NORMALIZED_PAIR},
{ { "pos", NORMALIZED_PAIR }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"maxSize", NORMALIZED_PAIR},
{ "maxSize", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"rotation", FLOAT},
{ "rotation", FLOAT }, {"rotationOrigin", NORMALIZED_PAIR},
{ "rotationOrigin", NORMALIZED_PAIR }, {"default", PATH},
{ "default", PATH }, {"delay", FLOAT},
{ "delay", FLOAT }, {"visible", BOOLEAN},
{ "visible", BOOLEAN }, {"zIndex", FLOAT},
{ "zIndex", FLOAT }, {"showSnapshotNoVideo", BOOLEAN},
{ "showSnapshotNoVideo", BOOLEAN }, {"showSnapshotDelay", BOOLEAN}}},
{ "showSnapshotDelay", BOOLEAN } } }, {"carousel",
{ "carousel", {{"type", STRING},
{ { "type", STRING }, {"size", NORMALIZED_PAIR},
{ "size", NORMALIZED_PAIR }, {"pos", NORMALIZED_PAIR},
{ "pos", NORMALIZED_PAIR }, {"origin", NORMALIZED_PAIR},
{ "origin", NORMALIZED_PAIR }, {"color", COLOR},
{ "color", COLOR }, {"colorEnd", COLOR},
{ "colorEnd", COLOR }, {"gradientType", STRING},
{ "gradientType", STRING }, {"logoScale", FLOAT},
{ "logoScale", FLOAT }, {"logoRotation", FLOAT},
{ "logoRotation", FLOAT }, {"logoRotationOrigin", NORMALIZED_PAIR},
{ "logoRotationOrigin", NORMALIZED_PAIR }, {"logoSize", NORMALIZED_PAIR},
{ "logoSize", NORMALIZED_PAIR }, {"logoAlignment", STRING},
{ "logoAlignment", STRING }, {"maxLogoCount", FLOAT},
{ "maxLogoCount", FLOAT }, {"zIndex", FLOAT}}}};
{ "zIndex", FLOAT } } }
};
#define MINIMUM_THEME_FORMAT_VERSION 3 #define MINIMUM_THEME_FORMAT_VERSION 3
#define CURRENT_THEME_FORMAT_VERSION 6 #define CURRENT_THEME_FORMAT_VERSION 6
@ -450,20 +447,20 @@ void ThemeData::parseElement(const pugi::xml_node& root,
switch (typeIt->second) { switch (typeIt->second) {
case NORMALIZED_RECT: { case NORMALIZED_RECT: {
Vector4f val; glm::vec4 val;
auto splits = Utils::String::delimitedStringToVector(str, " "); auto splits = Utils::String::delimitedStringToVector(str, " ");
if (splits.size() == 2) { if (splits.size() == 2) {
val = Vector4f(static_cast<float>(atof(splits.at(0).c_str())), val = glm::vec4{static_cast<float>(atof(splits.at(0).c_str())),
static_cast<float>(atof(splits.at(1).c_str())), static_cast<float>(atof(splits.at(1).c_str())),
static_cast<float>(atof(splits.at(0).c_str())), static_cast<float>(atof(splits.at(0).c_str())),
static_cast<float>(atof(splits.at(1).c_str()))); static_cast<float>(atof(splits.at(1).c_str()))};
} }
else if (splits.size() == 4) { else if (splits.size() == 4) {
val = Vector4f(static_cast<float>(atof(splits.at(0).c_str())), val = glm::vec4{static_cast<float>(atof(splits.at(0).c_str())),
static_cast<float>(atof(splits.at(1).c_str())), static_cast<float>(atof(splits.at(1).c_str())),
static_cast<float>(atof(splits.at(2).c_str())), static_cast<float>(atof(splits.at(2).c_str())),
static_cast<float>(atof(splits.at(3).c_str()))); static_cast<float>(atof(splits.at(3).c_str()))};
} }
element.properties[node.name()] = val; element.properties[node.name()] = val;
@ -475,11 +472,11 @@ void ThemeData::parseElement(const pugi::xml_node& root,
throw error << "invalid normalized pair (property \"" << node.name() throw error << "invalid normalized pair (property \"" << node.name()
<< "\", value \"" << str.c_str() << "\")"; << "\", value \"" << str.c_str() << "\")";
std::string first = str.substr(0, divider); std::string first{str.substr(0, divider)};
std::string second = str.substr(divider, std::string::npos); std::string second{str.substr(divider, std::string::npos)};
Vector2f val(static_cast<float>(atof(first.c_str())), glm::vec2 val{static_cast<float>(atof(first.c_str())),
static_cast<float>(atof(second.c_str()))); static_cast<float>(atof(second.c_str()))};
element.properties[node.name()] = val; element.properties[node.name()] = val;
break; break;
@ -602,7 +599,7 @@ std::vector<GuiComponent*> ThemeData::makeExtras(const std::shared_ptr<ThemeData
comp = new TextComponent(window); comp = new TextComponent(window);
if (comp) { if (comp) {
comp->setDefaultZIndex(10); comp->setDefaultZIndex(10.0f);
comp->applyTheme(theme, view, *it, ThemeFlags::ALL); comp->applyTheme(theme, view, *it, ThemeFlags::ALL);
comps.push_back(comp); comps.push_back(comp);
} }
@ -643,7 +640,7 @@ std::map<std::string, ThemeSet> ThemeData::getThemeSets()
for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin();
it != dirContent.cend(); it++) { it != dirContent.cend(); it++) {
if (Utils::FileSystem::isDirectory(*it)) { if (Utils::FileSystem::isDirectory(*it)) {
ThemeSet set = { *it }; ThemeSet set = {*it};
sets[set.getName()] = set; sets[set.getName()] = set;
} }
} }

View file

@ -11,8 +11,7 @@
#ifndef ES_CORE_THEME_DATA_H #ifndef ES_CORE_THEME_DATA_H
#define ES_CORE_THEME_DATA_H #define ES_CORE_THEME_DATA_H
#include "math/Vector2f.h" #include "math/Misc.h"
#include "math/Vector4f.h"
#include "utils/FileSystemUtil.h" #include "utils/FileSystemUtil.h"
#include <deque> #include <deque>
@ -103,20 +102,20 @@ public:
std::string type; std::string type;
struct Property { struct Property {
void operator=(const Vector4f& value) void operator=(const glm::vec4& value)
{ {
r = value; r = value;
const Vector4f initVector = value; const glm::vec4 initVector{value};
v = Vector2f(initVector.x(), initVector.y()); v = glm::vec2{initVector.x, initVector.y};
} }
void operator=(const Vector2f& value) { v = value; } void operator=(const glm::vec2& value) { v = value; }
void operator=(const std::string& value) { s = value; } void operator=(const std::string& value) { s = value; }
void operator=(const unsigned int& value) { i = value; } void operator=(const unsigned int& value) { i = value; }
void operator=(const float& value) { f = value; } void operator=(const float& value) { f = value; }
void operator=(const bool& value) { b = value; } void operator=(const bool& value) { b = value; }
Vector4f r; glm::vec4 r;
Vector2f v; glm::vec2 v;
std::string s; std::string s;
unsigned int i; unsigned int i;
float f; float f;
@ -127,7 +126,7 @@ public:
template <typename T> const T get(const std::string& prop) const template <typename T> const T get(const std::string& prop) const
{ {
if (std::is_same<T, Vector2f>::value) if (std::is_same<T, glm::vec2>::value)
return *(const T*)&properties.at(prop).v; return *(const T*)&properties.at(prop).v;
else if (std::is_same<T, std::string>::value) else if (std::is_same<T, std::string>::value)
return *(const T*)&properties.at(prop).s; return *(const T*)&properties.at(prop).s;
@ -137,7 +136,7 @@ public:
return *(const T*)&properties.at(prop).f; return *(const T*)&properties.at(prop).f;
else if (std::is_same<T, bool>::value) else if (std::is_same<T, bool>::value)
return *(const T*)&properties.at(prop).b; return *(const T*)&properties.at(prop).b;
else if (std::is_same<T, Vector4f>::value) else if (std::is_same<T, glm::vec4>::value)
return *(const T*)&properties.at(prop).r; return *(const T*)&properties.at(prop).r;
return T(); return T();
} }

View file

@ -18,6 +18,7 @@
#include "InputManager.h" #include "InputManager.h"
#include "Log.h" #include "Log.h"
#include "Sound.h" #include "Sound.h"
#include "math/Misc.h"
#include "resources/Font.h" #include "resources/Font.h"
#include <algorithm> #include <algorithm>
@ -348,7 +349,7 @@ void Window::update(int deltaTime)
void Window::render() void Window::render()
{ {
Transform4x4f transform = Transform4x4f::Identity(); glm::mat4 trans{Renderer::getIdentity()};
mRenderedHelpPrompts = false; mRenderedHelpPrompts = false;
@ -378,7 +379,7 @@ void Window::render()
renderBottom = false; renderBottom = false;
if (renderBottom) if (renderBottom)
bottom->render(transform); bottom->render(trans);
if (bottom != top || mRenderLaunchScreen) { if (bottom != top || mRenderLaunchScreen) {
#if defined(USE_OPENGL_21) #if defined(USE_OPENGL_21)
@ -468,21 +469,21 @@ void Window::render()
} }
#endif // USE_OPENGL_21 #endif // USE_OPENGL_21
mBackgroundOverlay->render(transform); mBackgroundOverlay->render(trans);
// Scale-up menu opening effect. // Scale-up menu opening effect.
if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up") { if (Settings::getInstance()->getString("MenuOpeningEffect") == "scale-up") {
if (mTopScale < 1.0f) { if (mTopScale < 1.0f) {
mTopScale = Math::clamp(mTopScale + 0.07f, 0.0f, 1.0f); mTopScale = Math::clamp(mTopScale + 0.07f, 0.0f, 1.0f);
Vector2f topCenter = top->getCenter(); glm::vec2 topCenter{top->getCenter()};
top->setOrigin({ 0.5f, 0.5f }); top->setOrigin({0.5f, 0.5f});
top->setPosition({ topCenter.x(), topCenter.y(), 0.0f }); top->setPosition({topCenter.x, topCenter.y, 0.0f});
top->setScale(mTopScale); top->setScale(mTopScale);
} }
} }
if (!mRenderLaunchScreen) if (!mRenderLaunchScreen)
top->render(transform); top->render(trans);
} }
else { else {
mCachedBackground = false; mCachedBackground = false;
@ -493,23 +494,23 @@ void Window::render()
// Render the quick list scrolling overlay, which is triggered in IList. // Render the quick list scrolling overlay, which is triggered in IList.
if (mListScrollOpacity != 0) { if (mListScrollOpacity != 0) {
Renderer::setMatrix(Transform4x4f::Identity()); Renderer::setMatrix(Renderer::getIdentity());
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()), Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), static_cast<float>(Renderer::getScreenHeight()),
0x00000000 | mListScrollOpacity, 0x00000000 | mListScrollOpacity); 0x00000000 | mListScrollOpacity, 0x00000000 | mListScrollOpacity);
Vector2f offset = mListScrollFont->sizeText(mListScrollText); glm::vec2 offset{mListScrollFont->sizeText(mListScrollText)};
offset[0] = (Renderer::getScreenWidth() - offset.x()) * 0.5f; offset.x = (Renderer::getScreenWidth() - offset.x) * 0.5f;
offset[1] = (Renderer::getScreenHeight() - offset.y()) * 0.5f; offset.y = (Renderer::getScreenHeight() - offset.y) * 0.5f;
TextCache* cache = mListScrollFont->buildTextCache(mListScrollText, offset.x(), offset.y(), TextCache* cache = mListScrollFont->buildTextCache(mListScrollText, offset.x, offset.y,
0xFFFFFF00 | mListScrollOpacity); 0xFFFFFF00 | mListScrollOpacity);
mListScrollFont->renderTextCache(cache); mListScrollFont->renderTextCache(cache);
delete cache; delete cache;
} }
if (!mRenderedHelpPrompts) if (!mRenderedHelpPrompts)
mHelp->render(transform); mHelp->render(trans);
unsigned int screensaverTimer = unsigned int screensaverTimer =
static_cast<unsigned int>(Settings::getInstance()->getInt("ScreensaverTimer")); static_cast<unsigned int>(Settings::getInstance()->getInt("ScreensaverTimer"));
@ -531,7 +532,7 @@ void Window::render()
renderScreensaver(); renderScreensaver();
if (!mRenderScreensaver && mInfoPopup) if (!mRenderScreensaver && mInfoPopup)
mInfoPopup->render(transform); mInfoPopup->render(trans);
if (mTimeSinceLastInput >= screensaverTimer && screensaverTimer != 0) { if (mTimeSinceLastInput >= screensaverTimer && screensaverTimer != 0) {
if (!isProcessing() && mAllowSleep && (!mScreensaver)) { if (!isProcessing() && mAllowSleep && (!mScreensaver)) {
@ -550,14 +551,14 @@ void Window::render()
mLaunchScreen->render(); mLaunchScreen->render();
if (Settings::getInstance()->getBool("DisplayGPUStatistics") && mFrameDataText) { if (Settings::getInstance()->getBool("DisplayGPUStatistics") && mFrameDataText) {
Renderer::setMatrix(Transform4x4f::Identity()); Renderer::setMatrix(Renderer::getIdentity());
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get()); mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
} }
} }
void Window::renderLoadingScreen(std::string text) void Window::renderLoadingScreen(std::string text)
{ {
Transform4x4f trans = Transform4x4f::Identity(); glm::mat4 trans{Renderer::getIdentity()};
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()), Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF); static_cast<float>(Renderer::getScreenHeight()), 0x000000FF, 0x000000FF);
@ -565,16 +566,16 @@ void Window::renderLoadingScreen(std::string text)
ImageComponent splash(this, true); ImageComponent splash(this, true);
splash.setResize(Renderer::getScreenWidth() * 0.6f, 0.0f); splash.setResize(Renderer::getScreenWidth() * 0.6f, 0.0f);
splash.setImage(":/graphics/splash.svg"); splash.setImage(":/graphics/splash.svg");
splash.setPosition((Renderer::getScreenWidth() - splash.getSize().x()) / 2.0f, splash.setPosition((Renderer::getScreenWidth() - splash.getSize().x) / 2.0f,
(Renderer::getScreenHeight() - splash.getSize().y()) / 2.0f * 0.6f); (Renderer::getScreenHeight() - splash.getSize().y) / 2.0f * 0.6f);
splash.render(trans); splash.render(trans);
auto& font = mDefaultFonts.at(1); auto& font = mDefaultFonts.at(1);
TextCache* cache = font->buildTextCache(text, 0.0f, 0.0f, 0x656565FF); TextCache* cache = font->buildTextCache(text, 0.0f, 0.0f, 0x656565FF);
float x = std::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f); float x = std::round((Renderer::getScreenWidth() - cache->metrics.size.x) / 2.0f);
float y = std::round(Renderer::getScreenHeight() * 0.835f); float y = std::round(Renderer::getScreenHeight() * 0.835f);
trans = trans.translate(Vector3f(x, y, 0.0f)); trans = glm::translate(trans, glm::vec3{x, y, 0.0f});
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
font->renderTextCache(cache); font->renderTextCache(cache);
delete cache; delete cache;
@ -590,7 +591,7 @@ void Window::renderListScrollOverlay(unsigned char opacity, const std::string& t
void Window::renderHelpPromptsEarly() void Window::renderHelpPromptsEarly()
{ {
mHelp->render(Transform4x4f::Identity()); mHelp->render(Renderer::getIdentity());
mRenderedHelpPrompts = true; mRenderedHelpPrompts = true;
} }
@ -633,17 +634,17 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt
// Sort prompts so it goes [dpad_all] [dpad_u/d] [dpad_l/r] [a/b/x/y/l/r] [start/back]. // Sort prompts so it goes [dpad_all] [dpad_u/d] [dpad_l/r] [a/b/x/y/l/r] [start/back].
std::sort(addPrompts.begin(), addPrompts.end(), std::sort(addPrompts.begin(), addPrompts.end(),
[](const HelpPrompt& a, const HelpPrompt& b) -> bool { [](const HelpPrompt& a, const HelpPrompt& b) -> bool {
static const std::vector<std::string> map = { "up/down/left/right", static const std::vector<std::string> map = {"up/down/left/right",
"up/down", "up/down",
"left/right", "left/right",
"a", "a",
"b", "b",
"x", "x",
"y", "y",
"l", "l",
"r", "r",
"start", "start",
"back" }; "back"};
int i = 0; int i = 0;
int aVal = 0; int aVal = 0;
int bVal = 0; int bVal = 0;

View file

@ -26,7 +26,6 @@ class HelpComponent;
class ImageComponent; class ImageComponent;
class InputConfig; class InputConfig;
class TextCache; class TextCache;
class Transform4x4f;
struct HelpStyle; struct HelpStyle;
class Window class Window
@ -77,7 +76,7 @@ public:
class InfoPopup class InfoPopup
{ {
public: public:
virtual void render(const Transform4x4f& parentTrans) = 0; virtual void render(const glm::mat4& parentTrans) = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual ~InfoPopup() {} virtual ~InfoPopup() {}
}; };

View file

@ -33,7 +33,7 @@ void AnimatedImageComponent::load(const AnimationDef* def)
} }
auto img = std::unique_ptr<ImageComponent>(new ImageComponent(mWindow)); auto img = std::unique_ptr<ImageComponent>(new ImageComponent(mWindow));
img->setResize(mSize.x(), mSize.y()); img->setResize(mSize.x, mSize.y);
img->setImage(std::string(def->frames[i].path), false); img->setImage(std::string(def->frames[i].path), false);
mFrames.push_back(ImageFrame(std::move(img), def->frames[i].time)); mFrames.push_back(ImageFrame(std::move(img), def->frames[i].time));
@ -55,7 +55,7 @@ void AnimatedImageComponent::reset()
void AnimatedImageComponent::onSizeChanged() void AnimatedImageComponent::onSizeChanged()
{ {
for (auto it = mFrames.cbegin(); it != mFrames.cend(); it++) { for (auto it = mFrames.cbegin(); it != mFrames.cend(); it++) {
it->first->setResize(mSize.x(), mSize.y()); it->first->setResize(mSize.x, mSize.y);
} }
} }
@ -86,7 +86,7 @@ void AnimatedImageComponent::update(int deltaTime)
} }
} }
void AnimatedImageComponent::render(const Transform4x4f& trans) void AnimatedImageComponent::render(const glm::mat4& trans)
{ {
if (mFrames.size()) if (mFrames.size())
mFrames.at(mCurrentFrame).first->render(getTransform() * trans); mFrames.at(mCurrentFrame).first->render(getTransform() * trans);

View file

@ -34,7 +34,7 @@ public:
void reset(); // Set to frame 0. void reset(); // Set to frame 0.
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& trans) override; void render(const glm::mat4& trans) override;
void onSizeChanged() override; void onSizeChanged() override;

View file

@ -14,18 +14,18 @@
// Animation definition. // Animation definition.
AnimationFrame BUSY_ANIMATION_FRAMES[] = { AnimationFrame BUSY_ANIMATION_FRAMES[] = {
{ ":/graphics/busy_0.svg", 300 }, {":/graphics/busy_0.svg", 300},
{ ":/graphics/busy_1.svg", 300 }, {":/graphics/busy_1.svg", 300},
{ ":/graphics/busy_2.svg", 300 }, {":/graphics/busy_2.svg", 300},
{ ":/graphics/busy_3.svg", 300 }, {":/graphics/busy_3.svg", 300},
}; };
const AnimationDef BUSY_ANIMATION_DEF = { BUSY_ANIMATION_FRAMES, 4, true }; const AnimationDef BUSY_ANIMATION_DEF = {BUSY_ANIMATION_FRAMES, 4, true};
BusyComponent::BusyComponent(Window* window) BusyComponent::BusyComponent(Window* window)
: GuiComponent(window) : GuiComponent(window)
, mBackground(window, ":/graphics/frame.png") , mBackground(window, ":/graphics/frame.png")
, mGrid(window, Vector2i(5, 3)) , mGrid(window, glm::ivec2{5, 3})
{ {
mAnimation = std::make_shared<AnimatedImageComponent>(mWindow); mAnimation = std::make_shared<AnimatedImageComponent>(mWindow);
mAnimation->load(&BUSY_ANIMATION_DEF); mAnimation->load(&BUSY_ANIMATION_DEF);
@ -33,8 +33,8 @@ BusyComponent::BusyComponent(Window* window)
0x777777FF); 0x777777FF);
// Col 0 = animation, col 1 = spacer, col 2 = text. // Col 0 = animation, col 1 = spacer, col 2 = text.
mGrid.setEntry(mAnimation, Vector2i(1, 1), false, true); mGrid.setEntry(mAnimation, glm::ivec2{1, 1}, false, true);
mGrid.setEntry(mText, Vector2i(3, 1), false, true); mGrid.setEntry(mText, glm::ivec2{3, 1}, false, true);
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);
@ -44,25 +44,25 @@ void BusyComponent::onSizeChanged()
{ {
mGrid.setSize(mSize); mGrid.setSize(mSize);
if (mSize.x() == 0 || mSize.y() == 0) if (mSize.x == 0.0f || mSize.y == 0.0f)
return; return;
const float middleSpacerWidth = 0.01f * Renderer::getScreenWidth(); const float middleSpacerWidth = 0.01f * Renderer::getScreenWidth();
const float textHeight = mText->getFont()->getLetterHeight(); const float textHeight = mText->getFont()->getLetterHeight();
mText->setSize(0, textHeight); mText->setSize(0, textHeight);
const float textWidth = mText->getSize().x() + (4 * Renderer::getScreenWidthModifier()); const float textWidth = mText->getSize().x + (4.0f * Renderer::getScreenWidthModifier());
mGrid.setColWidthPerc(1, textHeight / mSize.x()); // Animation is square. mGrid.setColWidthPerc(1, textHeight / mSize.x); // Animation is square.
mGrid.setColWidthPerc(2, middleSpacerWidth / mSize.x()); mGrid.setColWidthPerc(2, middleSpacerWidth / mSize.x);
mGrid.setColWidthPerc(3, textWidth / mSize.x()); mGrid.setColWidthPerc(3, textWidth / mSize.x);
mGrid.setRowHeightPerc(1, textHeight / mSize.y()); mGrid.setRowHeightPerc(1, textHeight / mSize.y);
mBackground.setCornerSize({ 16.0f * Renderer::getScreenWidthModifier(), mBackground.setCornerSize(
16.0f * Renderer::getScreenHeightModifier() }); {16.0f * Renderer::getScreenWidthModifier(), 16.0f * Renderer::getScreenHeightModifier()});
mBackground.fitTo(Vector2f(mGrid.getColWidth(1) + mGrid.getColWidth(2) + mGrid.getColWidth(3), mBackground.fitTo(glm::vec2{mGrid.getColWidth(1) + mGrid.getColWidth(2) + mGrid.getColWidth(3),
textHeight + (2.0f * Renderer::getScreenHeightModifier())), textHeight + (2.0f * Renderer::getScreenHeightModifier())},
mAnimation->getPosition(), Vector2f(0, 0)); mAnimation->getPosition(), glm::vec2{});
} }
void BusyComponent::reset() void BusyComponent::reset()

View file

@ -32,7 +32,7 @@ ButtonComponent::ButtonComponent(Window* window,
void ButtonComponent::onSizeChanged() void ButtonComponent::onSizeChanged()
{ {
// Fit to mBox. // Fit to mBox.
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mBox.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
} }
bool ButtonComponent::input(InputConfig* config, Input input) bool ButtonComponent::input(InputConfig* config, Input input)
@ -53,10 +53,10 @@ void ButtonComponent::setText(const std::string& text, const std::string& helpTe
mTextCache = std::unique_ptr<TextCache>(mFont->buildTextCache(mText, 0, 0, getCurTextColor())); mTextCache = std::unique_ptr<TextCache>(mFont->buildTextCache(mText, 0, 0, getCurTextColor()));
float minWidth = mFont->sizeText("DELETE").x() + (12.0f * Renderer::getScreenWidthModifier()); float minWidth = mFont->sizeText("DELETE").x + (12.0f * Renderer::getScreenWidthModifier());
setSize(std::max(mTextCache->metrics.size.x() + (12.0f * Renderer::getScreenWidthModifier()), setSize(std::max(mTextCache->metrics.size.x + (12.0f * Renderer::getScreenWidthModifier()),
minWidth), minWidth),
mTextCache->metrics.size.y()); mTextCache->metrics.size.y);
updateHelpPrompts(); updateHelpPrompts();
} }
@ -93,29 +93,29 @@ void ButtonComponent::updateImage()
mBox.setImagePath(mFocused ? ":/graphics/button_filled.svg" : ":/graphics/button.svg"); mBox.setImagePath(mFocused ? ":/graphics/button_filled.svg" : ":/graphics/button.svg");
} }
void ButtonComponent::render(const Transform4x4f& parentTrans) void ButtonComponent::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
mBox.render(trans); mBox.render(trans);
if (mTextCache) { if (mTextCache) {
Vector3f centerOffset((mSize.x() - mTextCache->metrics.size.x()) / 2.0f, glm::vec3 centerOffset{(mSize.x - mTextCache->metrics.size.x) / 2.0f,
(mSize.y() - mTextCache->metrics.size.y()) / 2.0f, 0); (mSize.y - mTextCache->metrics.size.y) / 2.0f, 0.0f};
trans = trans.translate(centerOffset); trans = glm::translate(trans, centerOffset);
if (Settings::getInstance()->getBool("DebugText")) { if (Settings::getInstance()->getBool("DebugText")) {
Renderer::drawRect(centerOffset.x(), 0.0f, mTextCache->metrics.size.x(), mSize.y(), Renderer::drawRect(centerOffset.x, 0.0f, mTextCache->metrics.size.x, mSize.y,
0x00000033, 0x00000033); 0x00000033, 0x00000033);
Renderer::drawRect(mBox.getPosition().x(), 0.0f, mBox.getSize().x(), mSize.y(), Renderer::drawRect(mBox.getPosition().x, 0.0f, mBox.getSize().x, mSize.y, 0x0000FF33,
0x0000FF33, 0x0000FF33); 0x0000FF33);
} }
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
mTextCache->setColor(getCurTextColor()); mTextCache->setColor(getCurTextColor());
mFont->renderTextCache(mTextCache.get()); mFont->renderTextCache(mTextCache.get());
trans = trans.translate(-centerOffset); trans = glm::translate(trans, -centerOffset);
} }
renderChildren(trans); renderChildren(trans);

View file

@ -26,7 +26,7 @@ public:
void setEnabled(bool state) override; void setEnabled(bool state) override;
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void setText(const std::string& text, const std::string& helpText); void setText(const std::string& text, const std::string& helpText);

View file

@ -12,21 +12,21 @@
using namespace GridFlags; using namespace GridFlags;
ComponentGrid::ComponentGrid(Window* window, const Vector2i& gridDimensions) ComponentGrid::ComponentGrid(Window* window, const glm::ivec2& gridDimensions)
: GuiComponent(window) : GuiComponent(window)
, mGridSize(gridDimensions) , mGridSize(gridDimensions)
, mCursor(0, 0) , mCursor(0, 0)
{ {
assert(gridDimensions.x() > 0 && gridDimensions.y() > 0); assert(gridDimensions.x > 0 && gridDimensions.y > 0);
mCells.reserve(gridDimensions.x() * gridDimensions.y()); mCells.reserve(gridDimensions.x * gridDimensions.y);
mColWidths = new float[gridDimensions.x()]; mColWidths = new float[gridDimensions.x];
mRowHeights = new float[gridDimensions.y()]; mRowHeights = new float[gridDimensions.y];
for (int x = 0; x < gridDimensions.x(); x++) for (int x = 0; x < gridDimensions.x; x++)
mColWidths[x] = 0; mColWidths[x] = 0;
for (int y = 0; y < gridDimensions.y(); y++) for (int y = 0; y < gridDimensions.y; y++)
mRowHeights[y] = 0; mRowHeights[y] = 0;
} }
@ -39,40 +39,40 @@ ComponentGrid::~ComponentGrid()
float ComponentGrid::getColWidth(int col) float ComponentGrid::getColWidth(int col)
{ {
if (mColWidths[col] != 0) if (mColWidths[col] != 0)
return mColWidths[col] * mSize.x(); return mColWidths[col] * mSize.x;
// Calculate automatic width. // Calculate automatic width.
float freeWidthPerc = 1; float freeWidthPerc = 1;
int between = 0; int between = 0;
for (int x = 0; x < mGridSize.x(); x++) { for (int x = 0; x < mGridSize.x; x++) {
freeWidthPerc -= mColWidths[x]; // If it's 0 it won't do anything. freeWidthPerc -= mColWidths[x]; // If it's 0 it won't do anything.
if (mColWidths[x] == 0) if (mColWidths[x] == 0)
between++; between++;
} }
return (freeWidthPerc * mSize.x()) / between; return (freeWidthPerc * mSize.x) / static_cast<float>(between);
} }
float ComponentGrid::getRowHeight(int row) float ComponentGrid::getRowHeight(int row)
{ {
if (mRowHeights[row] != 0) if (mRowHeights[row] != 0)
return mRowHeights[row] * mSize.y(); return mRowHeights[row] * mSize.y;
// Calculate automatic height. // Calculate automatic height.
float freeHeightPerc = 1; float freeHeightPerc = 1;
int between = 0; int between = 0;
for (int y = 0; y < mGridSize.y(); y++) { for (int y = 0; y < mGridSize.y; y++) {
freeHeightPerc -= mRowHeights[y]; // If it's 0 it won't do anything. freeHeightPerc -= mRowHeights[y]; // If it's 0 it won't do anything.
if (mRowHeights[y] == 0) if (mRowHeights[y] == 0)
between++; between++;
} }
return (freeHeightPerc * mSize.y()) / between; return (freeHeightPerc * mSize.y) / static_cast<float>(between);
} }
void ComponentGrid::setColWidthPerc(int col, float width, bool update) void ComponentGrid::setColWidthPerc(int col, float width, bool update)
{ {
assert(col >= 0 && col < mGridSize.x()); assert(col >= 0 && col < mGridSize.x);
mColWidths[col] = width; mColWidths[col] = width;
if (update) if (update)
@ -82,7 +82,7 @@ void ComponentGrid::setColWidthPerc(int col, float width, bool update)
void ComponentGrid::setRowHeightPerc(int row, float height, bool update) void ComponentGrid::setRowHeightPerc(int row, float height, bool update)
{ {
assert(height >= 0 && height <= 1); assert(height >= 0 && height <= 1);
assert(row >= 0 && row < mGridSize.y()); assert(row >= 0 && row < mGridSize.y);
mRowHeights[row] = height; mRowHeights[row] = height;
if (update) if (update)
@ -90,14 +90,14 @@ void ComponentGrid::setRowHeightPerc(int row, float height, bool update)
} }
void ComponentGrid::setEntry(const std::shared_ptr<GuiComponent>& comp, void ComponentGrid::setEntry(const std::shared_ptr<GuiComponent>& comp,
const Vector2i& pos, const glm::ivec2& pos,
bool canFocus, bool canFocus,
bool resize, bool resize,
const Vector2i& size, const glm::ivec2& size,
unsigned int border, unsigned int border,
GridFlags::UpdateType updateType) GridFlags::UpdateType updateType)
{ {
assert(pos.x() >= 0 && pos.x() < mGridSize.x() && pos.y() >= 0 && pos.y() < mGridSize.y()); assert(pos.x >= 0 && pos.x < mGridSize.x && pos.y >= 0 && pos.y < mGridSize.y);
assert(comp != nullptr); assert(comp != nullptr);
assert(comp->getParent() == nullptr); assert(comp->getParent() == nullptr);
@ -132,26 +132,25 @@ bool ComponentGrid::removeEntry(const std::shared_ptr<GuiComponent>& comp)
void ComponentGrid::updateCellComponent(const GridEntry& cell) void ComponentGrid::updateCellComponent(const GridEntry& cell)
{ {
// Size. // Size.
Vector2f size(0, 0); glm::vec2 size{0.0f};
for (int x = cell.pos.x(); x < cell.pos.x() + cell.dim.x(); x++) for (int x = cell.pos.x; x < cell.pos.x + cell.dim.x; x++)
size[0] += getColWidth(x); size.x += getColWidth(x);
for (int y = cell.pos.y(); y < cell.pos.y() + cell.dim.y(); y++) for (int y = cell.pos.y; y < cell.pos.y + cell.dim.y; y++)
size[1] += getRowHeight(y); size.y += getRowHeight(y);
if (cell.resize) if (cell.resize)
cell.component->setSize(size); cell.component->setSize(size);
// Position.
// Find top left corner. // Find top left corner.
Vector3f pos(0, 0, 0); glm::vec3 pos{};
for (int x = 0; x < cell.pos.x(); x++) for (int x = 0; x < cell.pos.x; x++)
pos[0] += getColWidth(x); pos.x += getColWidth(x);
for (int y = 0; y < cell.pos.y(); y++) for (int y = 0; y < cell.pos.y; y++)
pos[1] += getRowHeight(y); pos.y += getRowHeight(y);
// Center component. // Center component.
pos[0] = pos.x() + (size.x() - cell.component->getSize().x()) / 2; pos.x = pos.x + (size.x - cell.component->getSize().x) / 2.0f;
pos[1] = pos.y() + (size.y() - cell.component->getSize().y()) / 2; pos.y = pos.y + (size.y - cell.component->getSize().y) / 2.0f;
cell.component->setPosition(pos); cell.component->setPosition(pos);
} }
@ -162,58 +161,58 @@ void ComponentGrid::updateSeparators()
bool drawAll = Settings::getInstance()->getBool("DebugGrid"); bool drawAll = Settings::getInstance()->getBool("DebugGrid");
Vector2f pos; glm::vec2 pos;
Vector2f size; glm::vec2 size;
for (auto it = mCells.cbegin(); it != mCells.cend(); it++) { for (auto it = mCells.cbegin(); it != mCells.cend(); it++) {
if (!it->border && !drawAll) if (!it->border && !drawAll)
continue; continue;
// Find component position + size. // Find component position + size.
pos = Vector2f(0, 0); pos = glm::vec2{};
size = Vector2f(0, 0); size = glm::vec2{};
for (int x = 0; x < it->pos.x(); x++) for (int x = 0; x < it->pos.x; x++)
pos[0] += getColWidth(x); pos[0] += getColWidth(x);
for (int y = 0; y < it->pos.y(); y++) for (int y = 0; y < it->pos.y; y++)
pos[1] += getRowHeight(y); pos[1] += getRowHeight(y);
for (int x = it->pos.x(); x < it->pos.x() + it->dim.x(); x++) for (int x = it->pos.x; x < it->pos.x + it->dim.x; x++)
size[0] += getColWidth(x); size[0] += getColWidth(x);
for (int y = it->pos.y(); y < it->pos.y() + it->dim.y(); y++) for (int y = it->pos.y; y < it->pos.y + it->dim.y; y++)
size[1] += getRowHeight(y); size[1] += getRowHeight(y);
if (size == 0) if (size == glm::vec2{})
return; return;
if (it->border & BORDER_TOP || drawAll) { if (it->border & BORDER_TOP || drawAll) {
std::vector<float> coordVector; std::vector<float> coordVector;
coordVector.push_back(pos.x()); coordVector.push_back(pos.x);
coordVector.push_back(pos.y()); coordVector.push_back(pos.y);
coordVector.push_back(size.x()); coordVector.push_back(size.x);
coordVector.push_back(1.0f * Renderer::getScreenHeightModifier()); coordVector.push_back(1.0f * Renderer::getScreenHeightModifier());
mSeparators.push_back(coordVector); mSeparators.push_back(coordVector);
} }
if (it->border & BORDER_BOTTOM || drawAll) { if (it->border & BORDER_BOTTOM || drawAll) {
std::vector<float> coordVector; std::vector<float> coordVector;
coordVector.push_back(pos.x()); coordVector.push_back(pos.x);
coordVector.push_back(pos.y() + size.y()); coordVector.push_back(pos.y + size.y);
coordVector.push_back(size.x()); coordVector.push_back(size.x);
coordVector.push_back(1.0f * Renderer::getScreenHeightModifier()); coordVector.push_back(1.0f * Renderer::getScreenHeightModifier());
mSeparators.push_back(coordVector); mSeparators.push_back(coordVector);
} }
if (it->border & BORDER_LEFT || drawAll) { if (it->border & BORDER_LEFT || drawAll) {
std::vector<float> coordVector; std::vector<float> coordVector;
coordVector.push_back(pos.x()); coordVector.push_back(pos.x);
coordVector.push_back(pos.y()); coordVector.push_back(pos.y);
coordVector.push_back(1.0f * Renderer::getScreenWidthModifier()); coordVector.push_back(1.0f * Renderer::getScreenWidthModifier());
coordVector.push_back(size.y()); coordVector.push_back(size.y);
mSeparators.push_back(coordVector); mSeparators.push_back(coordVector);
} }
if (it->border & BORDER_RIGHT || drawAll) { if (it->border & BORDER_RIGHT || drawAll) {
std::vector<float> coordVector; std::vector<float> coordVector;
coordVector.push_back(pos.x() + size.x()); coordVector.push_back(pos.x + size.x);
coordVector.push_back(pos.y()); coordVector.push_back(pos.y);
coordVector.push_back(1.0f * Renderer::getScreenWidthModifier()); coordVector.push_back(1.0f * Renderer::getScreenWidthModifier());
coordVector.push_back(size.y()); coordVector.push_back(size.y);
mSeparators.push_back(coordVector); mSeparators.push_back(coordVector);
} }
} }
@ -229,13 +228,13 @@ void ComponentGrid::onSizeChanged()
const ComponentGrid::GridEntry* ComponentGrid::getCellAt(int x, int y) const const ComponentGrid::GridEntry* ComponentGrid::getCellAt(int x, int y) const
{ {
assert(x >= 0 && x < mGridSize.x() && y >= 0 && y < mGridSize.y()); assert(x >= 0 && x < mGridSize.x && y >= 0 && y < mGridSize.y);
for (auto it = mCells.cbegin(); it != mCells.cend(); it++) { for (auto it = mCells.cbegin(); it != mCells.cend(); it++) {
int xmin = it->pos.x(); int xmin = it->pos.x;
int xmax = xmin + it->dim.x(); int xmax = xmin + it->dim.x;
int ymin = it->pos.y(); int ymin = it->pos.y;
int ymax = ymin + it->dim.y(); int ymax = ymin + it->dim.y;
if (x >= xmin && y >= ymin && x < xmax && y < ymax) if (x >= xmin && y >= ymin && x < xmax && y < ymax)
return &(*it); return &(*it);
@ -254,16 +253,16 @@ bool ComponentGrid::input(InputConfig* config, Input input)
return false; return false;
if (config->isMappedLike("down", input)) if (config->isMappedLike("down", input))
return moveCursor(Vector2i(0, 1)); return moveCursor(glm::ivec2{0, 1});
if (config->isMappedLike("up", input)) if (config->isMappedLike("up", input))
return moveCursor(Vector2i(0, -1)); return moveCursor(glm::ivec2{0, -1});
if (config->isMappedLike("left", input)) if (config->isMappedLike("left", input))
return moveCursor(Vector2i(-1, 0)); return moveCursor(glm::ivec2{-1, 0});
if (config->isMappedLike("right", input)) if (config->isMappedLike("right", input))
return moveCursor(Vector2i(1, 0)); return moveCursor(glm::ivec2{1, 0});
return false; return false;
} }
@ -275,7 +274,7 @@ void ComponentGrid::resetCursor()
for (auto it = mCells.cbegin(); it != mCells.cend(); it++) { for (auto it = mCells.cbegin(); it != mCells.cend(); it++) {
if (it->canFocus) { if (it->canFocus) {
Vector2i origCursor = mCursor; glm::ivec2 origCursor = mCursor;
mCursor = it->pos; mCursor = it->pos;
onCursorMoved(origCursor, mCursor); onCursorMoved(origCursor, mCursor);
break; break;
@ -283,23 +282,22 @@ void ComponentGrid::resetCursor()
} }
} }
bool ComponentGrid::moveCursor(Vector2i dir) bool ComponentGrid::moveCursor(glm::ivec2 dir)
{ {
assert(dir.x() || dir.y()); assert(dir.x || dir.y);
const Vector2i origCursor = mCursor; const glm::ivec2 origCursor{mCursor};
const GridEntry* currentCursorEntry = getCellAt(mCursor); const GridEntry* currentCursorEntry = getCellAt(mCursor);
Vector2i searchAxis(dir.x() == 0, dir.y() == 0); glm::ivec2 searchAxis(dir.x == 0, dir.y == 0);
while (mCursor.x() >= 0 && mCursor.y() >= 0 && mCursor.x() < mGridSize.x() && while (mCursor.x >= 0 && mCursor.y >= 0 && mCursor.x < mGridSize.x && mCursor.y < mGridSize.y) {
mCursor.y() < mGridSize.y()) {
mCursor = mCursor + dir; mCursor = mCursor + dir;
Vector2i curDirPos = mCursor; glm::ivec2 curDirPos{mCursor};
const GridEntry* cursorEntry; const GridEntry* cursorEntry;
// Spread out on search axis+ // Spread out on search axis+
while (mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y() && mCursor.x() >= 0 && while (mCursor.x < mGridSize.x && mCursor.y < mGridSize.y && mCursor.x >= 0 &&
mCursor.y() >= 0) { mCursor.y >= 0) {
cursorEntry = getCellAt(mCursor); cursorEntry = getCellAt(mCursor);
if (cursorEntry && cursorEntry->canFocus && cursorEntry != currentCursorEntry) { if (cursorEntry && cursorEntry->canFocus && cursorEntry != currentCursorEntry) {
onCursorMoved(origCursor, mCursor); onCursorMoved(origCursor, mCursor);
@ -310,8 +308,8 @@ bool ComponentGrid::moveCursor(Vector2i dir)
// Now again on search axis- // Now again on search axis-
mCursor = curDirPos; mCursor = curDirPos;
while (mCursor.x() >= 0 && mCursor.y() >= 0 && mCursor.x() < mGridSize.x() && while (mCursor.x >= 0 && mCursor.y >= 0 && mCursor.x < mGridSize.x &&
mCursor.y() < mGridSize.y()) { mCursor.y < mGridSize.y) {
cursorEntry = getCellAt(mCursor); cursorEntry = getCellAt(mCursor);
if (cursorEntry && cursorEntry->canFocus && cursorEntry != currentCursorEntry) { if (cursorEntry && cursorEntry->canFocus && cursorEntry != currentCursorEntry) {
@ -360,9 +358,9 @@ void ComponentGrid::update(int deltaTime)
} }
} }
void ComponentGrid::render(const Transform4x4f& parentTrans) void ComponentGrid::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
renderChildren(trans); renderChildren(trans);
@ -381,7 +379,7 @@ void ComponentGrid::textInput(const std::string& text)
selectedEntry->component->textInput(text); selectedEntry->component->textInput(text);
} }
void ComponentGrid::onCursorMoved(Vector2i from, Vector2i to) void ComponentGrid::onCursorMoved(glm::ivec2 from, glm::ivec2 to)
{ {
const GridEntry* cell = getCellAt(from); const GridEntry* cell = getCellAt(from);
if (cell) if (cell)
@ -398,7 +396,7 @@ void ComponentGrid::setCursorTo(const std::shared_ptr<GuiComponent>& comp)
{ {
for (auto it = mCells.cbegin(); it != mCells.cend(); it++) { for (auto it = mCells.cbegin(); it != mCells.cend(); it++) {
if (it->component == comp) { if (it->component == comp) {
Vector2i oldCursor = mCursor; glm::ivec2 oldCursor{mCursor};
mCursor = it->pos; mCursor = it->pos;
onCursorMoved(oldCursor, mCursor); onCursorMoved(oldCursor, mCursor);
return; return;
@ -416,8 +414,8 @@ std::vector<HelpPrompt> ComponentGrid::getHelpPrompts()
if (e) if (e)
prompts = e->component->getHelpPrompts(); prompts = e->component->getHelpPrompts();
bool canScrollVert = mGridSize.y() > 1; bool canScrollVert = mGridSize.y > 1;
bool canScrollHoriz = mGridSize.x() > 1; bool canScrollHoriz = mGridSize.x > 1;
for (auto it = prompts.cbegin(); it != prompts.cend(); it++) { for (auto it = prompts.cbegin(); it != prompts.cend(); it++) {
if (it->first == "up/down/left/right") { if (it->first == "up/down/left/right") {
canScrollHoriz = false; canScrollHoriz = false;

View file

@ -10,7 +10,6 @@
#define ES_CORE_COMPONENTS_COMPONENT_GRID_H #define ES_CORE_COMPONENTS_COMPONENT_GRID_H
#include "GuiComponent.h" #include "GuiComponent.h"
#include "math/Vector2i.h"
#include "renderers/Renderer.h" #include "renderers/Renderer.h"
namespace GridFlags namespace GridFlags
@ -34,23 +33,23 @@ namespace GridFlags
class ComponentGrid : public GuiComponent class ComponentGrid : public GuiComponent
{ {
public: public:
ComponentGrid(Window* window, const Vector2i& gridDimensions); ComponentGrid(Window* window, const glm::ivec2& gridDimensions);
virtual ~ComponentGrid(); virtual ~ComponentGrid();
bool removeEntry(const std::shared_ptr<GuiComponent>& comp); bool removeEntry(const std::shared_ptr<GuiComponent>& comp);
void setEntry(const std::shared_ptr<GuiComponent>& comp, void setEntry(const std::shared_ptr<GuiComponent>& comp,
const Vector2i& pos, const glm::ivec2& pos,
bool canFocus, bool canFocus,
bool resize = true, bool resize = true,
const Vector2i& size = Vector2i(1, 1), const glm::ivec2& size = glm::ivec2{1, 1},
unsigned int border = GridFlags::BORDER_NONE, unsigned int border = GridFlags::BORDER_NONE,
GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS); GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS);
void textInput(const std::string& text) override; void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override; void onSizeChanged() override;
void resetCursor(); void resetCursor();
@ -65,7 +64,7 @@ public:
// Dito. // Dito.
void setRowHeightPerc(int row, float height, bool update = true); void setRowHeightPerc(int row, float height, bool update = true);
bool moveCursor(Vector2i dir); bool moveCursor(glm::ivec2 dir);
void setCursorTo(const std::shared_ptr<GuiComponent>& comp); void setCursorTo(const std::shared_ptr<GuiComponent>& comp);
std::shared_ptr<GuiComponent> getSelectedComponent() std::shared_ptr<GuiComponent> getSelectedComponent()
@ -86,16 +85,16 @@ private:
class GridEntry class GridEntry
{ {
public: public:
Vector2i pos; glm::ivec2 pos;
Vector2i dim; glm::ivec2 dim;
std::shared_ptr<GuiComponent> component; std::shared_ptr<GuiComponent> component;
bool canFocus; bool canFocus;
bool resize; bool resize;
GridFlags::UpdateType updateType; GridFlags::UpdateType updateType;
unsigned int border; unsigned int border;
GridEntry(const Vector2i& p = Vector2i::Zero(), GridEntry(const glm::ivec2& p = glm::ivec2{},
const Vector2i& d = Vector2i::Zero(), const glm::ivec2& d = glm::ivec2{},
const std::shared_ptr<GuiComponent>& cmp = nullptr, const std::shared_ptr<GuiComponent>& cmp = nullptr,
bool f = false, bool f = false,
bool r = true, bool r = true,
@ -118,14 +117,14 @@ private:
void updateCellComponent(const GridEntry& cell); void updateCellComponent(const GridEntry& cell);
void updateSeparators(); void updateSeparators();
void onCursorMoved(Vector2i from, Vector2i to); void onCursorMoved(glm::ivec2 from, glm::ivec2 to);
const GridEntry* getCellAt(int x, int y) const; const GridEntry* getCellAt(int x, int y) const;
const GridEntry* getCellAt(const Vector2i& pos) const { return getCellAt(pos.x(), pos.y()); } const GridEntry* getCellAt(const glm::ivec2& pos) const { return getCellAt(pos.x, pos.y); }
std::vector<std::vector<float>> mSeparators; std::vector<std::vector<float>> mSeparators;
Vector2i mGridSize; glm::ivec2 mGridSize;
std::vector<GridEntry> mCells; std::vector<GridEntry> mCells;
Vector2i mCursor; glm::ivec2 mCursor;
float* mRowHeights; float* mRowHeights;
float* mColWidths; float* mColWidths;

View file

@ -145,45 +145,47 @@ void ComponentList::updateCameraOffset()
{ {
// Move the camera to scroll. // Move the camera to scroll.
const float totalHeight = getTotalRowHeight(); const float totalHeight = getTotalRowHeight();
if (totalHeight > mSize.y()) { if (totalHeight > mSize.y) {
float target = mSelectorBarOffset + getRowHeight(mEntries.at(mCursor).data) / 2.0f - float target =
(mSize.y() / 2.0f); mSelectorBarOffset + getRowHeight(mEntries.at(mCursor).data) / 2.0f - (mSize.y / 2.0f);
// Clamp the camera to prevent a fraction of a row from being displayed. // Clamp the camera to prevent a fraction of a row from being displayed.
mCameraOffset = 0.0f; mCameraOffset = 0.0f;
unsigned int i = 0; unsigned int i = 0;
while (mCameraOffset < target && i < mEntries.size()) { while (mCameraOffset < target && i < mEntries.size()) {
mCameraOffset += getRowHeight(mEntries.at(i).data); mCameraOffset += getRowHeight(mEntries.at(i).data);
if (mCameraOffset > totalHeight - mSize.y()) if (mCameraOffset > totalHeight - mSize.y)
break; break;
i++; i++;
} }
if (mCameraOffset < 0) if (mCameraOffset < 0.0f)
mCameraOffset = 0; mCameraOffset = 0.0f;
} }
else { else {
mCameraOffset = 0; mCameraOffset = 0.0f;
} }
} }
void ComponentList::render(const Transform4x4f& parentTrans) void ComponentList::render(const glm::mat4& parentTrans)
{ {
if (!size()) if (!size())
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
// Clip everything to be inside our bounds. // Clip everything to be inside our bounds.
Vector3f dim(mSize.x(), mSize.y(), 0.0f); glm::vec3 dim{mSize.x, mSize.y, 0.0f};
dim = trans * dim - trans.translation(); dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x;
dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
Renderer::pushClipRect( Renderer::pushClipRect(
Vector2i(static_cast<int>(std::round(trans.translation().x())), glm::ivec2{static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans.translation().y()))), static_cast<int>(std::round(trans[3].y))},
Vector2i(static_cast<int>(std::round(dim.x())), static_cast<int>(std::round(dim.y())))); glm::ivec2{static_cast<int>(std::round(dim.x)), static_cast<int>(std::round(dim.y))});
// Scroll the camera. // Scroll the camera.
trans.translate(Vector3f(0.0f, -std::round(mCameraOffset), 0.0f)); trans = glm::translate(trans, glm::vec3{0.0f, -std::round(mCameraOffset), 0.0f});
// Draw our entries. // Draw our entries.
std::vector<GuiComponent*> drawAfterCursor; std::vector<GuiComponent*> drawAfterCursor;
@ -243,19 +245,14 @@ void ComponentList::render(const Transform4x4f& parentTrans)
// Draw selector bar. // Draw selector bar.
if (mFocused) { if (mFocused) {
// Inversion: src * (1 - dst) + dst * 0 = where src = 1
// Need a function that goes roughly 0x777777 -> 0xFFFFFF
// and 0xFFFFFF -> 0x777777
// (1 - dst) + 0x77
const float selectedRowHeight = getRowHeight(mEntries.at(mCursor).data); const float selectedRowHeight = getRowHeight(mEntries.at(mCursor).data);
if (opacity == 1) { if (opacity == 1) {
Renderer::drawRect(0.0f, mSelectorBarOffset, mSize.x(), selectedRowHeight, 0xFFFFFFFF, Renderer::drawRect(0.0f, mSelectorBarOffset, mSize.x, selectedRowHeight, 0xFFFFFFFF,
0xFFFFFFFF, false, opacity, trans, 0xFFFFFFFF, false, opacity, trans,
Renderer::Blend::ONE_MINUS_DST_COLOR, Renderer::Blend::ZERO); Renderer::Blend::ONE_MINUS_DST_COLOR, Renderer::Blend::ZERO);
Renderer::drawRect(0.0f, mSelectorBarOffset, mSize.x(), selectedRowHeight, 0x777777FF, Renderer::drawRect(0.0f, mSelectorBarOffset, mSize.x, selectedRowHeight, 0x777777FF,
0x777777FF, false, opacity, trans, Renderer::Blend::ONE, 0x777777FF, false, opacity, trans, Renderer::Blend::ONE,
Renderer::Blend::ONE); Renderer::Blend::ONE);
} }
@ -271,12 +268,12 @@ void ComponentList::render(const Transform4x4f& parentTrans)
// Draw separators. // Draw separators.
float y = 0; float y = 0;
for (unsigned int i = 0; i < mEntries.size(); i++) { for (unsigned int i = 0; i < mEntries.size(); i++) {
Renderer::drawRect(0.0f, y, mSize.x(), 1.0f * Renderer::getScreenHeightModifier(), Renderer::drawRect(0.0f, y, mSize.x, 1.0f * Renderer::getScreenHeightModifier(), 0xC6C7C6FF,
0xC6C7C6FF, 0xC6C7C6FF, false, opacity, trans); 0xC6C7C6FF, false, opacity, trans);
y += getRowHeight(mEntries.at(i).data); y += getRowHeight(mEntries.at(i).data);
} }
Renderer::drawRect(0.0f, y, mSize.x(), 1.0f * Renderer::getScreenHeightModifier(), 0xC6C7C6FF, Renderer::drawRect(0.0f, y, mSize.x, 1.0f * Renderer::getScreenHeightModifier(), 0xC6C7C6FF,
0xC6C7C6FF, false, opacity, trans); 0xC6C7C6FF, false, opacity, trans);
Renderer::popClipRect(); Renderer::popClipRect();
} }
@ -286,8 +283,8 @@ float ComponentList::getRowHeight(const ComponentListRow& row) const
// Returns the highest component height found in the row. // Returns the highest component height found in the row.
float height = 0; float height = 0;
for (unsigned int i = 0; i < row.elements.size(); i++) { for (unsigned int i = 0; i < row.elements.size(); i++) {
if (row.elements.at(i).component->getSize().y() > height) if (row.elements.at(i).component->getSize().y > height)
height = row.elements.at(i).component->getSize().y(); height = row.elements.at(i).component->getSize().y;
} }
return height; return height;
@ -316,27 +313,27 @@ void ComponentList::updateElementPosition(const ComponentListRow& row)
const auto comp = row.elements.at(i).component; const auto comp = row.elements.at(i).component;
// Center vertically. // Center vertically.
comp->setPosition(x, (rowHeight - comp->getSize().y()) / 2.0f + yOffset); comp->setPosition(x, (rowHeight - comp->getSize().y) / 2.0f + yOffset);
x += comp->getSize().x(); x += comp->getSize().x;
} }
} }
void ComponentList::updateElementSize(const ComponentListRow& row) void ComponentList::updateElementSize(const ComponentListRow& row)
{ {
float width = mSize.x() - mHorizontalPadding; float width = mSize.x - mHorizontalPadding;
std::vector<std::shared_ptr<GuiComponent>> resizeVec; std::vector<std::shared_ptr<GuiComponent>> resizeVec;
for (auto it = row.elements.cbegin(); it != row.elements.cend(); it++) { for (auto it = row.elements.cbegin(); it != row.elements.cend(); it++) {
if (it->resize_width) if (it->resize_width)
resizeVec.push_back(it->component); resizeVec.push_back(it->component);
else else
width -= it->component->getSize().x(); width -= it->component->getSize().x;
} }
// Redistribute the "unused" width equally among the components with resize_width set to true. // Redistribute the "unused" width equally among the components with resize_width set to true.
width = width / resizeVec.size(); width = width / resizeVec.size();
for (auto it = resizeVec.cbegin(); it != resizeVec.cend(); it++) for (auto it = resizeVec.cbegin(); it != resizeVec.cend(); it++)
(*it)->setSize(width, (*it)->getSize().y()); (*it)->setSize(width, (*it)->getSize().y);
} }
void ComponentList::textInput(const std::string& text) void ComponentList::textInput(const std::string& text)

View file

@ -66,7 +66,7 @@ public:
void textInput(const std::string& text) override; void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override; virtual std::vector<HelpPrompt> getHelpPrompts() override;
void onSizeChanged() override; void onSizeChanged() override;

View file

@ -27,8 +27,8 @@ DateTimeComponent::DateTimeComponent(Window* window,
const std::shared_ptr<Font>& font, const std::shared_ptr<Font>& font,
unsigned int color, unsigned int color,
Alignment align, Alignment align,
Vector3f pos, glm::vec3 pos,
Vector2f size, glm::vec2 size,
unsigned int bgcolor) unsigned int bgcolor)
: TextComponent(window, text, font, color, align, pos, size, bgcolor) : TextComponent(window, text, font, color, align, pos, size, bgcolor)
, mDisplayRelative(false) , mDisplayRelative(false)
@ -101,8 +101,9 @@ std::string DateTimeComponent::getDisplayString() const
return Utils::Time::timeToString(mTime.getTime(), mFormat); return Utils::Time::timeToString(mTime.getTime(), mFormat);
} }
void DateTimeComponent::render(const Transform4x4f& parentTrans) void DateTimeComponent::render(const glm::mat4& parentTrans)
{ {
// Render the component.
TextComponent::render(parentTrans); TextComponent::render(parentTrans);
} }

View file

@ -26,11 +26,11 @@ public:
const std::shared_ptr<Font>& font, const std::shared_ptr<Font>& font,
unsigned int color = 0x000000FF, unsigned int color = 0x000000FF,
Alignment align = ALIGN_LEFT, Alignment align = ALIGN_LEFT,
Vector3f pos = Vector3f::Zero(), glm::vec3 pos = {},
Vector2f size = Vector2f::Zero(), glm::vec2 size = {},
unsigned int bgcolor = 0x00000000); unsigned int bgcolor = 0x00000000);
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void setValue(const std::string& val) override; void setValue(const std::string& val) override;
std::string getValue() const override; std::string getValue() const override;

View file

@ -154,9 +154,9 @@ void DateTimeEditComponent::update(int deltaTime)
GuiComponent::update(deltaTime); GuiComponent::update(deltaTime);
} }
void DateTimeEditComponent::render(const Transform4x4f& parentTrans) void DateTimeEditComponent::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
if (mTextCache) { if (mTextCache) {
std::shared_ptr<Font> font = getFont(); std::shared_ptr<Font> font = getFont();
@ -164,28 +164,28 @@ void DateTimeEditComponent::render(const Transform4x4f& parentTrans)
if (mAlignRight) { if (mAlignRight) {
if (mTime != 0) if (mTime != 0)
referenceSize = font->sizeText("ABCDEFG").x(); referenceSize = font->sizeText("ABCDEFG").x;
else else
referenceSize = font->sizeText("ABCDEIJ").x(); referenceSize = font->sizeText("ABCDEIJ").x;
} }
// Vertically center. // Vertically center.
Vector3f off(0, (mSize.y() - mTextCache->metrics.size.y()) / 2.0f, 0.0f); glm::vec3 off{0.0f, (mSize.y - mTextCache->metrics.size.y) / 2.0f, 0.0f};
if (mAlignRight) if (mAlignRight)
off.x() += referenceSize - mTextCache->metrics.size.x(); off.x += referenceSize - mTextCache->metrics.size.x;
trans.translate(off); trans = glm::translate(trans, off);
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
if (Settings::getInstance()->getBool("DebugText")) { if (Settings::getInstance()->getBool("DebugText")) {
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
if (mTextCache->metrics.size.x() > 0) { if (mTextCache->metrics.size.x > 0.0f) {
Renderer::drawRect(0.0f, 0.0f - off.y(), mSize.x() - off.x(), mSize.y(), 0x0000FF33, Renderer::drawRect(0.0f, 0.0f - off.y, mSize.x - off.x, mSize.y, 0x0000FF33,
0x0000FF33); 0x0000FF33);
} }
Renderer::drawRect(0.0f, 0.0f, mTextCache->metrics.size.x(), Renderer::drawRect(0.0f, 0.0f, mTextCache->metrics.size.x, mTextCache->metrics.size.y,
mTextCache->metrics.size.y(), 0x00000033, 0x00000033); 0x00000033, 0x00000033);
} }
mTextCache->setColor((mColor & 0xFFFFFF00) | getOpacity()); mTextCache->setColor((mColor & 0xFFFFFF00) | getOpacity());
@ -300,22 +300,22 @@ void DateTimeEditComponent::updateTextCache()
return; return;
// Year. // Year.
Vector2f start(0, 0); glm::vec2 start{};
Vector2f end = font->sizeText(dispString.substr(0, 4)); glm::vec2 end{font->sizeText(dispString.substr(0, 4))};
Vector2f diff = end - start; glm::vec2 diff{end - start};
mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1])); mCursorBoxes.push_back(glm::vec4{start[0], start[1], diff[0], diff[1]});
// Month. // Month.
start[0] = font->sizeText(dispString.substr(0, 5)).x(); start[0] = font->sizeText(dispString.substr(0, 5)).x;
end = font->sizeText(dispString.substr(0, 7)); end = font->sizeText(dispString.substr(0, 7));
diff = end - start; diff = end - start;
mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1])); mCursorBoxes.push_back(glm::vec4{start[0], start[1], diff[0], diff[1]});
// Day. // Day.
start[0] = font->sizeText(dispString.substr(0, 8)).x(); start[0] = font->sizeText(dispString.substr(0, 8)).x;
end = font->sizeText(dispString.substr(0, 10)); end = font->sizeText(dispString.substr(0, 10));
diff = end - start; diff = end - start;
mCursorBoxes.push_back(Vector4f(start[0], start[1], diff[0], diff[1])); mCursorBoxes.push_back(glm::vec4{start[0], start[1], diff[0], diff[1]});
// The logic for handling time for 'mode = DISP_DATE_TIME' is missing, but // The logic for handling time for 'mode = DISP_DATE_TIME' is missing, but
// nobody will use it anyway so it's not worthwhile implementing. // nobody will use it anyway so it's not worthwhile implementing.

View file

@ -34,7 +34,7 @@ public:
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
unsigned int getColor() const override { return mColor; } unsigned int getColor() const override { return mColor; }
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override; void onSizeChanged() override;
// Set how the point in time will be displayed: // Set how the point in time will be displayed:
@ -82,7 +82,7 @@ private:
int mRelativeUpdateAccumulator; int mRelativeUpdateAccumulator;
std::unique_ptr<TextCache> mTextCache; std::unique_ptr<TextCache> mTextCache;
std::vector<Vector4f> mCursorBoxes; std::vector<glm::vec4> mCursorBoxes;
unsigned int mColor; unsigned int mColor;
Utils::Time::DateTime mOriginalValue; Utils::Time::DateTime mOriginalValue;

View file

@ -17,12 +17,12 @@ GridTileComponent::GridTileComponent(Window* window)
, mBackground(window, ":/graphics/frame.png") , mBackground(window, ":/graphics/frame.png")
{ {
mDefaultProperties.mSize = getDefaultTileSize(); mDefaultProperties.mSize = getDefaultTileSize();
mDefaultProperties.mPadding = Vector2f(16.0f * Renderer::getScreenWidthModifier(), mDefaultProperties.mPadding = glm::vec2{16.0f * Renderer::getScreenWidthModifier(),
16.0f * Renderer::getScreenHeightModifier()); 16.0f * Renderer::getScreenHeightModifier()};
mDefaultProperties.mImageColor = 0xAAAAAABB; mDefaultProperties.mImageColor = 0xAAAAAABB;
// Attempting to use frame.svg instead causes quite severe performance problems. // Attempting to use frame.svg instead causes quite severe performance problems.
mDefaultProperties.mBackgroundImage = ":/graphics/frame.png"; mDefaultProperties.mBackgroundImage = ":/graphics/frame.png";
mDefaultProperties.mBackgroundCornerSize = Vector2f(16.0f, 16.0f); mDefaultProperties.mBackgroundCornerSize = glm::vec2{16.0f, 16.0f};
mDefaultProperties.mBackgroundCenterColor = 0xAAAAEEFF; mDefaultProperties.mBackgroundCenterColor = 0xAAAAEEFF;
mDefaultProperties.mBackgroundEdgeColor = 0xAAAAEEFF; mDefaultProperties.mBackgroundEdgeColor = 0xAAAAEEFF;
@ -50,9 +50,9 @@ GridTileComponent::GridTileComponent(Window* window)
setVisible(true); setVisible(true);
} }
void GridTileComponent::render(const Transform4x4f& parentTrans) void GridTileComponent::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = getTransform() * parentTrans; glm::mat4 trans{getTransform() * parentTrans};
if (mVisible) if (mVisible)
renderChildren(trans); renderChildren(trans);
@ -76,14 +76,14 @@ void GridTileComponent::update(int deltaTime)
void applyThemeToProperties(const ThemeData::ThemeElement* elem, GridTileProperties* properties) void applyThemeToProperties(const ThemeData::ThemeElement* elem, GridTileProperties* properties)
{ {
Vector2f screen = Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2 screen{static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight())};
if (elem->has("size")) if (elem->has("size"))
properties->mSize = elem->get<Vector2f>("size") * screen; properties->mSize = elem->get<glm::vec2>("size") * screen;
if (elem->has("padding")) if (elem->has("padding"))
properties->mPadding = elem->get<Vector2f>("padding"); properties->mPadding = elem->get<glm::vec2>("padding");
if (elem->has("imageColor")) if (elem->has("imageColor"))
properties->mImageColor = elem->get<unsigned int>("imageColor"); properties->mImageColor = elem->get<unsigned int>("imageColor");
@ -92,7 +92,7 @@ void applyThemeToProperties(const ThemeData::ThemeElement* elem, GridTilePropert
properties->mBackgroundImage = elem->get<std::string>("backgroundImage"); properties->mBackgroundImage = elem->get<std::string>("backgroundImage");
if (elem->has("backgroundCornerSize")) if (elem->has("backgroundCornerSize"))
properties->mBackgroundCornerSize = elem->get<Vector2f>("backgroundCornerSize"); properties->mBackgroundCornerSize = elem->get<glm::vec2>("backgroundCornerSize");
if (elem->has("backgroundColor")) { if (elem->has("backgroundColor")) {
properties->mBackgroundCenterColor = elem->get<unsigned int>("backgroundColor"); properties->mBackgroundCenterColor = elem->get<unsigned int>("backgroundColor");
@ -111,9 +111,6 @@ void GridTileComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& /*element*/, const std::string& /*element*/,
unsigned int /*properties*/) unsigned int /*properties*/)
{ {
Vector2f screen = Vector2f(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()));
// Apply theme to the default gridtile. // Apply theme to the default gridtile.
const ThemeData::ThemeElement* elem = theme->getElement(view, "default", "gridtile"); const ThemeData::ThemeElement* elem = theme->getElement(view, "default", "gridtile");
if (elem) if (elem)
@ -133,15 +130,15 @@ void GridTileComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
applyThemeToProperties(elem, &mSelectedProperties); applyThemeToProperties(elem, &mSelectedProperties);
} }
Vector2f GridTileComponent::getDefaultTileSize() glm::vec2 GridTileComponent::getDefaultTileSize()
{ {
Vector2f screen = Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2 screen{glm::vec2(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight()))};
return screen * 0.22f; return screen * 0.22f;
} }
Vector2f GridTileComponent::getSelectedTileSize() const glm::vec2 GridTileComponent::getSelectedTileSize() const
{ {
// Return the tile size. // Return the tile size.
return mDefaultProperties.mSize * 1.2f; return mDefaultProperties.mSize * 1.2f;
@ -171,7 +168,7 @@ void GridTileComponent::setImage(const std::shared_ptr<TextureResource>& texture
void GridTileComponent::setSelected(bool selected, void GridTileComponent::setSelected(bool selected,
bool allowAnimation, bool allowAnimation,
Vector3f* pPosition, glm::vec3* pPosition,
bool force) bool force)
{ {
if (mSelected == selected && !force) if (mSelected == selected && !force)
@ -184,15 +181,15 @@ void GridTileComponent::setSelected(bool selected,
cancelAnimation(3); cancelAnimation(3);
this->setSelectedZoom(1); this->setSelectedZoom(1);
mAnimPosition = Vector3f(0, 0, 0); mAnimPosition = {};
resize(); resize();
} }
else { else {
mAnimPosition = Vector3f(pPosition->x(), pPosition->y(), pPosition->z()); mAnimPosition = glm::vec3{pPosition->x, pPosition->y, pPosition->z};
auto func = [this](float t) { auto func = [this](float t) {
t -= 1; // Cubic ease out. t -= 1;
float pct = Math::lerp(0, 1, t * t * t + 1); float pct = Math::lerp(0, 1, t * t * t + 1);
this->setSelectedZoom(pct); this->setSelectedZoom(pct);
}; };
@ -202,7 +199,7 @@ void GridTileComponent::setSelected(bool selected,
new LambdaAnimation(func, 250), 0, new LambdaAnimation(func, 250), 0,
[this] { [this] {
this->setSelectedZoom(1); this->setSelectedZoom(1);
mAnimPosition = Vector3f(0, 0, 0); mAnimPosition = {};
}, },
false, 3); false, 3);
} }
@ -218,7 +215,7 @@ void GridTileComponent::setSelected(bool selected,
this->setSelectedZoom(1); this->setSelectedZoom(1);
auto func = [this](float t) { auto func = [this](float t) {
t -= 1.0f; // Cubic ease out. t -= 1.0f;
float pct = Math::lerp(0, 1, t * t * t + 1.0f); float pct = Math::lerp(0, 1, t * t * t + 1.0f);
this->setSelectedZoom(1.0f - pct); this->setSelectedZoom(1.0f - pct);
}; };
@ -307,7 +304,7 @@ void GridTileComponent::calcCurrentProperties()
} }
} }
Vector3f GridTileComponent::getBackgroundPosition() glm::vec3 GridTileComponent::getBackgroundPosition()
{ {
return mBackground.getPosition() + mPosition; return mBackground.getPosition() + mPosition;
} }
@ -320,7 +317,7 @@ std::shared_ptr<TextureResource> GridTileComponent::getTexture()
return nullptr; return nullptr;
}; };
void GridTileComponent::forceSize(Vector2f size, float selectedZoom) void GridTileComponent::forceSize(glm::vec2 size, float selectedZoom)
{ {
mDefaultProperties.mSize = size; mDefaultProperties.mSize = size;
mSelectedProperties.mSize = size * selectedZoom; mSelectedProperties.mSize = size * selectedZoom;

View file

@ -13,11 +13,11 @@
#include "NinePatchComponent.h" #include "NinePatchComponent.h"
struct GridTileProperties { struct GridTileProperties {
Vector2f mSize; glm::vec2 mSize;
Vector2f mPadding; glm::vec2 mPadding;
unsigned int mImageColor; unsigned int mImageColor;
std::string mBackgroundImage; std::string mBackgroundImage;
Vector2f mBackgroundCornerSize; glm::vec2 mBackgroundCornerSize;
unsigned int mBackgroundCenterColor; unsigned int mBackgroundCenterColor;
unsigned int mBackgroundEdgeColor; unsigned int mBackgroundEdgeColor;
}; };
@ -27,7 +27,7 @@ class GridTileComponent : public GuiComponent
public: public:
GridTileComponent(Window* window); GridTileComponent(Window* window);
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view, const std::string& view,
const std::string& element, const std::string& element,
@ -35,8 +35,8 @@ public:
// Made this a static function because the ImageGridComponent needs to know the default tile // Made this a static function because the ImageGridComponent needs to know the default tile
// max size to calculate the grid dimension before it instantiates the GridTileComponents. // max size to calculate the grid dimension before it instantiates the GridTileComponents.
static Vector2f getDefaultTileSize(); static glm::vec2 getDefaultTileSize();
Vector2f getSelectedTileSize() const; glm::vec2 getSelectedTileSize() const;
bool isSelected() const; bool isSelected() const;
void reset() { setImage(""); } void reset() { setImage(""); }
@ -45,13 +45,13 @@ public:
void setImage(const std::shared_ptr<TextureResource>& texture); void setImage(const std::shared_ptr<TextureResource>& texture);
void setSelected(bool selected, void setSelected(bool selected,
bool allowAnimation = true, bool allowAnimation = true,
Vector3f* pPosition = nullptr, glm::vec3* pPosition = nullptr,
bool force = false); bool force = false);
void setVisible(bool visible); void setVisible(bool visible);
void forceSize(Vector2f size, float selectedZoom); void forceSize(glm::vec2 size, float selectedZoom);
Vector3f getBackgroundPosition(); glm::vec3 getBackgroundPosition();
virtual void update(int deltaTime) override; virtual void update(int deltaTime) override;
@ -73,7 +73,7 @@ private:
bool mSelected; bool mSelected;
bool mVisible; bool mVisible;
Vector3f mAnimPosition; glm::vec3 mAnimPosition;
}; };
#endif // ES_CORE_COMPONENTS_GRID_TILE_COMPONENT_H #endif // ES_CORE_COMPONENTS_GRID_TILE_COMPONENT_H

View file

@ -16,10 +16,10 @@
#include "resources/TextureResource.h" #include "resources/TextureResource.h"
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
#define ICON_TEXT_SPACING 8 // Space between [icon] and [text] (px). #define ICON_TEXT_SPACING 8.0f // Space between [icon] and [text] (px).
#define ENTRY_SPACING 16 // Space between [text] and next [icon] (px). #define ENTRY_SPACING 16.0f // Space between [text] and next [icon] (px).
static std::map<std::string, std::string> sIconPathMap {}; static std::map<std::string, std::string> sIconPathMap{};
HelpComponent::HelpComponent(Window* window) HelpComponent::HelpComponent(Window* window)
: GuiComponent(window) : GuiComponent(window)
@ -114,7 +114,7 @@ void HelpComponent::updateGrid()
std::shared_ptr<Font>& font = mStyle.font; std::shared_ptr<Font>& font = mStyle.font;
mGrid = std::make_shared<ComponentGrid>(mWindow, mGrid = std::make_shared<ComponentGrid>(mWindow,
Vector2i(static_cast<int>(mPrompts.size()) * 4, 1)); glm::ivec2{static_cast<int>(mPrompts.size()) * 4, 1});
// [icon] [spacer1] [text] [spacer2] // [icon] [spacer1] [text] [spacer2]
@ -135,7 +135,7 @@ void HelpComponent::updateGrid()
font, mStyle.textColor); font, mStyle.textColor);
labels.push_back(lbl); labels.push_back(lbl);
width += icon->getSize().x() + lbl->getSize().x() + width += icon->getSize().x + lbl->getSize().x +
((ICON_TEXT_SPACING + ENTRY_SPACING) * Renderer::getScreenWidthModifier()); ((ICON_TEXT_SPACING + ENTRY_SPACING) * Renderer::getScreenWidthModifier());
} }
@ -143,16 +143,16 @@ void HelpComponent::updateGrid()
for (unsigned int i = 0; i < icons.size(); i++) { for (unsigned int i = 0; i < icons.size(); i++) {
const int col = i * 4; const int col = i * 4;
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x() / width); mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
mGrid->setColWidthPerc(col + 1, mGrid->setColWidthPerc(col + 1,
(ICON_TEXT_SPACING * Renderer::getScreenWidthModifier()) / width); (ICON_TEXT_SPACING * Renderer::getScreenWidthModifier()) / width);
mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x() / width); mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width);
mGrid->setEntry(icons.at(i), Vector2i(col, 0), false, false); mGrid->setEntry(icons.at(i), glm::ivec2{col, 0}, false, false);
mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false); mGrid->setEntry(labels.at(i), glm::ivec2{col + 2, 0}, false, false);
} }
mGrid->setPosition(Vector3f(mStyle.position.x(), mStyle.position.y(), 0.0f)); mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
mGrid->setOrigin(mStyle.origin); mGrid->setOrigin(mStyle.origin);
} }
@ -187,9 +187,9 @@ void HelpComponent::setOpacity(unsigned char opacity)
mGrid->getChild(i)->setOpacity(opacity); mGrid->getChild(i)->setOpacity(opacity);
} }
void HelpComponent::render(const Transform4x4f& parentTrans) void HelpComponent::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
if (mGrid) if (mGrid)
mGrid->render(trans); mGrid->render(trans);

View file

@ -26,7 +26,7 @@ public:
void clearPrompts(); void clearPrompts();
void setPrompts(const std::vector<HelpPrompt>& prompts); void setPrompts(const std::vector<HelpPrompt>& prompts);
void render(const Transform4x4f& parent) override; void render(const glm::mat4& parent) override;
void setOpacity(unsigned char opacity) override; void setOpacity(unsigned char opacity) override;
void setStyle(const HelpStyle& style); void setStyle(const HelpStyle& style);

View file

@ -37,9 +37,9 @@ struct ScrollTierList {
// Default scroll tiers. // Default scroll tiers.
// clang-format off // clang-format off
const ScrollTier QUICK_SCROLL_TIERS[] = { const ScrollTier QUICK_SCROLL_TIERS[] = {
{ 500, 500 }, {500, 500},
{ 1200, 114 }, {1200, 114},
{ 0, 16 } {0, 16}
}; };
const ScrollTierList LIST_SCROLL_STYLE_QUICK = { const ScrollTierList LIST_SCROLL_STYLE_QUICK = {
3, 3,
@ -47,8 +47,8 @@ const ScrollTierList LIST_SCROLL_STYLE_QUICK = {
}; };
const ScrollTier SLOW_SCROLL_TIERS[] = { const ScrollTier SLOW_SCROLL_TIERS[] = {
{ 500, 500 }, {500, 500},
{ 0, 200 } {0, 200}
}; };
const ScrollTierList LIST_SCROLL_STYLE_SLOW = { const ScrollTierList LIST_SCROLL_STYLE_SLOW = {
@ -282,7 +282,7 @@ protected:
scroll(mScrollVelocity); scroll(mScrollVelocity);
} }
void listRenderTitleOverlay(const Transform4x4f& /*trans*/) void listRenderTitleOverlay(const glm::mat4& /*trans*/)
{ {
if (!Settings::getInstance()->getBool("ListScrollOverlay")) if (!Settings::getInstance()->getBool("ListScrollOverlay"))
return; return;

View file

@ -14,15 +14,15 @@
#include "resources/TextureResource.h" #include "resources/TextureResource.h"
#include "utils/CImgUtil.h" #include "utils/CImgUtil.h"
Vector2i ImageComponent::getTextureSize() const glm::ivec2 ImageComponent::getTextureSize() const
{ {
if (mTexture) if (mTexture)
return mTexture->getSize(); return mTexture->getSize();
else else
return Vector2i::Zero(); return glm::ivec2{};
} }
Vector2f ImageComponent::getSize() const glm::vec2 ImageComponent::getSize() const
{ {
return GuiComponent::getSize() * (mBottomRightCrop - mTopLeftCrop); return GuiComponent::getSize() * (mBottomRightCrop - mTopLeftCrop);
} }
@ -53,8 +53,8 @@ void ImageComponent::resize()
if (!mTexture) if (!mTexture)
return; return;
const Vector2f textureSize = mTexture->getSourceImageSize(); const glm::vec2 textureSize{mTexture->getSourceImageSize()};
if (textureSize == Vector2f::Zero()) if (textureSize == glm::vec2{})
return; return;
if (mTexture->isTiled()) { if (mTexture->isTiled()) {
@ -71,70 +71,69 @@ void ImageComponent::resize()
if (mTargetIsMax) { if (mTargetIsMax) {
mSize = textureSize; mSize = textureSize;
Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y())); glm::vec2 resizeScale{(mTargetSize.x / mSize.x), (mTargetSize.y / mSize.y)};
if (resizeScale.x() < resizeScale.y()) { if (resizeScale.x < resizeScale.y) {
// This will be mTargetSize.x(). We can't exceed it, nor be lower than it. // This will be mTargetSize.x. We can't exceed it, nor be lower than it.
mSize[0] *= resizeScale.x(); mSize.x *= resizeScale.x;
// We need to make sure we're not creating an image larger than max size. // We need to make sure we're not creating an image larger than max size.
mSize[1] = std::min(floorf(mSize[1] *= resizeScale.x()), mTargetSize.y()); mSize.y = std::min(floorf(mSize.y *= resizeScale.x), mTargetSize.y);
} }
else { else {
// This will be mTargetSize.y(). We can't exceed it. // This will be mTargetSize.y(). We can't exceed it.
mSize[1] = floorf(mSize[1] * resizeScale.y()); mSize.y = floorf(mSize.y * resizeScale.y);
// For SVG rasterization, always calculate width from rounded height (see comment // For SVG rasterization, always calculate width from rounded height (see comment
// above). We need to make sure we're not creating an image larger than max size. // above). We need to make sure we're not creating an image larger than max size.
mSize[0] = mSize.x = std::min((mSize.y / textureSize.y) * textureSize.x, mTargetSize.x);
std::min((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
} }
} }
else if (mTargetIsMin) { else if (mTargetIsMin) {
mSize = textureSize; mSize = textureSize;
Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y())); glm::vec2 resizeScale{(mTargetSize.x / mSize.x), (mTargetSize.y / mSize.y)};
if (resizeScale.x() > resizeScale.y()) { if (resizeScale.x > resizeScale.y) {
mSize[0] *= resizeScale.x(); mSize.x *= resizeScale.x;
mSize[1] *= resizeScale.x(); mSize.y *= resizeScale.x;
float cropPercent = (mSize.y() - mTargetSize.y()) / (mSize.y() * 2); float cropPercent = (mSize.y - mTargetSize.y) / (mSize.y * 2.0f);
crop(0, cropPercent, 0, cropPercent); crop(0.0f, cropPercent, 0.0f, cropPercent);
} }
else { else {
mSize[0] *= resizeScale.y(); mSize.x *= resizeScale.y;
mSize[1] *= resizeScale.y(); mSize.y *= resizeScale.y;
float cropPercent = (mSize.x() - mTargetSize.x()) / (mSize.x() * 2); float cropPercent = (mSize.x - mTargetSize.x) / (mSize.x * 2.0f);
crop(cropPercent, 0, cropPercent, 0); crop(cropPercent, 0.0f, cropPercent, 0.0f);
} }
// For SVG rasterization, always calculate width from rounded height (see comment // For SVG rasterization, always calculate width from rounded height (see comment
// above). We need to make sure we're not creating an image smaller than min size. // above). We need to make sure we're not creating an image smaller than min size.
mSize[1] = std::max(floorf(mSize[1]), mTargetSize.y()); mSize.y = std::max(floorf(mSize.y), mTargetSize.y);
mSize[0] = std::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x()); mSize.x = std::max((mSize.y / textureSize.y) * textureSize.x, mTargetSize.x);
} }
else { else {
// If both components are set, we just stretch. // If both components are set, we just stretch.
// If no components are set, we don't resize at all. // If no components are set, we don't resize at all.
mSize = mTargetSize == Vector2f::Zero() ? textureSize : mTargetSize; mSize = mTargetSize == glm::vec2{} ? textureSize : mTargetSize;
// If only one component is set, we resize in a way that maintains aspect ratio. // If only one component is set, we resize in a way that maintains aspect ratio.
// For SVG rasterization, we always calculate width from rounded height (see // For SVG rasterization, we always calculate width from rounded height (see
// comment above). // comment above).
if (!mTargetSize.x() && mTargetSize.y()) { if (!mTargetSize.x && mTargetSize.y) {
mSize[1] = floorf(mTargetSize.y()); mSize.y = floorf(mTargetSize.y);
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
} }
else if (mTargetSize.x() && !mTargetSize.y()) { else if (mTargetSize.x && !mTargetSize.y) {
mSize[1] = floorf((mTargetSize.x() / textureSize.x()) * textureSize.y()); mSize.y = floorf((mTargetSize.x / textureSize.x) * textureSize.y);
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
} }
} }
} }
mSize[0] = floorf(mSize.x()); mSize.x = floorf(mSize.x);
mSize[1] = floorf(mSize.y()); mSize.y = floorf(mSize.y);
// mSize.y() should already be rounded. // mSize.y() should already be rounded.
mTexture->rasterizeAt(static_cast<size_t>(mSize.x()), static_cast<size_t>(mSize.y())); mTexture->rasterizeAt(static_cast<size_t>(mSize.x), static_cast<size_t>(mSize.y));
onSizeChanged(); onSizeChanged();
} }
@ -178,7 +177,7 @@ void ImageComponent::setImage(const std::shared_ptr<TextureResource>& texture)
void ImageComponent::setResize(float width, float height) void ImageComponent::setResize(float width, float height)
{ {
mTargetSize = Vector2f(width, height); mTargetSize = glm::vec2{width, height};
mTargetIsMax = false; mTargetIsMax = false;
mTargetIsMin = false; mTargetIsMin = false;
resize(); resize();
@ -186,7 +185,7 @@ void ImageComponent::setResize(float width, float height)
void ImageComponent::setMaxSize(float width, float height) void ImageComponent::setMaxSize(float width, float height)
{ {
mTargetSize = Vector2f(width, height); mTargetSize = glm::vec2{width, height};
mTargetIsMax = true; mTargetIsMax = true;
mTargetIsMin = false; mTargetIsMin = false;
resize(); resize();
@ -194,7 +193,7 @@ void ImageComponent::setMaxSize(float width, float height)
void ImageComponent::setMinSize(float width, float height) void ImageComponent::setMinSize(float width, float height)
{ {
mTargetSize = Vector2f(width, height); mTargetSize = glm::vec2{width, height};
mTargetIsMax = false; mTargetIsMax = false;
mTargetIsMin = true; mTargetIsMin = true;
resize(); resize();
@ -203,25 +202,25 @@ void ImageComponent::setMinSize(float width, float height)
void ImageComponent::cropLeft(float percent) void ImageComponent::cropLeft(float percent)
{ {
assert(percent >= 0.0f && percent <= 1.0f); assert(percent >= 0.0f && percent <= 1.0f);
mTopLeftCrop.x() = percent; mTopLeftCrop.x = percent;
} }
void ImageComponent::cropTop(float percent) void ImageComponent::cropTop(float percent)
{ {
assert(percent >= 0.0f && percent <= 1.0f); assert(percent >= 0.0f && percent <= 1.0f);
mTopLeftCrop.y() = percent; mTopLeftCrop.y = percent;
} }
void ImageComponent::cropRight(float percent) void ImageComponent::cropRight(float percent)
{ {
assert(percent >= 0.0f && percent <= 1.0f); assert(percent >= 0.0f && percent <= 1.0f);
mBottomRightCrop.x() = 1.0f - percent; mBottomRightCrop.x = 1.0f - percent;
} }
void ImageComponent::cropBot(float percent) void ImageComponent::cropBot(float percent)
{ {
assert(percent >= 0.0f && percent <= 1.0f); assert(percent >= 0.0f && percent <= 1.0f);
mBottomRightCrop.y() = 1.0f - percent; mBottomRightCrop.y = 1.0f - percent;
} }
void ImageComponent::crop(float left, float top, float right, float bot) void ImageComponent::crop(float left, float top, float right, float bot)
@ -235,12 +234,12 @@ void ImageComponent::crop(float left, float top, float right, float bot)
void ImageComponent::uncrop() void ImageComponent::uncrop()
{ {
// Remove any applied crop. // Remove any applied crop.
crop(0, 0, 0, 0); crop(0.0f, 0.0f, 0.0f, 0.0f);
} }
void ImageComponent::cropTransparentPadding(float maxSizeX, float maxSizeY) void ImageComponent::cropTransparentPadding(float maxSizeX, float maxSizeY)
{ {
if (mSize == 0) if (mSize == glm::vec2{})
return; return;
std::vector<unsigned char> imageRGBA = mTexture.get()->getRawRGBAData(); std::vector<unsigned char> imageRGBA = mTexture.get()->getRawRGBAData();
@ -248,10 +247,10 @@ void ImageComponent::cropTransparentPadding(float maxSizeX, float maxSizeY)
if (imageRGBA.size() == 0) if (imageRGBA.size() == 0)
return; return;
Vector2i imageSize = mTexture.get()->getSize(); glm::ivec2 imageSize{mTexture.get()->getSize()};
cimg_library::CImg<unsigned char> imageCImg(imageSize.x(), imageSize.y(), 1, 4, 0); cimg_library::CImg<unsigned char> imageCImg(imageSize.x, imageSize.y, 1, 4, 0);
int paddingCoords[4] = {}; int paddingCoords[4]{};
// We need to convert our RGBA data to the CImg internal format as CImg does not interleave // We need to convert our RGBA data to the CImg internal format as CImg does not interleave
// the pixels (as in RGBARGBARGBA). // the pixels (as in RGBARGBARGBA).
@ -260,36 +259,36 @@ void ImageComponent::cropTransparentPadding(float maxSizeX, float maxSizeY)
// This will give us the coordinates for the fully transparent areas. // This will give us the coordinates for the fully transparent areas.
Utils::CImg::getTransparentPaddingCoords(imageCImg, paddingCoords); Utils::CImg::getTransparentPaddingCoords(imageCImg, paddingCoords);
Vector2f originalSize = mSize; glm::vec2 originalSize{mSize};
float cropLeft = static_cast<float>(paddingCoords[0]) / static_cast<float>(imageSize.x()); float cropLeft{static_cast<float>(paddingCoords[0]) / static_cast<float>(imageSize.x)};
float cropTop = static_cast<float>(paddingCoords[1]) / static_cast<float>(imageSize.y()); float cropTop{static_cast<float>(paddingCoords[1]) / static_cast<float>(imageSize.y)};
float cropRight = static_cast<float>(paddingCoords[2]) / static_cast<float>(imageSize.x()); float cropRight{static_cast<float>(paddingCoords[2]) / static_cast<float>(imageSize.x)};
float cropBottom = static_cast<float>(paddingCoords[3]) / static_cast<float>(imageSize.y()); float cropBottom{static_cast<float>(paddingCoords[3]) / static_cast<float>(imageSize.y)};
crop(cropLeft, cropTop, cropRight, cropBottom); crop(cropLeft, cropTop, cropRight, cropBottom);
// Cropping the image obviously leads to a reduction in size, so we need to determine // Cropping the image obviously leads to a reduction in size, so we need to determine
// how much to scale up after cropping to keep within the max size restrictions that // how much to scale up after cropping to keep within the max size restrictions that
// were passed as arguments. // were passed as arguments.
mSize.x() -= mSize.x() * (cropLeft + cropRight); mSize.x -= mSize.x * (cropLeft + cropRight);
mSize.y() -= mSize.y() * (cropTop + cropBottom); mSize.y -= mSize.y * (cropTop + cropBottom);
float scaleFactor = originalSize.y() / mSize.y(); float scaleFactor = originalSize.y / mSize.y;
if (scaleFactor * mSize.x() < maxSizeX) if (scaleFactor * mSize.x < maxSizeX)
scaleFactor = maxSizeX / mSize.x(); scaleFactor = maxSizeX / mSize.x;
if (scaleFactor * mSize.y() < maxSizeY) if (scaleFactor * mSize.y < maxSizeY)
scaleFactor = maxSizeY / mSize.y(); scaleFactor = maxSizeY / mSize.y;
if (scaleFactor * mSize.x() > maxSizeX) if (scaleFactor * mSize.x > maxSizeX)
scaleFactor = maxSizeX / mSize.x(); scaleFactor = maxSizeX / mSize.x;
if (scaleFactor * mSize.y() > maxSizeY) if (scaleFactor * mSize.y > maxSizeY)
scaleFactor = maxSizeY / mSize.y(); scaleFactor = maxSizeY / mSize.y;
setResize(mSize.x() * scaleFactor, mSize.y() * scaleFactor); setResize(mSize.x * scaleFactor, mSize.y * scaleFactor);
updateVertices(); updateVertices();
} }
@ -343,23 +342,23 @@ void ImageComponent::updateVertices()
// We go through this mess to make sure everything is properly rounded. // We go through this mess to make sure everything is properly rounded.
// If we just round vertices at the end, edge cases occur near sizes of 0.5. // If we just round vertices at the end, edge cases occur near sizes of 0.5.
const Vector2f topLeft = { 0, 0 }; const glm::vec2 topLeft{};
const Vector2f bottomRight = mSize; const glm::vec2 bottomRight{mSize};
const float px = mTexture->isTiled() ? mSize.x() / getTextureSize().x() : 1.0f; const float px{mTexture->isTiled() ? mSize.x / getTextureSize().x : 1.0f};
const float py = mTexture->isTiled() ? mSize.y() / getTextureSize().y() : 1.0f; const float py{mTexture->isTiled() ? mSize.y / getTextureSize().y : 1.0f};
// clang-format off // clang-format off
mVertices[0] = { { topLeft.x(), topLeft.y() }, { mTopLeftCrop.x(), py - mTopLeftCrop.y() }, 0 }; mVertices[0] = {{topLeft.x, topLeft.y }, {mTopLeftCrop.x, py - mTopLeftCrop.y }, 0};
mVertices[1] = { { topLeft.x(), bottomRight.y() }, { mTopLeftCrop.x(), 1.0f - mBottomRightCrop.y() }, 0 }; mVertices[1] = {{topLeft.x, bottomRight.y}, {mTopLeftCrop.x, 1.0f - mBottomRightCrop.y}, 0};
mVertices[2] = { { bottomRight.x(), topLeft.y() }, { mBottomRightCrop.x() * px, py - mTopLeftCrop.y() }, 0 }; mVertices[2] = {{bottomRight.x, topLeft.y }, {mBottomRightCrop.x * px, py - mTopLeftCrop.y }, 0};
mVertices[3] = { { bottomRight.x(), bottomRight.y() }, { mBottomRightCrop.x() * px, 1.0f - mBottomRightCrop.y() }, 0 }; mVertices[3] = {{bottomRight.x, bottomRight.y}, {mBottomRightCrop.x * px, 1.0f - mBottomRightCrop.y}, 0};
// clang-format on // clang-format on
updateColors(); updateColors();
// Round vertices. // Round vertices.
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
mVertices[i].pos.round(); mVertices[i].pos = glm::round(mVertices[i].pos);
if (mFlipX) { if (mFlipX) {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -387,23 +386,23 @@ void ImageComponent::updateColors()
mVertices[3].col = colorEnd; mVertices[3].col = colorEnd;
} }
void ImageComponent::render(const Transform4x4f& parentTrans) void ImageComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible()) if (!isVisible())
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
if (mTexture && mOpacity > 0) { if (mTexture && mOpacity > 0) {
if (Settings::getInstance()->getBool("DebugImage")) { if (Settings::getInstance()->getBool("DebugImage")) {
Vector2f targetSizePos = (mTargetSize - mSize) * mOrigin * -1; glm::vec2 targetSizePos{(mTargetSize - mSize) * mOrigin * glm::vec2{-1.0f}};
Renderer::drawRect(targetSizePos.x(), targetSizePos.y(), mTargetSize.x(), Renderer::drawRect(targetSizePos.x, targetSizePos.y, mTargetSize.x, mTargetSize.y,
mTargetSize.y(), 0xFF000033, 0xFF000033); 0xFF000033, 0xFF000033);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0xFF000033, 0xFF000033); Renderer::drawRect(0.0f, 0.0f, mSize.x, mSize.y, 0xFF000033, 0xFF000033);
} }
// An image with zero size would normally indicate a corrupt image file. // An image with zero size would normally indicate a corrupt image file.
if (mTexture->isInitialized() && mTexture->getSize() != 0) { if (mTexture->isInitialized() && mTexture->getSize() != glm::ivec2{}) {
// Actually draw the image. // Actually draw the image.
// The bind() function returns false if the texture is not currently loaded. A blank // The bind() function returns false if the texture is not currently loaded. A blank
// texture is bound in this case but we want to handle a fade so it doesn't just // texture is bound in this case but we want to handle a fade so it doesn't just
@ -483,17 +482,17 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (!elem) if (!elem)
return; return;
Vector2f scale = getParent() ? getParent()->getSize() : glm::vec2 scale{getParent() ? getParent()->getSize() :
Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight()))};
if (properties & ThemeFlags::SIZE) { if (properties & ThemeFlags::SIZE) {
if (elem->has("size")) if (elem->has("size"))
setResize(elem->get<Vector2f>("size") * scale); setResize(elem->get<glm::vec2>("size") * scale);
else if (elem->has("maxSize")) else if (elem->has("maxSize"))
setMaxSize(elem->get<Vector2f>("maxSize") * scale); setMaxSize(elem->get<glm::vec2>("maxSize") * scale);
else if (elem->has("minSize")) else if (elem->has("minSize"))
setMinSize(elem->get<Vector2f>("minSize") * scale); setMinSize(elem->get<glm::vec2>("minSize") * scale);
} }
if (elem->has("default")) if (elem->has("default"))

View file

@ -10,7 +10,6 @@
#define ES_CORE_COMPONENTS_IMAGE_COMPONENT_H #define ES_CORE_COMPONENTS_IMAGE_COMPONENT_H
#include "GuiComponent.h" #include "GuiComponent.h"
#include "math/Vector2i.h"
#include "renderers/Renderer.h" #include "renderers/Renderer.h"
class TextureResource; class TextureResource;
@ -39,18 +38,18 @@ public:
// Can be set before or after an image is loaded. // Can be set before or after an image is loaded.
// setMaxSize() and setResize() are mutually exclusive. // setMaxSize() and setResize() are mutually exclusive.
void setResize(float width, float height) override; void setResize(float width, float height) override;
void setResize(const Vector2f& size) { setResize(size.x(), size.y()); } void setResize(const glm::vec2& size) { setResize(size.x, size.y); }
// Resize the image to be as large as possible but fit within a box of this size. // Resize the image to be as large as possible but fit within a box of this size.
// Can be set before or after an image is loaded. // Can be set before or after an image is loaded.
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive. // Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
void setMaxSize(float width, float height); void setMaxSize(float width, float height);
void setMaxSize(const Vector2f& size) { setMaxSize(size.x(), size.y()); } void setMaxSize(const glm::vec2& size) { setMaxSize(size.x, size.y); }
void setMinSize(float width, float height); void setMinSize(float width, float height);
void setMinSize(const Vector2f& size) { setMinSize(size.x(), size.y()); } void setMinSize(const glm::vec2& size) { setMinSize(size.x, size.y); }
Vector2f getRotationSize() const override { return mRotateByTargetSize ? mTargetSize : mSize; } glm::vec2 getRotationSize() const override { return mRotateByTargetSize ? mTargetSize : mSize; }
// Applied AFTER image positioning and sizing. // Applied AFTER image positioning and sizing.
// cropTop(0.2) will crop 20% of the top of the image. // cropTop(0.2) will crop 20% of the top of the image.
@ -83,14 +82,14 @@ public:
// Returns the size of the current texture, or (0, 0) if none is loaded. // Returns the size of the current texture, or (0, 0) if none is loaded.
// May be different than drawn size (use getSize() for that). // May be different than drawn size (use getSize() for that).
Vector2i getTextureSize() const; glm::ivec2 getTextureSize() const;
Vector2f getSize() const override; glm::vec2 getSize() const override;
bool hasImage() { return static_cast<bool>(mTexture); } bool hasImage() { return static_cast<bool>(mTexture); }
std::shared_ptr<TextureResource> getTexture() { return mTexture; } std::shared_ptr<TextureResource> getTexture() { return mTexture; }
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view, const std::string& view,
@ -100,7 +99,7 @@ public:
virtual std::vector<HelpPrompt> getHelpPrompts() override; virtual std::vector<HelpPrompt> getHelpPrompts() override;
private: private:
Vector2f mTargetSize; glm::vec2 mTargetSize;
bool mFlipX, mFlipY, mTargetIsMax, mTargetIsMin; bool mFlipX, mFlipY, mTargetIsMax, mTargetIsMin;
@ -127,8 +126,8 @@ private:
bool mDynamic; bool mDynamic;
bool mRotateByTargetSize; bool mRotateByTargetSize;
Vector2f mTopLeftCrop; glm::vec2 mTopLeftCrop;
Vector2f mBottomRightCrop; glm::vec2 mBottomRightCrop;
}; };
#endif // ES_CORE_COMPONENTS_IMAGE_COMPONENT_H #endif // ES_CORE_COMPONENTS_IMAGE_COMPONENT_H

View file

@ -61,7 +61,7 @@ public:
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view, const std::string& view,
const std::string& element, const std::string& element,
@ -98,13 +98,13 @@ private:
// Tiles. // Tiles.
bool mLastRowPartial; bool mLastRowPartial;
Vector2f mAutoLayout; glm::vec2 mAutoLayout;
float mAutoLayoutZoom; float mAutoLayoutZoom;
Vector4f mPadding; glm::vec4 mPadding;
Vector2f mMargin; glm::vec2 mMargin;
Vector2f mTileSize; glm::vec2 mTileSize;
Vector2i mGridDimension; glm::ivec2 mGridDimension;
std::shared_ptr<ThemeData> mTheme; std::shared_ptr<ThemeData> mTheme;
std::vector<std::shared_ptr<GridTileComponent>> mTiles; std::vector<std::shared_ptr<GridTileComponent>> mTiles;
@ -126,14 +126,14 @@ template <typename T>
ImageGridComponent<T>::ImageGridComponent(Window* window) ImageGridComponent<T>::ImageGridComponent(Window* window)
: IList<ImageGridData, T>(window) : IList<ImageGridData, T>(window)
{ {
Vector2f screen = Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2 screen{static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight())};
mCamera = 0.0; mCamera = 0.0f;
mCameraDirection = 1.0; mCameraDirection = 1.0f;
mAutoLayout = Vector2f::Zero(); mAutoLayout = glm::vec2{};
mAutoLayoutZoom = 1.0; mAutoLayoutZoom = 1.0f;
mStartPosition = 0; mStartPosition = 0;
@ -144,7 +144,7 @@ ImageGridComponent<T>::ImageGridComponent(Window* window)
mSize = screen * 0.80f; mSize = screen * 0.80f;
mMargin = screen * 0.07f; mMargin = screen * 0.07f;
mPadding = Vector4f::Zero(); mPadding = {};
mTileSize = GridTileComponent::getDefaultTileSize(); mTileSize = GridTileComponent::getDefaultTileSize();
mAnimate = true; mAnimate = true;
@ -171,7 +171,7 @@ template <typename T> bool ImageGridComponent<T>::input(InputConfig* config, Inp
if (input.value != 0) { if (input.value != 0) {
int idx = isVertical() ? 0 : 1; int idx = isVertical() ? 0 : 1;
Vector2i dir = Vector2i::Zero(); glm::ivec2 dir{};
if (config->isMappedLike("up", input)) if (config->isMappedLike("up", input))
dir[1 ^ idx] = -1; dir[1 ^ idx] = -1;
else if (config->isMappedLike("down", input)) else if (config->isMappedLike("down", input))
@ -181,11 +181,11 @@ template <typename T> bool ImageGridComponent<T>::input(InputConfig* config, Inp
else if (config->isMappedLike("right", input)) else if (config->isMappedLike("right", input))
dir[0 ^ idx] = 1; dir[0 ^ idx] = 1;
if (dir != Vector2i::Zero()) { if (dir != glm::ivec2{}) {
if (isVertical()) if (isVertical())
listInput(dir.x() + dir.y() * mGridDimension.x()); listInput(dir.x + dir.y * mGridDimension.x);
else else
listInput(dir.x() + dir.y() * mGridDimension.y()); listInput(dir.x + dir.y * mGridDimension.y);
return true; return true;
} }
} }
@ -208,17 +208,15 @@ template <typename T> void ImageGridComponent<T>::update(int deltaTime)
(*it)->update(deltaTime); (*it)->update(deltaTime);
} }
template <typename T> void ImageGridComponent<T>::render(const Transform4x4f& parentTrans) template <typename T> void ImageGridComponent<T>::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = getTransform() * parentTrans; glm::mat4 trans{getTransform() * parentTrans};
Transform4x4f tileTrans = trans; glm::mat4 tileTrans{trans};
float offsetX = float offsetX{isVertical() ? 0.0f : mCamera * mCameraDirection * (mTileSize.x + mMargin.x)};
isVertical() ? 0.0f : mCamera * mCameraDirection * (mTileSize.x() + mMargin.x()); float offsetY{isVertical() ? mCamera * mCameraDirection * (mTileSize.y + mMargin.y) : 0.0f};
float offsetY =
isVertical() ? mCamera * mCameraDirection * (mTileSize.y() + mMargin.y()) : 0.0f;
tileTrans.translate(Vector3f(offsetX, offsetY, 0.0)); tileTrans = glm::translate(tileTrans, glm::vec3{offsetX, offsetY, 0.0f});
if (mEntriesDirty) { if (mEntriesDirty) {
updateTiles(); updateTiles();
@ -226,13 +224,13 @@ template <typename T> void ImageGridComponent<T>::render(const Transform4x4f& pa
} }
// Create a clipRect to hide tiles used to buffer texture loading. // Create a clipRect to hide tiles used to buffer texture loading.
float scaleX = trans.r0().x(); float scaleX = trans[0].x;
float scaleY = trans.r1().y(); float scaleY = trans[1].y;
Vector2i pos(static_cast<int>(std::round(trans.translation()[0])), glm::ivec2 pos{static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans.translation()[1]))); static_cast<int>(std::round(trans[3].y))};
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)), glm::ivec2 size{static_cast<int>(std::round(mSize.x * scaleX)),
static_cast<int>(std::round(mSize.y() * scaleY))); static_cast<int>(std::round(mSize.y * scaleY))};
Renderer::pushClipRect(pos, size); Renderer::pushClipRect(pos, size);
@ -271,20 +269,20 @@ void ImageGridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
// Keep the theme pointer to apply it on the tiles later on. // Keep the theme pointer to apply it on the tiles later on.
mTheme = theme; mTheme = theme;
Vector2f screen = Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2 screen{static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight())};
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "imagegrid"); const ThemeData::ThemeElement* elem = theme->getElement(view, element, "imagegrid");
if (elem) { if (elem) {
if (elem->has("margin")) if (elem->has("margin"))
mMargin = elem->get<Vector2f>("margin") * screen; mMargin = elem->get<glm::vec2>("margin") * screen;
if (elem->has("padding")) if (elem->has("padding"))
mPadding = elem->get<Vector4f>("padding") * mPadding =
Vector4f(screen.x(), screen.y(), screen.x(), screen.y()); elem->get<glm::vec4>("padding") * glm::vec4{screen.x, screen.y, screen.x, screen.y};
if (elem->has("autoLayout")) if (elem->has("autoLayout"))
mAutoLayout = elem->get<Vector2f>("autoLayout"); mAutoLayout = elem->get<glm::vec2>("autoLayout");
if (elem->has("autoLayoutSelectedZoom")) if (elem->has("autoLayoutSelectedZoom"))
mAutoLayoutZoom = elem->get<float>("autoLayoutSelectedZoom"); mAutoLayoutZoom = elem->get<float>("autoLayoutSelectedZoom");
@ -369,7 +367,7 @@ void ImageGridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
// grid dimension, and then (re)build the tiles. // grid dimension, and then (re)build the tiles.
elem = theme->getElement(view, "default", "gridtile"); elem = theme->getElement(view, "default", "gridtile");
mTileSize = elem && elem->has("size") ? elem->get<Vector2f>("size") * screen : mTileSize = elem && elem->has("size") ? elem->get<glm::vec2>("size") * screen :
GridTileComponent::getDefaultTileSize(); GridTileComponent::getDefaultTileSize();
// Apply size property which will trigger a call to onSizeChanged() which will build the tiles. // Apply size property which will trigger a call to onSizeChanged() which will build the tiles.
@ -401,8 +399,8 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
int oldStart = mStartPosition; int oldStart = mStartPosition;
int dimScrollable = (isVertical() ? mGridDimension.y() : mGridDimension.x()) - 2 * EXTRAITEMS; int dimScrollable = (isVertical() ? mGridDimension.y : mGridDimension.x) - 2 * EXTRAITEMS;
int dimOpposite = isVertical() ? mGridDimension.x() : mGridDimension.y(); int dimOpposite = isVertical() ? mGridDimension.x : mGridDimension.y;
int centralCol = static_cast<int>((static_cast<float>(dimScrollable) - 0.5f) / 2.0f); int centralCol = static_cast<int>((static_cast<float>(dimScrollable) - 0.5f) / 2.0f);
int maxCentralCol = dimScrollable / 2; int maxCentralCol = dimScrollable / 2;
@ -449,7 +447,7 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
} }
} }
Vector3f oldPos = Vector3f::Zero(); glm::vec3 oldPos{};
if (oldTile != nullptr && oldTile != newTile) { if (oldTile != nullptr && oldTile != newTile) {
oldPos = oldTile->getBackgroundPosition(); oldPos = oldTile->getBackgroundPosition();
@ -457,7 +455,7 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
} }
if (newTile != nullptr) if (newTile != nullptr)
newTile->setSelected(true, true, oldPos == Vector3f::Zero() ? nullptr : &oldPos, true); newTile->setSelected(true, true, oldPos == glm::vec3{} ? nullptr : &oldPos, true);
} }
int firstVisibleCol = mStartPosition / dimOpposite; int firstVisibleCol = mStartPosition / dimOpposite;
@ -506,7 +504,7 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
if (!moveCamera) if (!moveCamera)
return; return;
t -= 1.0f; // Cubic ease out. t -= 1.0f;
float pct = Math::lerp(0, 1.0f, t * t * t + 1.0f); float pct = Math::lerp(0, 1.0f, t * t * t + 1.0f);
t = startPos * (1.0f - pct) + endPos * pct; t = startPos * (1.0f - pct) + endPos * pct;
mCamera = t; mCamera = t;
@ -530,35 +528,33 @@ template <typename T> void ImageGridComponent<T>::buildTiles()
calcGridDimension(); calcGridDimension();
if (mCenterSelection) { if (mCenterSelection) {
int dimScrollable = int dimScrollable = (isVertical() ? mGridDimension.y : mGridDimension.x) - 2 * EXTRAITEMS;
(isVertical() ? mGridDimension.y() : mGridDimension.x()) - 2 * EXTRAITEMS;
mStartPosition -= static_cast<int>(floorf(dimScrollable / 2.0f)); mStartPosition -= static_cast<int>(floorf(dimScrollable / 2.0f));
} }
Vector2f tileDistance = mTileSize + mMargin; glm::vec2 tileDistance{mTileSize + mMargin};
if (mAutoLayout.x() != 0.0f && mAutoLayout.y() != 0.0f) { if (mAutoLayout.x != 0.0f && mAutoLayout.y != 0.0f) {
auto x = auto x = (mSize.x - (mMargin.x * (mAutoLayout.x - 1.0f)) - mPadding.x - mPadding.z) /
(mSize.x() - (mMargin.x() * (mAutoLayout.x() - 1.0f)) - mPadding.x() - mPadding.z()) / static_cast<int>(mAutoLayout.x);
static_cast<int>(mAutoLayout.x()); auto y = (mSize.y - (mMargin.y * (mAutoLayout.y - 1.0f)) - mPadding.y - mPadding.w) /
auto y = static_cast<int>(mAutoLayout.y);
(mSize.y() - (mMargin.y() * (mAutoLayout.y() - 1.0f)) - mPadding.y() - mPadding.w()) /
static_cast<int>(mAutoLayout.y());
mTileSize = Vector2f(x, y); mTileSize = glm::vec2{x, y};
tileDistance = mTileSize + mMargin; tileDistance = mTileSize + mMargin;
} }
bool vert = isVertical(); bool vert = isVertical();
Vector2f startPosition = mTileSize / 2.0f; glm::vec2 startPosition{mTileSize / 2.0f};
startPosition += mPadding.v2(); startPosition.x += mPadding.x;
startPosition.y += mPadding.y;
int X; int X;
int Y; int Y;
// Layout tile size and position. // Layout tile size and position.
for (int y = 0; y < (vert ? mGridDimension.y() : mGridDimension.x()); y++) { for (int y = 0; y < (vert ? mGridDimension.y : mGridDimension.x); y++) {
for (int x = 0; x < (vert ? mGridDimension.x() : mGridDimension.y()); x++) { for (int x = 0; x < (vert ? mGridDimension.x : mGridDimension.y); x++) {
// Create tiles. // Create tiles.
auto tile = std::make_shared<GridTileComponent>(mWindow); auto tile = std::make_shared<GridTileComponent>(mWindow);
@ -567,15 +563,15 @@ template <typename T> void ImageGridComponent<T>::buildTiles()
X = vert ? x : y - EXTRAITEMS; X = vert ? x : y - EXTRAITEMS;
Y = vert ? y - EXTRAITEMS : x; Y = vert ? y - EXTRAITEMS : x;
tile->setPosition(X * tileDistance.x() + startPosition.x(), tile->setPosition(X * tileDistance.x + startPosition.x,
Y * tileDistance.y() + startPosition.y()); Y * tileDistance.y + startPosition.y);
tile->setOrigin(0.5f, 0.5f); tile->setOrigin(0.5f, 0.5f);
tile->setImage(""); tile->setImage("");
if (mTheme) if (mTheme)
tile->applyTheme(mTheme, "grid", "gridtile", ThemeFlags::ALL); tile->applyTheme(mTheme, "grid", "gridtile", ThemeFlags::ALL);
if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0) if (mAutoLayout.x != 0 && mAutoLayout.y != 0.0f)
tile->forceSize(mTileSize, mAutoLayoutZoom); tile->forceSize(mTileSize, mAutoLayoutZoom);
mTiles.push_back(tile); mTiles.push_back(tile);
@ -617,7 +613,7 @@ void ImageGridComponent<T>::updateTiles(bool ascending,
int end = ascending ? static_cast<int>(mTiles.size()) : -1; int end = ascending ? static_cast<int>(mTiles.size()) : -1;
int img = mStartPosition + ti; int img = mStartPosition + ti;
img -= EXTRAITEMS * (isVertical() ? mGridDimension.x() : mGridDimension.y()); img -= EXTRAITEMS * (isVertical() ? mGridDimension.x : mGridDimension.y);
// Update the tiles. // Update the tiles.
while (ti != end) { while (ti != end) {
@ -677,7 +673,7 @@ void ImageGridComponent<T>::updateTileAtPos(int tilePos,
if (idx < 0 || idx >= mTiles.size()) if (idx < 0 || idx >= mTiles.size())
idx = 0; idx = 0;
Vector3f pos = mTiles.at(idx)->getBackgroundPosition(); glm::vec3 pos{mTiles.at(idx)->getBackgroundPosition()};
tile->setSelected(true, allowAnimation, &pos); tile->setSelected(true, allowAnimation, &pos);
} }
else { else {
@ -693,30 +689,30 @@ template <typename T> void ImageGridComponent<T>::calcGridDimension()
{ {
// grid_size = columns * tile_size + (columns - 1) * margin // grid_size = columns * tile_size + (columns - 1) * margin
// <=> columns = (grid_size + margin) / (tile_size + margin) // <=> columns = (grid_size + margin) / (tile_size + margin)
Vector2f gridDimension = (mSize + mMargin) / (mTileSize + mMargin); glm::vec2 gridDimension{(mSize + mMargin) / (mTileSize + mMargin)};
if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0) if (mAutoLayout.x != 0.0f && mAutoLayout.y != 0.0f)
gridDimension = mAutoLayout; gridDimension = mAutoLayout;
mLastRowPartial = floorf(gridDimension.y()) != gridDimension.y(); mLastRowPartial = floorf(gridDimension.y) != gridDimension.y;
// Ceil y dim so we can display partial last row. // Ceil y dim so we can display partial last row.
mGridDimension = Vector2i(static_cast<const int>(gridDimension.x()), mGridDimension = glm::ivec2{static_cast<const int>(gridDimension.x),
static_cast<const int>(ceilf(gridDimension.y()))); static_cast<const int>(ceilf(gridDimension.y))};
// Grid dimension validation. // Grid dimension validation.
if (mGridDimension.x() < 1) { if (mGridDimension.x < 1) {
LOG(LogError) << "Theme defined grid X dimension below 1"; LOG(LogError) << "Theme defined grid X dimension below 1";
} }
if (mGridDimension.y() < 1) { if (mGridDimension.y < 1) {
LOG(LogError) << "Theme defined grid Y dimension below 1"; LOG(LogError) << "Theme defined grid Y dimension below 1";
} }
// Add extra tiles to both sides. // Add extra tiles to both sides.
if (isVertical()) if (isVertical())
mGridDimension.y() += 2 * EXTRAITEMS; mGridDimension.y += 2 * EXTRAITEMS;
else else
mGridDimension.x() += 2 * EXTRAITEMS; mGridDimension.x += 2 * EXTRAITEMS;
} }
template <typename T> bool ImageGridComponent<T>::isScrollLoop() template <typename T> bool ImageGridComponent<T>::isScrollLoop()
@ -724,8 +720,8 @@ template <typename T> bool ImageGridComponent<T>::isScrollLoop()
if (!mScrollLoop) if (!mScrollLoop)
return false; return false;
if (isVertical()) if (isVertical())
return (mGridDimension.x() * (mGridDimension.y() - 2 * EXTRAITEMS)) <= mEntries.size(); return (mGridDimension.x * (mGridDimension.y - 2 * EXTRAITEMS)) <= mEntries.size();
return (mGridDimension.y() * (mGridDimension.x() - 2 * EXTRAITEMS)) <= mEntries.size(); return (mGridDimension.y * (mGridDimension.x - 2 * EXTRAITEMS)) <= mEntries.size();
} }
#endif // ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H #endif // ES_CORE_COMPONENTS_IMAGE_GRID_COMPONENT_H

View file

@ -21,7 +21,7 @@ MenuComponent::MenuComponent(Window* window,
const std::shared_ptr<Font>& titleFont) const std::shared_ptr<Font>& titleFont)
: GuiComponent(window) : GuiComponent(window)
, mBackground(window) , mBackground(window)
, mGrid(window, Vector2i(1, 3)) , mGrid(window, glm::ivec2{1, 3})
, mNeedsSaving(false) , mNeedsSaving(false)
{ {
addChild(&mBackground); addChild(&mBackground);
@ -34,11 +34,11 @@ MenuComponent::MenuComponent(Window* window,
mTitle->setHorizontalAlignment(ALIGN_CENTER); mTitle->setHorizontalAlignment(ALIGN_CENTER);
mTitle->setColor(0x555555FF); mTitle->setColor(0x555555FF);
setTitle(title, titleFont); setTitle(title, titleFont);
mGrid.setEntry(mTitle, Vector2i(0, 0), false); mGrid.setEntry(mTitle, glm::ivec2{}, false);
// Set up list which will never change (externally, anyway). // Set up list which will never change (externally, anyway).
mList = std::make_shared<ComponentList>(mWindow); mList = std::make_shared<ComponentList>(mWindow);
mGrid.setEntry(mList, Vector2i(0, 1), true); mGrid.setEntry(mList, glm::ivec2{0, 1}, true);
updateGrid(); updateGrid();
updateSize(); updateSize();
@ -74,7 +74,7 @@ void MenuComponent::setTitle(std::string title, const std::shared_ptr<Font>& fon
float MenuComponent::getButtonGridHeight() const float MenuComponent::getButtonGridHeight() const
{ {
return (mButtonGrid ? mButtonGrid->getSize().y() : return (mButtonGrid ? mButtonGrid->getSize().y :
Font::get(FONT_SIZE_MEDIUM)->getHeight() + Font::get(FONT_SIZE_MEDIUM)->getHeight() +
(BUTTON_GRID_VERT_PADDING * Renderer::getScreenHeightModifier())); (BUTTON_GRID_VERT_PADDING * Renderer::getScreenHeightModifier()));
} }
@ -106,11 +106,11 @@ void MenuComponent::updateSize()
void MenuComponent::onSizeChanged() void MenuComponent::onSizeChanged()
{ {
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3{}, glm::vec2{-32.0f, -32.0f});
// Update grid row/column sizes. // Update grid row/column sizes.
mGrid.setRowHeightPerc(0, TITLE_HEIGHT / mSize.y()); mGrid.setRowHeightPerc(0, TITLE_HEIGHT / mSize.y);
mGrid.setRowHeightPerc(2, getButtonGridHeight() / mSize.y()); mGrid.setRowHeightPerc(2, getButtonGridHeight() / mSize.y);
mGrid.setSize(mSize); mGrid.setSize(mSize);
} }
@ -134,7 +134,7 @@ void MenuComponent::updateGrid()
if (mButtons.size()) { if (mButtons.size()) {
mButtonGrid = makeButtonGrid(mWindow, mButtons); mButtonGrid = makeButtonGrid(mWindow, mButtons);
mGrid.setEntry(mButtonGrid, Vector2i(0, 2), true, false); mGrid.setEntry(mButtonGrid, glm::ivec2{0, 2}, true, false);
} }
} }
@ -142,26 +142,27 @@ std::shared_ptr<ComponentGrid> makeButtonGrid(
Window* window, const std::vector<std::shared_ptr<ButtonComponent>>& buttons) Window* window, const std::vector<std::shared_ptr<ButtonComponent>>& buttons)
{ {
std::shared_ptr<ComponentGrid> buttonGrid = std::shared_ptr<ComponentGrid> buttonGrid =
std::make_shared<ComponentGrid>(window, Vector2i(static_cast<int>(buttons.size()), 2)); std::make_shared<ComponentGrid>(window, glm::ivec2{static_cast<int>(buttons.size()), 2});
// Initialize to padding. // Initialize to padding.
float buttonGridWidth = float buttonGridWidth =
BUTTON_GRID_HORIZ_PADDING * Renderer::getScreenWidthModifier() * buttons.size(); BUTTON_GRID_HORIZ_PADDING * Renderer::getScreenWidthModifier() * buttons.size();
for (int i = 0; i < static_cast<int>(buttons.size()); i++) { for (int i = 0; i < static_cast<int>(buttons.size()); i++) {
buttonGrid->setEntry(buttons.at(i), Vector2i(i, 0), true, false); buttonGrid->setEntry(buttons.at(i), glm::ivec2{i, 0}, true, false);
buttonGridWidth += buttons.at(i)->getSize().x(); buttonGridWidth += buttons.at(i)->getSize().x;
} }
for (unsigned int i = 0; i < buttons.size(); i++) for (unsigned int i = 0; i < buttons.size(); i++)
buttonGrid->setColWidthPerc( buttonGrid->setColWidthPerc(
i, (buttons.at(i)->getSize().x() + i, (buttons.at(i)->getSize().x +
BUTTON_GRID_HORIZ_PADDING * Renderer::getScreenWidthModifier()) / BUTTON_GRID_HORIZ_PADDING * Renderer::getScreenWidthModifier()) /
buttonGridWidth); buttonGridWidth);
buttonGrid->setSize(buttonGridWidth, buttonGrid->setSize(buttonGridWidth,
buttons.at(0)->getSize().y() + buttons.at(0)->getSize().y +
(BUTTON_GRID_VERT_PADDING * Renderer::getScreenHeightModifier()) + 2); (BUTTON_GRID_VERT_PADDING * Renderer::getScreenHeightModifier()) +
2.0f);
// Spacer row to deal with dropshadow to make buttons look centered. // Spacer row to deal with dropshadow to make buttons look centered.
buttonGrid->setRowHeightPerc(1, 2 / buttonGrid->getSize().y()); buttonGrid->setRowHeightPerc(1, 2.0f / buttonGrid->getSize().y);
return buttonGrid; return buttonGrid;
} }

View file

@ -61,52 +61,51 @@ void NinePatchComponent::buildVertices()
mTexture = TextureResource::get(mPath, false, false, true, scaleFactor); mTexture = TextureResource::get(mPath, false, false, true, scaleFactor);
if (mTexture->getSize() == Vector2i::Zero()) { if (mTexture->getSize() == glm::ivec2{}) {
mVertices = nullptr; mVertices = nullptr;
LOG(LogWarning) << "NinePatchComponent has no texture"; LOG(LogWarning) << "NinePatchComponent has no texture";
return; return;
} }
Vector2f texSize;
mVertices = new Renderer::Vertex[6 * 9]; mVertices = new Renderer::Vertex[6 * 9];
texSize = Vector2f(static_cast<float>(mTexture->getSize().x()), glm::vec2 texSize{static_cast<float>(mTexture->getSize().x),
static_cast<float>(mTexture->getSize().y())); static_cast<float>(mTexture->getSize().y)};
// clang-format off const float imgSizeX[3]{mCornerSize.x, mSize.x - mCornerSize.x * 2.0f, mCornerSize.x};
const float imgSizeX[3] = { mCornerSize.x(), mSize.x() - mCornerSize.x() * 2.0f, mCornerSize.x() }; const float imgSizeY[3]{mCornerSize.y, mSize.y - mCornerSize.y * 2.0f, mCornerSize.y};
const float imgSizeY[3] = { mCornerSize.y(), mSize.y() - mCornerSize.y() * 2.0f, mCornerSize.y() }; const float imgPosX[3]{0, imgSizeX[0], imgSizeX[0] + imgSizeX[1]};
const float imgPosX[3] = { 0, imgSizeX[0], imgSizeX[0] + imgSizeX[1] }; const float imgPosY[3]{0, imgSizeY[0], imgSizeY[0] + imgSizeY[1]};
const float imgPosY[3] = { 0, imgSizeY[0], imgSizeY[0] + imgSizeY[1] };
// The "1 +" in posY and "-" in sizeY is to deal with texture coordinates having a bottom // The "1 +" in posY and "-" in sizeY is to deal with texture coordinates having a bottom
// left corner origin vs. verticies having a top left origin. // left corner origin vs. verticies having a top left origin.
const float texSizeX[3] = { mCornerSize.x() / texSize.x(), (texSize.x() - mCornerSize.x() * 2.0f) / texSize.x(), mCornerSize.x() / texSize.x() }; const float texSizeX[3]{mCornerSize.x / texSize.x, (texSize.x - mCornerSize.x * 2.0f) / texSize.x, mCornerSize.x / texSize.x};
const float texSizeY[3] = { -mCornerSize.y() / texSize.y(), -(texSize.y() - mCornerSize.y() * 2.0f) / texSize.y(), -mCornerSize.y() / texSize.y() }; const float texSizeY[3]{-mCornerSize.y / texSize.y, -(texSize.y - mCornerSize.y * 2.0f) / texSize.y, -mCornerSize.y / texSize.y};
const float texPosX[3] = { 0.0f, texSizeX[0], texSizeX[0] + texSizeX[1] };
const float texPosY[3] = { 1.0f, 1.0f + texSizeY[0], 1.0f + texSizeY[0] + texSizeY[1] }; const float texPosX[3]{0.0f, texSizeX[0], texSizeX[0] + texSizeX[1]};
const float texPosY[3]{1.0f, 1.0f + texSizeY[0], 1.0f + texSizeY[0] + texSizeY[1]};
// clang-format on // clang-format on
int v = 0; int v = 0;
for (int slice = 0; slice < 9; slice++) { for (int slice = 0; slice < 9; slice++) {
const int sliceX = slice % 3; const int sliceX{slice % 3};
const int sliceY = slice / 3; const int sliceY{slice / 3};
const Vector2f imgPos = Vector2f(imgPosX[sliceX], imgPosY[sliceY]); const glm::vec2 imgPos{imgPosX[sliceX], imgPosY[sliceY]};
const Vector2f imgSize = Vector2f(imgSizeX[sliceX], imgSizeY[sliceY]); const glm::vec2 imgSize{imgSizeX[sliceX], imgSizeY[sliceY]};
const Vector2f texPos = Vector2f(texPosX[sliceX], texPosY[sliceY]); const glm::vec2 texPos{texPosX[sliceX], texPosY[sliceY]};
const Vector2f texSize = Vector2f(texSizeX[sliceX], texSizeY[sliceY]); const glm::vec2 texSize{texSizeX[sliceX], texSizeY[sliceY]};
// clang-format off // clang-format off
mVertices[v + 1] = { { imgPos.x() , imgPos.y() }, { texPos.x(), texPos.y() }, 0 }; mVertices[v + 1] = {{imgPos.x , imgPos.y }, {texPos.x, texPos.y }, 0};
mVertices[v + 2] = { { imgPos.x() , imgPos.y() + imgSize.y() }, { texPos.x(), texPos.y() + texSize.y() }, 0 }; mVertices[v + 2] = {{imgPos.x , imgPos.y + imgSize.y}, {texPos.x, texPos.y + texSize.y}, 0};
mVertices[v + 3] = { { imgPos.x() + imgSize.x(), imgPos.y() }, { texPos.x() + texSize.x(), texPos.y() }, 0 }; mVertices[v + 3] = {{imgPos.x + imgSize.x, imgPos.y }, {texPos.x + texSize.x, texPos.y }, 0};
mVertices[v + 4] = { { imgPos.x() + imgSize.x(), imgPos.y() + imgSize.y() }, { texPos.x() + texSize.x(), texPos.y() + texSize.y() }, 0 }; mVertices[v + 4] = {{imgPos.x + imgSize.x, imgPos.y + imgSize.y}, {texPos.x + texSize.x, texPos.y + texSize.y}, 0};
// clang-format on // clang-format on
// Round vertices. // Round vertices.
for (int i = 1; i < 5; i++) for (int i = 1; i < 5; i++)
mVertices[v + i].pos.round(); mVertices[v + i].pos = glm::round(mVertices[v + i].pos);
// Make duplicates of first and last vertex so this can be rendered as a triangle strip. // Make duplicates of first and last vertex so this can be rendered as a triangle strip.
mVertices[v + 0] = mVertices[v + 1]; mVertices[v + 0] = mVertices[v + 1];
@ -118,12 +117,12 @@ void NinePatchComponent::buildVertices()
updateColors(); updateColors();
} }
void NinePatchComponent::render(const Transform4x4f& parentTrans) void NinePatchComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible()) if (!isVisible())
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
if (mTexture && mVertices != nullptr) { if (mTexture && mVertices != nullptr) {
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
@ -144,17 +143,15 @@ void NinePatchComponent::render(const Transform4x4f& parentTrans)
renderChildren(trans); renderChildren(trans);
} }
void NinePatchComponent::onSizeChanged() { buildVertices(); } void NinePatchComponent::fitTo(glm::vec2 size, glm::vec3 position, glm::vec2 padding)
void NinePatchComponent::fitTo(Vector2f size, Vector3f position, Vector2f padding)
{ {
size += padding; size += padding;
position[0] -= padding.x() / 2.0f; position[0] -= padding.x / 2.0f;
position[1] -= padding.y() / 2.0f; position[1] -= padding.y / 2.0f;
setSize(size + mCornerSize * 2.0f); setSize(size + mCornerSize * 2.0f);
setPosition(position.x() + Math::lerp(-mCornerSize.x(), mCornerSize.x(), mOrigin.x()), setPosition(position.x + Math::lerp(-mCornerSize.x, mCornerSize.x, mOrigin.x),
position.y() + Math::lerp(-mCornerSize.y(), mCornerSize.y(), mOrigin.y())); position.y + Math::lerp(-mCornerSize.y, mCornerSize.y, mOrigin.y));
} }
void NinePatchComponent::setImagePath(const std::string& path) void NinePatchComponent::setImagePath(const std::string& path)

View file

@ -35,13 +35,10 @@ public:
unsigned int centerColor = 0xFFFFFFFF); unsigned int centerColor = 0xFFFFFFFF);
virtual ~NinePatchComponent(); virtual ~NinePatchComponent();
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override; void onSizeChanged() override { buildVertices(); }
void fitTo(glm::vec2 size, glm::vec3 position = {}, glm::vec2 padding = {});
void fitTo(Vector2f size,
Vector3f position = Vector3f::Zero(),
Vector2f padding = Vector2f::Zero());
void setImagePath(const std::string& path); void setImagePath(const std::string& path);
// Apply a color shift to the "edge" parts of the ninepatch. // Apply a color shift to the "edge" parts of the ninepatch.
@ -54,8 +51,8 @@ public:
const std::string& element, const std::string& element,
unsigned int properties) override; unsigned int properties) override;
const Vector2f& getCornerSize() const { return mCornerSize; } const glm::vec2& getCornerSize() const { return mCornerSize; }
void setCornerSize(const Vector2f& size) void setCornerSize(const glm::vec2& size)
{ {
mCornerSize = size; mCornerSize = size;
buildVertices(); buildVertices();
@ -68,7 +65,7 @@ private:
Renderer::Vertex* mVertices; Renderer::Vertex* mVertices;
std::string mPath; std::string mPath;
Vector2f mCornerSize; glm::vec2 mCornerSize;
unsigned int mEdgeColor; unsigned int mEdgeColor;
unsigned int mCenterColor; unsigned int mCenterColor;
std::shared_ptr<TextureResource> mTexture; std::shared_ptr<TextureResource> mTexture;

View file

@ -58,7 +58,7 @@ public:
addChild(&mRightArrow); addChild(&mRightArrow);
} }
setSize(mLeftArrow.getSize().x() + mRightArrow.getSize().x(), font->getHeight()); setSize(mLeftArrow.getSize().x + mRightArrow.getSize().x, font->getHeight());
} }
// Handles positioning/resizing of text and arrows. // Handles positioning/resizing of text and arrows.
@ -67,19 +67,19 @@ public:
mLeftArrow.setResize(0, mText.getFont()->getLetterHeight()); mLeftArrow.setResize(0, mText.getFont()->getLetterHeight());
mRightArrow.setResize(0, mText.getFont()->getLetterHeight()); mRightArrow.setResize(0, mText.getFont()->getLetterHeight());
if (mSize.x() < (mLeftArrow.getSize().x() + mRightArrow.getSize().x())) { if (mSize.x < (mLeftArrow.getSize().x + mRightArrow.getSize().x)) {
LOG(LogWarning) << "OptionListComponent too narrow"; LOG(LogWarning) << "OptionListComponent too narrow";
} }
mText.setSize(mSize.x() - mLeftArrow.getSize().x() - mRightArrow.getSize().x(), mText.setSize(mSize.x - mLeftArrow.getSize().x - mRightArrow.getSize().x,
mText.getFont()->getHeight()); mText.getFont()->getHeight());
// Position. // Position.
mLeftArrow.setPosition(0, (mSize.y() - mLeftArrow.getSize().y()) / 2); mLeftArrow.setPosition(0.0f, (mSize.y - mLeftArrow.getSize().y) / 2.0f);
mText.setPosition(mLeftArrow.getPosition().x() + mLeftArrow.getSize().x(), mText.setPosition(mLeftArrow.getPosition().x + mLeftArrow.getSize().x,
(mSize.y() - mText.getSize().y()) / 2); (mSize.y - mText.getSize().y) / 2.0f);
mRightArrow.setPosition(mText.getPosition().x() + mText.getSize().x(), mRightArrow.setPosition(mText.getPosition().x + mText.getSize().x,
(mSize.y() - mRightArrow.getSize().y()) / 2); (mSize.y - mRightArrow.getSize().y) / 2.0f);
} }
bool input(InputConfig* config, Input input) override bool input(InputConfig* config, Input input) override
@ -232,10 +232,10 @@ private:
std::stringstream ss; std::stringstream ss;
ss << getSelectedObjects().size() << " SELECTED"; ss << getSelectedObjects().size() << " SELECTED";
mText.setText(ss.str()); mText.setText(ss.str());
mText.setSize(0, mText.getSize().y()); mText.setSize(0, mText.getSize().y);
setSize(mText.getSize().x() + mRightArrow.getSize().x() + setSize(mText.getSize().x + mRightArrow.getSize().x +
24 * Renderer::getScreenWidthModifier(), 24.0f * Renderer::getScreenWidthModifier(),
mText.getSize().y()); mText.getSize().y);
if (mParent) // Hack since there's no "on child size changed" callback. if (mParent) // Hack since there's no "on child size changed" callback.
mParent->onSizeChanged(); mParent->onSizeChanged();
} }
@ -244,11 +244,10 @@ private:
for (auto it = mEntries.cbegin(); it != mEntries.cend(); it++) { for (auto it = mEntries.cbegin(); it != mEntries.cend(); it++) {
if (it->selected) { if (it->selected) {
mText.setText(Utils::String::toUpper(it->name)); mText.setText(Utils::String::toUpper(it->name));
mText.setSize(0, mText.getSize().y()); mText.setSize(0.0f, mText.getSize().y);
setSize(mText.getSize().x() + mLeftArrow.getSize().x() + setSize(mText.getSize().x + mLeftArrow.getSize().x + mRightArrow.getSize().x +
mRightArrow.getSize().x() +
24.0f * Renderer::getScreenWidthModifier(), 24.0f * Renderer::getScreenWidthModifier(),
mText.getSize().y()); mText.getSize().y);
if (mParent) // Hack since there's no "on child size changed" callback. if (mParent) // Hack since there's no "on child size changed" callback.
mParent->onSizeChanged(); mParent->onSizeChanged();
break; break;
@ -356,7 +355,7 @@ private:
}); });
} }
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2.0f, mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x) / 2.0f,
Renderer::getScreenHeight() * 0.13f); Renderer::getScreenHeight() * 0.13f);
addChild(&mMenu); addChild(&mMenu);
} }

View file

@ -25,7 +25,7 @@ RatingComponent::RatingComponent(Window* window, bool colorizeChanges)
mFilledTexture = TextureResource::get(":/graphics/star_filled.svg", true); mFilledTexture = TextureResource::get(":/graphics/star_filled.svg", true);
mUnfilledTexture = TextureResource::get(":/graphics/star_unfilled.svg", true); mUnfilledTexture = TextureResource::get(":/graphics/star_unfilled.svg", true);
mValue = 0.5f; mValue = 0.5f;
mSize = Vector2f(64.0f * NUM_RATING_STARS, 64.0f); mSize = glm::vec2{64.0f * NUM_RATING_STARS, 64.0f};
updateVertices(); updateVertices();
updateColors(); updateColors();
} }
@ -96,13 +96,13 @@ void RatingComponent::setColorShift(unsigned int color)
void RatingComponent::onSizeChanged() void RatingComponent::onSizeChanged()
{ {
if (mSize.y() == 0) if (mSize.y == 0.0f)
mSize[1] = mSize.x() / NUM_RATING_STARS; mSize.y = mSize.x / NUM_RATING_STARS;
else if (mSize.x() == 0) else if (mSize.x == 0.0f)
mSize[0] = mSize.y() * NUM_RATING_STARS; mSize.x = mSize.y * NUM_RATING_STARS;
if (mSize.y() > 0) { if (mSize.y > 0.0f) {
size_t heightPx = static_cast<size_t>(std::round(mSize.y())); size_t heightPx = static_cast<size_t>(std::round(mSize.y));
if (mFilledTexture) if (mFilledTexture)
mFilledTexture->rasterizeAt(heightPx, heightPx); mFilledTexture->rasterizeAt(heightPx, heightPx);
if (mUnfilledTexture) if (mUnfilledTexture)
@ -115,21 +115,21 @@ void RatingComponent::onSizeChanged()
void RatingComponent::updateVertices() void RatingComponent::updateVertices()
{ {
const float numStars = NUM_RATING_STARS; const float numStars = NUM_RATING_STARS;
const float h = getSize().y(); // Ss the same as a single star's width. const float h = getSize().y; // Ss the same as a single star's width.
const float w = getSize().y() * mValue * numStars; const float w = getSize().y * mValue * numStars;
const float fw = getSize().y() * numStars; const float fw = getSize().y * numStars;
const unsigned int color = Renderer::convertRGBAToABGR(mColorShift); const unsigned int color = Renderer::convertRGBAToABGR(mColorShift);
// clang-format off // clang-format off
mVertices[0] = { { 0.0f, 0.0f }, { 0.0f, 1.0f }, color }; mVertices[0] = {{0.0f, 0.0f}, {0.0f, 1.0f}, color};
mVertices[1] = { { 0.0f, h }, { 0.0f, 0.0f }, color }; mVertices[1] = {{0.0f, h }, {0.0f, 0.0f}, color};
mVertices[2] = { { w, 0.0f }, { mValue * numStars, 1.0f }, color }; mVertices[2] = {{w, 0.0f}, {mValue * numStars, 1.0f}, color};
mVertices[3] = { { w, h }, { mValue * numStars, 0.0f }, color }; mVertices[3] = {{w, h }, {mValue * numStars, 0.0f}, color};
mVertices[4] = { { 0.0f, 0.0f }, { 0.0f, 1.0f }, color }; mVertices[4] = {{0.0f, 0.0f}, {0.0f, 1.0f}, color};
mVertices[5] = { { 0.0f, h }, { 0.0f, 0.0f }, color }; mVertices[5] = {{0.0f, h }, {0.0f, 0.0f}, color};
mVertices[6] = { { fw, 0.0f }, { numStars, 1.0f }, color }; mVertices[6] = {{fw, 0.0f}, {numStars, 1.0f}, color};
mVertices[7] = { { fw, h }, { numStars, 0.0f }, color }; mVertices[7] = {{fw, h }, {numStars, 0.0f}, color};
// clang-format on // clang-format on
} }
@ -141,18 +141,18 @@ void RatingComponent::updateColors()
mVertices[i].col = color; mVertices[i].col = color;
} }
void RatingComponent::render(const Transform4x4f& parentTrans) void RatingComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible() || mFilledTexture == nullptr || mUnfilledTexture == nullptr) if (!isVisible() || mFilledTexture == nullptr || mUnfilledTexture == nullptr)
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
if (mOpacity > 0) { if (mOpacity > 0) {
if (Settings::getInstance()->getBool("DebugImage")) { if (Settings::getInstance()->getBool("DebugImage")) {
Renderer::drawRect(0.0f, 0.0f, mSize.y() * NUM_RATING_STARS, mSize.y(), 0xFF000033, Renderer::drawRect(0.0f, 0.0f, mSize.y * NUM_RATING_STARS, mSize.y, 0xFF000033,
0xFF000033); 0xFF000033);
} }

View file

@ -27,7 +27,7 @@ public:
void setValue(const std::string& value) override; void setValue(const std::string& value) override;
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override; void onSizeChanged() override;
@ -48,8 +48,6 @@ public:
virtual std::vector<HelpPrompt> getHelpPrompts() override; virtual std::vector<HelpPrompt> getHelpPrompts() override;
private: private:
Vector2f mTargetSize;
void updateVertices(); void updateVertices();
void updateColors(); void updateColors();

View file

@ -11,7 +11,6 @@
#include "Window.h" #include "Window.h"
#include "animations/LambdaAnimation.h" #include "animations/LambdaAnimation.h"
#include "math/Vector2i.h"
#include "renderers/Renderer.h" #include "renderers/Renderer.h"
#include "resources/Font.h" #include "resources/Font.h"
@ -45,7 +44,7 @@ ScrollableContainer::ScrollableContainer(Window* window)
void ScrollableContainer::setAutoScroll(bool autoScroll) void ScrollableContainer::setAutoScroll(bool autoScroll)
{ {
if (autoScroll) { if (autoScroll) {
mScrollDir = Vector2f(0, 1); mScrollDir = glm::vec2{0.0f, 1.0f};
mAutoScrollDelay = static_cast<int>(mAutoScrollDelayConstant); mAutoScrollDelay = static_cast<int>(mAutoScrollDelayConstant);
mAutoScrollSpeed = mAutoScrollSpeedConstant; mAutoScrollSpeed = mAutoScrollSpeedConstant;
mAutoScrollSpeed = mAutoScrollSpeed =
@ -53,7 +52,7 @@ void ScrollableContainer::setAutoScroll(bool autoScroll)
reset(); reset();
} }
else { else {
mScrollDir = Vector2f(0, 0); mScrollDir = glm::vec2{};
mAutoScrollDelay = 0; mAutoScrollDelay = 0;
mAutoScrollSpeed = 0; mAutoScrollSpeed = 0;
mAutoScrollAccumulator = 0; mAutoScrollAccumulator = 0;
@ -71,7 +70,7 @@ void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant,
void ScrollableContainer::reset() void ScrollableContainer::reset()
{ {
mScrollPos = Vector2f(0, 0); mScrollPos = glm::vec2{};
mAutoScrollResetAccumulator = 0; mAutoScrollResetAccumulator = 0;
mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed; mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed;
mAtEnd = false; mAtEnd = false;
@ -82,16 +81,16 @@ void ScrollableContainer::update(int deltaTime)
// Don't scroll if the media viewer or screensaver is active or if text scrolling is disabled; // Don't scroll if the media viewer or screensaver is active or if text scrolling is disabled;
if (mWindow->isMediaViewerActive() || mWindow->isScreensaverActive() || if (mWindow->isMediaViewerActive() || mWindow->isScreensaverActive() ||
!mWindow->getAllowTextScrolling()) { !mWindow->getAllowTextScrolling()) {
if (mScrollPos != 0 && !mWindow->isLaunchScreenDisplayed()) if (mScrollPos != glm::vec2{} && !mWindow->isLaunchScreenDisplayed())
reset(); reset();
return; return;
} }
const Vector2f contentSize = getContentSize(); const glm::vec2 contentSize{getContentSize()};
int adjustedAutoScrollSpeed = mAutoScrollSpeed; int adjustedAutoScrollSpeed = mAutoScrollSpeed;
// Adjust the scrolling speed based on the width of the container. // Adjust the scrolling speed based on the width of the container.
float widthModifier = contentSize.x() / static_cast<float>(Renderer::getScreenWidth()); float widthModifier = contentSize.x / static_cast<float>(Renderer::getScreenWidth());
adjustedAutoScrollSpeed = static_cast<int>(adjustedAutoScrollSpeed * widthModifier); adjustedAutoScrollSpeed = static_cast<int>(adjustedAutoScrollSpeed * widthModifier);
// Also adjust the scrolling speed based on the size of the font. // Also adjust the scrolling speed based on the size of the font.
@ -105,28 +104,28 @@ void ScrollableContainer::update(int deltaTime)
if (adjustedAutoScrollSpeed != 0) { if (adjustedAutoScrollSpeed != 0) {
mAutoScrollAccumulator += deltaTime; mAutoScrollAccumulator += deltaTime;
while (mAutoScrollAccumulator >= adjustedAutoScrollSpeed) { while (mAutoScrollAccumulator >= adjustedAutoScrollSpeed) {
if (contentSize.y() > mSize.y()) if (contentSize.y > mSize.y)
mScrollPos += mScrollDir; mScrollPos += mScrollDir;
mAutoScrollAccumulator -= adjustedAutoScrollSpeed; mAutoScrollAccumulator -= adjustedAutoScrollSpeed;
} }
} }
// Clip scrolling within bounds. // Clip scrolling within bounds.
if (mScrollPos.x() < 0) if (mScrollPos.x < 0.0f)
mScrollPos[0] = 0; mScrollPos.x = 0.0f;
if (mScrollPos.y() < 0) if (mScrollPos.y < 0.0f)
mScrollPos[1] = 0; mScrollPos.y = 0.0f;
if (mScrollPos.x() + getSize().x() > contentSize.x()) { if (mScrollPos.x + getSize().x > contentSize.x) {
mScrollPos[0] = contentSize.x() - getSize().x(); mScrollPos.x = contentSize.x - getSize().x;
mAtEnd = true; mAtEnd = true;
} }
if (contentSize.y() < getSize().y()) { if (contentSize.y < getSize().y) {
mScrollPos[1] = 0; mScrollPos.y = 0.0f;
} }
else if (mScrollPos.y() + getSize().y() > contentSize.y()) { else if (mScrollPos.y + getSize().y > contentSize.y) {
mScrollPos[1] = contentSize.y() - getSize().y(); mScrollPos.y = contentSize.y - getSize().y;
mAtEnd = true; mAtEnd = true;
} }
@ -136,7 +135,7 @@ void ScrollableContainer::update(int deltaTime)
// Fade in the text as it resets to the start position. // Fade in the text as it resets to the start position.
auto func = [this](float t) { auto func = [this](float t) {
this->setOpacity(static_cast<unsigned char>(Math::lerp(0.0f, 1.0f, t) * 255)); this->setOpacity(static_cast<unsigned char>(Math::lerp(0.0f, 1.0f, t) * 255));
mScrollPos = Vector2f(0, 0); mScrollPos = glm::vec2{};
mAutoScrollResetAccumulator = 0; mAutoScrollResetAccumulator = 0;
mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed; mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed;
mAtEnd = false; mAtEnd = false;
@ -148,39 +147,41 @@ void ScrollableContainer::update(int deltaTime)
GuiComponent::update(deltaTime); GuiComponent::update(deltaTime);
} }
void ScrollableContainer::render(const Transform4x4f& parentTrans) void ScrollableContainer::render(const glm::mat4& parentTrans)
{ {
if (!isVisible()) if (!isVisible())
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
Vector2i clipPos(static_cast<int>(trans.translation().x()), glm::ivec2 clipPos{static_cast<int>(trans[3].x), static_cast<int>(trans[3].y)};
static_cast<int>(trans.translation().y()));
Vector3f dimScaled = trans * Vector3f(mSize.x(), mSize.y(), 0); glm::vec3 dimScaled{};
Vector2i clipDim(static_cast<int>((dimScaled.x()) - trans.translation().x()), dimScaled.x = std::fabs(trans[3].x + mSize.x);
static_cast<int>((dimScaled.y()) - trans.translation().y())); dimScaled.y = std::fabs(trans[3].y + mSize.y);
glm::ivec2 clipDim{static_cast<int>(dimScaled.x - trans[3].x),
static_cast<int>(dimScaled.y - trans[3].y)};
Renderer::pushClipRect(clipPos, clipDim); Renderer::pushClipRect(clipPos, clipDim);
trans.translate(-Vector3f(mScrollPos.x(), mScrollPos.y(), 0)); trans = glm::translate(trans, -glm::vec3{mScrollPos.x, mScrollPos.y, 0.0f});
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
GuiComponent::renderChildren(trans); GuiComponent::renderChildren(trans);
Renderer::popClipRect(); Renderer::popClipRect();
} }
Vector2f ScrollableContainer::getContentSize() glm::vec2 ScrollableContainer::getContentSize()
{ {
Vector2f max(0, 0); glm::vec2 max{};
for (unsigned int i = 0; i < mChildren.size(); i++) { for (unsigned int i = 0; i < mChildren.size(); i++) {
Vector2f pos(mChildren.at(i)->getPosition()[0], mChildren.at(i)->getPosition()[1]); glm::vec2 pos{mChildren.at(i)->getPosition().x, mChildren.at(i)->getPosition().y};
Vector2f bottomRight = mChildren.at(i)->getSize() + pos; glm::vec2 bottomRight{mChildren.at(i)->getSize() + pos};
if (bottomRight.x() > max.x()) if (bottomRight.x > max.x)
max.x() = bottomRight.x(); max.x = bottomRight.x;
if (bottomRight.y() > max.y()) if (bottomRight.y > max.y)
max.y() = bottomRight.y(); max.y = bottomRight.y;
if (!mFontSize) if (!mFontSize)
mFontSize = static_cast<float>(mChildren.at(i)->getFont()->getSize()); mFontSize = static_cast<float>(mChildren.at(i)->getFont()->getSize());
} }

View file

@ -24,8 +24,8 @@ class ScrollableContainer : public GuiComponent
public: public:
ScrollableContainer(Window* window); ScrollableContainer(Window* window);
Vector2f getScrollPos() const { return mScrollPos; } glm::vec2 getScrollPos() const { return mScrollPos; }
void setScrollPos(const Vector2f& pos) { mScrollPos = pos; } void setScrollPos(const glm::vec2& pos) { mScrollPos = pos; }
void setAutoScroll(bool autoScroll); void setAutoScroll(bool autoScroll);
void setScrollParameters(float autoScrollDelayConstant, void setScrollParameters(float autoScrollDelayConstant,
@ -34,13 +34,13 @@ public:
void reset(); void reset();
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
private: private:
Vector2f getContentSize(); glm::vec2 getContentSize();
Vector2f mScrollPos; glm::vec2 mScrollPos;
Vector2f mScrollDir; glm::vec2 mScrollDir;
float mFontSize; float mFontSize;
float mSmallFontSize; float mSmallFontSize;

View file

@ -74,23 +74,23 @@ void SliderComponent::update(int deltaTime)
GuiComponent::update(deltaTime); GuiComponent::update(deltaTime);
} }
void SliderComponent::render(const Transform4x4f& parentTrans) void SliderComponent::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
// Render suffix. // Render suffix.
if (mValueCache) if (mValueCache)
mFont->renderTextCache(mValueCache.get()); mFont->renderTextCache(mValueCache.get());
float width = float width{mSize.x - mKnob.getSize().x -
mSize.x() - mKnob.getSize().x() - (mValueCache ?
(mValueCache ? mValueCache->metrics.size.x() + (4.0f * Renderer::getScreenWidthModifier()) : mValueCache->metrics.size.x + (4.0f * Renderer::getScreenWidthModifier()) :
0); 0.0f)};
// Render line. // Render line.
const float lineWidth = 2.0f * Renderer::getScreenHeightModifier(); const float lineWidth{2.0f * Renderer::getScreenHeightModifier()};
Renderer::drawRect(mKnob.getSize().x() / 2.0f, mSize.y() / 2.0f - lineWidth / 2.0f, width, Renderer::drawRect(mKnob.getSize().x / 2.0f, mSize.y / 2.0f - lineWidth / 2.0f, width,
lineWidth, 0x777777FF, 0x777777FF); lineWidth, 0x777777FF, 0x777777FF);
// Render knob. // Render knob.
@ -115,7 +115,7 @@ float SliderComponent::getValue() { return mValue; }
void SliderComponent::onSizeChanged() void SliderComponent::onSizeChanged()
{ {
if (!mSuffix.empty()) if (!mSuffix.empty())
mFont = Font::get(static_cast<int>(mSize.y()), FONT_PATH_LIGHT); mFont = Font::get(static_cast<int>(mSize.y), FONT_PATH_LIGHT);
onValueChanged(); onValueChanged();
} }
@ -139,21 +139,21 @@ void SliderComponent::onValueChanged()
ss << mSuffix; ss << mSuffix;
const std::string max = ss.str(); const std::string max = ss.str();
Vector2f textSize = mFont->sizeText(max); glm::vec2 textSize = mFont->sizeText(max);
mValueCache = std::shared_ptr<TextCache>(mFont->buildTextCache( mValueCache = std::shared_ptr<TextCache>(mFont->buildTextCache(
val, mSize.x() - textSize.x(), (mSize.y() - textSize.y()) / 2.0f, 0x777777FF)); val, mSize.x - textSize.x, (mSize.y - textSize.y) / 2.0f, 0x777777FF));
mValueCache->metrics.size[0] = textSize.x(); // Fudge the width. mValueCache->metrics.size.x = textSize.x; // Fudge the width.
} }
// Update knob position/size. // Update knob position/size.
mKnob.setResize(0, mSize.y() * 0.7f); mKnob.setResize(0, mSize.y * 0.7f);
float lineLength = float lineLength =
mSize.x() - mKnob.getSize().x() - mSize.x - mKnob.getSize().x -
(mValueCache ? mValueCache->metrics.size.x() + (4.0f * Renderer::getScreenWidthModifier()) : (mValueCache ? mValueCache->metrics.size.x + (4.0f * Renderer::getScreenWidthModifier()) :
0); 0.0f);
mKnob.setPosition(((mValue - mMin / 2.0f) / mMax) * lineLength + mKnob.getSize().x() / 2.0f, mKnob.setPosition(((mValue - mMin / 2.0f) / mMax) * lineLength + mKnob.getSize().x / 2.0f,
mSize.y() / 2.0f); mSize.y / 2.0f);
} }
std::vector<HelpPrompt> SliderComponent::getHelpPrompts() std::vector<HelpPrompt> SliderComponent::getHelpPrompts()

View file

@ -29,7 +29,7 @@ public:
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override; void onSizeChanged() override;

View file

@ -42,9 +42,9 @@ bool SwitchComponent::input(InputConfig* config, Input input)
return false; return false;
} }
void SwitchComponent::render(const Transform4x4f& parentTrans) void SwitchComponent::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
mImage.render(trans); mImage.render(trans);
renderChildren(trans); renderChildren(trans);
} }

View file

@ -19,7 +19,7 @@ public:
SwitchComponent(Window* window, bool state = false); SwitchComponent(Window* window, bool state = false);
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onSizeChanged() override { mImage.setSize(mSize); } void onSizeChanged() override { mImage.setSize(mSize); }
void setResize(float width, float height) override { mImage.setResize(width, height); } void setResize(float width, float height) override { mImage.setResize(width, height); }

View file

@ -33,8 +33,8 @@ TextComponent::TextComponent(Window* window,
const std::shared_ptr<Font>& font, const std::shared_ptr<Font>& font,
unsigned int color, unsigned int color,
Alignment align, Alignment align,
Vector3f pos, glm::vec3 pos,
Vector2f size, glm::vec2 size,
unsigned int bgcolor, unsigned int bgcolor,
float margin) float margin)
: GuiComponent(window) : GuiComponent(window)
@ -60,7 +60,7 @@ TextComponent::TextComponent(Window* window,
void TextComponent::onSizeChanged() void TextComponent::onSizeChanged()
{ {
mAutoCalcExtent = Vector2i((getSize().x() == 0), (getSize().y() == 0)); mAutoCalcExtent = glm::ivec2{(getSize().x == 0), (getSize().y == 0)};
onTextChanged(); onTextChanged();
} }
@ -115,66 +115,66 @@ void TextComponent::setUppercase(bool uppercase)
onTextChanged(); onTextChanged();
} }
void TextComponent::render(const Transform4x4f& parentTrans) void TextComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible()) if (!isVisible())
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
if (mRenderBackground) { if (mRenderBackground) {
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), mBgColor, mBgColor); Renderer::drawRect(0.0f, 0.0f, mSize.x, mSize.y, mBgColor, mBgColor);
} }
if (mTextCache) { if (mTextCache) {
const Vector2f& textSize = mTextCache->metrics.size; const glm::vec2& textSize{mTextCache->metrics.size};
float yOff = 0; float yOff = 0.0f;
switch (mVerticalAlignment) { switch (mVerticalAlignment) {
case ALIGN_TOP: { case ALIGN_TOP: {
yOff = 0; yOff = 0.0f;
break; break;
} }
case ALIGN_BOTTOM: { case ALIGN_BOTTOM: {
yOff = (getSize().y() - textSize.y()); yOff = (getSize().y - textSize.y);
break; break;
} }
case ALIGN_CENTER: { case ALIGN_CENTER: {
yOff = (getSize().y() - textSize.y()) / 2.0f; yOff = (getSize().y - textSize.y) / 2.0f;
break; break;
} }
default: { default: {
break; break;
} }
} }
Vector3f off(0, yOff, 0); glm::vec3 off{0.0f, yOff, 0.0f};
if (Settings::getInstance()->getBool("DebugText")) { if (Settings::getInstance()->getBool("DebugText")) {
// Draw the "textbox" area, what we are aligned within. // Draw the "textbox" area, what we are aligned within.
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x0000FF33, 0x0000FF33); Renderer::drawRect(0.0f, 0.0f, mSize.x, mSize.y, 0x0000FF33, 0x0000FF33);
} }
trans.translate(off); trans = glm::translate(trans, off);
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
// Draw the text area, where the text actually is located. // Draw the text area, where the text actually is located.
if (Settings::getInstance()->getBool("DebugText")) { if (Settings::getInstance()->getBool("DebugText")) {
switch (mHorizontalAlignment) { switch (mHorizontalAlignment) {
case ALIGN_LEFT: { case ALIGN_LEFT: {
Renderer::drawRect(0.0f, 0.0f, mTextCache->metrics.size.x(), Renderer::drawRect(0.0f, 0.0f, mTextCache->metrics.size.x,
mTextCache->metrics.size.y(), 0x00000033, 0x00000033); mTextCache->metrics.size.y, 0x00000033, 0x00000033);
break; break;
} }
case ALIGN_CENTER: { case ALIGN_CENTER: {
Renderer::drawRect((mSize.x() - mTextCache->metrics.size.x()) / 2.0f, 0.0f, Renderer::drawRect((mSize.x - mTextCache->metrics.size.x) / 2.0f, 0.0f,
mTextCache->metrics.size.x(), mTextCache->metrics.size.y(), mTextCache->metrics.size.x, mTextCache->metrics.size.y,
0x00000033, 0x00000033); 0x00000033, 0x00000033);
break; break;
} }
case ALIGN_RIGHT: { case ALIGN_RIGHT: {
Renderer::drawRect(mSize.x() - mTextCache->metrics.size.x(), 0.0f, Renderer::drawRect(mSize.x - mTextCache->metrics.size.x, 0.0f,
mTextCache->metrics.size.x(), mTextCache->metrics.size.y(), mTextCache->metrics.size.x, mTextCache->metrics.size.y,
0x00000033, 0x00000033); 0x00000033, 0x00000033);
break; break;
} }
@ -189,15 +189,15 @@ void TextComponent::render(const Transform4x4f& parentTrans)
void TextComponent::calculateExtent() void TextComponent::calculateExtent()
{ {
if (mAutoCalcExtent.x()) { if (mAutoCalcExtent.x) {
mSize = mFont->sizeText(mUppercase ? Utils::String::toUpper(mText) : mText, mLineSpacing); mSize = mFont->sizeText(mUppercase ? Utils::String::toUpper(mText) : mText, mLineSpacing);
} }
else { else {
if (mAutoCalcExtent.y()) if (mAutoCalcExtent.y)
mSize[1] = mFont mSize.y = mFont
->sizeWrappedText(mUppercase ? Utils::String::toUpper(mText) : mText, ->sizeWrappedText(mUppercase ? Utils::String::toUpper(mText) : mText,
getSize().x(), mLineSpacing) getSize().x, mLineSpacing)
.y(); .y;
} }
} }
@ -213,7 +213,7 @@ void TextComponent::onTextChanged()
std::string text = mUppercase ? Utils::String::toUpper(mText) : mText; std::string text = mUppercase ? Utils::String::toUpper(mText) : mText;
std::shared_ptr<Font> f = mFont; std::shared_ptr<Font> f = mFont;
const bool isMultiline = (mSize.y() == 0 || mSize.y() > f->getHeight() * 1.2f); const bool isMultiline = (mSize.y == 0.0f || mSize.y > f->getHeight() * 1.2f);
bool addAbbrev = false; bool addAbbrev = false;
if (!isMultiline) { if (!isMultiline) {
@ -223,15 +223,15 @@ void TextComponent::onTextChanged()
addAbbrev = newline != std::string::npos; addAbbrev = newline != std::string::npos;
} }
Vector2f size = f->sizeText(text); glm::vec2 size{f->sizeText(text)};
if (!isMultiline && mSize.x() > 0.0f && text.size() && (size.x() > mSize.x() || addAbbrev)) { if (!isMultiline && mSize.x > 0.0f && text.size() && (size.x > mSize.x || addAbbrev)) {
// Abbreviate text. // Abbreviate text.
const std::string abbrev = "..."; const std::string abbrev = "...";
Vector2f abbrevSize = f->sizeText(abbrev); glm::vec2 abbrevSize{f->sizeText(abbrev)};
// mMargin adds a margin around the text if it's abbreviated. // mMargin adds a margin around the text if it's abbreviated.
float marginAdjustedSize = mSize.x() - (mSize.x() * mMargin); float marginAdjustedSize = mSize.x - (mSize.x * mMargin);
while (text.size() && size.x() + abbrevSize.x() > marginAdjustedSize) { while (text.size() && size.x + abbrevSize.x > marginAdjustedSize) {
size_t newSize = Utils::String::prevCursor(text, text.size()); size_t newSize = Utils::String::prevCursor(text, text.size());
text.erase(newSize, text.size() - newSize); text.erase(newSize, text.size() - newSize);
size = f->sizeText(text); size = f->sizeText(text);
@ -240,12 +240,12 @@ void TextComponent::onTextChanged()
text.append(abbrev); text.append(abbrev);
mTextCache = std::shared_ptr<TextCache>( mTextCache = std::shared_ptr<TextCache>(
f->buildTextCache(text, Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), f->buildTextCache(text, glm::vec2{}, (mColor >> 8 << 8) | mOpacity, mSize.x,
mHorizontalAlignment, mLineSpacing, mNoTopMargin)); mHorizontalAlignment, mLineSpacing, mNoTopMargin));
} }
else { else {
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache( mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(
f->wrapText(text, mSize.x()), Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), f->wrapText(text, mSize.x), glm::vec2{}, (mColor >> 8 << 8) | mOpacity, mSize.x,
mHorizontalAlignment, mLineSpacing, mNoTopMargin)); mHorizontalAlignment, mLineSpacing, mNoTopMargin));
} }
} }

View file

@ -30,8 +30,8 @@ public:
const std::shared_ptr<Font>& font, const std::shared_ptr<Font>& font,
unsigned int color = 0x000000FF, unsigned int color = 0x000000FF,
Alignment align = ALIGN_LEFT, Alignment align = ALIGN_LEFT,
Vector3f pos = Vector3f::Zero(), glm::vec3 pos = {},
Vector2f size = Vector2f::Zero(), glm::vec2 size = {},
unsigned int bgcolor = 0x00000000, unsigned int bgcolor = 0x00000000,
float margin = 0.0f); float margin = 0.0f);
@ -48,7 +48,7 @@ public:
void setBackgroundColor(unsigned int color); void setBackgroundColor(unsigned int color);
void setRenderBackground(bool render) { mRenderBackground = render; } void setRenderBackground(bool render) { mRenderBackground = render; }
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
std::string getValue() const override { return mText; } std::string getValue() const override { return mText; }
void setValue(const std::string& value) override { setText(value); } void setValue(const std::string& value) override { setText(value); }
@ -88,7 +88,7 @@ private:
bool mRenderBackground; bool mRenderBackground;
bool mUppercase; bool mUppercase;
Vector2i mAutoCalcExtent; glm::ivec2 mAutoCalcExtent;
std::shared_ptr<TextCache> mTextCache; std::shared_ptr<TextCache> mTextCache;
Alignment mHorizontalAlignment; Alignment mHorizontalAlignment;
Alignment mVerticalAlignment; Alignment mVerticalAlignment;

View file

@ -28,7 +28,7 @@ TextEditComponent::TextEditComponent(Window* window)
{ {
addChild(&mBox); addChild(&mBox);
onFocusLost(); onFocusLost();
mResolutionAdjustment = -(34 * Renderer::getScreenWidthModifier() - 34); mResolutionAdjustment = -(34.0f * Renderer::getScreenWidthModifier() - 34.0f);
setSize(4096, mFont->getHeight() + (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier())); setSize(4096, mFont->getHeight() + (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier()));
} }
@ -46,9 +46,9 @@ void TextEditComponent::onFocusLost()
void TextEditComponent::onSizeChanged() void TextEditComponent::onSizeChanged()
{ {
mBox.fitTo(mSize, Vector3f::Zero(), mBox.fitTo(mSize, glm::vec3{},
Vector2f(-34 + mResolutionAdjustment, glm::vec2{-34.0f + mResolutionAdjustment,
-32 - (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier()))); -32.0f - (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier())});
onTextChanged(); // Wrap point probably changed. onTextChanged(); // Wrap point probably changed.
} }
@ -239,10 +239,9 @@ void TextEditComponent::setCursor(size_t pos)
void TextEditComponent::onTextChanged() void TextEditComponent::onTextChanged()
{ {
std::string wrappedText = std::string wrappedText = (isMultiline() ? mFont->wrapText(mText, getTextAreaSize().x) : mText);
(isMultiline() ? mFont->wrapText(mText, getTextAreaSize().x()) : mText);
mTextCache = std::unique_ptr<TextCache>( mTextCache = std::unique_ptr<TextCache>(
mFont->buildTextCache(wrappedText, 0, 0, 0x77777700 | getOpacity())); mFont->buildTextCache(wrappedText, 0.0f, 0.0f, 0x77777700 | getOpacity()));
if (mCursor > static_cast<int>(mText.length())) if (mCursor > static_cast<int>(mText.length()))
mCursor = static_cast<unsigned int>(mText.length()); mCursor = static_cast<unsigned int>(mText.length());
@ -251,44 +250,45 @@ void TextEditComponent::onTextChanged()
void TextEditComponent::onCursorChanged() void TextEditComponent::onCursorChanged()
{ {
if (isMultiline()) { if (isMultiline()) {
Vector2f textSize = glm::vec2 textSize{mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x, mCursor)};
mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor);
// Need to scroll down? // Need to scroll down?
if (mScrollOffset.y() + getTextAreaSize().y() < textSize.y() + mFont->getHeight()) if (mScrollOffset.y + getTextAreaSize().y < textSize.y + mFont->getHeight())
mScrollOffset[1] = textSize.y() - getTextAreaSize().y() + mFont->getHeight(); mScrollOffset.y = textSize.y - getTextAreaSize().y + mFont->getHeight();
// Need to scroll up? // Need to scroll up?
else if (mScrollOffset.y() > textSize.y()) else if (mScrollOffset.y > textSize.y)
mScrollOffset[1] = textSize.y(); mScrollOffset.y = textSize.y;
} }
else { else {
Vector2f cursorPos = mFont->sizeText(mText.substr(0, mCursor)); glm::vec2 cursorPos{mFont->sizeText(mText.substr(0, mCursor))};
if (mScrollOffset.x() + getTextAreaSize().x() < cursorPos.x()) if (mScrollOffset.x + getTextAreaSize().x < cursorPos.x)
mScrollOffset[0] = cursorPos.x() - getTextAreaSize().x(); mScrollOffset.x = cursorPos.x - getTextAreaSize().x;
else if (mScrollOffset.x() > cursorPos.x()) else if (mScrollOffset.x > cursorPos.x)
mScrollOffset[0] = cursorPos.x(); mScrollOffset.x = cursorPos.x;
} }
} }
void TextEditComponent::render(const Transform4x4f& parentTrans) void TextEditComponent::render(const glm::mat4& parentTrans)
{ {
Transform4x4f trans = getTransform() * parentTrans; glm::mat4 trans{getTransform() * parentTrans};
renderChildren(trans); renderChildren(trans);
// Text + cursor rendering. // Text + cursor rendering.
// Offset into our "text area" (padding). // Offset into our "text area" (padding).
trans.translation() += Vector3f(getTextAreaPos().x(), getTextAreaPos().y(), 0); trans = glm::translate(trans, glm::vec3{getTextAreaPos().x, getTextAreaPos().y, 0.0f});
Vector2i clipPos(static_cast<int>(trans.translation().x()), glm::ivec2 clipPos{static_cast<int>(trans[3].x), static_cast<int>(trans[3].y)};
static_cast<int>(trans.translation().y()));
// Use "text area" size for clipping. // Use "text area" size for clipping.
Vector3f dimScaled = trans * Vector3f(getTextAreaSize().x(), getTextAreaSize().y(), 0); glm::vec3 dimScaled{};
Vector2i clipDim(static_cast<int>((dimScaled.x()) - trans.translation().x()), dimScaled.x = std::fabs(trans[3].x + getTextAreaSize().x);
static_cast<int>((dimScaled.y()) - trans.translation().y())); dimScaled.y = std::fabs(trans[3].y + getTextAreaSize().y);
glm::ivec2 clipDim{static_cast<int>(dimScaled.x - trans[3].x),
static_cast<int>(dimScaled.y - trans[3].y)};
Renderer::pushClipRect(clipPos, clipDim); Renderer::pushClipRect(clipPos, clipDim);
trans.translate(Vector3f(-mScrollOffset.x(), -mScrollOffset.y(), 0)); trans = glm::translate(trans, glm::vec3{-mScrollOffset.x, -mScrollOffset.y, 0.0f});
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
if (mTextCache) if (mTextCache)
@ -299,9 +299,9 @@ void TextEditComponent::render(const Transform4x4f& parentTrans)
// Draw cursor. // Draw cursor.
if (mEditing) { if (mEditing) {
Vector2f cursorPos; glm::vec2 cursorPos;
if (isMultiline()) { if (isMultiline()) {
cursorPos = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor); cursorPos = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x, mCursor);
} }
else { else {
cursorPos = mFont->sizeText(mText.substr(0, mCursor)); cursorPos = mFont->sizeText(mText.substr(0, mCursor));
@ -309,24 +309,24 @@ void TextEditComponent::render(const Transform4x4f& parentTrans)
} }
float cursorHeight = mFont->getHeight() * 0.8f; float cursorHeight = mFont->getHeight() * 0.8f;
Renderer::drawRect( Renderer::drawRect(cursorPos.x, cursorPos.y + (mFont->getHeight() - cursorHeight) / 2.0f,
cursorPos.x(), cursorPos.y() + (mFont->getHeight() - cursorHeight) / 2.0f, 2.0f * Renderer::getScreenWidthModifier(), cursorHeight, 0x000000FF,
2.0f * Renderer::getScreenWidthModifier(), cursorHeight, 0x000000FF, 0x000000FF); 0x000000FF);
} }
} }
Vector2f TextEditComponent::getTextAreaPos() const glm::vec2 TextEditComponent::getTextAreaPos() const
{ {
return Vector2f( return glm::vec2{
(-mResolutionAdjustment + (TEXT_PADDING_HORIZ * Renderer::getScreenWidthModifier())) / 2.0f, (-mResolutionAdjustment + (TEXT_PADDING_HORIZ * Renderer::getScreenWidthModifier())) / 2.0f,
(TEXT_PADDING_VERT * Renderer::getScreenHeightModifier()) / 2.0f); (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier()) / 2.0f};
} }
Vector2f TextEditComponent::getTextAreaSize() const glm::vec2 TextEditComponent::getTextAreaSize() const
{ {
return Vector2f(mSize.x() + mResolutionAdjustment - return glm::vec2{mSize.x + mResolutionAdjustment -
(TEXT_PADDING_HORIZ * Renderer::getScreenWidthModifier()), (TEXT_PADDING_HORIZ * Renderer::getScreenWidthModifier()),
mSize.y() - (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier())); mSize.y - (TEXT_PADDING_VERT * Renderer::getScreenHeightModifier())};
} }
std::vector<HelpPrompt> TextEditComponent::getHelpPrompts() std::vector<HelpPrompt> TextEditComponent::getHelpPrompts()

View file

@ -25,7 +25,7 @@ public:
void textInput(const std::string& text) override; void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void onFocusGained() override; void onFocusGained() override;
void onFocusLost() override; void onFocusLost() override;
@ -52,9 +52,9 @@ private:
void updateCursorRepeat(int deltaTime); void updateCursorRepeat(int deltaTime);
void moveCursor(int amt); void moveCursor(int amt);
bool isMultiline() { return (getSize().y() > mFont->getHeight() * 1.25f); } bool isMultiline() { return (getSize().y > mFont->getHeight() * 1.25f); }
Vector2f getTextAreaPos() const; glm::vec2 getTextAreaPos() const;
Vector2f getTextAreaSize() const; glm::vec2 getTextAreaSize() const;
std::string mText; std::string mText;
std::string mTextOrig; std::string mTextOrig;
@ -65,7 +65,7 @@ private:
int mCursorRepeatTimer; int mCursorRepeatTimer;
int mCursorRepeatDir; int mCursorRepeatDir;
Vector2f mScrollOffset; glm::vec2 mScrollOffset;
NinePatchComponent mBox; NinePatchComponent mBox;
float mResolutionAdjustment; float mResolutionAdjustment;

View file

@ -48,7 +48,7 @@ public:
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void applyTheme(const std::shared_ptr<ThemeData>& theme, void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view, const std::string& view,
const std::string& element, const std::string& element,
@ -155,22 +155,22 @@ TextListComponent<T>::TextListComponent(Window* window)
mColors[1] = 0x00FF00FF; mColors[1] = 0x00FF00FF;
} }
template <typename T> void TextListComponent<T>::render(const Transform4x4f& parentTrans) template <typename T> void TextListComponent<T>::render(const glm::mat4& parentTrans)
{ {
if (size() == 0) if (size() == 0)
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
std::shared_ptr<Font>& font = mFont; std::shared_ptr<Font>& font{mFont};
int startEntry = 0; int startEntry{0};
float y = 0; float y{0.0f};
const float entrySize = const float entrySize{std::max(font->getHeight(1.0), static_cast<float>(font->getSize())) *
std::max(font->getHeight(1.0), static_cast<float>(font->getSize())) * mLineSpacing; mLineSpacing};
// Number of entries that can fit on the screen simultaneously. // Number of entries that can fit on the screen simultaneously.
int screenCount = static_cast<int>(mSize.y() / entrySize + 0.5f); int screenCount = static_cast<int>(mSize.y / entrySize + 0.5f);
if (size() >= screenCount) { if (size() >= screenCount) {
startEntry = mCursor - screenCount / 2; startEntry = mCursor - screenCount / 2;
@ -193,25 +193,26 @@ template <typename T> void TextListComponent<T>::render(const Transform4x4f& par
} }
else { else {
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, (mCursor - startEntry) * entrySize + mSelectorOffsetY, Renderer::drawRect(0.0f, (mCursor - startEntry) * entrySize + mSelectorOffsetY, mSize.x,
mSize.x(), mSelectorHeight, mSelectorColor, mSelectorColorEnd, mSelectorHeight, mSelectorColor, mSelectorColorEnd,
mSelectorColorGradientHorizontal); mSelectorColorGradientHorizontal);
} }
} }
if (Settings::getInstance()->getBool("DebugText")) { if (Settings::getInstance()->getBool("DebugText")) {
Renderer::drawRect(mHorizontalMargin, 0.0f, mSize.x() - mHorizontalMargin * 2.0f, mSize.y(), Renderer::drawRect(mHorizontalMargin, 0.0f, mSize.x - mHorizontalMargin * 2.0f, mSize.y,
0x00000033, 0x00000033); 0x00000033, 0x00000033);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x0000FF33, 0x0000FF33); Renderer::drawRect(0.0f, 0.0f, mSize.x, mSize.y, 0x0000FF33, 0x0000FF33);
} }
// Clip to inside margins. // Clip to inside margins.
Vector3f dim(mSize.x(), mSize.y(), 0.0f); glm::vec3 dim{mSize.x, mSize.y, 0.0f};
dim = trans * dim - trans.translation(); dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x;
dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
Renderer::pushClipRect( Renderer::pushClipRect(
Vector2i(static_cast<int>(trans.translation().x() + mHorizontalMargin), glm::ivec2{static_cast<int>(trans[3].x + mHorizontalMargin), static_cast<int>(trans[3].y)},
static_cast<int>(trans.translation().y())), glm::ivec2{static_cast<int>(dim.x - mHorizontalMargin * 2.0f), static_cast<int>(dim.y)});
Vector2i(static_cast<int>(dim.x() - mHorizontalMargin * 2.0f), static_cast<int>(dim.y())));
for (int i = startEntry; i < listCutoff; i++) { for (int i = startEntry; i < listCutoff; i++) {
typename IList<TextListData, T>::Entry& entry = mEntries.at(static_cast<unsigned int>(i)); typename IList<TextListData, T>::Entry& entry = mEntries.at(static_cast<unsigned int>(i));
@ -235,34 +236,35 @@ template <typename T> void TextListComponent<T>::render(const Transform4x4f& par
else else
entry.data.textCache->setColor(color); entry.data.textCache->setColor(color);
Vector3f offset(0.0f, y, 0.0f); glm::vec3 offset{0.0f, y, 0.0f};
switch (mAlignment) { switch (mAlignment) {
case ALIGN_LEFT: case ALIGN_LEFT:
offset[0] = mHorizontalMargin; offset.x = mHorizontalMargin;
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
offset[0] = offset.x =
static_cast<float>((mSize.x() - entry.data.textCache->metrics.size.x()) / 2.0f); static_cast<float>((mSize.x - entry.data.textCache->metrics.size.x) / 2.0f);
if (offset[0] < mHorizontalMargin) if (offset.x < mHorizontalMargin)
offset[0] = mHorizontalMargin; offset.x = mHorizontalMargin;
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
offset[0] = (mSize.x() - entry.data.textCache->metrics.size.x()); offset.x = (mSize.x - entry.data.textCache->metrics.size.x);
offset[0] -= mHorizontalMargin; offset.x -= mHorizontalMargin;
if (offset[0] < mHorizontalMargin) if (offset.x < mHorizontalMargin)
offset[0] = mHorizontalMargin; offset.x = mHorizontalMargin;
break; break;
} }
// Render text. // Render text.
Transform4x4f drawTrans = trans; glm::mat4 drawTrans{trans};
// Currently selected item text might be scrolling. // Currently selected item text might be scrolling.
if (mCursor == i && mMarqueeOffset > 0) if (mCursor == i && mMarqueeOffset > 0)
drawTrans.translate(offset - Vector3f(static_cast<float>(mMarqueeOffset), 0.0f, 0.0f)); drawTrans = glm::translate(
drawTrans, offset - glm::vec3{static_cast<float>(mMarqueeOffset), 0.0f, 0.0f});
else else
drawTrans.translate(offset); drawTrans = glm::translate(drawTrans, offset);
// Needed to avoid flickering when returning to the start position. // Needed to avoid flickering when returning to the start position.
if (mMarqueeOffset == 0 && mMarqueeOffset2 == 0) if (mMarqueeOffset == 0 && mMarqueeOffset2 == 0)
@ -275,13 +277,13 @@ template <typename T> void TextListComponent<T>::render(const Transform4x4f& par
if ((mCursor == i && mMarqueeOffset2 < 0) || (mCursor == i && mMarqueeScroll)) { if ((mCursor == i && mMarqueeOffset2 < 0) || (mCursor == i && mMarqueeScroll)) {
mMarqueeScroll = true; mMarqueeScroll = true;
drawTrans = trans; drawTrans = trans;
drawTrans.translate(offset - Vector3f(static_cast<float>(mMarqueeOffset2), 0.0f, 0.0f)); drawTrans = glm::translate(
drawTrans, offset - glm::vec3{static_cast<float>(mMarqueeOffset2), 0.0f, 0.0f});
Renderer::setMatrix(drawTrans); Renderer::setMatrix(drawTrans);
font->renderTextCache(entry.data.textCache.get()); font->renderTextCache(entry.data.textCache.get());
} }
y += entrySize; y += entrySize;
} }
Renderer::popClipRect(); Renderer::popClipRect();
listRenderTitleOverlay(trans); listRenderTitleOverlay(trans);
GuiComponent::renderChildren(trans); GuiComponent::renderChildren(trans);
@ -347,13 +349,13 @@ template <typename T> void TextListComponent<T>::update(int deltaTime)
const float textLength = mFont const float textLength = mFont
->sizeText(Utils::String::toUpper( ->sizeText(Utils::String::toUpper(
mEntries.at(static_cast<unsigned int>(mCursor)).name)) mEntries.at(static_cast<unsigned int>(mCursor)).name))
.x(); .x;
const float limit = mSize.x() - mHorizontalMargin * 2.0f; const float limit = mSize.x - mHorizontalMargin * 2.0f;
if (textLength > limit) { if (textLength > limit) {
// Loop. // Loop.
// Pixels per second (based on nes-mini font at 1920x1080 to produce a speed of 200). // Pixels per second (based on nes-mini font at 1920x1080 to produce a speed of 200).
const float speed = mFont->sizeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ").x() * 0.247f; const float speed = mFont->sizeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ").x * 0.247f;
const float delay = 3000.0f; const float delay = 3000.0f;
const float scrollLength = textLength; const float scrollLength = textLength;
const float returnLength = speed * 1.5f; const float returnLength = speed * 1.5f;
@ -450,7 +452,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (elem->has("horizontalMargin")) { if (elem->has("horizontalMargin")) {
mHorizontalMargin = elem->get<float>("horizontalMargin") * mHorizontalMargin = elem->get<float>("horizontalMargin") *
(this->mParent ? this->mParent->getSize().x() : (this->mParent ? this->mParent->getSize().x :
static_cast<float>(Renderer::getScreenWidth())); static_cast<float>(Renderer::getScreenWidth()));
} }
} }
@ -464,7 +466,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("selectorHeight")) if (elem->has("selectorHeight"))
setSelectorHeight(elem->get<float>("selectorHeight") * Renderer::getScreenHeight()); setSelectorHeight(elem->get<float>("selectorHeight") * Renderer::getScreenHeight());
if (elem->has("selectorOffsetY")) { if (elem->has("selectorOffsetY")) {
float scale = this->mParent ? this->mParent->getSize().y() : float scale = this->mParent ? this->mParent->getSize().y :
static_cast<float>(Renderer::getScreenHeight()); static_cast<float>(Renderer::getScreenHeight());
setSelectorOffsetY(elem->get<float>("selectorOffsetY") * scale); setSelectorOffsetY(elem->get<float>("selectorOffsetY") * scale);
} }
@ -477,7 +479,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
std::string path = elem->get<std::string>("selectorImagePath"); std::string path = elem->get<std::string>("selectorImagePath");
bool tile = elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile"); bool tile = elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile");
mSelectorImage.setImage(path, tile); mSelectorImage.setImage(path, tile);
mSelectorImage.setSize(mSize.x(), mSelectorHeight); mSelectorImage.setSize(mSize.x, mSelectorHeight);
mSelectorImage.setColorShift(mSelectorColor); mSelectorImage.setColorShift(mSelectorColor);
mSelectorImage.setColorShiftEnd(mSelectorColorEnd); mSelectorImage.setColorShiftEnd(mSelectorColorEnd);
} }

View file

@ -171,12 +171,12 @@ void VideoComponent::topWindow(bool isTop)
manageState(); manageState();
} }
void VideoComponent::render(const Transform4x4f& parentTrans) void VideoComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible()) if (!isVisible())
return; return;
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
GuiComponent::renderChildren(trans); GuiComponent::renderChildren(trans);
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
@ -191,7 +191,7 @@ void VideoComponent::render(const Transform4x4f& parentTrans)
pauseVideo(); pauseVideo();
} }
void VideoComponent::renderSnapshot(const Transform4x4f& parentTrans) void VideoComponent::renderSnapshot(const glm::mat4& parentTrans)
{ {
// This function is called when the video is not currently being played. We need to // This function is called when the video is not currently being played. We need to
// work out if we should display a static image. If the menu is open, then always render // work out if we should display a static image. If the menu is open, then always render
@ -223,24 +223,24 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (!elem) if (!elem)
return; return;
Vector2f scale = getParent() ? getParent()->getSize() : glm::vec2 scale{getParent() ? getParent()->getSize() :
Vector2f(static_cast<float>(Renderer::getScreenWidth()), glm::vec2{static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight())); static_cast<float>(Renderer::getScreenHeight())}};
if (properties & ThemeFlags::SIZE) { if (properties & ThemeFlags::SIZE) {
if (elem->has("size")) { if (elem->has("size")) {
setResize(elem->get<Vector2f>("size") * scale); setResize(elem->get<glm::vec2>("size") * scale);
mVideoAreaSize = elem->get<Vector2f>("size") * scale; mVideoAreaSize = elem->get<glm::vec2>("size") * scale;
} }
else if (elem->has("maxSize")) { else if (elem->has("maxSize")) {
setMaxSize(elem->get<Vector2f>("maxSize") * scale); setMaxSize(elem->get<glm::vec2>("maxSize") * scale);
mVideoAreaSize = elem->get<Vector2f>("maxSize") * scale; mVideoAreaSize = elem->get<glm::vec2>("maxSize") * scale;
} }
} }
if (properties & ThemeFlags::POSITION) { if (properties & ThemeFlags::POSITION) {
if (elem->has("pos")) if (elem->has("pos"))
mVideoAreaPos = elem->get<Vector2f>("pos") * scale; mVideoAreaPos = elem->get<glm::vec2>("pos") * scale;
} }
if (elem->has("default")) if (elem->has("default"))

View file

@ -61,8 +61,8 @@ public:
void onPositionChanged() override { mStaticImage.setPosition(mPosition); } void onPositionChanged() override { mStaticImage.setPosition(mPosition); }
void onSizeChanged() override { mStaticImage.onSizeChanged(); } void onSizeChanged() override { mStaticImage.onSizeChanged(); }
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void renderSnapshot(const Transform4x4f& parentTrans); void renderSnapshot(const glm::mat4& parentTrans);
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view, const std::string& view,
@ -78,13 +78,13 @@ public:
// zero, no resizing. This can be set before or after a video is loaded. // zero, no resizing. This can be set before or after a video is loaded.
// setMaxSize() and setResize() are mutually exclusive. // setMaxSize() and setResize() are mutually exclusive.
virtual void setResize(float width, float height) override = 0; virtual void setResize(float width, float height) override = 0;
void setResize(const Vector2f& size) { setResize(size.x(), size.y()); } void setResize(const glm::vec2& size) { setResize(size.x, size.y); }
// Resize the video to be as large as possible but fit within a box of this size. // Resize the video to be as large as possible but fit within a box of this size.
// This can be set before or after a video is loaded. // This can be set before or after a video is loaded.
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive. // Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
virtual void setMaxSize(float width, float height) = 0; virtual void setMaxSize(float width, float height) = 0;
void setMaxSize(const Vector2f& size) { setMaxSize(size.x(), size.y()); } void setMaxSize(const glm::vec2& size) { setMaxSize(size.x, size.y); }
private: private:
// Start the video immediately. // Start the video immediately.
@ -110,9 +110,9 @@ protected:
Window* mWindow; Window* mWindow;
unsigned mVideoWidth; unsigned mVideoWidth;
unsigned mVideoHeight; unsigned mVideoHeight;
Vector2f mTargetSize; glm::vec2 mTargetSize;
Vector2f mVideoAreaPos; glm::vec2 mVideoAreaPos;
Vector2f mVideoAreaSize; glm::vec2 mVideoAreaSize;
std::shared_ptr<TextureResource> mTexture; std::shared_ptr<TextureResource> mTexture;
std::string mStaticImagePath; std::string mStaticImagePath;
ImageComponent mStaticImage; ImageComponent mStaticImage;

View file

@ -57,7 +57,7 @@ VideoFFmpegComponent::~VideoFFmpegComponent() { stopVideo(); }
void VideoFFmpegComponent::setResize(float width, float height) void VideoFFmpegComponent::setResize(float width, float height)
{ {
// This resize function is used when stretching videos to full screen in the video screensaver. // This resize function is used when stretching videos to full screen in the video screensaver.
mTargetSize = Vector2f(width, height); mTargetSize = glm::vec2{width, height};
mTargetIsMax = false; mTargetIsMax = false;
mStaticImage.setResize(width, height); mStaticImage.setResize(width, height);
resize(); resize();
@ -67,7 +67,7 @@ void VideoFFmpegComponent::setMaxSize(float width, float height)
{ {
// This resize function is used in most instances, such as non-stretched video screensaver // This resize function is used in most instances, such as non-stretched video screensaver
// and the gamelist videos. // and the gamelist videos.
mTargetSize = Vector2f(width, height); mTargetSize = glm::vec2{width, height};
mTargetIsMax = true; mTargetIsMax = true;
mStaticImage.setMaxSize(width, height); mStaticImage.setMaxSize(width, height);
resize(); resize();
@ -78,51 +78,51 @@ void VideoFFmpegComponent::resize()
if (!mTexture) if (!mTexture)
return; return;
const Vector2f textureSize(static_cast<float>(mVideoWidth), static_cast<float>(mVideoHeight)); const glm::vec2 textureSize{static_cast<float>(mVideoWidth), static_cast<float>(mVideoHeight)};
if (textureSize == Vector2f::Zero()) if (textureSize == glm::vec2{})
return; return;
if (mTargetIsMax) { if (mTargetIsMax) {
mSize = textureSize; mSize = textureSize;
Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y())); glm::vec2 resizeScale{(mTargetSize.x / mSize.x), (mTargetSize.y / mSize.y)};
if (resizeScale.x() < resizeScale.y()) { if (resizeScale.x < resizeScale.y) {
mSize[0] *= resizeScale.x(); mSize.x *= resizeScale.x;
mSize[1] *= resizeScale.x(); mSize.y *= resizeScale.x;
} }
else { else {
mSize[0] *= resizeScale.y(); mSize.x *= resizeScale.y;
mSize[1] *= resizeScale.y(); mSize.y *= resizeScale.y;
} }
mSize[1] = std::round(mSize[1]); mSize.y = std::round(mSize.y);
mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x(); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
} }
else { else {
// If both components are set, we just stretch. // If both components are set, we just stretch.
// If no components are set, we don't resize at all. // If no components are set, we don't resize at all.
mSize = mTargetSize == Vector2f::Zero() ? textureSize : mTargetSize; mSize = mTargetSize == glm::vec2{} ? textureSize : mTargetSize;
// If only one component is set, we resize in a way that maintains aspect ratio. // If only one component is set, we resize in a way that maintains aspect ratio.
if (!mTargetSize.x() && mTargetSize.y()) { if (!mTargetSize.x && mTargetSize.y) {
mSize[1] = std::round(mTargetSize.y()); mSize.y = std::round(mTargetSize.y);
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
} }
else if (mTargetSize.x() && !mTargetSize.y()) { else if (mTargetSize.x && !mTargetSize.y) {
mSize[1] = std::round((mTargetSize.x() / textureSize.x()) * textureSize.y()); mSize.y = std::round((mTargetSize.x / textureSize.x) * textureSize.y);
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
} }
} }
onSizeChanged(); onSizeChanged();
} }
void VideoFFmpegComponent::render(const Transform4x4f& parentTrans) void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
{ {
VideoComponent::render(parentTrans); VideoComponent::render(parentTrans);
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
GuiComponent::renderChildren(trans); GuiComponent::renderChildren(trans);
if (mIsPlaying && mFormatContext) { if (mIsPlaying && mFormatContext) {
@ -146,15 +146,15 @@ void VideoFFmpegComponent::render(const Transform4x4f& parentTrans)
} }
// clang-format off // clang-format off
vertices[0] = { { 0.0f , 0.0f }, { 0.0f, 0.0f }, color }; vertices[0] = {{0.0f , 0.0f }, {0.0f, 0.0f}, color};
vertices[1] = { { 0.0f , mSize.y() }, { 0.0f, 1.0f }, color }; vertices[1] = {{0.0f , mSize.y}, {0.0f, 1.0f}, color};
vertices[2] = { { mSize.x(), 0.0f }, { 1.0f, 0.0f }, color }; vertices[2] = {{mSize.x , 0.0f }, {1.0f, 0.0f}, color};
vertices[3] = { { mSize.x(), mSize.y() }, { 1.0f, 1.0f }, color }; vertices[3] = {{mSize.x , mSize.y}, {1.0f, 1.0f}, color};
// clang-format on // clang-format on
// Round vertices. // Round vertices.
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
vertices[i].pos.round(); vertices[i].pos = glm::round(vertices[i].pos);
// This is needed to avoid a slight gap before the video starts playing. // This is needed to avoid a slight gap before the video starts playing.
if (!mDecodedFrame) if (!mDecodedFrame)
@ -290,7 +290,7 @@ bool VideoFFmpegComponent::setupVideoFilters()
{ {
int returnValue = 0; int returnValue = 0;
char errorMessage[512]; char errorMessage[512];
const enum AVPixelFormat outPixFormats[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE }; const enum AVPixelFormat outPixFormats[] = {AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE};
mVFilterInputs = avfilter_inout_alloc(); mVFilterInputs = avfilter_inout_alloc();
mVFilterOutputs = avfilter_inout_alloc(); mVFilterOutputs = avfilter_inout_alloc();
@ -416,8 +416,8 @@ bool VideoFFmpegComponent::setupAudioFilters()
{ {
int returnValue = 0; int returnValue = 0;
char errorMessage[512]; char errorMessage[512];
const int outSampleRates[] = { AudioManager::getInstance()->sAudioFormat.freq, -1 }; const int outSampleRates[] = {AudioManager::getInstance()->sAudioFormat.freq, -1};
const enum AVSampleFormat outSampleFormats[] = { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }; const enum AVSampleFormat outSampleFormats[] = {AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE};
mAFilterInputs = avfilter_inout_alloc(); mAFilterInputs = avfilter_inout_alloc();
mAFilterOutputs = avfilter_inout_alloc(); mAFilterOutputs = avfilter_inout_alloc();
@ -798,51 +798,49 @@ void VideoFFmpegComponent::calculateBlackRectangle()
// otherwise it will exactly match the video size. The reason to add a black rectangle // otherwise it will exactly match the video size. The reason to add a black rectangle
// behind videos in this second instance is that the scanline rendering will make the // behind videos in this second instance is that the scanline rendering will make the
// video partially transparent so this may avoid some unforseen issues with some themes. // video partially transparent so this may avoid some unforseen issues with some themes.
if (mVideoAreaPos != 0 && mVideoAreaSize != 0) { if (mVideoAreaPos != glm::vec2{} && mVideoAreaSize != glm::vec2{}) {
mVideoRectangleCoords.clear(); mVideoRectangleCoords.clear();
if (Settings::getInstance()->getBool("GamelistVideoPillarbox")) { if (Settings::getInstance()->getBool("GamelistVideoPillarbox")) {
float rectHeight; float rectHeight;
float rectWidth; float rectWidth;
// Video is in landscape orientation. // Video is in landscape orientation.
if (mSize.x() > mSize.y()) { if (mSize.x > mSize.y) {
// Checking the Y size should not normally be required as landscape format // Checking the Y size should not normally be required as landscape format
// should mean the height can't be higher than the max size defined by the // should mean the height can't be higher than the max size defined by the
// theme. But as the height in mSize is provided by FFmpeg in integer format // theme. But as the height in mSize is provided by FFmpeg in integer format
// and then scaled, there could be rounding errors that make the video height // and then scaled, there could be rounding errors that make the video height
// slightly higher than allowed. It's only a single pixel or a few pixels, but // slightly higher than allowed. It's only a single pixel or a few pixels, but
// it's still visible for some videos. // it's still visible for some videos.
if (mSize.y() < mVideoAreaSize.y() && mSize.y() / mVideoAreaSize.y() < 0.90) if (mSize.y < mVideoAreaSize.y && mSize.y / mVideoAreaSize.y < 0.90f)
rectHeight = mVideoAreaSize.y(); rectHeight = mVideoAreaSize.y;
else else
rectHeight = mSize.y(); rectHeight = mSize.y;
// Don't add a black border that is too narrow, that's what the 0.85 constant // Don't add a black border that is too narrow, that's what the 0.85 constant
// takes care of. // takes care of.
if (mSize.x() < mVideoAreaSize.x() && mSize.x() / mVideoAreaSize.x() < 0.85) if (mSize.x < mVideoAreaSize.x && mSize.x / mVideoAreaSize.x < 0.85f)
rectWidth = mVideoAreaSize.x(); rectWidth = mVideoAreaSize.x;
else else
rectWidth = mSize.x(); rectWidth = mSize.x;
} }
// Video is in portrait orientation (or completely square). // Video is in portrait orientation (or completely square).
else { else {
rectWidth = mVideoAreaSize.x(); rectWidth = mVideoAreaSize.x;
rectHeight = mSize.y(); rectHeight = mSize.y;
} }
// Populate the rectangle coordinates to be used in render(). // Populate the rectangle coordinates to be used in render().
mVideoRectangleCoords.push_back( mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.x - rectWidth * mOrigin.x));
std::round(mVideoAreaPos.x() - rectWidth * mOrigin.x())); mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.y - rectHeight * mOrigin.y));
mVideoRectangleCoords.push_back(
std::round(mVideoAreaPos.y() - rectHeight * mOrigin.y()));
mVideoRectangleCoords.push_back(std::round(rectWidth)); mVideoRectangleCoords.push_back(std::round(rectWidth));
mVideoRectangleCoords.push_back(std::round(rectHeight)); mVideoRectangleCoords.push_back(std::round(rectHeight));
} }
// If the option to display pillarboxes is disabled, then make the rectangle equivalent // If the option to display pillarboxes is disabled, then make the rectangle equivalent
// to the size of the video. // to the size of the video.
else { else {
mVideoRectangleCoords.push_back(std::round(mPosition.x() - mSize.x() * mOrigin.x())); mVideoRectangleCoords.push_back(std::round(mPosition.x - mSize.x * mOrigin.x));
mVideoRectangleCoords.push_back(std::round(mPosition.y() - mSize.y() * mOrigin.y())); mVideoRectangleCoords.push_back(std::round(mPosition.y - mSize.y * mOrigin.y));
mVideoRectangleCoords.push_back(std::round(mSize.x())); mVideoRectangleCoords.push_back(std::round(mSize.x));
mVideoRectangleCoords.push_back(std::round(mSize.y())); mVideoRectangleCoords.push_back(std::round(mSize.y));
} }
} }
} }

View file

@ -50,7 +50,7 @@ private:
// Used internally whenever the resizing parameters or texture change. // Used internally whenever the resizing parameters or texture change.
void resize(); void resize();
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
virtual void updatePlayer() override; virtual void updatePlayer() override;
// This will run the frame processing in a separate thread. // This will run the frame processing in a separate thread.

View file

@ -63,7 +63,7 @@ void VideoVlcComponent::deinit()
void VideoVlcComponent::setResize(float width, float height) void VideoVlcComponent::setResize(float width, float height)
{ {
// This resize function is used when stretching videos to full screen in the video screensaver. // This resize function is used when stretching videos to full screen in the video screensaver.
mTargetSize = Vector2f(width, height); mTargetSize = glm::vec2{width, height};
mTargetIsMax = false; mTargetIsMax = false;
mStaticImage.setResize(width, height); mStaticImage.setResize(width, height);
resize(); resize();
@ -73,7 +73,7 @@ void VideoVlcComponent::setMaxSize(float width, float height)
{ {
// This resize function is used in most instances, such as non-stretched video screensaver // This resize function is used in most instances, such as non-stretched video screensaver
// and the gamelist videos. // and the gamelist videos.
mTargetSize = Vector2f(width, height); mTargetSize = glm::vec2{width, height};
mTargetIsMax = true; mTargetIsMax = true;
mStaticImage.setMaxSize(width, height); mStaticImage.setMaxSize(width, height);
resize(); resize();
@ -83,7 +83,7 @@ void VideoVlcComponent::setupVLC()
{ {
// If VLC hasn't been initialised yet then do it now. // If VLC hasn't been initialised yet then do it now.
if (!mVLC) { if (!mVLC) {
const char* args[] = { "--quiet" }; const char* args[] = {"--quiet"};
#if defined(__APPLE__) #if defined(__APPLE__)
// It's required to set the VLC_PLUGIN_PATH variable on macOS, or the libVLC // It's required to set the VLC_PLUGIN_PATH variable on macOS, or the libVLC
@ -127,48 +127,48 @@ void VideoVlcComponent::resize()
if (!mTexture) if (!mTexture)
return; return;
const Vector2f textureSize(static_cast<float>(mVideoWidth), static_cast<float>(mVideoHeight)); const glm::vec2 textureSize(static_cast<float>(mVideoWidth), static_cast<float>(mVideoHeight));
if (textureSize == Vector2f::Zero()) if (textureSize == glm::vec2{})
return; return;
if (mTargetIsMax) { if (mTargetIsMax) {
mSize = textureSize; mSize = textureSize;
Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y())); glm::vec2 resizeScale{(mTargetSize.x / mSize.x), (mTargetSize.y / mSize.y)};
if (resizeScale.x() < resizeScale.y()) { if (resizeScale.x < resizeScale.y) {
mSize[0] *= resizeScale.x(); mSize.x *= resizeScale.x;
mSize[1] *= resizeScale.x(); mSize.y *= resizeScale.x;
} }
else { else {
mSize[0] *= resizeScale.y(); mSize.x *= resizeScale.y;
mSize[1] *= resizeScale.y(); mSize.y *= resizeScale.y;
} }
mSize[1] = std::round(mSize[1]); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x(); mSize.y = std::round(mSize[1]);
} }
else { else {
// If both components are set, we just stretch. // If both components are set, we just stretch.
// If no components are set, we don't resize at all. // If no components are set, we don't resize at all.
mSize = mTargetSize == Vector2f::Zero() ? textureSize : mTargetSize; mSize = mTargetSize == glm::vec2{} ? textureSize : mTargetSize;
// If only one component is set, we resize in a way that maintains aspect ratio. // If only one component is set, we resize in a way that maintains aspect ratio.
if (!mTargetSize.x() && mTargetSize.y()) { if (!mTargetSize.x && mTargetSize.y) {
mSize[1] = std::round(mTargetSize.y()); mSize.y = std::round(mTargetSize.y);
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
} }
else if (mTargetSize.x() && !mTargetSize.y()) { else if (mTargetSize.x && !mTargetSize.y) {
mSize[1] = std::round((mTargetSize.x() / textureSize.x()) * textureSize.y()); mSize.y = std::round((mTargetSize.x / textureSize.x) * textureSize.y);
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x(); mSize.x = (mSize.y / textureSize.y) * textureSize.x;
} }
} }
onSizeChanged(); onSizeChanged();
} }
void VideoVlcComponent::render(const Transform4x4f& parentTrans) void VideoVlcComponent::render(const glm::mat4& parentTrans)
{ {
// Set the audio volume. As libVLC is very unreliable we need to make an additional // Set the audio volume. As libVLC is very unreliable we need to make an additional
// attempt here in the render loop in addition to the initialization in startVideo(). // attempt here in the render loop in addition to the initialization in startVideo().
@ -179,7 +179,7 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans)
setAudioVolume(); setAudioVolume();
VideoComponent::render(parentTrans); VideoComponent::render(parentTrans);
Transform4x4f trans = parentTrans * getTransform(); glm::mat4 trans{parentTrans * getTransform()};
GuiComponent::renderChildren(trans); GuiComponent::renderChildren(trans);
// Check the actual VLC state, i.e. if the video is really playing rather than // Check the actual VLC state, i.e. if the video is really playing rather than
@ -213,15 +213,15 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans)
} }
// clang-format off // clang-format off
vertices[0] = { { 0.0f , 0.0f }, { 0.0f, 0.0f }, color }; vertices[0] = {{0.0f , 0.0f }, {0.0f, 0.0f}, color};
vertices[1] = { { 0.0f , mSize.y() }, { 0.0f, 1.0f }, color }; vertices[1] = {{0.0f , mSize.y}, {0.0f, 1.0f}, color};
vertices[2] = { { mSize.x(), 0.0f }, { 1.0f, 0.0f }, color }; vertices[2] = {{mSize.x, 0.0f }, {1.0f, 0.0f}, color};
vertices[3] = { { mSize.x(), mSize.y() }, { 1.0f, 1.0f }, color }; vertices[3] = {{mSize.x, mSize.y}, {1.0f, 1.0f}, color};
// clang-format on // clang-format on
// Round vertices. // Round vertices.
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
vertices[i].pos.round(); vertices[i].pos = glm::round(vertices[i].pos);
// Build a texture for the video frame. // Build a texture for the video frame.
mTexture->initFromPixels(reinterpret_cast<unsigned char*>(mContext.surface->pixels), mTexture->initFromPixels(reinterpret_cast<unsigned char*>(mContext.surface->pixels),
@ -255,51 +255,49 @@ void VideoVlcComponent::calculateBlackRectangle()
// otherwise it will exactly match the video size. The reason to add a black rectangle // otherwise it will exactly match the video size. The reason to add a black rectangle
// behind videos in this second instance is that the scanline rendering will make the // behind videos in this second instance is that the scanline rendering will make the
// video partially transparent so this may avoid some unforseen issues with some themes. // video partially transparent so this may avoid some unforseen issues with some themes.
if (mVideoAreaPos != 0 && mVideoAreaSize != 0) { if (mVideoAreaPos != glm::vec2{} && mVideoAreaSize != glm::vec2{}) {
mVideoRectangleCoords.clear(); mVideoRectangleCoords.clear();
if (Settings::getInstance()->getBool("GamelistVideoPillarbox")) { if (Settings::getInstance()->getBool("GamelistVideoPillarbox")) {
float rectHeight; float rectHeight;
float rectWidth; float rectWidth;
// Video is in landscape orientation. // Video is in landscape orientation.
if (mSize.x() > mSize.y()) { if (mSize.x > mSize.y) {
// Checking the Y size should not normally be required as landscape format // Checking the Y size should not normally be required as landscape format
// should mean the height can't be higher than the max size defined by the // should mean the height can't be higher than the max size defined by the
// theme. But as the height in mSize is provided by libVLC in integer format // theme. But as the height in mSize is provided by libVLC in integer format
// and then scaled, there could be rounding errors that make the video height // and then scaled, there could be rounding errors that make the video height
// slightly higher than allowed. It's only a single pixel or a few pixels, but // slightly higher than allowed. It's only a single pixel or a few pixels, but
// it's still visible for some videos. // it's still visible for some videos.
if (mSize.y() < mVideoAreaSize.y() && mSize.y() / mVideoAreaSize.y() < 0.90) if (mSize.y < mVideoAreaSize.y && mSize.y / mVideoAreaSize.y < 0.90f)
rectHeight = mVideoAreaSize.y(); rectHeight = mVideoAreaSize.y;
else else
rectHeight = mSize.y(); rectHeight = mSize.y;
// Don't add a black border that is too narrow, that's what the 0.85 constant // Don't add a black border that is too narrow, that's what the 0.85 constant
// takes care of. // takes care of.
if (mSize.x() < mVideoAreaSize.x() && mSize.x() / mVideoAreaSize.x() < 0.85) if (mSize.x < mVideoAreaSize.x && mSize.x / mVideoAreaSize.x < 0.85f)
rectWidth = mVideoAreaSize.x(); rectWidth = mVideoAreaSize.x;
else else
rectWidth = mSize.x(); rectWidth = mSize.x;
} }
// Video is in portrait orientation (or completely square). // Video is in portrait orientation (or completely square).
else { else {
rectWidth = mVideoAreaSize.x(); rectWidth = mVideoAreaSize.x;
rectHeight = mSize.y(); rectHeight = mSize.y;
} }
// Populate the rectangle coordinates to be used in render(). // Populate the rectangle coordinates to be used in render().
mVideoRectangleCoords.push_back( mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.x - rectWidth * mOrigin.x));
std::round(mVideoAreaPos.x() - rectWidth * mOrigin.x())); mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.y - rectHeight * mOrigin.y));
mVideoRectangleCoords.push_back(
std::round(mVideoAreaPos.y() - rectHeight * mOrigin.y()));
mVideoRectangleCoords.push_back(std::round(rectWidth)); mVideoRectangleCoords.push_back(std::round(rectWidth));
mVideoRectangleCoords.push_back(std::round(rectHeight)); mVideoRectangleCoords.push_back(std::round(rectHeight));
} }
// If the option to display pillarboxes is disabled, then make the rectangle equivalent // If the option to display pillarboxes is disabled, then make the rectangle equivalent
// to the size of the video. // to the size of the video.
else { else {
mVideoRectangleCoords.push_back(std::round(mPosition.x() - mSize.x() * mOrigin.x())); mVideoRectangleCoords.push_back(std::round(mPosition.x - mSize.x * mOrigin.x));
mVideoRectangleCoords.push_back(std::round(mPosition.y() - mSize.y() * mOrigin.y())); mVideoRectangleCoords.push_back(std::round(mPosition.y - mSize.y * mOrigin.y));
mVideoRectangleCoords.push_back(std::round(mSize.x())); mVideoRectangleCoords.push_back(std::round(mSize.x));
mVideoRectangleCoords.push_back(std::round(mSize.y())); mVideoRectangleCoords.push_back(std::round(mSize.y));
} }
} }
} }

View file

@ -53,7 +53,7 @@ private:
// Used internally whenever the resizing parameters or texture change. // Used internally whenever the resizing parameters or texture change.
void resize(); void resize();
void render(const Transform4x4f& parentTrans) override; void render(const glm::mat4& parentTrans) override;
void calculateBlackRectangle(); void calculateBlackRectangle();
void setAudioVolume(); void setAudioVolume();

Some files were not shown because too many files have changed in this diff Show more