瀏覽代碼

RE-ADDED: Fade() function to avoid multiple breaking changes

Probably there is a better way to do this but this is a temporary solution for backward compatibility
raysan5 5 年之前
父節點
當前提交
afcc584fb6
共有 2 個文件被更改,包括 10 次插入0 次删除
  1. 1 0
      src/raylib.h
  2. 9 0
      src/textures.c

+ 1 - 0
src/raylib.h

@@ -1190,6 +1190,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest
 RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destRec, Vector2 origin, float rotation, Color tint);  // Draws a texture (or part of it) that stretches or shrinks nicely
 
 // Color/pixel related functions
+RLAPI Color Fade(Color color, float alpha);                                 // Returns color with alpha applied, alpha goes from 0.0f to 1.0f
 RLAPI int ColorToInt(Color color);                                          // Returns hexadecimal value for a Color
 RLAPI Vector4 ColorNormalize(Color color);                                  // Returns Color normalized as float [0..1]
 RLAPI Color ColorFromNormalized(Vector4 normalized);                        // Returns Color from normalized values [0..1]

+ 9 - 0
src/textures.c

@@ -3246,6 +3246,15 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destR
     }
 }
 
+// Returns color with alpha applied, alpha goes from 0.0f to 1.0f
+Color Fade(Color color, float alpha)
+{
+    if (alpha < 0.0f) alpha = 0.0f;
+    else if (alpha > 1.0f) alpha = 1.0f;
+
+    return (Color){color.r, color.g, color.b, (unsigned char)(255.0f*alpha)};
+}
+
 // Returns hexadecimal value for a Color
 int ColorToInt(Color color)
 {