Replaced the internal Vector2f data type and functions with the GLM library equivalent.

This commit is contained in:
Leon Styhre 2021-08-16 18:25:01 +02:00
parent 64a7b8e54a
commit 1fb0ccef0d
74 changed files with 964 additions and 997 deletions

View file

@ -121,7 +121,7 @@ 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(trans); mImage->render(trans);
#if defined(USE_OPENGL_21) #if defined(USE_OPENGL_21)

View file

@ -608,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

@ -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

@ -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, {}, 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,28 +33,28 @@ 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, {}, 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.

View file

@ -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()));
@ -170,10 +170,10 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
mMarquee->setOrigin(0.5f, 0.5f); mMarquee->setOrigin(0.5f, 0.5f);
glm::vec3 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);
@ -185,7 +185,7 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
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, {}, Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3({}), glm::vec2(-32.0f, -32.0f));
mBackground.setEdgeColor(0xEEEEEEFF); mBackground.setEdgeColor(0xEEEEEEFF);
} }

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

@ -78,7 +78,7 @@ 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, glm::vec3 {}, Vector2f(0.0f, 0.0f), Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER, glm::vec3({}), glm::vec2({}),
0x00000000, 0.05f); 0x00000000, 0.05f);
mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true); mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true);
mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true); mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true);
@ -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;
@ -353,8 +353,8 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window,
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, {}, 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.
glm::vec3 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

@ -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, {}, 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

@ -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, {}, 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

@ -88,13 +88,13 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int
mMD_ReleaseDate->setColor(mdColor); mMD_ReleaseDate->setColor(mdColor);
mMD_ReleaseDate->setUppercase(true); mMD_ReleaseDate->setUppercase(true);
mMD_Developer = std::make_shared<TextComponent>( mMD_Developer = std::make_shared<TextComponent>(
mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3({}), glm::vec2({}), 0x00000000, 0.02f);
mMD_Publisher = std::make_shared<TextComponent>( mMD_Publisher = std::make_shared<TextComponent>(
mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3({}), glm::vec2({}), 0x00000000, 0.02f);
mMD_Genre = std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT, mMD_Genre = std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT,
glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); glm::vec3({}), glm::vec2({}), 0x00000000, 0.02f);
mMD_Players = std::make_shared<TextComponent>( mMD_Players = std::make_shared<TextComponent>(mWindow, "", font, mdColor, ALIGN_LEFT,
mWindow, "", font, mdColor, ALIGN_LEFT, glm::vec3 {}, Vector2f::Zero(), 0x00000000, 0.02f); glm::vec3({}), glm::vec2({}), 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")
@ -180,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.
@ -199,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.
@ -226,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);
@ -239,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);
@ -249,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);
@ -266,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.
@ -300,7 +299,7 @@ void GuiScraperSearch::updateViewStyle()
mGrid.setEntry(mDescContainer, Vector2i(3, 0), false, false, Vector2i(1, 3), mGrid.setEntry(mDescContainer, Vector2i(3, 0), false, false, Vector2i(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.
@ -315,7 +314,7 @@ void GuiScraperSearch::updateViewStyle()
mGrid.setEntry(mDescContainer, Vector2i(1, 2), false, false, Vector2i(2, 1), mGrid.setEntry(mDescContainer, Vector2i(1, 2), false, false, Vector2i(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);
} }
} }
@ -566,7 +565,7 @@ void GuiScraperSearch::render(const glm::mat4& parentTrans)
glm::mat4 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

@ -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

@ -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);
@ -474,83 +474,76 @@ void SystemView::getViewElements(const std::shared_ptr<ThemeData>& theme)
void SystemView::renderCarousel(const glm::mat4& trans) void SystemView::renderCarousel(const glm::mat4& trans)
{ {
// Background box behind logos. // Background box behind logos.
glm::mat4 carouselTrans = trans; glm::mat4 carouselTrans = trans;
carouselTrans = carouselTrans =
glm::translate(carouselTrans, glm::vec3(mCarousel.pos.x(), mCarousel.pos.y(), 0.0f)); glm::translate(carouselTrans, glm::vec3(mCarousel.pos.x, mCarousel.pos.y, 0.0f));
carouselTrans = glm::translate( carouselTrans = glm::translate(carouselTrans,
carouselTrans, glm::vec3(mCarousel.origin.x() * mCarousel.size.x() * -1.0f, glm::vec3(mCarousel.origin.x * mCarousel.size.x * -1.0f,
mCarousel.origin.y() * mCarousel.size.y() * -1.0f, 0.0f)); mCarousel.origin.y * mCarousel.size.y * -1.0f, 0.0f));
glm::vec2 clipPos(carouselTrans[3].x, carouselTrans[3].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)), Vector2i(static_cast<int>(clipPos.x), static_cast<int>(clipPos.y)),
Vector2i(static_cast<int>(mCarousel.size.x()), static_cast<int>(mCarousel.size.y()))); Vector2i(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(0.0f, 0.0f);
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 - 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 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 - xOff = (mCarousel.size.x - mCarousel.logoSize.x) / 2.0f - (mCamOffset * logoSpacing.x);
(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;
} }
} }
@ -578,7 +571,7 @@ void SystemView::renderCarousel(const glm::mat4& trans)
glm::mat4 logoTrans = carouselTrans; glm::mat4 logoTrans = carouselTrans;
logoTrans = glm::translate( logoTrans = glm::translate(
logoTrans, glm::vec3(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0.0f)); logoTrans, glm::vec3(i * logoSpacing.x + xOff, i * logoSpacing.y + yOff, 0.0f));
float distance = i - mCamOffset; float distance = i - mCamOffset;
@ -610,7 +603,7 @@ void SystemView::renderExtras(const glm::mat4& trans, float lower, float upper)
int bufferIndex = getScrollingVelocity() + 1; int bufferIndex = getScrollingVelocity() + 1;
Renderer::pushClipRect(Vector2i::Zero(), Renderer::pushClipRect(Vector2i::Zero(),
Vector2i(static_cast<int>(mSize.x()), static_cast<int>(mSize.y()))); Vector2i(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++) {
@ -625,14 +618,14 @@ void SystemView::renderExtras(const glm::mat4& trans, float lower, float upper)
glm::mat4 extrasTrans = trans; glm::mat4 extrasTrans = trans;
if (mCarousel.type == HORIZONTAL || mCarousel.type == HORIZONTAL_WHEEL) if (mCarousel.type == HORIZONTAL || mCarousel.type == HORIZONTAL_WHEEL)
extrasTrans = glm::translate( extrasTrans = glm::translate(
extrasTrans, glm::vec3((i - mExtrasCamOffset) * mSize.x(), 0.0f, 0.0f)); extrasTrans, glm::vec3((i - mExtrasCamOffset) * mSize.x, 0.0f, 0.0f));
else else
extrasTrans = glm::translate( extrasTrans = glm::translate(
extrasTrans, glm::vec3(0.0f, (i - mExtrasCamOffset) * mSize.y(), 0.0f)); extrasTrans, glm::vec3(0.0f, (i - mExtrasCamOffset) * mSize.y, 0.0f));
Renderer::pushClipRect( Renderer::pushClipRect(
Vector2i(static_cast<int>(extrasTrans[3].x), static_cast<int>(extrasTrans[3].y)), Vector2i(static_cast<int>(extrasTrans[3].x), static_cast<int>(extrasTrans[3].y)),
Vector2i(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];
@ -650,7 +643,7 @@ 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);
} }
void SystemView::getDefaultElements(void) void SystemView::getDefaultElements(void)
@ -658,33 +651,33 @@ 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)
@ -700,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;
@ -717,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"))
@ -725,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;
}; };

View file

