mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -72,7 +72,10 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
|
||||
, toLoop(0)
|
||||
{
|
||||
ALenum fmt = getFormat(soundData->getChannels(), soundData->getBitDepth());
|
||||
staticBuffer = new StaticDataBuffer(fmt, soundData->getData(), soundData->getSize(), soundData->getSampleRate());
|
||||
staticBuffer.set(new StaticDataBuffer(fmt, soundData->getData(), soundData->getSize(), soundData->getSampleRate()));
|
||||
|
||||
// The buffer has a +2 retain count right now, but we want it to have +1.
|
||||
staticBuffer->release();
|
||||
|
||||
float z[3] = {0, 0, 0};
|
||||
|
||||
|
||||
@@ -689,6 +689,12 @@ Color Graphics::getBackgroundColor() const
|
||||
|
||||
void Graphics::setFont(Font *font)
|
||||
{
|
||||
// Hack: the Lua-facing love.graphics.print function will set the current
|
||||
// font if needed, but only on its first call... we want to make sure a nil
|
||||
// font is never accidentally set (e.g. via love.graphics.reset.)
|
||||
if (font == nullptr)
|
||||
return;
|
||||
|
||||
DisplayState &state = states.back();
|
||||
state.font.set(font);
|
||||
}
|
||||
@@ -1319,11 +1325,6 @@ void Graphics::pop()
|
||||
{
|
||||
DisplayState &newstate = states[states.size() - 2];
|
||||
|
||||
// Hack: the Lua-facing love.graphics.print function will set the current
|
||||
// font if needed, but only on its first call... we always want a font.
|
||||
if (newstate.font.get() == nullptr)
|
||||
newstate.font.set(states.back().font.get());
|
||||
|
||||
restoreStateChecked(newstate);
|
||||
|
||||
// The last two states in the stack should be equal now.
|
||||
|
||||
@@ -144,6 +144,11 @@ public:
|
||||
|
||||
virtual double getPixelScale() const = 0;
|
||||
|
||||
virtual double toPixels(double x) const = 0;
|
||||
virtual void toPixels(double wx, double wy, double &px, double &py) const = 0;
|
||||
virtual double fromPixels(double x) const = 0;
|
||||
virtual void fromPixels(double px, double py, double &wx, double &wy) const = 0;
|
||||
|
||||
virtual const void *getHandle() const = 0;
|
||||
|
||||
virtual bool showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow) = 0;
|
||||
|
||||
@@ -672,6 +672,30 @@ double Window::getPixelScale() const
|
||||
return scale;
|
||||
}
|
||||
|
||||
double Window::toPixels(double x) const
|
||||
{
|
||||
return x * getPixelScale();
|
||||
}
|
||||
|
||||
void Window::toPixels(double wx, double wy, double &px, double &py) const
|
||||
{
|
||||
double scale = getPixelScale();
|
||||
px = wx * scale;
|
||||
py = wy * scale;
|
||||
}
|
||||
|
||||
double Window::fromPixels(double x) const
|
||||
{
|
||||
return x / getPixelScale();
|
||||
}
|
||||
|
||||
void Window::fromPixels(double px, double py, double &wx, double &wy) const
|
||||
{
|
||||
double scale = getPixelScale();
|
||||
wx = px / scale;
|
||||
wy = py / scale;
|
||||
}
|
||||
|
||||
const void *Window::getHandle() const
|
||||
{
|
||||
return window;
|
||||
|
||||
@@ -82,6 +82,11 @@ public:
|
||||
|
||||
double getPixelScale() const;
|
||||
|
||||
double toPixels(double x) const;
|
||||
void toPixels(double wx, double wy, double &px, double &py) const;
|
||||
double fromPixels(double x) const;
|
||||
void fromPixels(double px, double py, double &wx, double &wy) const;
|
||||
|
||||
const void *getHandle() const;
|
||||
|
||||
bool showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow);
|
||||
|
||||
@@ -307,6 +307,48 @@ int w_getPixelScale(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_toPixels(lua_State *L)
|
||||
{
|
||||
double wx = luaL_checknumber(L, 1);
|
||||
|
||||
if (lua_isnoneornil(L, 2))
|
||||
{
|
||||
lua_pushnumber(L, instance()->toPixels(wx));
|
||||
return 1;
|
||||
}
|
||||
|
||||
double wy = luaL_checknumber(L, 2);
|
||||
double px = 0.0, py = 0.0;
|
||||
|
||||
instance()->toPixels(wx, wy, px, py);
|
||||
|
||||
lua_pushnumber(L, px);
|
||||
lua_pushnumber(L, py);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_fromPixels(lua_State *L)
|
||||
{
|
||||
double px = luaL_checknumber(L, 1);
|
||||
|
||||
if (lua_isnoneornil(L, 2))
|
||||
{
|
||||
lua_pushnumber(L, instance()->fromPixels(px));
|
||||
return 1;
|
||||
}
|
||||
|
||||
double py = luaL_checknumber(L, 2);
|
||||
double wx = 0.0, wy = 0.0;
|
||||
|
||||
instance()->fromPixels(px, py, wx, wy);
|
||||
|
||||
lua_pushnumber(L, wx);
|
||||
lua_pushnumber(L, wy);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_minimize(lua_State* /*L*/)
|
||||
{
|
||||
instance()->minimize();
|
||||
@@ -392,6 +434,8 @@ static const luaL_Reg functions[] =
|
||||
{ "hasMouseFocus", w_hasMouseFocus },
|
||||
{ "isVisible", w_isVisible },
|
||||
{ "getPixelScale", w_getPixelScale },
|
||||
{ "toPixels", w_toPixels },
|
||||
{ "fromPixels", w_fromPixels },
|
||||
{ "minimize", w_minimize },
|
||||
{ "showMessageBox", w_showMessageBox },
|
||||
{ 0, 0 }
|
||||
|
||||
@@ -46,6 +46,8 @@ int w_hasFocus(lua_State *L);
|
||||
int w_hasMouseFocus(lua_State *L);
|
||||
int w_isVisible(lua_State *L);
|
||||
int w_getPixelScale(lua_State *L);
|
||||
int w_toPixels(lua_State *L);
|
||||
int w_fromPixels(lua_State *L);
|
||||
int w_minimize(lua_State *L);
|
||||
int w_showMessageBox(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_window(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user