Skip to content

Commit

Permalink
Add an (R, G, B, A) color overload
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthaTi committed Jan 17, 2025
1 parent 66bce2e commit 5dbf801
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 14 additions & 4 deletions source/fluid/types.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ unittest {

}

/// Create a color from RGBA values.
Color color(ubyte r, ubyte g, ubyte b, ubyte a = ubyte.max) pure nothrow {

Color color;
color.r = r;
color.g = g;
color.b = b;
color.a = a;
return color;

}

/// Create a color from hex code.
Color color(string hexCode)() {

Expand Down Expand Up @@ -330,7 +342,7 @@ struct Image {

// Invalid index, return white
else
return Color(0xff, 0xff, 0xff, pixel.alpha);
return color(0xff, 0xff, 0xff, pixel.alpha);

}

Expand Down Expand Up @@ -501,8 +513,6 @@ struct Image {
case Format.rgba:
return this;

// At the moment, this loads the palette available at the time of generation.
// Could it be possible to update the palette later?
case Format.palettedAlpha:
auto colors = new Color[palettedAlphaPixels.length];
foreach (i, pixel; palettedAlphaPixels) {
Expand All @@ -513,7 +523,7 @@ struct Image {
case Format.alpha:
auto colors = new Color[alphaPixels.length];
foreach (i, pixel; alphaPixels) {
colors[i] = Color(0xff, 0xff, 0xff, pixel);
colors[i] = color(0xff, 0xff, 0xff, pixel);
}
return Image(colors, width, height);

Expand Down
4 changes: 3 additions & 1 deletion tour/dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"fileVersion": 1,
"versions": {
"arsd-official": "11.5.3",
"bindbc-freetype": "1.1.1",
"bindbc-loader": "1.1.5",
"bolts": "1.3.1",
"elemi": "1.2.3",
"fluid-tree-sitter": "0.1.7",
"libdparse": "0.23.2",
"optional": "1.3.0",
"raylib-d": "5.5.0",
"silly": "1.1.1"
}
}
}

0 comments on commit 5dbf801

Please sign in to comment.