Perform colorToInt conversion manually during compiletime (#176)

This commit is contained in:
Nikolas 2025-03-04 17:50:50 +01:00
parent 94fa7e23b0
commit e4d66a8dae
No known key found for this signature in database
GPG Key ID: E95F679E3CDD9784
3 changed files with 15 additions and 5 deletions

View File

@ -366,6 +366,7 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str,
"ComputeSHA1", "ComputeSHA1",
"SetWindowIcons", "SetWindowIcons",
"CheckCollisionPointPoly", "CheckCollisionPointPoly",
"ColorToInt",
"GetFontDefault", "GetFontDefault",
"LoadFont", "LoadFont",
"LoadFontEx", "LoadFontEx",

View File

@ -2211,6 +2211,13 @@ pub fn loadRenderTexture(width: i32, height: i32) RaylibError!RenderTexture2D {
return if (isValid) render_texture else RaylibError.LoadRenderTexture; return if (isValid) render_texture else RaylibError.LoadRenderTexture;
} }
pub fn colorToInt(color: Color) i32 {
return if (@inComptime())
(@as(i32, color.r) << 24) | (@as(i32, color.g) << 16) | (@as(i32, color.b) << 8) | @as(i32, color.a)
else
@as(i32, cdef.ColorToInt(color));
}
/// Get the default Font /// Get the default Font
pub fn getFontDefault() RaylibError!Font { pub fn getFontDefault() RaylibError!Font {
// TODO: GetFontDefault requires SUPPORT_DEFAULT_FONT. Error out if unset. // TODO: GetFontDefault requires SUPPORT_DEFAULT_FONT. Error out if unset.

View File

@ -2211,6 +2211,13 @@ pub fn loadRenderTexture(width: i32, height: i32) RaylibError!RenderTexture2D {
return if (isValid) render_texture else RaylibError.LoadRenderTexture; return if (isValid) render_texture else RaylibError.LoadRenderTexture;
} }
pub fn colorToInt(color: Color) i32 {
return if (@inComptime())
(@as(i32, color.r) << 24) | (@as(i32, color.g) << 16) | (@as(i32, color.b) << 8) | @as(i32, color.a)
else
@as(i32, cdef.ColorToInt(color));
}
/// Get the default Font /// Get the default Font
pub fn getFontDefault() RaylibError!Font { pub fn getFontDefault() RaylibError!Font {
// TODO: GetFontDefault requires SUPPORT_DEFAULT_FONT. Error out if unset. // TODO: GetFontDefault requires SUPPORT_DEFAULT_FONT. Error out if unset.
@ -4218,11 +4225,6 @@ pub fn fade(color: Color, alpha: f32) Color {
return cdef.Fade(color, alpha); return cdef.Fade(color, alpha);
} }
/// Get hexadecimal value for a Color (0xRRGGBBAA)
pub fn colorToInt(color: Color) i32 {
return @as(i32, cdef.ColorToInt(color));
}
/// Get Color normalized as float [0..1] /// Get Color normalized as float [0..1]
pub fn colorNormalize(color: Color) Vector4 { pub fn colorNormalize(color: Color) Vector4 {
return cdef.ColorNormalize(color); return cdef.ColorNormalize(color);