mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user