Skip to content

Commit

Permalink
Use Haiku API's IsDark()
Browse files Browse the repository at this point in the history
As it came with Haiku R1beta5.
  • Loading branch information
humdingerb committed Sep 4, 2024
1 parent 8a34ed9 commit 3176460
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,21 @@ LoadPreferences()
}


bool
IsDark(rgb_color color)
{
// From http://alienryderflex.com/hsp.html
// Useful in particular to decide if the color is "light" or "dark"
// by checking if the perceptual brightness is > 127.
// TODO: Once Haiku Beta5 is out, we can use its IsDark()

int32 brightness
= (uint8)roundf(sqrtf(0.299f * color.red * color.red + 0.587f * color.green * color.green
+ 0.114 * color.blue * color.blue));

return brightness <= 127;
}


const float
GetMutedTint(const rgb_color color, const CapitalBeMuted& type)
{
switch (type) {
case CB_MUTED_TEXT:
{
return IsDark(color) ? B_DARKEN_2_TINT : B_LIGHTEN_1_TINT;
return color.IsDark() ? B_DARKEN_2_TINT : B_LIGHTEN_1_TINT;
}
case CB_MUTED_BG:
{
return IsDark(color) ? B_LIGHTEN_2_TINT : B_DARKEN_1_TINT;
return color.IsDark() ? B_LIGHTEN_2_TINT : B_DARKEN_1_TINT;
}
case CB_ALT_ROW:
{
return IsDark(color) ? 0.94 : 1.05;
return color.IsDark() ? 0.94 : 1.05;
}
default:
return B_NO_TINT;
Expand Down

0 comments on commit 3176460

Please sign in to comment.