@ -878,9 +878,8 @@ void ViewController::render(const glm::mat4& parentTrans)
if (it->second == mCurrentView || (it->second == mPreviousView && isCameraMoving())) { if (it->second == mCurrentView || (it->second == mPreviousView && isCameraMoving())) {
// Clipping. // Clipping.
glm::vec3 guiStart = it->second->getPosition(); glm::vec3 guiStart = it->second->getPosition();
glm::vec3 guiEnd = glm::vec3 guiEnd = it->second->getPosition() +
it->second->getPosition() + glm::vec3(it->second->getSize().x, it->second->getSize().y, 0.0f);
glm::vec3(it->second->getSize().x(), it->second->getSize().y(), 0.0f);
if (guiEnd.x >= viewStart.x && guiEnd.y >= viewStart.y && guiStart.x <= viewEnd.x && if (guiEnd.x >= viewStart.x && guiEnd.y >= viewStart.y && guiStart.x <= viewEnd.x &&
guiStart.y <= viewEnd.y) guiStart.y <= viewEnd.y)

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);
@ -165,7 +165,7 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
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));
@ -187,10 +187,10 @@ 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);
glm::vec3 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;
@ -201,12 +201,12 @@ void DetailedGameListView::initMDLabels()
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() + glm::vec3(0.0f, lc->getSize().y() + rowPadding, 0.0f); 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 +227,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() +
glm::vec3(labels[i]->getSize().x(), heightDiff, 0.0f)); 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);
@ -264,7 +264,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
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 +277,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() == glm::vec3 {}) if (mGamelistInfo.getPosition() == glm::vec3({}))
mGamelistInfo.setVisible(false); mGamelistInfo.setVisible(false);
else else
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
@ -298,10 +298,10 @@ 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);
glm::vec3 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;
@ -312,12 +312,12 @@ void GridGameListView::initMDLabels()
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() + glm::vec3(0.0f, lc->getSize().y() + rowPadding, 0.0f); 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 +338,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() +
glm::vec3(labels[i]->getSize().x(), heightDiff, 0.0f)); 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

@ -69,8 +69,8 @@ void IGameListView::render(const glm::mat4& parentTrans)
Vector2i pos(static_cast<int>(std::round(trans[3].x)), Vector2i pos(static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans[3].y))); static_cast<int>(std::round(trans[3].y)));
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)), Vector2i 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

@ -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);
@ -187,14 +187,14 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
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() == glm::vec3 {}) if (mGamelistInfo.getPosition() == glm::vec3({}))
mGamelistInfo.setVisible(false); mGamelistInfo.setVisible(false);
else else
mGamelistInfo.setVisible(true); mGamelistInfo.setVisible(true);
@ -209,10 +209,10 @@ 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);
glm::vec3 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;
@ -223,12 +223,12 @@ void VideoGameListView::initMDLabels()
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() + glm::vec3(0.0f, lc->getSize().y() + rowPadding, 0.0f); 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 +249,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() +
glm::vec3(labels[i]->getSize().x(), heightDiff, 0.0f)); 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

@ -25,9 +25,9 @@ GuiComponent::GuiComponent(Window* window)
, mOpacity(255) , mOpacity(255)
, mSaturation(1.0f) , mSaturation(1.0f)
, mPosition({}) , mPosition({})
, mOrigin(Vector2f::Zero()) , mOrigin({})
, mRotationOrigin(0.5f, 0.5f) , mRotationOrigin(0.5f, 0.5f)
, mSize(Vector2f::Zero()) , mSize({})
, mTransform(Renderer::getIdentity()) , mTransform(Renderer::getIdentity())
, mIsProcessing(false) , mIsProcessing(false)
, mVisible(true) , mVisible(true)
@ -101,20 +101,20 @@ void GuiComponent::setPosition(float x, float y, float z)
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)
@ -181,9 +181,9 @@ const glm::mat4& GuiComponent::getTransform()
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)
@ -196,8 +196,8 @@ const glm::mat4& GuiComponent::getTransform()
if (xOff != 0.0f || yOff != 0.0f) if (xOff != 0.0f || yOff != 0.0f)
mTransform = glm::translate(mTransform, glm::vec3(xOff, yOff, 0.0f)); mTransform = glm::translate(mTransform, glm::vec3(xOff, yOff, 0.0f));
} }
mTransform = glm::translate(mTransform, glm::vec3(mOrigin.x() * mSize.x() * -1.0f, mTransform = glm::translate(
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;
} }
@ -302,8 +302,8 @@ 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, "");
@ -312,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(glm::vec3(denormalized.x(), denormalized.y(), 0.0f)); 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

@ -71,29 +71,29 @@ public:
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)
@ -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; }
@ -250,9 +250,9 @@ protected:
std::vector<GuiComponent*> mChildren; std::vector<GuiComponent*> mChildren;
glm::vec3 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;

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(0.0f, 0.0f);
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

@ -478,7 +478,7 @@ void ThemeData::parseElement(const pugi::xml_node& root,
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;
@ -602,7 +602,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);
} }

View file

@ -11,7 +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 "utils/FileSystemUtil.h" #include "utils/FileSystemUtil.h"
#include <deque> #include <deque>
@ -106,16 +106,16 @@ public:
{ {
r = value; r = value;
const glm::vec4 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; }
glm::vec4 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;
@ -126,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;

View file

@ -475,9 +475,9 @@ void Window::render()
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);
} }
} }
@ -499,11 +499,11 @@ void Window::render()
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;
@ -566,14 +566,14 @@ 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 = glm::translate(trans, glm::vec3(x, y, 0.0f)); trans = glm::translate(trans, glm::vec3(x, y, 0.0f));
Renderer::setMatrix(trans); Renderer::setMatrix(trans);

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);
} }
} }

View file

@ -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::getScreenWidthModifier(),
16.0f * Renderer::getScreenHeightModifier() }); 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(0.0f, 0.0f));
} }
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, {}, 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();
} }
@ -100,15 +100,15 @@ void ButtonComponent::render(const glm::mat4& parentTrans)
mBox.render(trans); mBox.render(trans);
if (mTextCache) { if (mTextCache) {
glm::vec3 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.0f); (mSize.y - mTextCache->metrics.size.y) / 2.0f, 0.0f);
trans = glm::translate(trans, 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);

View file

@ -39,7 +39,7 @@ 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;
@ -50,13 +50,13 @@ float ComponentGrid::getColWidth(int col)
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;
@ -67,7 +67,7 @@ float ComponentGrid::getRowHeight(int row)
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)
@ -132,11 +132,11 @@ 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, 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);
@ -144,13 +144,13 @@ void ComponentGrid::updateCellComponent(const GridEntry& cell)
// Find top left corner. // Find top left corner.
glm::vec3 pos {}; 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.0f; pos.x = pos.x + (size.x - cell.component->getSize().x) / 2.0f;
pos[1] = pos.y + (size.y() - cell.component->getSize().y()) / 2.0f; pos.y = pos.y + (size.y - cell.component->getSize().y) / 2.0f;
cell.component->setPosition(pos); cell.component->setPosition(pos);
} }
@ -161,16 +161,16 @@ 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(0.0f, 0.0f);
size = Vector2f(0, 0); size = glm::vec2(0.0f, 0.0f);
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++)
@ -180,39 +180,39 @@ void ComponentGrid::updateSeparators()
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);
} }
} }

View file

@ -145,25 +145,25 @@ 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;
} }
} }
@ -175,7 +175,7 @@ void ComponentList::render(const glm::mat4& parentTrans)
glm::mat4 trans = parentTrans * getTransform(); glm::mat4 trans = parentTrans * getTransform();
// Clip everything to be inside our bounds. // Clip everything to be inside our bounds.
glm::vec3 dim(mSize.x(), mSize.y(), 0.0f); glm::vec3 dim(mSize.x, mSize.y, 0.0f);
dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x; 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; dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
@ -248,11 +248,11 @@ void ComponentList::render(const glm::mat4& parentTrans)
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);
} }
@ -268,12 +268,12 @@ void ComponentList::render(const glm::mat4& 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();
} }
@ -283,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;
@ -313,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

