mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-21 21:55:38 +00:00
Replaced the custom math functions with standard C++ functions.
This commit is contained in:
parent
407d2ad374
commit
963f93e0f8
|
@ -74,13 +74,14 @@ Many bugs have been fixed, and numerous features that were only partially implem
|
|||
* Game counting is now done during sorting instead of every time a system is selected. This should make the UI more responsive in case of large game libraries
|
||||
* All required fonts bundled with the application, no dependencies on the OS to provide them any longer
|
||||
* Made pugixml an external dependency instead of bundling it
|
||||
* Replaced the custom math functions with standard C++ functions whenever possible
|
||||
* Modernized the audio code, for example using SDL_AudioStream instead of the older SDL_AudioCVT
|
||||
* Overhaul of application settings, now the configuration file is only updated when there have been actual configuration changes
|
||||
* Decreased CPU usage dramatically by only rendering the currently visible view (previously all views were always rendered)
|
||||
* Updated the CMake/CPack install and package configuration files to work as expected (can now generate DEB, RPM, DMG and NSIS installation packages with correct dependencies)
|
||||
* Added support for Clang/LLVM, made the application build with no errors or warnings using this compiler (Unix and macOS only)
|
||||
* License files included for all the libraries and resources that are bundled with the application
|
||||
* Updated the MAME ROM index files to include ROMs up to MAME version 0.221 and created scripts to easily generate these index files in the future
|
||||
* Updated the MAME ROM index files to include ROMs up to MAME version 0.226 and created scripts to easily generate these index files in the future
|
||||
* Greatly expanded the application documentation (which is hosted in the ES-DE repository on GitLab)
|
||||
|
||||
### Bug fixes
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "Log.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#define UNKNOWN_LABEL "UNKNOWN"
|
||||
#define INCLUDE_UNKNOWN false;
|
||||
|
||||
|
@ -165,7 +167,7 @@ std::string FileFilterIndex::getIndexableKey(FileData* game,
|
|||
// been used for scraping the ratings, or if the gamelist.xml file
|
||||
// has been manually edited.
|
||||
ratingNumber = static_cast<int>(
|
||||
(Math::ceilf(stof(ratingString) / 0.1) / 10) * 5);
|
||||
(ceilf(stof(ratingString) / 0.1) / 10) * 5);
|
||||
|
||||
if (ratingNumber < 0)
|
||||
ratingNumber = 0;
|
||||
|
|
|
@ -435,7 +435,7 @@ void GuiMenu::openSoundSettings()
|
|||
s->addWithLabel("SYSTEM VOLUME", system_volume);
|
||||
s->addSaveFunc([system_volume] {
|
||||
VolumeControl::getInstance()->
|
||||
setVolume(static_cast<int>(Math::round(system_volume->getValue())));
|
||||
setVolume(static_cast<int>(std::round(system_volume->getValue())));
|
||||
});
|
||||
#endif
|
||||
|
||||
|
@ -612,7 +612,7 @@ void GuiMenu::openOtherSettings()
|
|||
s->addSaveFunc([max_vram, s] {
|
||||
if (max_vram->getValue() != Settings::getInstance()->getInt("MaxVRAM")) {
|
||||
Settings::getInstance()->setInt("MaxVRAM",
|
||||
static_cast<int>(Math::round(max_vram->getValue())));
|
||||
static_cast<int>(std::round(max_vram->getValue())));
|
||||
s->setNeedsSaving();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -319,7 +319,7 @@ GuiMetaDataEd::GuiMetaDataEd(
|
|||
mGrid.setEntry(mButtons, Vector2i(0, 2), true, false);
|
||||
|
||||
// Resize + center.
|
||||
float width = static_cast<float>(Math::min(Renderer::getScreenHeight(),
|
||||
float width = static_cast<float>(std::min(Renderer::getScreenHeight(),
|
||||
static_cast<int>(Renderer::getScreenWidth() * 0.90f)));
|
||||
setSize(width, Renderer::getScreenHeight() * 0.82f);
|
||||
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2,
|
||||
|
|
|
@ -24,10 +24,10 @@ GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const std::string&
|
|||
getInt("ScreensaverTimer") / (1000 * 60)));
|
||||
addWithLabel("START SCREENSAVER AFTER (MINUTES)", screensaver_timer);
|
||||
addSaveFunc([screensaver_timer, this] {
|
||||
if (static_cast<int>(Math::round(screensaver_timer->getValue()) * (1000 * 60)) !=
|
||||
if (static_cast<int>(std::round(screensaver_timer->getValue()) * (1000 * 60)) !=
|
||||
Settings::getInstance()->getInt("ScreensaverTimer")) {
|
||||
Settings::getInstance()->setInt("ScreensaverTimer",
|
||||
static_cast<int>(Math::round(screensaver_timer->getValue()) * (1000 * 60)));
|
||||
static_cast<int>(std::round(screensaver_timer->getValue()) * (1000 * 60)));
|
||||
setNeedsSaving();
|
||||
}
|
||||
});
|
||||
|
@ -108,7 +108,7 @@ void GuiScreensaverOptions::openSlideshowScreensaverOptions()
|
|||
static_cast<float>(Settings::getInstance()->
|
||||
getInt("ScreensaverSwapImageTimeout") / (1000))) {
|
||||
Settings::getInstance()->setInt("ScreensaverSwapImageTimeout",
|
||||
static_cast<int>(Math::round(screensaver_swap_image_timeout->getValue()) *
|
||||
static_cast<int>(std::round(screensaver_swap_image_timeout->getValue()) *
|
||||
(1000)));
|
||||
s->setNeedsSaving();
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ void GuiScreensaverOptions::openVideoScreensaverOptions()
|
|||
static_cast<float>(Settings::getInstance()->
|
||||
getInt("ScreensaverSwapVideoTimeout") / (1000))) {
|
||||
Settings::getInstance()->setInt("ScreensaverSwapVideoTimeout",
|
||||
static_cast<int>(Math::round(screensaver_swap_video_timeout->getValue()) *
|
||||
static_cast<int>(std::round(screensaver_swap_video_timeout->getValue()) *
|
||||
(1000)));
|
||||
s->setNeedsSaving();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "Settings.h"
|
||||
#include "SystemData.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <pugixml.hpp>
|
||||
|
||||
|
@ -326,7 +327,7 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
|
|||
if (game.child("note")) {
|
||||
float ratingVal = (game.child("note").text().as_int() / 20.0f);
|
||||
// Round up to the closest .1 value, i.e. to the closest half-star.
|
||||
ratingVal = Math::ceilf(ratingVal / 0.1) / 10;
|
||||
ratingVal = ceilf(ratingVal / 0.1) / 10;
|
||||
std::stringstream ss;
|
||||
ss << ratingVal;
|
||||
if (ratingVal > 0) {
|
||||
|
|
|
@ -545,7 +545,7 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
|
|||
}
|
||||
|
||||
int center = static_cast<int>(mCamOffset);
|
||||
int logoCount = Math::min(mCarousel.maxLogoCount, static_cast<int>(mEntries.size()));
|
||||
int logoCount = std::min(mCarousel.maxLogoCount, static_cast<int>(mEntries.size()));
|
||||
|
||||
// Adding texture loading buffers depending on scrolling speed and status.
|
||||
int bufferIndex = getScrollingVelocity() + 1;
|
||||
|
@ -570,12 +570,12 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
|
|||
float distance = i - mCamOffset;
|
||||
|
||||
float scale = 1.0f + ((mCarousel.logoScale - 1.0f) * (1.0f - fabs(distance)));
|
||||
scale = Math::min(mCarousel.logoScale, Math::max(1.0f, scale));
|
||||
scale = std::min(mCarousel.logoScale, std::max(1.0f, scale));
|
||||
scale /= mCarousel.logoScale;
|
||||
|
||||
int opacity = static_cast<int>(Math::round(0x80 + ((0xFF - 0x80) *
|
||||
int opacity = static_cast<int>(std::round(0x80 + ((0xFF - 0x80) *
|
||||
(1.0f - fabs(distance)))));
|
||||
opacity = Math::max(static_cast<int>(0x80), opacity);
|
||||
opacity = std::max(static_cast<int>(0x80), opacity);
|
||||
|
||||
const std::shared_ptr<GuiComponent> &comp = mEntries.at(index).data.logo;
|
||||
if (mCarousel.type == VERTICAL_WHEEL || mCarousel.type == HORIZONTAL_WHEEL) {
|
||||
|
@ -706,7 +706,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
|
|||
if (elem->has("logoSize"))
|
||||
mCarousel.logoSize = elem->get<Vector2f>("logoSize") * mSize;
|
||||
if (elem->has("maxLogoCount"))
|
||||
mCarousel.maxLogoCount = static_cast<int>(Math::round(elem->get<float>("maxLogoCount")));
|
||||
mCarousel.maxLogoCount = static_cast<int>(std::round(elem->get<float>("maxLogoCount")));
|
||||
if (elem->has("zIndex"))
|
||||
mCarousel.zIndex = elem->get<float>("zIndex");
|
||||
if (elem->has("logoRotation"))
|
||||
|
|
|
@ -205,7 +205,7 @@ std::string GridGameListView::getQuickSystemSelectLeftButton()
|
|||
|
||||
bool GridGameListView::input(InputConfig* config, Input input)
|
||||
{
|
||||
if (input.value == 0 and (config->isMappedLike("left", input) ||
|
||||
if (input.value == 0 && (config->isMappedLike("left", input) ||
|
||||
config->isMappedLike("right", input) ||
|
||||
(config->isMappedLike("up", input)) ||
|
||||
(config->isMappedLike("down", input)) ))
|
||||
|
|
|
@ -58,10 +58,10 @@ void IGameListView::render(const Transform4x4f& parentTrans)
|
|||
float scaleX = trans.r0().x();
|
||||
float scaleY = trans.r1().y();
|
||||
|
||||
Vector2i pos(static_cast<int>(Math::round(trans.translation()[0])),
|
||||
static_cast<int>(Math::round(trans.translation()[1])));
|
||||
Vector2i size(static_cast<int>(Math::round(mSize.x() * scaleX)),
|
||||
static_cast<int>(Math::round(mSize.y() * scaleY)));
|
||||
Vector2i pos(static_cast<int>(std::round(trans.translation()[0])),
|
||||
static_cast<int>(std::round(trans.translation()[1])));
|
||||
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)),
|
||||
static_cast<int>(std::round(mSize.y() * scaleY)));
|
||||
|
||||
Renderer::pushClipRect(pos, size);
|
||||
renderChildren(trans);
|
||||
|
|
|
@ -471,8 +471,8 @@ void Window::renderLoadingScreen(std::string text)
|
|||
auto& font = mDefaultFonts.at(1);
|
||||
TextCache* cache = font->buildTextCache(text, 0, 0, 0x656565FF);
|
||||
|
||||
float x = Math::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f);
|
||||
float y = Math::round(Renderer::getScreenHeight() * 0.835f);
|
||||
float x = std::round((Renderer::getScreenWidth() - cache->metrics.size.x()) / 2.0f);
|
||||
float y = std::round(Renderer::getScreenHeight() * 0.835f);
|
||||
trans = trans.translate(Vector3f(x, y, 0.0f));
|
||||
Renderer::setMatrix(trans);
|
||||
font->renderTextCache(cache);
|
||||
|
|
|
@ -56,7 +56,7 @@ void ButtonComponent::setText(const std::string& text, const std::string& helpTe
|
|||
mTextCache = std::unique_ptr<TextCache>(mFont->buildTextCache(mText, 0, 0, getCurTextColor()));
|
||||
|
||||
float minWidth = mFont->sizeText("DELETE").x() + 12;
|
||||
setSize(Math::max(mTextCache->metrics.size.x() + 12, minWidth), mTextCache->metrics.size.y());
|
||||
setSize(std::max(mTextCache->metrics.size.x() + 12, minWidth), mTextCache->metrics.size.y());
|
||||
|
||||
updateHelpPrompts();
|
||||
}
|
||||
|
|
|
@ -183,10 +183,10 @@ void ComponentList::render(const Transform4x4f& parentTrans)
|
|||
dim = trans * dim - trans.translation();
|
||||
Renderer::pushClipRect(Vector2i(static_cast<int>(trans.translation().x()),
|
||||
static_cast<int>(trans.translation().y())), Vector2i(static_cast<int>(
|
||||
Math::round(dim.x())), static_cast<int>(Math::round(dim.y() + 1))));
|
||||
std::round(dim.x())), static_cast<int>(std::round(dim.y() + 1))));
|
||||
|
||||
// Scroll the camera.
|
||||
trans.translate(Vector3f(0, -Math::round(mCameraOffset), 0));
|
||||
trans.translate(Vector3f(0, -std::round(mCameraOffset), 0));
|
||||
|
||||
// Draw our entries.
|
||||
std::vector<GuiComponent*> drawAfterCursor;
|
||||
|
|
|
@ -77,7 +77,7 @@ void HelpComponent::updateGrid()
|
|||
std::vector< std::shared_ptr<TextComponent> > labels;
|
||||
|
||||
float width = 0;
|
||||
const float height = Math::round(font->getLetterHeight() * 1.25f);
|
||||
const float height = std::round(font->getLetterHeight() * 1.25f);
|
||||
|
||||
for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); it++) {
|
||||
auto icon = std::make_shared<ImageComponent>(mWindow);
|
||||
|
|
|
@ -72,8 +72,8 @@ void ImageComponent::resize()
|
|||
// ratios), it can cause cutoff when the aspect ratio breaks.
|
||||
// So we always make sure the resultant height is an integer to make sure cutoff doesn't
|
||||
// happen, and scale width from that (you'll see this scattered throughout the function).
|
||||
// It's important to use the floorf() function rather than round() for this, as we never
|
||||
// want to round up since that can lead to the cutoff just described.
|
||||
// It's important to use the floorf rather than round for this, as we never want to round
|
||||
// up since that can lead to the cutoff just described.
|
||||
if (mTargetIsMax) {
|
||||
mSize = textureSize;
|
||||
|
||||
|
@ -83,14 +83,14 @@ void ImageComponent::resize()
|
|||
// This will be mTargetSize.x(). We can't exceed it, nor be lower than it.
|
||||
mSize[0] *= resizeScale.x();
|
||||
// We need to make sure we're not creating an image larger than max size.
|
||||
mSize[1] = Math::min(Math::floorf(mSize[1] *= resizeScale.x()), mTargetSize.y());
|
||||
mSize[1] = std::min(floorf(mSize[1] *= resizeScale.x()), mTargetSize.y());
|
||||
}
|
||||
else {
|
||||
// This will be mTargetSize.y(). We can't exceed it.
|
||||
mSize[1] = Math::floorf(mSize[1] * resizeScale.y());
|
||||
mSize[1] = floorf(mSize[1] * resizeScale.y());
|
||||
// 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.
|
||||
mSize[0] = Math::min((mSize[1] / textureSize.y()) * textureSize.x(),
|
||||
mSize[0] = std::min((mSize[1] / textureSize.y()) * textureSize.x(),
|
||||
mTargetSize.x());
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ void ImageComponent::resize()
|
|||
}
|
||||
// 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.
|
||||
mSize[1] = Math::max(Math::floorf(mSize[1]), mTargetSize.y());
|
||||
mSize[0] = Math::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
|
||||
mSize[1] = std::max(floorf(mSize[1]), mTargetSize.y());
|
||||
mSize[0] = std::max((mSize[1] / textureSize.y()) * textureSize.x(), mTargetSize.x());
|
||||
|
||||
}
|
||||
else {
|
||||
|
@ -128,18 +128,18 @@ void ImageComponent::resize()
|
|||
// For SVG rasterization, we always calculate width from rounded height (see
|
||||
// comment above).
|
||||
if (!mTargetSize.x() && mTargetSize.y()) {
|
||||
mSize[1] = Math::floorf(mTargetSize.y());
|
||||
mSize[1] = floorf(mTargetSize.y());
|
||||
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x();
|
||||
}
|
||||
else if (mTargetSize.x() && !mTargetSize.y()) {
|
||||
mSize[1] = Math::floorf((mTargetSize.x() / textureSize.x()) * textureSize.y());
|
||||
mSize[1] = floorf((mTargetSize.x() / textureSize.x()) * textureSize.y());
|
||||
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mSize[0] = Math::floorf(mSize.x());
|
||||
mSize[1] = Math::floorf(mSize.y());
|
||||
mSize[0] = floorf(mSize.x());
|
||||
mSize[1] = floorf(mSize.y());
|
||||
// mSize.y() should already be rounded.
|
||||
mTexture->rasterizeAt(static_cast<size_t>(mSize.x()), static_cast<size_t>(mSize.y()));
|
||||
|
||||
|
|
|
@ -225,10 +225,10 @@ void ImageGridComponent<T>::render(const Transform4x4f& parentTrans)
|
|||
float scaleX = trans.r0().x();
|
||||
float scaleY = trans.r1().y();
|
||||
|
||||
Vector2i pos(static_cast<int>(Math::round(trans.translation()[0])),
|
||||
static_cast<int>(Math::round(trans.translation()[1])));
|
||||
Vector2i size(static_cast<int>(Math::round(mSize.x() * scaleX)),
|
||||
static_cast<int>(Math::round(mSize.y() * scaleY)));
|
||||
Vector2i pos(static_cast<int>(std::round(trans.translation()[0])),
|
||||
static_cast<int>(std::round(trans.translation()[1])));
|
||||
Vector2i size(static_cast<int>(std::round(mSize.x() * scaleX)),
|
||||
static_cast<int>(std::round(mSize.y() * scaleY)));
|
||||
|
||||
Renderer::pushClipRect(pos, size);
|
||||
|
||||
|
@ -520,7 +520,7 @@ void ImageGridComponent<T>::buildTiles()
|
|||
if (mCenterSelection) {
|
||||
int dimScrollable = (isVertical() ? mGridDimension.y() :
|
||||
mGridDimension.x()) - 2 * EXTRAITEMS;
|
||||
mStartPosition -= static_cast<int>(Math::floorf(dimScrollable / 2.0f));
|
||||
mStartPosition -= static_cast<int>(floorf(dimScrollable / 2.0f));
|
||||
}
|
||||
|
||||
Vector2f tileDistance = mTileSize + mMargin;
|
||||
|
@ -683,10 +683,10 @@ void ImageGridComponent<T>::calcGridDimension()
|
|||
if (mAutoLayout.x() != 0 && mAutoLayout.y() != 0)
|
||||
gridDimension = mAutoLayout;
|
||||
|
||||
mLastRowPartial = Math::floorf(gridDimension.y()) != gridDimension.y();
|
||||
mLastRowPartial = floorf(gridDimension.y()) != gridDimension.y();
|
||||
|
||||
// Ceil y dim so we can display partial last row.
|
||||
mGridDimension = Vector2i(gridDimension.x(), Math::ceilf(gridDimension.y()));
|
||||
mGridDimension = Vector2i(gridDimension.x(), ceilf(gridDimension.y()));
|
||||
|
||||
// Grid dimension validation.
|
||||
if (mGridDimension.x() < 1) {
|
||||
|
|
|
@ -95,7 +95,7 @@ void MenuComponent::updateSize()
|
|||
}
|
||||
}
|
||||
|
||||
float width = static_cast<float>(Math::min(static_cast<int>(Renderer::getScreenHeight()),
|
||||
float width = static_cast<float>(std::min(static_cast<int>(Renderer::getScreenHeight()),
|
||||
static_cast<int>(Renderer::getScreenWidth() * 0.90f)));
|
||||
setSize(width, height);
|
||||
}
|
||||
|
@ -166,6 +166,6 @@ std::shared_ptr<ImageComponent> makeArrow(Window* window)
|
|||
{
|
||||
auto bracket = std::make_shared<ImageComponent>(window);
|
||||
bracket->setImage(":/graphics/arrow.svg");
|
||||
bracket->setResize(0, Math::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()));
|
||||
bracket->setResize(0, std::round(Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()));
|
||||
return bracket;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ void RatingComponent::setValue(const std::string& value)
|
|||
}
|
||||
else {
|
||||
// Round up to the closest .1 value, i.e. to the closest half-icon.
|
||||
mValue = Math::ceilf(stof(value) / 0.1) / 10;
|
||||
mValue = ceilf(stof(value) / 0.1) / 10;
|
||||
mOriginalValue = static_cast<int>(mValue * 10);
|
||||
|
||||
// If the argument to colorize the rating icons has been passed, set the
|
||||
|
@ -104,7 +104,7 @@ void RatingComponent::onSizeChanged()
|
|||
mSize[0] = mSize.y() * NUM_RATING_STARS;
|
||||
|
||||
if (mSize.y() > 0) {
|
||||
size_t heightPx = static_cast<size_t>(Math::round(mSize.y()));
|
||||
size_t heightPx = static_cast<size_t>(std::round(mSize.y()));
|
||||
if (mFilledTexture)
|
||||
mFilledTexture->rasterizeAt(heightPx, heightPx);
|
||||
if (mUnfilledTexture)
|
||||
|
|
|
@ -156,7 +156,7 @@ void TextListComponent<T>::render(const Transform4x4f& parentTrans)
|
|||
if (size() == 0)
|
||||
return;
|
||||
|
||||
const float entrySize = Math::max(font->getHeight(1.0),
|
||||
const float entrySize = std::max(font->getHeight(1.0),
|
||||
static_cast<float>(font->getSize())) * mLineSpacing;
|
||||
|
||||
int startEntry = 0;
|
||||
|
@ -420,7 +420,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|||
}
|
||||
|
||||
setFont(Font::getFromTheme(elem, properties, mFont));
|
||||
const float selectorHeight = Math::max(mFont->getHeight(1.0),
|
||||
const float selectorHeight = std::max(mFont->getHeight(1.0),
|
||||
static_cast<float>(mFont->getSize())) * mLineSpacing;
|
||||
setSelectorHeight(selectorHeight);
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ void VideoVlcComponent::resize()
|
|||
mSize[1] *= resizeScale.y();
|
||||
}
|
||||
|
||||
mSize[1] = Math::round(mSize[1]);
|
||||
mSize[1] = std::round(mSize[1]);
|
||||
mSize[0] = (mSize[1] / textureSize.y()) * textureSize.x();
|
||||
|
||||
}
|
||||
|
@ -141,17 +141,17 @@ void VideoVlcComponent::resize()
|
|||
|
||||
// If only one component is set, we resize in a way that maintains aspect ratio.
|
||||
if (!mTargetSize.x() && mTargetSize.y()) {
|
||||
mSize[1] = Math::round(mTargetSize.y());
|
||||
mSize[1] = std::round(mTargetSize.y());
|
||||
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x();
|
||||
}
|
||||
else if (mTargetSize.x() && !mTargetSize.y()) {
|
||||
mSize[1] = Math::round((mTargetSize.x() / textureSize.x()) * textureSize.y());
|
||||
mSize[1] = std::round((mTargetSize.x() / textureSize.x()) * textureSize.y());
|
||||
mSize[0] = (mSize.y() / textureSize.y()) * textureSize.x();
|
||||
}
|
||||
}
|
||||
|
||||
mTexture->rasterizeAt(static_cast<size_t>(Math::round(mSize.x())),
|
||||
static_cast<size_t>(Math::round(mSize.y())));
|
||||
mTexture->rasterizeAt(static_cast<size_t>(std::round(mSize.x())),
|
||||
static_cast<size_t>(std::round(mSize.y())));
|
||||
|
||||
onSizeChanged();
|
||||
}
|
||||
|
@ -261,20 +261,20 @@ void VideoVlcComponent::calculateBlackRectangle()
|
|||
rectHeight = mSize.y();
|
||||
}
|
||||
// Populate the rectangle coordinates to be used in render().
|
||||
mVideoRectangleCoords.push_back(Math::round(mVideoAreaPos.x() -
|
||||
mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.x() -
|
||||
rectWidth * mOrigin.x()));
|
||||
mVideoRectangleCoords.push_back(Math::round(mVideoAreaPos.y() -
|
||||
mVideoRectangleCoords.push_back(std::round(mVideoAreaPos.y() -
|
||||
rectHeight * mOrigin.y()));
|
||||
mVideoRectangleCoords.push_back(Math::round(rectWidth));
|
||||
mVideoRectangleCoords.push_back(Math::round(rectHeight));
|
||||
mVideoRectangleCoords.push_back(std::round(rectWidth));
|
||||
mVideoRectangleCoords.push_back(std::round(rectHeight));
|
||||
}
|
||||
// If the option to display pillarboxes is disabled, then make the rectangle equivalent
|
||||
// to the size of the video.
|
||||
else {
|
||||
mVideoRectangleCoords.push_back(Math::round(mPosition.x() - mSize.x() * mOrigin.x()));
|
||||
mVideoRectangleCoords.push_back(Math::round(mPosition.y() - mSize.y() * mOrigin.y()));
|
||||
mVideoRectangleCoords.push_back(Math::round(mSize.x()));
|
||||
mVideoRectangleCoords.push_back(Math::round(mSize.y()));
|
||||
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(mSize.x()));
|
||||
mVideoRectangleCoords.push_back(std::round(mSize.y()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,13 +63,13 @@ GuiMsgBox::GuiMsgBox(Window* window, const HelpStyle& helpstyle, const std::stri
|
|||
// Decide final width.
|
||||
if (mMsg->getSize().x() < width && mButtonGrid->getSize().x() < width) {
|
||||
// mMsg and buttons are narrower than width.
|
||||
width = Math::max(mButtonGrid->getSize().x(), mMsg->getSize().x());
|
||||
width = Math::max(width, minWidth);
|
||||
width = std::max(mButtonGrid->getSize().x(), mMsg->getSize().x());
|
||||
width = std::max(width, minWidth);
|
||||
}
|
||||
|
||||
// Now that we know width, we can find height.
|
||||
mMsg->setSize(width, 0); // mMsg->getSize.y() now returns the proper length.
|
||||
const float msgHeight = Math::max(Font::get(FONT_SIZE_LARGE)->getHeight(),
|
||||
const float msgHeight = std::max(Font::get(FONT_SIZE_LARGE)->getHeight(),
|
||||
mMsg->getSize().y()*1.225f);
|
||||
setSize(width + HORIZONTAL_PADDING_PX*2, msgHeight + mButtonGrid->getSize().y());
|
||||
|
||||
|
|
|
@ -8,59 +8,13 @@
|
|||
|
||||
#include "math/Misc.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace Math
|
||||
{
|
||||
// Added here to avoid including math.h whenever these are used.
|
||||
float cosf(const float _num)
|
||||
{
|
||||
return ::cosf(_num);
|
||||
}
|
||||
|
||||
float sinf(const float _num)
|
||||
{
|
||||
return ::sinf(_num);
|
||||
}
|
||||
|
||||
float floorf(const float _num)
|
||||
{
|
||||
return ::floorf(_num);
|
||||
}
|
||||
|
||||
float ceilf(const float _num)
|
||||
{
|
||||
return ::ceilf(_num);
|
||||
}
|
||||
|
||||
int min(const int _num1, const int _num2)
|
||||
{
|
||||
return (_num1 < _num2) ? _num1 : _num2;
|
||||
}
|
||||
|
||||
int max(const int _num1, const int _num2)
|
||||
{
|
||||
return (_num1 > _num2) ? _num1 : _num2;
|
||||
}
|
||||
|
||||
float min(const float _num1, const float _num2)
|
||||
{
|
||||
return (_num1 < _num2) ? _num1 : _num2;
|
||||
}
|
||||
|
||||
float max(const float _num1, const float _num2)
|
||||
{
|
||||
return (_num1 > _num2) ? _num1 : _num2;
|
||||
}
|
||||
|
||||
float clamp(const float _num, const float _min, const float _max)
|
||||
{
|
||||
return max(min(_num, _max), _min);
|
||||
}
|
||||
|
||||
float round(const float _num)
|
||||
{
|
||||
return static_cast<float>(static_cast<int>((_num + 0.5)));
|
||||
return std::fmax(std::fmin(_num, _max), _min);
|
||||
}
|
||||
|
||||
float lerp(const float _start, const float _end, const float _fraction)
|
||||
|
|
|
@ -15,19 +15,10 @@
|
|||
|
||||
namespace Math
|
||||
{
|
||||
// Added here to avoid including math.h whenever these are used.
|
||||
float cosf(const float _num);
|
||||
float sinf(const float _num);
|
||||
float floorf(const float _num);
|
||||
float ceilf(const float _num);
|
||||
|
||||
int min(const int _num1, const int _num2);
|
||||
int max(const int _num1, const int _num2);
|
||||
float min(const float _num1, const float _num2);
|
||||
float max(const float _num1, const float _num2);
|
||||
// When moving to the C++20 standard these functions are no longer required.
|
||||
float clamp(const float _num, const float _min, const float _max);
|
||||
float round(const float _num);
|
||||
float lerp(const float _start, const float _end, const float _fraction);
|
||||
|
||||
float smoothStep(const float _left, const float _right, const float _x);
|
||||
float smootherStep(const float _left, const float _right, const float _x);
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "math/Transform4x4f.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
const Transform4x4f Transform4x4f::operator*(const Transform4x4f& _other) const
|
||||
{
|
||||
const float* tm = reinterpret_cast<const float*>(this);
|
||||
|
@ -187,8 +189,8 @@ Transform4x4f& Transform4x4f::rotate(const float _angle, const Vector3f& _axis)
|
|||
{
|
||||
float* tm = reinterpret_cast<float*>(this);
|
||||
const float* av = reinterpret_cast<const float*>(&_axis);
|
||||
const float s = Math::sinf(-_angle);
|
||||
const float c = Math::cosf(-_angle);
|
||||
const float s = sinf(-_angle);
|
||||
const float c = cosf(-_angle);
|
||||
const float t = 1 - c;
|
||||
const float x = av[0];
|
||||
const float y = av[1];
|
||||
|
@ -234,8 +236,8 @@ Transform4x4f& Transform4x4f::rotate(const float _angle, const Vector3f& _axis)
|
|||
Transform4x4f& Transform4x4f::rotateX(const float _angle)
|
||||
{
|
||||
float* tm = reinterpret_cast<float*>(this);
|
||||
const float s = Math::sinf(-_angle);
|
||||
const float c = Math::cosf(-_angle);
|
||||
const float s = sinf(-_angle);
|
||||
const float c = cosf(-_angle);
|
||||
const float temp[6] = { tm[ 4] * c + tm[ 8] * -s,
|
||||
tm[ 5] * c + tm[ 9] * -c,
|
||||
tm[ 6] * c + tm[10] * -s,
|
||||
|
@ -256,8 +258,8 @@ Transform4x4f& Transform4x4f::rotateX(const float _angle)
|
|||
Transform4x4f& Transform4x4f::rotateY(const float _angle)
|
||||
{
|
||||
float* tm = reinterpret_cast<float*>(this);
|
||||
const float s = Math::sinf(-_angle);
|
||||
const float c = Math::cosf(-_angle);
|
||||
const float s = sinf(-_angle);
|
||||
const float c = cosf(-_angle);
|
||||
const float temp[6] = { tm[ 0] * c + tm[ 8] * s,
|
||||
tm[ 1] * c + tm[ 9] * s,
|
||||
tm[ 2] * c + tm[10] * s,
|
||||
|
@ -278,8 +280,8 @@ Transform4x4f& Transform4x4f::rotateY(const float _angle)
|
|||
Transform4x4f& Transform4x4f::rotateZ(const float _angle)
|
||||
{
|
||||
float* tm = reinterpret_cast<float*>(this);
|
||||
const float s = Math::sinf(-_angle);
|
||||
const float c = Math::cosf(-_angle);
|
||||
const float s = sinf(-_angle);
|
||||
const float c = cosf(-_angle);
|
||||
const float temp[6] = { tm[ 0] * c + tm[ 4] * -s,
|
||||
tm[ 1] * c + tm[ 5] * -s,
|
||||
tm[ 2] * c + tm[ 6] * -s,
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
|
||||
class TextCache;
|
||||
|
||||
#define FONT_SIZE_MINI (static_cast<unsigned int>(0.030f * Math::min(static_cast<int>( \
|
||||
#define FONT_SIZE_MINI (static_cast<unsigned int>(0.030f * std::min(static_cast<int>( \
|
||||
Renderer::getScreenHeight()), static_cast<int>(Renderer::getScreenWidth()))))
|
||||
#define FONT_SIZE_SMALL (static_cast<unsigned int>(0.035f * Math::min(static_cast<int>( \
|
||||
#define FONT_SIZE_SMALL (static_cast<unsigned int>(0.035f * std::min(static_cast<int>( \
|
||||
Renderer::getScreenHeight()), static_cast<int>(Renderer::getScreenWidth()))))
|
||||
#define FONT_SIZE_MEDIUM (static_cast<unsigned int>(0.045f * Math::min(static_cast<int>( \
|
||||
#define FONT_SIZE_MEDIUM (static_cast<unsigned int>(0.045f * std::min(static_cast<int>( \
|
||||
Renderer::getScreenHeight()), static_cast<int>(Renderer::getScreenWidth()))))
|
||||
#define FONT_SIZE_LARGE (static_cast<unsigned int>(0.085f * Math::min(static_cast<int>( \
|
||||
#define FONT_SIZE_LARGE (static_cast<unsigned int>(0.085f * std::min(static_cast<int>( \
|
||||
Renderer::getScreenHeight()), static_cast<int>(Renderer::getScreenWidth()))))
|
||||
|
||||
#define FONT_PATH_LIGHT ":/fonts/opensans_hebrew_condensed_light.ttf"
|
||||
|
|
|
@ -69,17 +69,17 @@ bool TextureData::initSVGFromMemory(const std::string& fileData)
|
|||
mSourceWidth = svgImage->width;
|
||||
mSourceHeight = svgImage->height;
|
||||
}
|
||||
mWidth = static_cast<size_t>(Math::round(mSourceWidth));
|
||||
mHeight = static_cast<size_t>(Math::round(mSourceHeight));
|
||||
mWidth = static_cast<size_t>(std::round(mSourceWidth));
|
||||
mHeight = static_cast<size_t>(std::round(mSourceHeight));
|
||||
|
||||
if (mWidth == 0) {
|
||||
// Auto scale width to keep aspect ratio.
|
||||
mWidth = static_cast<size_t>(Math::round((static_cast<float>(mHeight) /
|
||||
mWidth = static_cast<size_t>(std::round((static_cast<float>(mHeight) /
|
||||
svgImage->height) * svgImage->width));
|
||||
}
|
||||
else if (mHeight == 0) {
|
||||
// Auto scale height to keep aspect ratio.
|
||||
mHeight = static_cast<size_t>(Math::round((static_cast<float>(mWidth) /
|
||||
mHeight = static_cast<size_t>(std::round((static_cast<float>(mWidth) /
|
||||
svgImage->width) * svgImage->height));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue