mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 05:26:13 +01:00
use aggregate initialization
This commit is contained in:
1 parent
84f580e207
commit
ef81fbd337
5 files changed
+53
-70
No files matched your search
@@ -45,33 +45,26 @@ const sfColor sfTransparent = sfColor_fromRGBA(0, 0, 0, 0);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfColor sfColor_fromRGB(uint8_t red, uint8_t green, uint8_t blue)
|
sfColor sfColor_fromRGB(uint8_t red, uint8_t green, uint8_t blue)
|
||||||
{
|
{
|
||||||
return sfColor_fromRGBA(red, green, blue, 255);
|
return {red, green, blue, 255};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfColor sfColor_fromRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
|
sfColor sfColor_fromRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
|
||||||
{
|
{
|
||||||
sfColor color;
|
return {red, green, blue, alpha};
|
||||||
|
|
||||||
color.r = red;
|
|
||||||
color.g = green;
|
|
||||||
color.b = blue;
|
|
||||||
color.a = alpha;
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfColor sfColor_fromInteger(uint32_t color)
|
sfColor sfColor_fromInteger(uint32_t color)
|
||||||
{
|
{
|
||||||
auto red = static_cast<uint8_t>((color & 0xff000000) >> 24);
|
return {
|
||||||
auto green = static_cast<uint8_t>((color & 0x00ff0000) >> 16);
|
static_cast<uint8_t>((color & 0xff000000) >> 24),
|
||||||
auto blue = static_cast<uint8_t>((color & 0x0000ff00) >> 8);
|
static_cast<uint8_t>((color & 0x00ff0000) >> 16),
|
||||||
auto alpha = static_cast<uint8_t>((color & 0x000000ff) >> 0);
|
static_cast<uint8_t>((color & 0x0000ff00) >> 8),
|
||||||
|
static_cast<uint8_t>((color & 0x000000ff) >> 0),
|
||||||
return sfColor_fromRGBA(red, green, blue, alpha);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -85,43 +78,34 @@ uint32_t sfColor_toInteger(sfColor color)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfColor sfColor_add(sfColor color1, sfColor color2)
|
sfColor sfColor_add(sfColor color1, sfColor color2)
|
||||||
{
|
{
|
||||||
int red = std::min(color1.r + color2.r, 255);
|
return {
|
||||||
int green = std::min(color1.g + color2.g, 255);
|
static_cast<uint8_t>(std::min(color1.r + color2.r, 255)),
|
||||||
int blue = std::min(color1.b + color2.b, 255);
|
static_cast<uint8_t>(std::min(color1.g + color2.g, 255)),
|
||||||
int alpha = std::min(color1.a + color2.a, 255);
|
static_cast<uint8_t>(std::min(color1.b + color2.b, 255)),
|
||||||
|
static_cast<uint8_t>(std::min(color1.a + color2.a, 255)),
|
||||||
return sfColor_fromRGBA(static_cast<uint8_t>(red),
|
};
|
||||||
static_cast<uint8_t>(green),
|
|
||||||
static_cast<uint8_t>(blue),
|
|
||||||
static_cast<uint8_t>(alpha));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfColor sfColor_subtract(sfColor color1, sfColor color2)
|
sfColor sfColor_subtract(sfColor color1, sfColor color2)
|
||||||
{
|
{
|
||||||
int red = std::max(color1.r - color2.r, 0);
|
return {
|
||||||
int green = std::max(color1.g - color2.g, 0);
|
static_cast<uint8_t>(std::max(color1.r - color2.r, 0)),
|
||||||
int blue = std::max(color1.b - color2.b, 0);
|
static_cast<uint8_t>(std::max(color1.g - color2.g, 0)),
|
||||||
int alpha = std::max(color1.a - color2.a, 0);
|
static_cast<uint8_t>(std::max(color1.b - color2.b, 0)),
|
||||||
|
static_cast<uint8_t>(std::max(color1.a - color2.a, 0)),
|
||||||
return sfColor_fromRGBA(static_cast<uint8_t>(red),
|
};
|
||||||
static_cast<uint8_t>(green),
|
|
||||||
static_cast<uint8_t>(blue),
|
|
||||||
static_cast<uint8_t>(alpha));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfColor sfColor_modulate(sfColor color1, sfColor color2)
|
sfColor sfColor_modulate(sfColor color1, sfColor color2)
|
||||||
{
|
{
|
||||||
int red = color1.r * color2.r / 255;
|
return {
|
||||||
int green = color1.g * color2.g / 255;
|
static_cast<uint8_t>(color1.r * color2.r / 255),
|
||||||
int blue = color1.b * color2.b / 255;
|
static_cast<uint8_t>(color1.g * color2.g / 255),
|
||||||
int alpha = color1.a * color2.a / 255;
|
static_cast<uint8_t>(color1.b * color2.b / 255),
|
||||||
|
static_cast<uint8_t>(color1.a * color2.a / 255),
|
||||||
return sfColor_fromRGBA(static_cast<uint8_t>(red),
|
};
|
||||||
static_cast<uint8_t>(green),
|
|
||||||
static_cast<uint8_t>(blue),
|
|
||||||
static_cast<uint8_t>(alpha));
|
|
||||||
}
|
}
|
||||||
@@ -201,13 +201,14 @@ void sfShader_setVec4Uniform(sfShader* shader, const char* name, sfGlslVec4 vect
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void sfShader_setColorUniform(sfShader* shader, const char* name, sfColor color)
|
void sfShader_setColorUniform(sfShader* shader, const char* name, sfColor color)
|
||||||
{
|
{
|
||||||
sfGlslVec4 vec4;
|
sfShader_setVec4Uniform(shader,
|
||||||
vec4.x = color.r / 255.f;
|
name,
|
||||||
vec4.y = color.g / 255.f;
|
{
|
||||||
vec4.z = color.b / 255.f;
|
color.r / 255.f,
|
||||||
vec4.w = color.a / 255.f;
|
color.g / 255.f,
|
||||||
|
color.b / 255.f,
|
||||||
sfShader_setVec4Uniform(shader, name, vec4);
|
color.a / 255.f,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@@ -249,13 +250,14 @@ void sfShader_setIvec4Uniform(sfShader* shader, const char* name, sfGlslIvec4 ve
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void sfShader_setIntColorUniform(sfShader* shader, const char* name, sfColor color)
|
void sfShader_setIntColorUniform(sfShader* shader, const char* name, sfColor color)
|
||||||
{
|
{
|
||||||
sfGlslIvec4 ivec4;
|
sfShader_setIvec4Uniform(shader,
|
||||||
ivec4.x = static_cast<int>(color.r);
|
name,
|
||||||
ivec4.y = static_cast<int>(color.g);
|
{
|
||||||
ivec4.z = static_cast<int>(color.b);
|
static_cast<int>(color.r),
|
||||||
ivec4.w = static_cast<int>(color.a);
|
static_cast<int>(color.g),
|
||||||
|
static_cast<int>(color.b),
|
||||||
sfShader_setIvec4Uniform(shader, name, ivec4);
|
static_cast<int>(color.a),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -48,8 +48,13 @@ const sfTransform sfTransform_Identity = {
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTransform sfTransform_fromMatrix(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
|
sfTransform sfTransform_fromMatrix(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
|
||||||
{
|
{
|
||||||
sfTransform transform = {a00, a01, a02, a10, a11, a12, a20, a21, a22};
|
// clang-format off
|
||||||
return transform;
|
return {
|
||||||
|
a00, a01, a02,
|
||||||
|
a10, a11, a12,
|
||||||
|
a20, a21, a22,
|
||||||
|
};
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTransformable* sfTransformable_create()
|
sfTransformable* sfTransformable_create()
|
||||||
{
|
{
|
||||||
auto* transformable = new sfTransformable;
|
return new sfTransformable;
|
||||||
|
|
||||||
return transformable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,25 +56,19 @@ int64_t sfTime_asMicroseconds(sfTime time)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTime sfSeconds(float amount)
|
sfTime sfSeconds(float amount)
|
||||||
{
|
{
|
||||||
sfTime time;
|
return {static_cast<int64_t>(amount * 1000000)};
|
||||||
time.microseconds = static_cast<int64_t>(amount * 1000000);
|
|
||||||
return time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTime sfMilliseconds(int32_t amount)
|
sfTime sfMilliseconds(int32_t amount)
|
||||||
{
|
{
|
||||||
sfTime time;
|
return {static_cast<int64_t>(amount * 1000)};
|
||||||
time.microseconds = static_cast<int64_t>(amount) * 1000;
|
|
||||||
return time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTime sfMicroseconds(int64_t amount)
|
sfTime sfMicroseconds(int64_t amount)
|
||||||
{
|
{
|
||||||
sfTime time;
|
return {amount};
|
||||||
time.microseconds = amount;
|
|
||||||
return time;
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user