64 lines
1.3 KiB
C++

#include <cmath>
#include <algorithm>
#include "Math.hpp"
#include "values/mrand.hpp"
#include <raymath.h>
Color ColorAddValue(Color c, int add)
{
int r = std::clamp(c.r + add, 0, 255);
int g = std::clamp(c.g + add, 0, 255);
int b = std::clamp(c.b + add, 0, 255);
return {(unsigned char)r, (unsigned char)g, (unsigned char)b, c.a};
}
Color ColorAdd(Color c1, Color c2)
{
int r = std::clamp(c1.r + c2.r, 0, 255);
int g = std::clamp(c1.g + c2.g, 0, 255);
int b = std::clamp(c1.b + c2.b, 0, 255);
int a = std::clamp(c1.a + c2.a, 0, 255);
return {(unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a};
}
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom)
{
float br = box.width / box.height;
float tr = textW / textH;
Rectangle ret = {0, 0, 0, 0};
float hm = box.height * margin;
float wm = box.width * margin;
ret.height = box.height - hm;
ret.width = box.width - wm;
if (br < tr)
{
// bolj kvadrat izracunaj visino iz sirine
ret.height = ret.width / tr;
}
else
{
// bolj podolgovat izracunaj sirino iz visine
ret.width = ret.height * tr;
}
if (topOrBottom)
{
ret.y = box.y + hm;
}
else
{
ret.y = box.y + box.height - hm - ret.height;
}
ret.x = box.x + wm;
return ret;
}