Clamp all color arguments to [0, 1] in cases where values outside that range don't make sense (fixed-point color values & sRGB colors). Closes issue #1315.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-11-21 19:49:52 -04:00
parent 1cd1a8d32e
commit 6dea2ab714
9 changed files with 59 additions and 36 deletions
+12
View File
@@ -22,6 +22,7 @@
#define LOVE_RUNTIME_H
// LOVE
#include "config.h"
#include "types.h"
#include "deprecation.h"
@@ -35,6 +36,7 @@ extern "C" {
// C++
#include <exception>
#include <algorithm>
namespace love
{
@@ -204,6 +206,16 @@ inline float luax_checkfloat(lua_State *L, int idx)
return static_cast<float>(luaL_checknumber(L, idx));
}
inline lua_Number luax_checknumberclamped01(lua_State *L, int idx)
{
return std::min(std::max(luaL_checknumber(L, idx), 0.0), 1.0);
}
inline lua_Number luax_optnumberclamped01(lua_State *L, int idx, double def)
{
return std::min(std::max(luaL_optnumber(L, idx, def), 0.0), 1.0);
}
/**
* Require at least 'min' number of items on the stack.
* @param L The Lua state.