From 844900db390dbaf4240a8cc476e02e654b07c1ac Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 24 Sep 2017 16:09:05 -0300 Subject: [PATCH] Rename all cases of 'pixel density' to 'DPI scale' in love's APIs. --HG-- branch : minor --- src/modules/font/BMFontRasterizer.cpp | 4 +- src/modules/font/BMFontRasterizer.h | 2 +- src/modules/font/Font.cpp | 16 +++--- src/modules/font/Font.h | 10 ++-- src/modules/font/ImageRasterizer.cpp | 4 +- src/modules/font/ImageRasterizer.h | 2 +- src/modules/font/Rasterizer.cpp | 4 +- src/modules/font/Rasterizer.h | 4 +- src/modules/font/freetype/Font.cpp | 10 ++-- src/modules/font/freetype/Font.h | 2 +- .../font/freetype/TrueTypeRasterizer.cpp | 6 +-- .../font/freetype/TrueTypeRasterizer.h | 2 +- src/modules/font/wrap_Font.cpp | 16 +++--- src/modules/graphics/Canvas.cpp | 4 +- src/modules/graphics/Canvas.h | 2 +- src/modules/graphics/Deprecations.cpp | 2 +- src/modules/graphics/Font.cpp | 28 +++++------ src/modules/graphics/Font.h | 4 +- src/modules/graphics/Graphics.cpp | 10 ++-- src/modules/graphics/Graphics.h | 6 +-- src/modules/graphics/Image.cpp | 4 +- src/modules/graphics/Image.h | 2 +- src/modules/graphics/Texture.cpp | 2 +- src/modules/graphics/Texture.h | 2 +- src/modules/graphics/Video.cpp | 6 +-- src/modules/graphics/Video.h | 2 +- src/modules/graphics/opengl/Graphics.cpp | 12 ++--- src/modules/graphics/wrap_Font.cpp | 6 +-- src/modules/graphics/wrap_Graphics.cpp | 50 +++++++++---------- src/modules/graphics/wrap_Graphics.lua | 2 +- src/modules/graphics/wrap_Texture.cpp | 6 +-- src/modules/window/Window.h | 2 +- src/modules/window/sdl/Window.cpp | 10 ++-- src/modules/window/sdl/Window.h | 2 +- src/modules/window/wrap_Window.cpp | 6 +-- src/scripts/nogame.lua | 2 +- src/scripts/nogame.lua.h | 4 +- 37 files changed, 129 insertions(+), 129 deletions(-) diff --git a/src/modules/font/BMFontRasterizer.cpp b/src/modules/font/BMFontRasterizer.cpp index 2a66ff300..81db0d252 100644 --- a/src/modules/font/BMFontRasterizer.cpp +++ b/src/modules/font/BMFontRasterizer.cpp @@ -131,12 +131,12 @@ std::string BMFontLine::getAttributeString(const char *name) const } // anonymous namespace -BMFontRasterizer::BMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &imagelist, float pixeldensity) +BMFontRasterizer::BMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &imagelist, float dpiscale) : fontSize(0) , unicode(false) , lineHeight(0) { - this->pixelDensity = pixeldensity; + this->dpiScale = dpiscale; const std::string &filename = fontdef->getFilename(); diff --git a/src/modules/font/BMFontRasterizer.h b/src/modules/font/BMFontRasterizer.h index 56455e412..af9e8ead8 100644 --- a/src/modules/font/BMFontRasterizer.h +++ b/src/modules/font/BMFontRasterizer.h @@ -42,7 +42,7 @@ class BMFontRasterizer : public Rasterizer { public: - BMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &imagelist, float pixeldensity); + BMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &imagelist, float dpiscale); virtual ~BMFontRasterizer(); // Implements Rasterizer. diff --git a/src/modules/font/Font.cpp b/src/modules/font/Font.cpp index c303504ad..989d74e34 100644 --- a/src/modules/font/Font.cpp +++ b/src/modules/font/Font.cpp @@ -48,18 +48,18 @@ Rasterizer *Font::newTrueTypeRasterizer(int size, TrueTypeRasterizer::Hinting hi return newTrueTypeRasterizer(data.get(), size, hinting); } -Rasterizer *Font::newTrueTypeRasterizer(int size, float pixeldensity, TrueTypeRasterizer::Hinting hinting) +Rasterizer *Font::newTrueTypeRasterizer(int size, float dpiscale, TrueTypeRasterizer::Hinting hinting) { StrongRef data(new DefaultFontData, Acquire::NORETAIN); - return newTrueTypeRasterizer(data.get(), size, pixeldensity, hinting); + return newTrueTypeRasterizer(data.get(), size, dpiscale, hinting); } -Rasterizer *Font::newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &images, float pixeldensity) +Rasterizer *Font::newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &images, float dpiscale) { - return new BMFontRasterizer(fontdef, images, pixeldensity); + return new BMFontRasterizer(fontdef, images, dpiscale); } -Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::string &text, int extraspacing, float pixeldensity) +Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::string &text, int extraspacing, float dpiscale) { std::vector glyphs; glyphs.reserve(text.size()); @@ -77,12 +77,12 @@ Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::st throw love::Exception("UTF-8 decoding error: %s", e.what()); } - return newImageRasterizer(data, &glyphs[0], (int) glyphs.size(), extraspacing, pixeldensity); + return newImageRasterizer(data, &glyphs[0], (int) glyphs.size(), extraspacing, dpiscale); } -Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing, float pixeldensity) +Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing, float dpiscale) { - return new ImageRasterizer(data, glyphs, numglyphs, extraspacing, pixeldensity); + return new ImageRasterizer(data, glyphs, numglyphs, extraspacing, dpiscale); } GlyphData *Font::newGlyphData(Rasterizer *r, const std::string &text) diff --git a/src/modules/font/Font.h b/src/modules/font/Font.h index 741a99185..97f82e3d9 100644 --- a/src/modules/font/Font.h +++ b/src/modules/font/Font.h @@ -48,14 +48,14 @@ public: virtual Rasterizer *newRasterizer(love::filesystem::FileData *data) = 0; virtual Rasterizer *newTrueTypeRasterizer(int size, TrueTypeRasterizer::Hinting hinting); - virtual Rasterizer *newTrueTypeRasterizer(int size, float pixeldensity, TrueTypeRasterizer::Hinting hinting); + virtual Rasterizer *newTrueTypeRasterizer(int size, float dpiscale, TrueTypeRasterizer::Hinting hinting); virtual Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, TrueTypeRasterizer::Hinting hinting) = 0; - virtual Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, float pixeldensity, TrueTypeRasterizer::Hinting hinting) = 0; + virtual Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, float dpiscale, TrueTypeRasterizer::Hinting hinting) = 0; - virtual Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &images, float pixeldensity); + virtual Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector &images, float dpiscale); - virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &glyphs, int extraspacing, float pixeldensity); - virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int length, int extraspacing, float pixeldensity); + virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &glyphs, int extraspacing, float dpiscale); + virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int length, int extraspacing, float dpiscale); virtual GlyphData *newGlyphData(Rasterizer *r, const std::string &glyph); virtual GlyphData *newGlyphData(Rasterizer *r, uint32 glyph); diff --git a/src/modules/font/ImageRasterizer.cpp b/src/modules/font/ImageRasterizer.cpp index 00507a00f..7644f87a2 100644 --- a/src/modules/font/ImageRasterizer.cpp +++ b/src/modules/font/ImageRasterizer.cpp @@ -31,13 +31,13 @@ namespace font static_assert(sizeof(Color) == 4, "sizeof(Color) must equal 4 bytes!"); -ImageRasterizer::ImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing, float pixeldensity) +ImageRasterizer::ImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs, int extraspacing, float dpiscale) : imageData(data) , glyphs(glyphs) , numglyphs(numglyphs) , extraSpacing(extraspacing) { - this->pixelDensity = pixeldensity; + this->dpiScale = dpiscale; if (data->getFormat() != PIXELFORMAT_RGBA8) throw love::Exception("Only 32-bit RGBA images are supported in Image Fonts!"); diff --git a/src/modules/font/ImageRasterizer.h b/src/modules/font/ImageRasterizer.h index 8b4d5aba2..d455d9159 100644 --- a/src/modules/font/ImageRasterizer.h +++ b/src/modules/font/ImageRasterizer.h @@ -39,7 +39,7 @@ namespace font class ImageRasterizer : public Rasterizer { public: - ImageRasterizer(love::image::ImageData *imageData, uint32 *glyphs, int numglyphs, int extraspacing, float pixeldensity); + ImageRasterizer(love::image::ImageData *imageData, uint32 *glyphs, int numglyphs, int extraspacing, float dpiscale); virtual ~ImageRasterizer(); // Implement Rasterizer diff --git a/src/modules/font/Rasterizer.cpp b/src/modules/font/Rasterizer.cpp index 54d5a51bf..aa65812cb 100644 --- a/src/modules/font/Rasterizer.cpp +++ b/src/modules/font/Rasterizer.cpp @@ -102,9 +102,9 @@ float Rasterizer::getKerning(uint32 /*leftglyph*/, uint32 /*rightglyph*/) const return 0.0f; } -float Rasterizer::getPixelDensity() const +float Rasterizer::getDPIScale() const { - return pixelDensity; + return dpiScale; } } // font diff --git a/src/modules/font/Rasterizer.h b/src/modules/font/Rasterizer.h index 04c97982e..f41a3a2e7 100644 --- a/src/modules/font/Rasterizer.h +++ b/src/modules/font/Rasterizer.h @@ -120,12 +120,12 @@ public: virtual DataType getDataType() const = 0; - float getPixelDensity() const; + float getDPIScale() const; protected: FontMetrics metrics; - float pixelDensity; + float dpiScale; }; // Rasterizer diff --git a/src/modules/font/freetype/Font.cpp b/src/modules/font/freetype/Font.cpp index 6ccd42be2..10f477801 100644 --- a/src/modules/font/freetype/Font.cpp +++ b/src/modules/font/freetype/Font.cpp @@ -58,17 +58,17 @@ Rasterizer *Font::newRasterizer(love::filesystem::FileData *data) Rasterizer *Font::newTrueTypeRasterizer(love::Data *data, int size, TrueTypeRasterizer::Hinting hinting) { - float pixeldensity = 1.0f; + float dpiscale = 1.0f; auto window = Module::getInstance(Module::M_WINDOW); if (window != nullptr) - pixeldensity = window->getPixelDensity(); + dpiscale = window->getDPIScale(); - return newTrueTypeRasterizer(data, size, pixeldensity, hinting); + return newTrueTypeRasterizer(data, size, dpiscale, hinting); } -Rasterizer *Font::newTrueTypeRasterizer(love::Data *data, int size, float pixeldensity, TrueTypeRasterizer::Hinting hinting) +Rasterizer *Font::newTrueTypeRasterizer(love::Data *data, int size, float dpiscale, TrueTypeRasterizer::Hinting hinting) { - return new TrueTypeRasterizer(library, data, size, pixeldensity, hinting); + return new TrueTypeRasterizer(library, data, size, dpiscale, hinting); } const char *Font::getName() const diff --git a/src/modules/font/freetype/Font.h b/src/modules/font/freetype/Font.h index 63d91a185..3ffba9679 100644 --- a/src/modules/font/freetype/Font.h +++ b/src/modules/font/freetype/Font.h @@ -46,7 +46,7 @@ public: // Implements Font Rasterizer *newRasterizer(love::filesystem::FileData *data) override; Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, TrueTypeRasterizer::Hinting hinting) override; - Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, float pixeldensity, TrueTypeRasterizer::Hinting hinting) override; + Rasterizer *newTrueTypeRasterizer(love::Data *data, int size, float dpiscale, TrueTypeRasterizer::Hinting hinting) override; // Implement Module const char *getName() const override; diff --git a/src/modules/font/freetype/TrueTypeRasterizer.cpp b/src/modules/font/freetype/TrueTypeRasterizer.cpp index 4c9bdd034..9c6d93861 100644 --- a/src/modules/font/freetype/TrueTypeRasterizer.cpp +++ b/src/modules/font/freetype/TrueTypeRasterizer.cpp @@ -32,12 +32,12 @@ namespace font namespace freetype { -TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, love::Data *data, int size, float pixeldensity, Hinting hinting) +TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, love::Data *data, int size, float dpiscale, Hinting hinting) : data(data) , hinting(hinting) { - this->pixelDensity = pixeldensity; - size = floorf(size * pixeldensity + 0.5f); + this->dpiScale = dpiscale; + size = floorf(size * dpiscale + 0.5f); if (size <= 0) throw love::Exception("Invalid TrueType font size: %d", size); diff --git a/src/modules/font/freetype/TrueTypeRasterizer.h b/src/modules/font/freetype/TrueTypeRasterizer.h index 0a0d0efa0..43aef647a 100644 --- a/src/modules/font/freetype/TrueTypeRasterizer.h +++ b/src/modules/font/freetype/TrueTypeRasterizer.h @@ -44,7 +44,7 @@ class TrueTypeRasterizer : public love::font::TrueTypeRasterizer { public: - TrueTypeRasterizer(FT_Library library, love::Data *data, int size, float pixeldensity, Hinting hinting); + TrueTypeRasterizer(FT_Library library, love::Data *data, int size, float dpiscale, Hinting hinting); virtual ~TrueTypeRasterizer(); // Implement Rasterizer diff --git a/src/modules/font/wrap_Font.cpp b/src/modules/font/wrap_Font.cpp index 7972f8a5b..eab7837cc 100644 --- a/src/modules/font/wrap_Font.cpp +++ b/src/modules/font/wrap_Font.cpp @@ -82,8 +82,8 @@ int w_newTrueTypeRasterizer(lua_State *L) luax_catchexcept(L, [&](){ t = instance()->newTrueTypeRasterizer(size, hinting); }); else { - float pixeldensity = (float) luaL_checknumber(L, 3); - luax_catchexcept(L, [&](){ t = instance()->newTrueTypeRasterizer(size, pixeldensity, hinting); }); + float dpiscale = (float) luaL_checknumber(L, 3); + luax_catchexcept(L, [&](){ t = instance()->newTrueTypeRasterizer(size, dpiscale, hinting); }); } } else @@ -113,9 +113,9 @@ int w_newTrueTypeRasterizer(lua_State *L) } else { - float pixeldensity = (float) luaL_checknumber(L, 4); + float dpiscale = (float) luaL_checknumber(L, 4); luax_catchexcept(L, - [&]() { t = instance()->newTrueTypeRasterizer(d, size, pixeldensity, hinting); }, + [&]() { t = instance()->newTrueTypeRasterizer(d, size, dpiscale, hinting); }, [&](bool) { d->release(); } ); } @@ -138,7 +138,7 @@ int w_newBMFontRasterizer(lua_State *L) filesystem::FileData *d = filesystem::luax_getfiledata(L, 1); std::vector images; - float pixeldensity = (float) luaL_optnumber(L, 3, 1.0); + float dpiscale = (float) luaL_optnumber(L, 3, 1.0); if (lua_istable(L, 2)) { @@ -163,7 +163,7 @@ int w_newBMFontRasterizer(lua_State *L) } luax_catchexcept(L, - [&]() { t = instance()->newBMFontRasterizer(d, images, pixeldensity); }, + [&]() { t = instance()->newBMFontRasterizer(d, images, dpiscale); }, [&](bool) { d->release(); for (auto id : images) id->release(); } ); @@ -181,9 +181,9 @@ int w_newImageRasterizer(lua_State *L) image::ImageData *d = luax_checktype(L, 1); std::string glyphs = luax_checkstring(L, 2); int extraspacing = (int) luaL_optinteger(L, 3, 0); - float pixeldensity = (float) luaL_optnumber(L, 4, 1.0); + float dpiscale = (float) luaL_optnumber(L, 4, 1.0); - luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing, pixeldensity); }); + luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing, dpiscale); }); luax_pushtype(L, t); t->release(); diff --git a/src/modules/graphics/Canvas.cpp b/src/modules/graphics/Canvas.cpp index a0626112f..8026196ca 100644 --- a/src/modules/graphics/Canvas.cpp +++ b/src/modules/graphics/Canvas.cpp @@ -36,8 +36,8 @@ Canvas::Canvas(const Settings &settings) width = settings.width; height = settings.height; - pixelWidth = (int) ((width * settings.pixeldensity) + 0.5); - pixelHeight = (int) ((height * settings.pixeldensity) + 0.5); + pixelWidth = (int) ((width * settings.dpiScale) + 0.5); + pixelHeight = (int) ((height * settings.dpiScale) + 0.5); format = settings.format; diff --git a/src/modules/graphics/Canvas.h b/src/modules/graphics/Canvas.h index 37714a342..62d9758ee 100644 --- a/src/modules/graphics/Canvas.h +++ b/src/modules/graphics/Canvas.h @@ -55,7 +55,7 @@ public: MipmapMode mipmaps = MIPMAPS_NONE; PixelFormat format = PIXELFORMAT_NORMAL; TextureType type = TEXTURE_2D; - float pixeldensity = 1.0f; + float dpiScale = 1.0f; int msaa = 0; OptionalBool readable; }; diff --git a/src/modules/graphics/Deprecations.cpp b/src/modules/graphics/Deprecations.cpp index 0f45c04e4..1eaab7b19 100644 --- a/src/modules/graphics/Deprecations.cpp +++ b/src/modules/graphics/Deprecations.cpp @@ -76,7 +76,7 @@ void Deprecations::draw(Graphics *gfx) { auto hinting = font::TrueTypeRasterizer::HINTING_NORMAL; - if (!isGammaCorrect() && gfx->getScreenPixelDensity() <= 1.0) + if (!isGammaCorrect() && gfx->getScreenDPIScale() <= 1.0) hinting = font::TrueTypeRasterizer::HINTING_LIGHT; font.set(gfx->newDefaultFont(9, hinting), Acquire::NORETAIN); diff --git a/src/modules/graphics/Font.cpp b/src/modules/graphics/Font.cpp index a746a431a..f54a0f7ac 100644 --- a/src/modules/graphics/Font.cpp +++ b/src/modules/graphics/Font.cpp @@ -54,7 +54,7 @@ Font::Font(love::font::Rasterizer *r, const Texture::Filter &f) , textureWidth(128) , textureHeight(128) , filter(f) - , pixelDensity(r->getPixelDensity()) + , dpiScale(r->getDPIScale()) , useSpacesAsTab(false) , textureCacheID(0) { @@ -247,7 +247,7 @@ const Font::Glyph &Font::addGlyph(uint32 glyph) Glyph g; g.texture = 0; - g.spacing = floorf(gd->getAdvance() / pixelDensity + 0.5f); + g.spacing = floorf(gd->getAdvance() / dpiScale + 0.5f); memset(g.vertices, 0, sizeof(GlyphVertex) * 4); @@ -275,18 +275,18 @@ const Font::Glyph &Font::addGlyph(uint32 glyph) // 1---3 const GlyphVertex verts[4] = { - {float(-o), float(-o), normToUint16((tX-o)/tWidth), normToUint16((tY-o)/tHeight), c}, - {float(-o), (h+o)/pixelDensity, normToUint16((tX-o)/tWidth), normToUint16((tY+h+o)/tHeight), c}, - {(w+o)/pixelDensity, float(-o), normToUint16((tX+w+o)/tWidth), normToUint16((tY-o)/tHeight), c}, - {(w+o)/pixelDensity, (h+o)/pixelDensity, normToUint16((tX+w+o)/tWidth), normToUint16((tY+h+o)/tHeight), c} + {float(-o), float(-o), normToUint16((tX-o)/tWidth), normToUint16((tY-o)/tHeight), c}, + {float(-o), (h+o)/dpiScale, normToUint16((tX-o)/tWidth), normToUint16((tY+h+o)/tHeight), c}, + {(w+o)/dpiScale, float(-o), normToUint16((tX+w+o)/tWidth), normToUint16((tY-o)/tHeight), c}, + {(w+o)/dpiScale, (h+o)/dpiScale, normToUint16((tX+w+o)/tWidth), normToUint16((tY+h+o)/tHeight), c} }; // Copy vertex data to the glyph and set proper bearing. for (int i = 0; i < 4; i++) { g.vertices[i] = verts[i]; - g.vertices[i].x += gd->getBearingX() / pixelDensity; - g.vertices[i].y -= gd->getBearingY() / pixelDensity; + g.vertices[i].x += gd->getBearingX() / dpiScale; + g.vertices[i].y -= gd->getBearingY() / dpiScale; } textureX += w + TEXTURE_PADDING; @@ -321,7 +321,7 @@ float Font::getKerning(uint32 leftglyph, uint32 rightglyph) { if (r->hasGlyph(leftglyph) && r->hasGlyph(rightglyph)) { - k = floorf(r->getKerning(leftglyph, rightglyph) / pixelDensity + 0.5f); + k = floorf(r->getKerning(leftglyph, rightglyph) / dpiScale + 0.5f); break; } } @@ -382,7 +382,7 @@ void Font::getCodepointsFromString(const std::vector &strs, Color float Font::getHeight() const { - return (float) floorf(height / pixelDensity + 0.5f); + return (float) floorf(height / dpiScale + 0.5f); } std::vector Font::generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantcolor, std::vector &vertices, float extra_spacing, Vector2 offset, TextInfo *info) @@ -921,12 +921,12 @@ const Texture::Filter &Font::getFilter() const int Font::getAscent() const { - return floorf(rasterizers[0]->getAscent() / pixelDensity + 0.5f); + return floorf(rasterizers[0]->getAscent() / dpiScale + 0.5f); } int Font::getDescent() const { - return floorf(rasterizers[0]->getDescent() / pixelDensity + 0.5f); + return floorf(rasterizers[0]->getDescent() / dpiScale + 0.5f); } float Font::getBaseline() const @@ -992,9 +992,9 @@ void Font::setFallbacks(const std::vector &fallbacks) rasterizers.push_back(f->rasterizers[0]); } -float Font::getPixelDensity() const +float Font::getDPIScale() const { - return pixelDensity; + return dpiScale; } uint32 Font::getTextureCacheID() const diff --git a/src/modules/graphics/Font.h b/src/modules/graphics/Font.h index 154d5eb9c..21d04cec2 100644 --- a/src/modules/graphics/Font.h +++ b/src/modules/graphics/Font.h @@ -171,7 +171,7 @@ public: void setFallbacks(const std::vector &fallbacks); - float getPixelDensity() const; + float getDPIScale() const; uint32 getTextureCacheID() const; @@ -228,7 +228,7 @@ private: Texture::Filter filter; - float pixelDensity; + float dpiScale; int textureX, textureY; int rowHeight; diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 8bf633209..2867a8976 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -172,9 +172,9 @@ Font *Graphics::newDefaultFont(int size, font::TrueTypeRasterizer::Hinting hinti return newFont(r.get(), filter); } -Video *Graphics::newVideo(love::video::VideoStream *stream, float pixeldensity) +Video *Graphics::newVideo(love::video::VideoStream *stream, float dpiscale) { - return new Video(this, stream, pixeldensity); + return new Video(this, stream, dpiscale); } bool Graphics::validateShader(bool gles, const Shader::ShaderSource &source, std::string &err) @@ -202,7 +202,7 @@ int Graphics::getPixelHeight() const return pixelHeight; } -double Graphics::getCurrentPixelDensity() const +double Graphics::getCurrentDPIScale() const { if (states.back().renderTargets.colors.size() > 0) { @@ -210,10 +210,10 @@ double Graphics::getCurrentPixelDensity() const return (double) c->getPixelHeight() / (double) c->getHeight(); } - return getScreenPixelDensity(); + return getScreenDPIScale(); } -double Graphics::getScreenPixelDensity() const +double Graphics::getScreenDPIScale() const { return (double) getPixelHeight() / (double) getHeight(); } diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 5a21917d8..5f2d6874b 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -372,7 +372,7 @@ public: Quad *newQuad(Quad::Viewport v, double sw, double sh); Font *newFont(love::font::Rasterizer *data, const Texture::Filter &filter = Texture::defaultFilter); Font *newDefaultFont(int size, font::TrueTypeRasterizer::Hinting hinting, const Texture::Filter &filter = Texture::defaultFilter); - Video *newVideo(love::video::VideoStream *stream, float pixeldensity); + Video *newVideo(love::video::VideoStream *stream, float dpiscale); virtual SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage) = 0; @@ -450,8 +450,8 @@ public: int getPixelWidth() const; int getPixelHeight() const; - double getCurrentPixelDensity() const; - double getScreenPixelDensity() const; + double getCurrentDPIScale() const; + double getScreenDPIScale() const; /** * Sets the current constant color. diff --git a/src/modules/graphics/Image.cpp b/src/modules/graphics/Image.cpp index 0ff8489a8..016194a49 100644 --- a/src/modules/graphics/Image.cpp +++ b/src/modules/graphics/Image.cpp @@ -83,8 +83,8 @@ void Image::init(PixelFormat fmt, int w, int h, const Settings &settings) pixelWidth = w; pixelHeight = h; - width = (int) (pixelWidth / settings.pixeldensity + 0.5); - height = (int) (pixelHeight / settings.pixeldensity + 0.5); + width = (int) (pixelWidth / settings.dpiScale + 0.5); + height = (int) (pixelHeight / settings.dpiScale + 0.5); mipmapCount = mipmapsType == MIPMAPS_NONE ? 1 : getMipmapCount(w, h); format = fmt; diff --git a/src/modules/graphics/Image.h b/src/modules/graphics/Image.h index 349e8d563..7718cde56 100644 --- a/src/modules/graphics/Image.h +++ b/src/modules/graphics/Image.h @@ -50,7 +50,7 @@ public: { bool mipmaps = false; bool linear = false; - float pixeldensity = 1.0f; + float dpiScale = 1.0f; }; struct Slices diff --git a/src/modules/graphics/Texture.cpp b/src/modules/graphics/Texture.cpp index ee6fad7eb..f3d1992ff 100644 --- a/src/modules/graphics/Texture.cpp +++ b/src/modules/graphics/Texture.cpp @@ -239,7 +239,7 @@ int Texture::getPixelHeight(int mip) const return std::max(pixelHeight >> mip, 1); } -float Texture::getPixelDensity() const +float Texture::getDPIScale() const { return (float) pixelHeight / (float) height; } diff --git a/src/modules/graphics/Texture.h b/src/modules/graphics/Texture.h index 9bf3dea43..e63b99ad8 100644 --- a/src/modules/graphics/Texture.h +++ b/src/modules/graphics/Texture.h @@ -136,7 +136,7 @@ public: int getPixelWidth(int mip = 0) const; int getPixelHeight(int mip = 0) const; - float getPixelDensity() const; + float getDPIScale() const; virtual void setFilter(const Filter &f); virtual const Filter &getFilter() const; diff --git a/src/modules/graphics/Video.cpp b/src/modules/graphics/Video.cpp index 830114318..2147748f8 100644 --- a/src/modules/graphics/Video.cpp +++ b/src/modules/graphics/Video.cpp @@ -31,10 +31,10 @@ namespace graphics love::Type Video::type("Video", &Drawable::type); -Video::Video(Graphics *gfx, love::video::VideoStream *stream, float pixeldensity) +Video::Video(Graphics *gfx, love::video::VideoStream *stream, float dpiscale) : stream(stream) - , width(stream->getWidth() / pixeldensity) - , height(stream->getHeight() / pixeldensity) + , width(stream->getWidth() / dpiscale) + , height(stream->getHeight() / dpiscale) , filter(Texture::defaultFilter) { filter.mipmap = Texture::FILTER_NONE; diff --git a/src/modules/graphics/Video.h b/src/modules/graphics/Video.h index ec9cecb26..1f0367490 100644 --- a/src/modules/graphics/Video.h +++ b/src/modules/graphics/Video.h @@ -41,7 +41,7 @@ public: static love::Type type; - Video(Graphics *gfx, love::video::VideoStream *stream, float pixeldensity = 1.0f); + Video(Graphics *gfx, love::video::VideoStream *stream, float dpiscale = 1.0f); virtual ~Video(); // Drawable diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 6c2579a41..01d0e442d 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1027,13 +1027,13 @@ void Graphics::setScissor(const Rect &rect) glEnable(GL_SCISSOR_TEST); - double density = getCurrentPixelDensity(); + double dpiscale = getCurrentDPIScale(); Rect glrect; - glrect.x = (int) (rect.x * density); - glrect.y = (int) (rect.y * density); - glrect.w = (int) (rect.w * density); - glrect.h = (int) (rect.h * density); + glrect.x = (int) (rect.x * dpiscale); + glrect.y = (int) (rect.y * dpiscale); + glrect.w = (int) (rect.w * dpiscale); + glrect.h = (int) (rect.h * dpiscale); // OpenGL's reversed y-coordinate is compensated for in OpenGL::setScissor. gl.setScissor(glrect, isCanvasActive()); @@ -1260,7 +1260,7 @@ void Graphics::setPointSize(float size) if (streamBufferState.primitiveMode == vertex::PrimitiveMode::POINTS) flushStreamDraws(); - gl.setPointSize(size * getCurrentPixelDensity()); + gl.setPointSize(size * getCurrentDPIScale()); states.back().pointSize = size; } diff --git a/src/modules/graphics/wrap_Font.cpp b/src/modules/graphics/wrap_Font.cpp index 748763b4d..cf8d8a75c 100644 --- a/src/modules/graphics/wrap_Font.cpp +++ b/src/modules/graphics/wrap_Font.cpp @@ -226,10 +226,10 @@ int w_Font_setFallbacks(lua_State *L) return 0; } -int w_Font_getPixelDensity(lua_State *L) +int w_Font_getDPIScale(lua_State *L) { Font *t = luax_checkfont(L, 1); - lua_pushnumber(L, t->getPixelDensity()); + lua_pushnumber(L, t->getDPIScale()); return 1; } @@ -247,7 +247,7 @@ static const luaL_Reg w_Font_functions[] = { "getBaseline", w_Font_getBaseline }, { "hasGlyphs", w_Font_hasGlyphs }, { "setFallbacks", w_Font_setFallbacks }, - { "getPixelDensity", w_Font_getPixelDensity }, + { "getDPIScale", w_Font_getDPIScale }, { 0, 0 } }; diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index 990c48b6c..942580d2a 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -234,9 +234,9 @@ int w_getPixelDimensions(lua_State *L) return 2; } -int w_getPixelDensity(lua_State *L) +int w_getDPIScale(lua_State *L) { - lua_pushnumber(L, instance()->getScreenPixelDensity()); + lua_pushnumber(L, instance()->getScreenDPIScale()); return 1; } @@ -631,7 +631,7 @@ int w_getStencilTest(lua_State *L) return 2; } -static void parsePixelDensity(Data *d, float *pixeldensity) +static void parseDPIScale(Data *d, float *dpiscale) { auto fd = dynamic_cast(d); if (fd == nullptr) @@ -648,8 +648,8 @@ static void parsePixelDensity(Data *d, float *pixeldensity) { char *end = nullptr; long density = strtol(fname.c_str() + atpos + 1, &end, 10); - if (end != nullptr && density > 0 && pixeldensity != nullptr) - *pixeldensity = (float) density; + if (end != nullptr && density > 0 && dpiscale != nullptr) + *dpiscale = (float) density; } } @@ -662,14 +662,14 @@ static Image::Settings w__optImageSettings(lua_State *L, int idx, const Image::S luaL_checktype(L, idx, LUA_TTABLE); settings.mipmaps = luax_boolflag(L, idx, "mipmaps", s.mipmaps); settings.linear = luax_boolflag(L, idx, "linear", s.linear); - settings.pixeldensity = (float) luax_numberflag(L, idx, "pixeldensity", s.pixeldensity); + settings.dpiScale = (float) luax_numberflag(L, idx, "dpiscale", s.dpiScale); } return settings; } static std::pair, StrongRef> -getImageData(lua_State *L, int idx, bool allowcompressed, float *density) +getImageData(lua_State *L, int idx, bool allowcompressed, float *dpiscale) { StrongRef idata; StrongRef cdata; @@ -687,8 +687,8 @@ getImageData(lua_State *L, int idx, bool allowcompressed, float *density) StrongRef fdata(filesystem::luax_getdata(L, idx), Acquire::NORETAIN); - if (density != nullptr) - parsePixelDensity(fdata, density); + if (dpiscale != nullptr) + parseDPIScale(fdata, dpiscale); if (allowcompressed && imagemodule->isCompressed(fdata)) luax_catchexcept(L, [&]() { cdata.set(imagemodule->newCompressedData(fdata), Acquire::NORETAIN); }); @@ -724,7 +724,7 @@ int w_newCubeImage(lua_State *L) if (!lua_istable(L, 1)) { - auto data = getImageData(L, 1, true, &settings.pixeldensity); + auto data = getImageData(L, 1, true, &settings.dpiScale); std::vector> faces; @@ -758,7 +758,7 @@ int w_newCubeImage(lua_State *L) { lua_rawgeti(L, -1, mip + 1); - auto data = getImageData(L, -1, true, face == 0 && mip == 0 ? &settings.pixeldensity : nullptr); + auto data = getImageData(L, -1, true, face == 0 && mip == 0 ? &settings.dpiScale : nullptr); if (data.first.get()) slices.set(face, mip, data.first); else @@ -776,7 +776,7 @@ int w_newCubeImage(lua_State *L) { lua_rawgeti(L, 1, i + 1); - auto data = getImageData(L, -1, true, i == 0 ? &settings.pixeldensity : nullptr); + auto data = getImageData(L, -1, true, i == 0 ? &settings.dpiScale : nullptr); if (data.first.get()) { @@ -829,7 +829,7 @@ int w_newArrayImage(lua_State *L) { lua_rawgeti(L, -1, mip + 1); - auto data = getImageData(L, -1, true, slice == 0 && mip == 0 ? &settings.pixeldensity : nullptr); + auto data = getImageData(L, -1, true, slice == 0 && mip == 0 ? &settings.dpiScale : nullptr); if (data.first.get()) slices.set(slice, mip, data.first); else @@ -844,7 +844,7 @@ int w_newArrayImage(lua_State *L) for (int slice = 0; slice < tlen; slice++) { lua_rawgeti(L, 1, slice + 1); - auto data = getImageData(L, -1, true, slice == 0 ? &settings.pixeldensity : nullptr); + auto data = getImageData(L, -1, true, slice == 0 ? &settings.dpiScale : nullptr); if (data.first.get()) slices.set(slice, 0, data.first); else @@ -856,7 +856,7 @@ int w_newArrayImage(lua_State *L) } else { - auto data = getImageData(L, 1, true, &settings.pixeldensity); + auto data = getImageData(L, 1, true, &settings.dpiScale); if (data.first.get()) slices.set(0, 0, data.first); else @@ -893,7 +893,7 @@ int w_newVolumeImage(lua_State *L) { lua_rawgeti(L, -1, mip + 1); - auto data = getImageData(L, -1, true, slice == 0 && mip == 0 ? &settings.pixeldensity : nullptr); + auto data = getImageData(L, -1, true, slice == 0 && mip == 0 ? &settings.dpiScale : nullptr); if (data.first.get()) slices.set(slice, mip, data.first); else @@ -908,7 +908,7 @@ int w_newVolumeImage(lua_State *L) for (int layer = 0; layer < tlen; layer++) { lua_rawgeti(L, 1, layer + 1); - auto data = getImageData(L, -1, true, layer == 0 ? &settings.pixeldensity : nullptr); + auto data = getImageData(L, -1, true, layer == 0 ? &settings.dpiScale : nullptr); if (data.first.get()) slices.set(layer, 0, data.first); else @@ -920,7 +920,7 @@ int w_newVolumeImage(lua_State *L) } else { - auto data = getImageData(L, 1, true, &settings.pixeldensity); + auto data = getImageData(L, 1, true, &settings.dpiScale); if (data.first.get()) { @@ -951,7 +951,7 @@ int w_newImage(lua_State *L) for (int i = 0; i < n; i++) { lua_rawgeti(L, 1, i + 1); - auto data = getImageData(L, -1, true, i == 0 ? &settings.pixeldensity : nullptr); + auto data = getImageData(L, -1, true, i == 0 ? &settings.dpiScale : nullptr); if (data.first.get()) slices.set(0, i, data.first); else @@ -961,7 +961,7 @@ int w_newImage(lua_State *L) } else { - auto data = getImageData(L, 1, true, &settings.pixeldensity); + auto data = getImageData(L, 1, true, &settings.dpiScale); if (data.first.get()) slices.set(0, 0, data.first); else @@ -1131,7 +1131,7 @@ int w_newCanvas(lua_State *L) settings.height = (int) luaL_optinteger(L, 2, instance()->getHeight()); // Default to the screen's current pixel density scale. - settings.pixeldensity = instance()->getScreenPixelDensity(); + settings.dpiScale = instance()->getScreenDPIScale(); int startidx = 3; @@ -1146,7 +1146,7 @@ int w_newCanvas(lua_State *L) { luaL_checktype(L, startidx, LUA_TTABLE); - settings.pixeldensity = (float) luax_numberflag(L, startidx, "pixeldensity", settings.pixeldensity); + settings.dpiScale = (float) luax_numberflag(L, startidx, "dpiscale", settings.dpiScale); settings.msaa = luax_intflag(L, startidx, "msaa", settings.msaa); lua_getfield(L, startidx, "format"); @@ -1596,10 +1596,10 @@ int w_newVideo(lua_State *L) luax_convobj(L, 1, "video", "newVideoStream"); auto stream = luax_checktype(L, 1); - float pixeldensity = (float) luaL_optnumber(L, 2, 1.0); + float dpiscale = (float) luaL_optnumber(L, 2, 1.0); Video *video = nullptr; - luax_catchexcept(L, [&]() { video = instance()->newVideo(stream, pixeldensity); }); + luax_catchexcept(L, [&]() { video = instance()->newVideo(stream, dpiscale); }); luax_pushtype(L, video); video->release(); @@ -2838,7 +2838,7 @@ static const luaL_Reg functions[] = { "getPixelWidth", w_getPixelWidth }, { "getPixelHeight", w_getPixelHeight }, { "getPixelDimensions", w_getPixelDimensions }, - { "getPixelDensity", w_getPixelDensity }, + { "getDPIScale", w_getDPIScale }, { "setScissor", w_setScissor }, { "intersectScissor", w_intersectScissor }, diff --git a/src/modules/graphics/wrap_Graphics.lua b/src/modules/graphics/wrap_Graphics.lua index 4994b6633..fb0902c6d 100644 --- a/src/modules/graphics/wrap_Graphics.lua +++ b/src/modules/graphics/wrap_Graphics.lua @@ -488,7 +488,7 @@ function love.graphics.newVideo(file, settings) settings = settings == nil and {} or settings if type(settings) ~= "table" then error("bad argument #2 to newVideo (expected table)", 2) end - local video = love.graphics._newVideo(file, settings.pixeldensity) + local video = love.graphics._newVideo(file, settings.dpiscale) local source, success if settings.audio ~= false and love.audio then diff --git a/src/modules/graphics/wrap_Texture.cpp b/src/modules/graphics/wrap_Texture.cpp index 2da808c0b..65c95ee77 100644 --- a/src/modules/graphics/wrap_Texture.cpp +++ b/src/modules/graphics/wrap_Texture.cpp @@ -122,10 +122,10 @@ int w_Texture_getPixelDimensions(lua_State *L) return 2; } -int w_Texture_getPixelDensity(lua_State *L) +int w_Texture_getDPIScale(lua_State *L) { Texture *t = luax_checktexture(L, 1); - lua_pushnumber(L, t->getPixelDensity()); + lua_pushnumber(L, t->getDPIScale()); return 1; } @@ -312,7 +312,7 @@ const luaL_Reg w_Texture_functions[] = { "getPixelWidth", w_Texture_getPixelWidth }, { "getPixelHeight", w_Texture_getPixelHeight }, { "getPixelDimensions", w_Texture_getPixelDimensions }, - { "getPixelDensity", w_Texture_getPixelDensity }, + { "getDPIScale", w_Texture_getDPIScale }, { "setFilter", w_Texture_setFilter }, { "getFilter", w_Texture_getFilter }, { "setMipmapFilter", w_Texture_setMipmapFilter }, diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index 890efdb54..ba2373723 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -179,7 +179,7 @@ public: virtual void windowToDPICoords(double *x, double *y) const = 0; virtual void DPIToWindowCoords(double *x, double *y) const = 0; - virtual double getPixelDensity() const = 0; + virtual double getDPIScale() const = 0; virtual double toPixels(double x) const = 0; virtual void toPixels(double wx, double wy, double &px, double &py) const = 0; diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 4abc9ea84..9e78adeff 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -1026,7 +1026,7 @@ void Window::DPIToWindowCoords(double *x, double *y) const *y = py; } -double Window::getPixelDensity() const +double Window::getDPIScale() const { #ifdef LOVE_ANDROID return love::android::getScreenScale(); @@ -1037,24 +1037,24 @@ double Window::getPixelDensity() const double Window::toPixels(double x) const { - return x * getPixelDensity(); + return x * getDPIScale(); } void Window::toPixels(double wx, double wy, double &px, double &py) const { - double scale = getPixelDensity(); + double scale = getDPIScale(); px = wx * scale; py = wy * scale; } double Window::fromPixels(double x) const { - return x / getPixelDensity(); + return x / getDPIScale(); } void Window::fromPixels(double px, double py, double &wx, double &wy) const { - double scale = getPixelDensity(); + double scale = getDPIScale(); wx = px / scale; wy = py / scale; } diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index f734deee2..a21d95a3b 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -101,7 +101,7 @@ public: void windowToDPICoords(double *x, double *y) const; void DPIToWindowCoords(double *x, double *y) const; - double getPixelDensity() const; + double getDPIScale() const; double toPixels(double x) const; void toPixels(double wx, double wy, double &px, double &py) const; diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index a56f8b854..c2f1b4bf4 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -419,9 +419,9 @@ int w_isVisible(lua_State *L) return 1; } -int w_getPixelDensity(lua_State *L) +int w_getDPIScale(lua_State *L) { - lua_pushnumber(L, instance()->getPixelDensity()); + lua_pushnumber(L, instance()->getDPIScale()); return 1; } @@ -581,7 +581,7 @@ static const luaL_Reg functions[] = { "hasFocus", w_hasFocus }, { "hasMouseFocus", w_hasMouseFocus }, { "isVisible", w_isVisible }, - { "getPixelDensity", w_getPixelDensity }, + { "getDPIScale", w_getDPIScale }, { "toPixels", w_toPixels }, { "fromPixels", w_fromPixels }, { "minimize", w_minimize }, diff --git a/src/scripts/nogame.lua b/src/scripts/nogame.lua index 47b388498..9a02ad407 100644 --- a/src/scripts/nogame.lua +++ b/src/scripts/nogame.lua @@ -729,7 +729,7 @@ function love.nogame() local ww, wh = love.graphics.getDimensions() - if love.window.getPixelDensity() > 1 then + if love.window.getDPIScale() > 1 then mosaic_image = g_images.mosaic[2] end diff --git a/src/scripts/nogame.lua.h b/src/scripts/nogame.lua.h index 76b7387fc..7f6b8ad0a 100644 --- a/src/scripts/nogame.lua.h +++ b/src/scripts/nogame.lua.h @@ -3130,8 +3130,8 @@ const unsigned char nogame_lua[] = 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x67, 0x65, 0x74, 0x44, 0x69, 0x6d, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x28, 0x29, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x67, - 0x65, 0x74, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x44, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x79, 0x28, 0x29, 0x20, 0x3e, - 0x20, 0x31, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x65, 0x74, 0x44, 0x50, 0x49, 0x53, 0x63, 0x61, 0x6c, 0x65, 0x28, 0x29, 0x20, 0x3e, 0x20, 0x31, 0x20, 0x74, + 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x6d, 0x6f, 0x73, 0x61, 0x69, 0x63, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x20, 0x3d, 0x20, 0x67, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x6d, 0x6f, 0x73, 0x61, 0x69, 0x63, 0x5b, 0x32, 0x5d, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,