@ -28,7 +28,7 @@ DateTimeComponent::DateTimeComponent(Window* window,
unsigned int color, unsigned int color,
Alignment align, Alignment align,
glm::vec3 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)

View file

@ -27,7 +27,7 @@ public:
unsigned int color = 0x000000FF, unsigned int color = 0x000000FF,
Alignment align = ALIGN_LEFT, Alignment align = ALIGN_LEFT,
glm::vec3 pos = {}, glm::vec3 pos = {},
Vector2f size = Vector2f::Zero(), glm::vec2 size = {},
unsigned int bgcolor = 0x00000000); unsigned int bgcolor = 0x00000000);
void render(const glm::mat4& parentTrans) override; void render(const glm::mat4& parentTrans) override;

View file

@ -164,28 +164,28 @@ void DateTimeEditComponent::render(const glm::mat4& 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.
glm::vec3 off(0.0f, (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 = glm::translate(trans, 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,19 +300,19 @@ void DateTimeEditComponent::updateTextCache()
return; return;
// Year. // Year.
Vector2f start(0, 0); glm::vec2 start(0.0f, 0.0f);
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(glm::vec4(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(glm::vec4(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(glm::vec4(start[0], start[1], diff[0], diff[1])); mCursorBoxes.push_back(glm::vec4(start[0], start[1], diff[0], diff[1]));

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;
@ -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;
@ -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;
}; };
@ -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(""); }
@ -49,7 +49,7 @@ public:
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);
glm::vec3 getBackgroundPosition(); glm::vec3 getBackgroundPosition();

View file

@ -16,8 +16,8 @@
#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 {};
@ -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), Vector2i(col, 0), false, false);
mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false); mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false);
} }
mGrid->setPosition({ 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);
} }

View file

@ -22,7 +22,7 @@ Vector2i ImageComponent::getTextureSize() const
return Vector2i::Zero(); return Vector2i::Zero();
} }
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();
@ -260,7 +259,7 @@ 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());
@ -272,24 +271,24 @@ void ImageComponent::cropTransparentPadding(float maxSizeX, float maxSizeY)
// 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 = { 0.0f, 0.0f };
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++)
@ -397,10 +396,10 @@ void ImageComponent::render(const glm::mat4& parentTrans)
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() != 0) {
@ -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

@ -39,18 +39,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.
@ -85,7 +85,7 @@ public:
// May be different than drawn size (use getSize() for that). // May be different than drawn size (use getSize() for that).
Vector2i getTextureSize() const; Vector2i 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; }
@ -100,7 +100,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 +127,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

@ -98,12 +98,12 @@ private:
// Tiles. // Tiles.
bool mLastRowPartial; bool mLastRowPartial;
Vector2f mAutoLayout; glm::vec2 mAutoLayout;
float mAutoLayoutZoom; float mAutoLayoutZoom;
glm::vec4 mPadding; glm::vec4 mPadding;
Vector2f mMargin; glm::vec2 mMargin;
Vector2f mTileSize; glm::vec2 mTileSize;
Vector2i mGridDimension; Vector2i 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;
@ -213,10 +213,8 @@ template <typename T> void ImageGridComponent<T>::render(const glm::mat4& parent
glm::mat4 trans = getTransform() * parentTrans; glm::mat4 trans = getTransform() * parentTrans;
glm::mat4 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 = glm::translate(tileTrans, glm::vec3(offsetX, offsetY, 0.0f)); tileTrans = glm::translate(tileTrans, glm::vec3(offsetX, offsetY, 0.0f));
@ -231,8 +229,8 @@ template <typename T> void ImageGridComponent<T>::render(const glm::mat4& parent
Vector2i pos(static_cast<int>(std::round(trans[3].x)), Vector2i pos(static_cast<int>(std::round(trans[3].x)),
static_cast<int>(std::round(trans[3].y))); static_cast<int>(std::round(trans[3].y)));
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)), Vector2i 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<glm::vec4>("padding") * mPadding =
glm::vec4(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.
@ -457,7 +455,7 @@ template <typename T> void ImageGridComponent<T>::onCursorChanged(const CursorSt
} }
if (newTile != nullptr) if (newTile != nullptr)
newTile->setSelected(true, true, oldPos == glm::vec3 {} ? nullptr : &oldPos, true); newTile->setSelected(true, true, oldPos == glm::vec3({}) ? nullptr : &oldPos, true);
} }
int firstVisibleCol = mStartPosition / dimOpposite; int firstVisibleCol = mStartPosition / dimOpposite;
@ -535,22 +533,22 @@ template <typename T> void ImageGridComponent<T>::buildTiles()
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 = (mSize.x() - (mMargin.x() * (mAutoLayout.x() - 1.0f)) - mPadding.x - mPadding.z) / auto x = (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 = (mSize.y - (mMargin.y * (mAutoLayout.y - 1.0f)) - mPadding.y - mPadding.w) /
static_cast<int>(mAutoLayout.y()); 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.x() += mPadding.x; startPosition.x += mPadding.x;
startPosition.y() += mPadding.y; startPosition.y += mPadding.y;
int X; int X;
int Y; int Y;
@ -566,15 +564,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);
@ -692,16 +690,16 @@ 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 = Vector2i(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) {

View file

@ -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, {}, 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);
} }
@ -149,19 +149,20 @@ std::shared_ptr<ComponentGrid> makeButtonGrid(
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), Vector2i(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

@ -67,22 +67,22 @@ void NinePatchComponent::buildVertices()
return; return;
} }
Vector2f texSize; glm::vec2 texSize;
mVertices = new Renderer::Vertex[6 * 9]; mVertices = new Renderer::Vertex[6 * 9];
texSize = Vector2f(static_cast<float>(mTexture->getSize().x()), texSize = glm::vec2(static_cast<float>(mTexture->getSize().x()),
static_cast<float>(mTexture->getSize().y())); static_cast<float>(mTexture->getSize().y()));
// clang-format off // 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 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 texPosY[3] = { 1.0f, 1.0f + texSizeY[0], 1.0f + texSizeY[0] + texSizeY[1] };
// clang-format on // clang-format on
@ -92,21 +92,21 @@ void NinePatchComponent::buildVertices()
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 = glm::vec2(imgPosX[sliceX], imgPosY[sliceY]);
const Vector2f imgSize = Vector2f(imgSizeX[sliceX], imgSizeY[sliceY]); const glm::vec2 imgSize = glm::vec2(imgSizeX[sliceX], imgSizeY[sliceY]);
const Vector2f texPos = Vector2f(texPosX[sliceX], texPosY[sliceY]); const glm::vec2 texPos = glm::vec2(texPosX[sliceX], texPosY[sliceY]);
const Vector2f texSize = Vector2f(texSizeX[sliceX], texSizeY[sliceY]); const glm::vec2 texSize = glm::vec2(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];
@ -146,15 +146,15 @@ void NinePatchComponent::render(const glm::mat4& parentTrans)
void NinePatchComponent::onSizeChanged() { buildVertices(); } void NinePatchComponent::onSizeChanged() { buildVertices(); }
void NinePatchComponent::fitTo(Vector2f size, glm::vec3 position, Vector2f padding) void NinePatchComponent::fitTo(glm::vec2 size, glm::vec3 position, glm::vec2 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

@ -39,7 +39,7 @@ public:
void onSizeChanged() override; void onSizeChanged() override;
void fitTo(Vector2f size, glm::vec3 position = {}, Vector2f padding = Vector2f::Zero()); void fitTo(glm::vec2 size, glm::vec3 position = {}, glm::vec2 padding = {});
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.
@ -52,8 +52,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();
@ -66,7 +66,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.0f, (mSize.y() - mLeftArrow.getSize().y()) / 2.0f); 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.0f); (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.0f); (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,9 +115,9 @@ 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
@ -152,7 +152,7 @@ void RatingComponent::render(const glm::mat4& parentTrans)
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

@ -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

@ -45,7 +45,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 +53,7 @@ void ScrollableContainer::setAutoScroll(bool autoScroll)
reset(); reset();
} }
else { else {
mScrollDir = Vector2f(0, 0); mScrollDir = glm::vec2(0.0f, 0.0f);
mAutoScrollDelay = 0; mAutoScrollDelay = 0;
mAutoScrollSpeed = 0; mAutoScrollSpeed = 0;
mAutoScrollAccumulator = 0; mAutoScrollAccumulator = 0;
@ -71,7 +71,7 @@ void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant,
void ScrollableContainer::reset() void ScrollableContainer::reset()
{ {
mScrollPos = Vector2f(0, 0); mScrollPos = glm::vec2(0.0f, 0.0f);
mAutoScrollResetAccumulator = 0; mAutoScrollResetAccumulator = 0;
mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed; mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed;
mAtEnd = false; mAtEnd = false;
@ -82,16 +82,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 +105,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 +136,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(0.0f, 0.0f);
mAutoScrollResetAccumulator = 0; mAutoScrollResetAccumulator = 0;
mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed; mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed;
mAtEnd = false; mAtEnd = false;
@ -159,31 +159,31 @@ void ScrollableContainer::render(const glm::mat4& parentTrans)
glm::vec3 dimScaled {}; glm::vec3 dimScaled {};
dimScaled.x = std::fabs(trans[3].x + mSize.x()); dimScaled.x = std::fabs(trans[3].x + mSize.x);
dimScaled.y = std::fabs(trans[3].y + mSize.y()); dimScaled.y = std::fabs(trans[3].y + mSize.y);
Vector2i clipDim(static_cast<int>(dimScaled.x - trans[3].x), Vector2i clipDim(static_cast<int>(dimScaled.x - trans[3].x),
static_cast<int>(dimScaled.y - trans[3].y)); static_cast<int>(dimScaled.y - trans[3].y));
Renderer::pushClipRect(clipPos, clipDim); Renderer::pushClipRect(clipPos, clipDim);
trans = glm::translate(trans, -glm::vec3(mScrollPos.x(), mScrollPos.y(), 0.0f)); 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(0.0f, 0.0f);
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,
@ -37,10 +37,10 @@ public:
void render(const glm::mat4& 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

@ -84,13 +84,13 @@ void SliderComponent::render(const glm::mat4& parentTrans)
mFont->renderTextCache(mValueCache.get()); mFont->renderTextCache(mValueCache.get());
float width = float width =
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);
// 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

@ -34,7 +34,7 @@ TextComponent::TextComponent(Window* window,
unsigned int color, unsigned int color,
Alignment align, Alignment align,
glm::vec3 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 = Vector2i((getSize().x == 0), (getSize().y == 0));
onTextChanged(); onTextChanged();
} }
@ -124,23 +124,23 @@ void TextComponent::render(const glm::mat4& parentTrans)
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: {
@ -152,7 +152,7 @@ void TextComponent::render(const glm::mat4& parentTrans)
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 = glm::translate(trans, off); trans = glm::translate(trans, off);
@ -162,19 +162,19 @@ void TextComponent::render(const glm::mat4& parentTrans)
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;
} }
@ -194,10 +194,10 @@ void TextComponent::calculateExtent()
} }
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

@ -31,7 +31,7 @@ public:
unsigned int color = 0x000000FF, unsigned int color = 0x000000FF,
Alignment align = ALIGN_LEFT, Alignment align = ALIGN_LEFT,
glm::vec3 pos = {}, 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);

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, {}, 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,23 +250,22 @@ 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;
} }
} }
@ -278,19 +276,19 @@ void TextEditComponent::render(const glm::mat4& parentTrans)
// Text + cursor rendering. // Text + cursor rendering.
// Offset into our "text area" (padding). // Offset into our "text area" (padding).
trans = glm::translate(trans, glm::vec3(getTextAreaPos().x(), getTextAreaPos().y(), 0.0f)); trans = glm::translate(trans, glm::vec3(getTextAreaPos().x, getTextAreaPos().y, 0.0f));
Vector2i clipPos(static_cast<int>(trans[3].x), static_cast<int>(trans[3].y)); Vector2i clipPos(static_cast<int>(trans[3].x), static_cast<int>(trans[3].y));
// Use "text area" size for clipping. // Use "text area" size for clipping.
glm::vec3 dimScaled {}; glm::vec3 dimScaled {};
dimScaled.x = std::fabs(trans[3].x + getTextAreaSize().x()); dimScaled.x = std::fabs(trans[3].x + getTextAreaSize().x);
dimScaled.y = std::fabs(trans[3].y + getTextAreaSize().y()); dimScaled.y = std::fabs(trans[3].y + getTextAreaSize().y);
Vector2i clipDim(static_cast<int>(dimScaled.x - trans[3].x), Vector2i clipDim(static_cast<int>(dimScaled.x - trans[3].x),
static_cast<int>(dimScaled.y - trans[3].y)); static_cast<int>(dimScaled.y - trans[3].y));
Renderer::pushClipRect(clipPos, clipDim); Renderer::pushClipRect(clipPos, clipDim);
trans = glm::translate(trans, glm::vec3(-mScrollOffset.x(), -mScrollOffset.y(), 0.0f)); trans = glm::translate(trans, glm::vec3(-mScrollOffset.x, -mScrollOffset.y, 0.0f));
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
if (mTextCache) if (mTextCache)
@ -301,9 +299,9 @@ void TextEditComponent::render(const glm::mat4& 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));
@ -311,24 +309,24 @@ void TextEditComponent::render(const glm::mat4& 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

@ -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

@ -170,7 +170,7 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
std::max(font->getHeight(1.0), static_cast<float>(font->getSize())) * mLineSpacing; std::max(font->getHeight(1.0), static_cast<float>(font->getSize())) * 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,20 +193,20 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
} }
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.
glm::vec3 dim(mSize.x(), mSize.y(), 0.0f); glm::vec3 dim(mSize.x, mSize.y, 0.0f);
dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x; 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; dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
@ -244,12 +244,12 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
break; break;
case ALIGN_CENTER: case ALIGN_CENTER:
offset.x = 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.x < mHorizontalMargin) if (offset.x < mHorizontalMargin)
offset.x = mHorizontalMargin; offset.x = mHorizontalMargin;
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
offset.x = (mSize.x() - entry.data.textCache->metrics.size.x()); offset.x = (mSize.x - entry.data.textCache->metrics.size.x);
offset.x -= mHorizontalMargin; offset.x -= mHorizontalMargin;
if (offset.x < mHorizontalMargin) if (offset.x < mHorizontalMargin)
offset.x = mHorizontalMargin; offset.x = mHorizontalMargin;
@ -349,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;
@ -452,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()));
} }
} }
@ -466,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);
} }
@ -479,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

@ -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

@ -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,41 +78,41 @@ 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[1.0f]);
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;
} }
} }
@ -147,14 +147,14 @@ void VideoFFmpegComponent::render(const glm::mat4& 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)
@ -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

@ -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();
@ -127,41 +127,41 @@ 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;
} }
} }
@ -214,14 +214,14 @@ void VideoVlcComponent::render(const glm::mat4& 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

@ -97,21 +97,21 @@ GuiComplexTextEditPopup::GuiComplexTextEditPopup(
mText->setSize(0, textHeight); mText->setSize(0, textHeight);
mInfoString2->setSize(infoWidth, mInfoString2->getFont()->getHeight()); mInfoString2->setSize(infoWidth, mInfoString2->getFont()->getHeight());
setSize(windowWidth, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y() + setSize(windowWidth, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y +
mButtonGrid->getSize().y() * 1.85f); mButtonGrid->getSize().y * 1.85f);
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);
mText->startEditing(); mText->startEditing();
} }
void GuiComplexTextEditPopup::onSizeChanged() void GuiComplexTextEditPopup::onSizeChanged()
{ {
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3({}), glm::vec2(-32.0f, -32.0f));
mText->setSize(mSize.x() - 40.0f, mText->getSize().y()); mText->setSize(mSize.x - 40.0f, mText->getSize().y);
// Update grid. // Update grid.
mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y()); mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y);
mGrid.setRowHeightPerc(2, mButtonGrid->getSize().y() / mSize.y()); mGrid.setRowHeightPerc(2, mButtonGrid->getSize().y / mSize.y);
mGrid.setSize(mSize); mGrid.setSize(mSize);
} }

