Rename all cases of 'pixel density' to 'DPI scale' in love's APIs.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-09-24 16:09:05 -03:00
parent 1b3745b58b
commit 844900db39
37 changed files with 129 additions and 129 deletions
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -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;
};
+1 -1
View File
@@ -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);
+14 -14
View File
@@ -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<ColoredString> &strs, Color
float Font::getHeight() const
{
return (float) floorf(height / pixelDensity + 0.5f);
return (float) floorf(height / dpiScale + 0.5f);
}
std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantcolor, std::vector<GlyphVertex> &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<Font *> &fallbacks)
rasterizers.push_back(f->rasterizers[0]);
}
float Font::getPixelDensity() const
float Font::getDPIScale() const
{
return pixelDensity;
return dpiScale;
}
uint32 Font::getTextureCacheID() const
+2 -2
View File
@@ -171,7 +171,7 @@ public:
void setFallbacks(const std::vector<Font *> &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;
+5 -5
View File
@@ -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();
}
+3 -3
View File
@@ -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.
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -50,7 +50,7 @@ public:
{
bool mipmaps = false;
bool linear = false;
float pixeldensity = 1.0f;
float dpiScale = 1.0f;
};
struct Slices
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -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
+6 -6
View File
@@ -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;
}
+3 -3
View File
@@ -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 }
};
+25 -25
View File
@@ -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<love::filesystem::FileData *>(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<image::ImageData>, StrongRef<image::CompressedImageData>>
getImageData(lua_State *L, int idx, bool allowcompressed, float *density)
getImageData(lua_State *L, int idx, bool allowcompressed, float *dpiscale)
{
StrongRef<image::ImageData> idata;
StrongRef<image::CompressedImageData> cdata;
@@ -687,8 +687,8 @@ getImageData(lua_State *L, int idx, bool allowcompressed, float *density)
StrongRef<Data> 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<StrongRef<love::image::ImageData>> 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<love::video::VideoStream>(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 },
+1 -1
View File
@@ -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
+3 -3
View File
@@ -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 },