View file

@ -87,20 +87,20 @@ GuiDetectDevice::GuiDetectDevice(Window* window,
float width = Math::clamp(0.60f * aspectValue, 0.50f, 0.80f) * Renderer::getScreenWidth(); float width = Math::clamp(0.60f * aspectValue, 0.50f, 0.80f) * Renderer::getScreenWidth();
setSize(width, Renderer::getScreenHeight() * 0.5f); setSize(width, Renderer::getScreenHeight() * 0.5f);
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 GuiDetectDevice::onSizeChanged() void GuiDetectDevice::onSizeChanged()
{ {
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3({}), glm::vec2(-32.0f, -32.0f));
// Grid. // Grid.
mGrid.setSize(mSize); mGrid.setSize(mSize);
mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y()); mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y);
// mGrid.setRowHeightPerc(1, mDeviceInfo->getFont()->getHeight() / mSize.y()); // mGrid.setRowHeightPerc(1, mDeviceInfo->getFont()->getHeight() / mSize.y());
mGrid.setRowHeightPerc(2, mMsg1->getFont()->getHeight() / mSize.y()); mGrid.setRowHeightPerc(2, mMsg1->getFont()->getHeight() / mSize.y);
mGrid.setRowHeightPerc(3, mMsg2->getFont()->getHeight() / mSize.y()); mGrid.setRowHeightPerc(3, mMsg2->getFont()->getHeight() / mSize.y);
// mGrid.setRowHeightPerc(4, mDeviceHeld->getFont()->getHeight() / mSize.y()); // mGrid.setRowHeightPerc(4, mDeviceHeld->getFont()->getHeight() / mSize.y());
} }

View file

@ -192,8 +192,8 @@ GuiInputConfig::GuiInputConfig(Window* window,
float width = Math::clamp(0.60f * aspectValue, 0.50f, 0.80f) * Renderer::getScreenWidth(); float width = Math::clamp(0.60f * aspectValue, 0.50f, 0.80f) * Renderer::getScreenWidth();
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);
} }
void GuiInputConfig::populateConfigList() void GuiInputConfig::populateConfigList()
@ -293,16 +293,16 @@ void GuiInputConfig::update(int deltaTime)
void GuiInputConfig::onSizeChanged() void GuiInputConfig::onSizeChanged()
{ {
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3({}), glm::vec2(-32.0f, -32.0f));
// Update grid. // Update grid.
mGrid.setSize(mSize); mGrid.setSize(mSize);
mGrid.setRowHeightPerc(1, mTitle->getFont()->getHeight() * 0.75f / mSize.y()); mGrid.setRowHeightPerc(1, mTitle->getFont()->getHeight() * 0.75f / mSize.y);
mGrid.setRowHeightPerc(2, mSubtitle1->getFont()->getHeight() / mSize.y()); mGrid.setRowHeightPerc(2, mSubtitle1->getFont()->getHeight() / mSize.y);
mGrid.setRowHeightPerc(3, mSubtitle2->getFont()->getHeight() / mSize.y()); mGrid.setRowHeightPerc(3, mSubtitle2->getFont()->getHeight() / mSize.y);
mGrid.setRowHeightPerc(5, (mList->getRowHeight(0) * 5 + 2) / mSize.y()); mGrid.setRowHeightPerc(5, (mList->getRowHeight(0) * 5.0f + 2.0f) / mSize.y);
mGrid.setRowHeightPerc(6, mButtonGrid->getSize().y() / mSize.y()); mGrid.setRowHeightPerc(6, mButtonGrid->getSize().y / mSize.y);
} }
void GuiInputConfig::rowDone() void GuiInputConfig::rowDone()

View file

@ -12,7 +12,7 @@
#include "components/ButtonComponent.h" #include "components/ButtonComponent.h"
#include "components/MenuComponent.h" #include "components/MenuComponent.h"
#define HORIZONTAL_PADDING_PX 20 #define HORIZONTAL_PADDING_PX 20.0f
GuiMsgBox::GuiMsgBox(Window* window, GuiMsgBox::GuiMsgBox(Window* window,
const HelpStyle& helpstyle, const HelpStyle& helpstyle,
@ -74,25 +74,25 @@ GuiMsgBox::GuiMsgBox(Window* window,
mGrid.setEntry(mButtonGrid, Vector2i(0, 1), true, false, Vector2i(1, 1), GridFlags::BORDER_TOP); mGrid.setEntry(mButtonGrid, Vector2i(0, 1), true, false, Vector2i(1, 1), GridFlags::BORDER_TOP);
// Decide final width. // Decide final width.
if (mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width) { if (mMsg->getSize().x < width && mButtonGrid->getSize().x < width) {
// mMsg and buttons are narrower than width. // mMsg and buttons are narrower than width.
width = std::max(mButtonGrid->getSize().x(), mMsg->getSize().x()); width = std::max(mButtonGrid->getSize().x, mMsg->getSize().x);
width = std::max(width, minWidth); width = std::max(width, minWidth);
} }
else if (mButtonGrid->getSize().x() > width) { else if (mButtonGrid->getSize().x > width) {
width = mButtonGrid->getSize().x(); width = mButtonGrid->getSize().x;
} }
// Now that we know width, we can find height. // Now that we know width, we can find height.
mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length. mMsg->setSize(width, 0.0f); // mMsg->getSize.y() now returns the proper length.
const float msgHeight = const float msgHeight =
std::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y() * 1.225f); std::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y * 1.225f);
setSize(width + HORIZONTAL_PADDING_PX * 2 * Renderer::getScreenWidthModifier(), setSize(width + HORIZONTAL_PADDING_PX * 2.0f * Renderer::getScreenWidthModifier(),
msgHeight + mButtonGrid->getSize().y()); msgHeight + mButtonGrid->getSize().y);
// Center for good measure. // Center for good measure.
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);
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);
@ -113,21 +113,21 @@ void GuiMsgBox::changeText(const std::string& newText)
float minWidth = Renderer::getScreenWidth() * 0.3f; float minWidth = Renderer::getScreenWidth() * 0.3f;
// Decide final width. // Decide final width.
if (mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width) { if (mMsg->getSize().x < width && mButtonGrid->getSize().x < width) {
// mMsg and buttons are narrower than width. // mMsg and buttons are narrower than width.
width = std::max(mButtonGrid->getSize().x(), mMsg->getSize().x()); width = std::max(mButtonGrid->getSize().x, mMsg->getSize().x);
width = std::max(width, minWidth); width = std::max(width, minWidth);
} }
else if (mButtonGrid->getSize().x() > mSize.x()) { else if (mButtonGrid->getSize().x > mSize.x) {
width = mButtonGrid->getSize().x(); width = mButtonGrid->getSize().x;
} }
// Now that we know width, we can find height. // Now that we know width, we can find height.
mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length. mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length.
const float msgHeight = const float msgHeight =
std::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y() * 1.225f); std::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y * 1.225f);
setSize(width + HORIZONTAL_PADDING_PX * 2 * Renderer::getScreenWidthModifier(), setSize(width + HORIZONTAL_PADDING_PX * 2.0f * Renderer::getScreenWidthModifier(),
msgHeight + mButtonGrid->getSize().y()); msgHeight + mButtonGrid->getSize().y);
} }
bool GuiMsgBox::input(InputConfig* config, Input input) bool GuiMsgBox::input(InputConfig* config, Input input)
@ -153,14 +153,14 @@ bool GuiMsgBox::input(InputConfig* config, Input input)
void GuiMsgBox::onSizeChanged() void GuiMsgBox::onSizeChanged()
{ {
mGrid.setSize(mSize); mGrid.setSize(mSize);
mGrid.setRowHeightPerc(1, mButtonGrid->getSize().y() / mSize.y()); mGrid.setRowHeightPerc(1, mButtonGrid->getSize().y / mSize.y);
// Update messagebox size. // Update messagebox size.
mMsg->setSize(mSize.x() - HORIZONTAL_PADDING_PX * 2 * Renderer::getScreenWidthModifier(), mMsg->setSize(mSize.x - HORIZONTAL_PADDING_PX * 2.0f * Renderer::getScreenWidthModifier(),
mGrid.getRowHeight(0)); mGrid.getRowHeight(0));
mGrid.onSizeChanged(); mGrid.onSizeChanged();
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3({}), glm::vec2(-32.0f, -32.0f));
} }
void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func) void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func)

View file

@ -69,22 +69,22 @@ GuiTextEditPopup::GuiTextEditPopup(Window* window,
float aspectValue = 1.778f / Renderer::getScreenAspectRatio(); float aspectValue = 1.778f / Renderer::getScreenAspectRatio();
float width = Math::clamp(0.50f * aspectValue, 0.40f, 0.70f) * Renderer::getScreenWidth(); float width = Math::clamp(0.50f * aspectValue, 0.40f, 0.70f) * Renderer::getScreenWidth();
setSize(width, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y() + setSize(width, mTitle->getFont()->getHeight() + textHeight + mButtonGrid->getSize().y +
mButtonGrid->getSize().y() / 2.0f); mButtonGrid->getSize().y / 2.0f);
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);
mText->startEditing(); mText->startEditing();
} }
void GuiTextEditPopup::onSizeChanged() void GuiTextEditPopup::onSizeChanged()
{ {
mBackground.fitTo(mSize, {}, Vector2f(-32.0f, -32.0f)); mBackground.fitTo(mSize, glm::vec3({}), glm::vec2(-32.0f, -32.0f));
mText->setSize(mSize.x() - 40, mText->getSize().y()); mText->setSize(mSize.x - 40.0f, mText->getSize().y);
// Update grid. // Update grid.
mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y()); mGrid.setRowHeightPerc(0, mTitle->getFont()->getHeight() / mSize.y);
mGrid.setRowHeightPerc(2, mButtonGrid->getSize().y() / mSize.y()); mGrid.setRowHeightPerc(2, mButtonGrid->getSize().y / mSize.y);
mGrid.setSize(mSize); mGrid.setSize(mSize);
} }

View file

@ -493,7 +493,7 @@ namespace Renderer
// 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);
if (_opacity < 1.0) { if (_opacity < 1.0) {
vertices[0].shaders = SHADER_OPACITY; vertices[0].shaders = SHADER_OPACITY;

View file

@ -12,7 +12,6 @@
#include "Log.h" #include "Log.h"
#include "Shader_GL21.h" #include "Shader_GL21.h"
#include "math/Misc.h" #include "math/Misc.h"
#include "math/Vector2f.h"
#include <string> #include <string>
#include <vector> #include <vector>
@ -115,14 +114,14 @@ namespace Renderer
struct Vertex { struct Vertex {
Vertex() {} Vertex() {}
Vertex(const Vector2f& _pos, const Vector2f& _tex, const unsigned int _col) Vertex(const glm::vec2& _pos, const glm::vec2& _tex, const unsigned int _col)
: pos(_pos) : pos(_pos)
, tex(_tex) , tex(_tex)
, col(_col) , col(_col)
{ {
} }
Vector2f pos; glm::vec2 pos;
Vector2f tex; glm::vec2 tex;
unsigned int col; unsigned int col;
float saturation = 1.0; float saturation = 1.0;
float opacity = 1.0; float opacity = 1.0;

View file

@ -314,14 +314,14 @@ Font::Glyph* Font::getGlyph(unsigned int id)
Glyph& glyph = mGlyphMap[id]; Glyph& glyph = mGlyphMap[id];
glyph.texture = tex; glyph.texture = tex;
glyph.texPos = Vector2f(cursor.x() / static_cast<float>(tex->textureSize.x()), glyph.texPos = glm::vec2(cursor.x() / static_cast<float>(tex->textureSize.x()),
cursor.y() / static_cast<float>(tex->textureSize.y())); cursor.y() / static_cast<float>(tex->textureSize.y()));
glyph.texSize = Vector2f(glyphSize.x() / static_cast<float>(tex->textureSize.x()), glyph.texSize = glm::vec2(glyphSize.x() / static_cast<float>(tex->textureSize.x()),
glyphSize.y() / static_cast<float>(tex->textureSize.y())); glyphSize.y() / static_cast<float>(tex->textureSize.y()));
glyph.advance = Vector2f(static_cast<float>(g->metrics.horiAdvance) / 64.0f, glyph.advance = glm::vec2(static_cast<float>(g->metrics.horiAdvance) / 64.0f,
static_cast<float>(g->metrics.vertAdvance) / 64.0f); static_cast<float>(g->metrics.vertAdvance) / 64.0f);
glyph.bearing = Vector2f(static_cast<float>(g->metrics.horiBearingX) / 64.0f, glyph.bearing = glm::vec2(static_cast<float>(g->metrics.horiBearingX) / 64.0f,
static_cast<float>(g->metrics.horiBearingY) / 64.0f); static_cast<float>(g->metrics.horiBearingY) / 64.0f);
// Upload glyph bitmap to texture. // Upload glyph bitmap to texture.
@ -354,10 +354,10 @@ void Font::rebuildTextures()
FontTexture* tex = it->second.texture; FontTexture* tex = it->second.texture;
// Find the position/size. // Find the position/size.
Vector2i cursor(static_cast<int>(it->second.texPos.x() * tex->textureSize.x()), Vector2i cursor(static_cast<int>(it->second.texPos.x * tex->textureSize.x()),
static_cast<int>(it->second.texPos.y() * tex->textureSize.y())); static_cast<int>(it->second.texPos.y * tex->textureSize.y()));
Vector2i glyphSize(static_cast<int>(it->second.texSize.x() * tex->textureSize.x()), Vector2i glyphSize(static_cast<int>(it->second.texSize.x * tex->textureSize.x()),
static_cast<int>(it->second.texSize.y() * tex->textureSize.y())); static_cast<int>(it->second.texSize.y * tex->textureSize.y()));
// Upload to texture. // Upload to texture.
Renderer::updateTexture(tex->textureId, Renderer::Texture::ALPHA, cursor.x(), cursor.y(), Renderer::updateTexture(tex->textureId, Renderer::Texture::ALPHA, cursor.x(), cursor.y(),
@ -383,7 +383,7 @@ void Font::renderTextCache(TextCache* cache)
} }
} }
Vector2f Font::sizeText(std::string text, float lineSpacing) glm::vec2 Font::sizeText(std::string text, float lineSpacing)
{ {
float lineWidth = 0.0f; float lineWidth = 0.0f;
float highestWidth = 0.0f; float highestWidth = 0.0f;
@ -406,21 +406,21 @@ Vector2f Font::sizeText(std::string text, float lineSpacing)
Glyph* glyph = getGlyph(character); Glyph* glyph = getGlyph(character);
if (glyph) if (glyph)
lineWidth += glyph->advance.x(); lineWidth += glyph->advance.x;
} }
if (lineWidth > highestWidth) if (lineWidth > highestWidth)
highestWidth = lineWidth; highestWidth = lineWidth;
return Vector2f(highestWidth, y); return glm::vec2(highestWidth, y);
} }
std::string Font::getTextMaxWidth(std::string text, float maxWidth) std::string Font::getTextMaxWidth(std::string text, float maxWidth)
{ {
float width = sizeText(text).x(); float width = sizeText(text).x;
while (width > maxWidth) { while (width > maxWidth) {
text.pop_back(); text.pop_back();
width = sizeText(text).x(); width = sizeText(text).x;
} }
return text; return text;
} }
@ -435,7 +435,7 @@ float Font::getLetterHeight()
{ {
Glyph* glyph = getGlyph('S'); Glyph* glyph = getGlyph('S');
assert(glyph); assert(glyph);
return glyph->texSize.y() * glyph->texture->textureSize.y(); return glyph->texSize.y * glyph->texture->textureSize.y();
} }
// Breaks up a normal string with newlines to make it fit xLen. // Breaks up a normal string with newlines to make it fit xLen.
@ -448,8 +448,8 @@ std::string Font::wrapText(std::string text, float xLen)
std::string temp; std::string temp;
size_t space; size_t space;
Vector2f textSize; glm::vec2 textSize;
float dotsSize = sizeText("...").x(); float dotsSize = sizeText("...").x;
// While there's text or we still have text to render. // While there's text or we still have text to render.
while (text.length() > 0) { while (text.length() > 0) {
@ -465,7 +465,7 @@ std::string Font::wrapText(std::string text, float xLen)
textSize = sizeText(temp); textSize = sizeText(temp);
// If the word will fit on the line, add it to our line, and continue. // If the word will fit on the line, add it to our line, and continue.
if (textSize.x() <= xLen) { if (textSize.x <= xLen) {
line = temp; line = temp;
continue; continue;
} }
@ -473,7 +473,7 @@ std::string Font::wrapText(std::string text, float xLen)
// The next word won't fit, so break here. // The next word won't fit, so break here.
// If the word is too long to fit within xLen, then abbreviate it. // If the word is too long to fit within xLen, then abbreviate it.
if (xLen > 0 && sizeText(word).x() > xLen) { if (xLen > 0 && sizeText(word).x > xLen) {
float length = xLen - dotsSize; float length = xLen - dotsSize;
if (length < 0) if (length < 0)
length = 0; length = 0;
@ -495,13 +495,13 @@ std::string Font::wrapText(std::string text, float xLen)
return out; return out;
} }
Vector2f Font::sizeWrappedText(std::string text, float xLen, float lineSpacing) glm::vec2 Font::sizeWrappedText(std::string text, float xLen, float lineSpacing)
{ {
text = wrapText(text, xLen); text = wrapText(text, xLen);
return sizeText(text, lineSpacing); return sizeText(text, lineSpacing);
} }
Vector2f Font::getWrappedTextCursorOffset(std::string text, glm::vec2 Font::getWrappedTextCursorOffset(std::string text,
float xLen, float xLen,
size_t stop, size_t stop,
float lineSpacing) float lineSpacing)
@ -535,10 +535,10 @@ Vector2f Font::getWrappedTextCursorOffset(std::string text,
Glyph* glyph = getGlyph(character); Glyph* glyph = getGlyph(character);
if (glyph) if (glyph)
lineWidth += glyph->advance.x(); lineWidth += glyph->advance.x;
} }
return Vector2f(lineWidth, y); return glm::vec2(lineWidth, y);
} }
// //
@ -560,7 +560,7 @@ float Font::getNewlineStartOffset(const std::string& text,
return (xLen - sizeText(text.substr(charStart, endChar != std::string::npos ? return (xLen - sizeText(text.substr(charStart, endChar != std::string::npos ?
endChar - charStart : endChar - charStart :
endChar)) endChar))
.x()) / .x) /
2.0f; 2.0f;
} }
case ALIGN_RIGHT: { case ALIGN_RIGHT: {
@ -568,7 +568,7 @@ float Font::getNewlineStartOffset(const std::string& text,
return xLen - (sizeText(text.substr(charStart, endChar != std::string::npos ? return xLen - (sizeText(text.substr(charStart, endChar != std::string::npos ?
endChar - charStart : endChar - charStart :
endChar)) endChar))
.x()); .x);
} }
default: default:
return 0; return 0;
@ -576,7 +576,7 @@ float Font::getNewlineStartOffset(const std::string& text,
} }
TextCache* Font::buildTextCache(const std::string& text, TextCache* Font::buildTextCache(const std::string& text,
Vector2f offset, glm::vec2 offset,
unsigned int color, unsigned int color,
float xLen, float xLen,
Alignment alignment, Alignment alignment,
@ -592,7 +592,7 @@ TextCache* Font::buildTextCache(const std::string& text,
yBot = getHeight(1.5); yBot = getHeight(1.5);
} }
else { else {
yTop = getGlyph('S')->bearing.y(); yTop = getGlyph('S')->bearing.y;
yBot = getHeight(lineSpacing); yBot = getHeight(lineSpacing);
} }
@ -631,37 +631,35 @@ TextCache* Font::buildTextCache(const std::string& text,
verts.resize(oldVertSize + 6); verts.resize(oldVertSize + 6);
Renderer::Vertex* vertices = verts.data() + oldVertSize; Renderer::Vertex* vertices = verts.data() + oldVertSize;
const float glyphStartX = x + glyph->bearing.x(); const float glyphStartX = x + glyph->bearing.x;
const Vector2i& textureSize = glyph->texture->textureSize; const Vector2i& textureSize = glyph->texture->textureSize;
const unsigned int convertedColor = Renderer::convertRGBAToABGR(color); const unsigned int convertedColor = Renderer::convertRGBAToABGR(color);
vertices[1] = { { glyphStartX, y - glyph->bearing.y() }, vertices[1] = { { glyphStartX, y - glyph->bearing.y },
{ glyph->texPos.x(), glyph->texPos.y() }, { glyph->texPos.x, glyph->texPos.y },
convertedColor }; convertedColor };
vertices[2] = { { glyphStartX, vertices[2] = { { glyphStartX,
y - glyph->bearing.y() + (glyph->texSize.y() * textureSize.y()) }, y - glyph->bearing.y + (glyph->texSize.y * textureSize.y()) },
{ glyph->texPos.x(), glyph->texPos.y() + glyph->texSize.y() }, { glyph->texPos.x, glyph->texPos.y + glyph->texSize.y },
convertedColor }; convertedColor };
vertices[3] = { { glyphStartX + glyph->texSize.x() * textureSize.x(), vertices[3] = { { glyphStartX + glyph->texSize.x * textureSize.x(), y - glyph->bearing.y },
y - glyph->bearing.y() }, { glyph->texPos.x + glyph->texSize.x, glyph->texPos.y },
{ glyph->texPos.x() + glyph->texSize.x(), glyph->texPos.y() },
convertedColor }; convertedColor };
vertices[4] = { { glyphStartX + glyph->texSize.x() * textureSize.x(), vertices[4] = { { glyphStartX + glyph->texSize.x * textureSize.x(),
y - glyph->bearing.y() + (glyph->texSize.y() * textureSize.y()) }, y - glyph->bearing.y + (glyph->texSize.y * textureSize.y()) },
{ glyph->texPos.x() + glyph->texSize.x(), { glyph->texPos.x + glyph->texSize.x, glyph->texPos.y + glyph->texSize.y },
glyph->texPos.y() + glyph->texSize.y() },
convertedColor }; convertedColor };
// Round vertices. // Round vertices.
for (int i = 1; i < 5; i++) for (int i = 1; i < 5; i++)
vertices[i].pos.round(); vertices[i].pos = glm::round(vertices[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.
vertices[0] = vertices[1]; vertices[0] = vertices[1];
vertices[5] = vertices[4]; vertices[5] = vertices[4];
// Advance. // Advance.
x += glyph->advance.x(); x += glyph->advance.x;
} }
// TextCache::CacheMetrics metrics = { sizeText(text, lineSpacing) }; // TextCache::CacheMetrics metrics = { sizeText(text, lineSpacing) };
@ -689,7 +687,7 @@ TextCache* Font::buildTextCache(const std::string& text,
float lineSpacing, float lineSpacing,
bool noTopMargin) bool noTopMargin)
{ {
return buildTextCache(text, Vector2f(offsetX, offsetY), color, 0.0f, ALIGN_LEFT, lineSpacing, return buildTextCache(text, glm::vec2(offsetX, offsetY), color, 0.0f, ALIGN_LEFT, lineSpacing,
noTopMargin); noTopMargin);
} }

View file

@ -11,7 +11,6 @@
#define ES_CORE_RESOURCES_FONT_H #define ES_CORE_RESOURCES_FONT_H
#include "ThemeData.h" #include "ThemeData.h"
#include "math/Vector2f.h"
#include "math/Vector2i.h" #include "math/Vector2i.h"
#include "renderers/Renderer.h" #include "renderers/Renderer.h"
#include "resources/ResourceManager.h" #include "resources/ResourceManager.h"
@ -54,7 +53,7 @@ public:
static std::shared_ptr<Font> get(int size, const std::string& path = getDefaultPath()); static std::shared_ptr<Font> get(int size, const std::string& path = getDefaultPath());
// Returns the expected size of a string when rendered. Extra spacing is applied to the Y axis. // Returns the expected size of a string when rendered. Extra spacing is applied to the Y axis.
Vector2f sizeText(std::string text, float lineSpacing = 1.5f); glm::vec2 sizeText(std::string text, float lineSpacing = 1.5f);
// Returns the portion of a string that fits within the passed argument maxWidth. // Returns the portion of a string that fits within the passed argument maxWidth.
std::string getTextMaxWidth(std::string text, float maxWidth); std::string getTextMaxWidth(std::string text, float maxWidth);
@ -67,7 +66,7 @@ public:
bool noTopMargin = false); bool noTopMargin = false);
TextCache* buildTextCache(const std::string& text, TextCache* buildTextCache(const std::string& text,
Vector2f offset, glm::vec2 offset,
unsigned int color, unsigned int color,
float xLen, float xLen,
Alignment alignment = ALIGN_LEFT, Alignment alignment = ALIGN_LEFT,
@ -80,10 +79,10 @@ public:
std::string wrapText(std::string text, float xLen); std::string wrapText(std::string text, float xLen);
// Returns the expected size of a string after wrapping is applied. // Returns the expected size of a string after wrapping is applied.
Vector2f sizeWrappedText(std::string text, float xLen, float lineSpacing = 1.5f); glm::vec2 sizeWrappedText(std::string text, float xLen, float lineSpacing = 1.5f);
// Returns the position of the cursor after moving a "cursor" amount of characters. // Returns the position of the cursor after moving a "cursor" amount of characters.
Vector2f getWrappedTextCursorOffset(std::string text, glm::vec2 getWrappedTextCursorOffset(std::string text,
float xLen, float xLen,
size_t cursor, size_t cursor,
float lineSpacing = 1.5f); float lineSpacing = 1.5f);
@ -158,11 +157,11 @@ private:
struct Glyph { struct Glyph {
FontTexture* texture; FontTexture* texture;
Vector2f texPos; glm::vec2 texPos;
Vector2f texSize; // In texels! glm::vec2 texSize; // In texels.
Vector2f advance; glm::vec2 advance;
Vector2f bearing; glm::vec2 bearing;
}; };
std::map<unsigned int, Glyph> mGlyphMap; std::map<unsigned int, Glyph> mGlyphMap;
@ -202,7 +201,7 @@ protected:
public: public:
struct CacheMetrics { struct CacheMetrics {
Vector2f size; glm::vec2 size;
} metrics; } metrics;
void setColor(unsigned int color); void setColor(unsigned int color);

View file

@ -47,7 +47,7 @@ TextureResource::TextureResource(const std::string& path,
} }
mSize = Vector2i(static_cast<int>(data->width()), static_cast<int>(data->height())); mSize = Vector2i(static_cast<int>(data->width()), static_cast<int>(data->height()));
mSourceSize = Vector2f(data->sourceWidth(), data->sourceHeight()); mSourceSize = glm::vec2(data->sourceWidth(), data->sourceHeight());
} }
else { else {
// Create a texture managed by this class because it cannot be dynamically // Create a texture managed by this class because it cannot be dynamically
@ -76,7 +76,7 @@ void TextureResource::initFromPixels(const unsigned char* dataRGBA, size_t width
mTextureData->initFromRGBA(dataRGBA, width, height); mTextureData->initFromRGBA(dataRGBA, width, height);
// Cache the image dimensions. // Cache the image dimensions.
mSize = Vector2i(static_cast<int>(width), static_cast<int>(height)); mSize = Vector2i(static_cast<int>(width), static_cast<int>(height));
mSourceSize = Vector2f(mTextureData->sourceWidth(), mTextureData->sourceHeight()); mSourceSize = glm::vec2(mTextureData->sourceWidth(), mTextureData->sourceHeight());
} }
void TextureResource::initFromMemory(const char* data, size_t length) void TextureResource::initFromMemory(const char* data, size_t length)
@ -89,7 +89,7 @@ void TextureResource::initFromMemory(const char* data, size_t length)
// Get the size from the texture data. // Get the size from the texture data.
mSize = mSize =
Vector2i(static_cast<int>(mTextureData->width()), static_cast<int>(mTextureData->height())); Vector2i(static_cast<int>(mTextureData->width()), static_cast<int>(mTextureData->height()));
mSourceSize = Vector2f(mTextureData->sourceWidth(), mTextureData->sourceHeight()); mSourceSize = glm::vec2(mTextureData->sourceWidth(), mTextureData->sourceHeight());
} }
void TextureResource::manualUnload(std::string path, bool tile) void TextureResource::manualUnload(std::string path, bool tile)
@ -197,7 +197,7 @@ void TextureResource::rasterizeAt(size_t width, size_t height)
data = mTextureData; data = mTextureData;
else else
data = sTextureDataManager.get(this); data = sTextureDataManager.get(this);
mSourceSize = Vector2f(static_cast<float>(width), static_cast<float>(height)); mSourceSize = glm::vec2(static_cast<float>(width), static_cast<float>(height));
data->setSourceSize(static_cast<float>(width), static_cast<float>(height)); data->setSourceSize(static_cast<float>(width), static_cast<float>(height));
if (mForceLoad || (mTextureData != nullptr)) if (mForceLoad || (mTextureData != nullptr))
data->load(); data->load();

View file

@ -9,7 +9,7 @@
#ifndef ES_CORE_RESOURCES_TEXTURE_RESOURCE_H #ifndef ES_CORE_RESOURCES_TEXTURE_RESOURCE_H
#define ES_CORE_RESOURCES_TEXTURE_RESOURCE_H #define ES_CORE_RESOURCES_TEXTURE_RESOURCE_H
#include "math/Vector2f.h" #include "math/Misc.h"
#include "math/Vector2i.h" #include "math/Vector2i.h"
#include "resources/ResourceManager.h" #include "resources/ResourceManager.h"
#include "resources/TextureDataManager.h" #include "resources/TextureDataManager.h"
@ -45,7 +45,7 @@ public:
// situations. An alternative is to set a scaling factor directly when loading the texture // situations. An alternative is to set a scaling factor directly when loading the texture
// using get(), by using the scaleDuringLoad parameter (which also works for raster graphics). // using get(), by using the scaleDuringLoad parameter (which also works for raster graphics).
void rasterizeAt(size_t width, size_t height); void rasterizeAt(size_t width, size_t height);
Vector2f getSourceImageSize() const { return mSourceSize; } glm::vec2 getSourceImageSize() const { return mSourceSize; }
virtual ~TextureResource(); virtual ~TextureResource();
@ -74,7 +74,7 @@ private:
static TextureDataManager sTextureDataManager; static TextureDataManager sTextureDataManager;
Vector2i mSize; Vector2i mSize;
Vector2f mSourceSize; glm::vec2 mSourceSize;
bool mForceLoad; bool mForceLoad;
typedef std::pair<std::string, bool> TextureKeyType; typedef std::pair<std::string, bool> TextureKeyType;