Tracker: Override Open with... pose view text color and back color

Make TextColor() and BackColor() virtual in BPoseView so that we can
override them in subclasses. These are used to invert colors on select.

Move InvertColor() and InvertedBackColor() to Utilities.

Move Desktop...() methods to DesktopPoseView overrides, this does the
same thing but in DesktopPoseView as an override.

Add override methods to Open with... pose view. Open with... window
text color were not updating with color settings making text unreadable
in dark mode. Open with... background and text colors update based on
tooltip colors which was chosen previously.

Change-Id: Id605f1887d6018766b09a6de372b6071de8b83ea
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8105
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
This commit is contained in:
John Scipione
2024-08-24 18:19:16 +00:00
committed by nephele nephele
parent 946839b850
commit 9d4d102df2
8 changed files with 103 additions and 90 deletions
+51
View File
@@ -281,3 +281,54 @@ DesktopPoseView::AdaptToDesktopIntegrationChange(BMessage* message)
ShowVolumes(false, mountSharedVolumesOntoDesktop);
ShowVolumes(mountVolumesOnDesktop, mountSharedVolumesOntoDesktop);
}
rgb_color
DesktopPoseView::TextColor(bool selected) const
{
// The desktop color is chosen independently for the desktop.
// The text color is chosen globally for all directories.
// It's fairly easy to get something unreadable (even with the default
// settings, it's expected that text will be black on white in Tracker
// folders, but white on blue on the desktop).
// So here we check if the colors are different enough, and otherwise,
// force the text to be either white or black.
rgb_color textColor = HighColor();
rgb_color viewColor = ViewColor();
// The colors are different enough, we can use them as is
if (rgb_color::Contrast(viewColor, textColor) > 127)
return textColor;
return viewColor.IsLight() ? kBlack : kWhite;
}
rgb_color
DesktopPoseView::BackColor(bool selected) const
{
// returns black or white color depending on the desktop background
int32 thresh = 0;
rgb_color color = LowColor();
if (color.red > 150)
thresh++;
if (color.green > 150)
thresh++;
if (color.blue > 150)
thresh++;
if (thresh > 1) {
color.red = 255;
color.green = 255;
color.blue = 255;
} else {
color.red = 0;
color.green = 0;
color.blue = 0;
}
return color;
}
+3
View File
@@ -72,6 +72,9 @@ protected:
void AdaptToVolumeChange(BMessage*);
void AdaptToDesktopIntegrationChange(BMessage*);
virtual rgb_color TextColor(bool selected = false) const;
virtual rgb_color BackColor(bool selected = false) const;
private:
typedef BPoseView _inherited;
};
+21 -1
View File
@@ -572,7 +572,27 @@ OpenWithPoseView::AttachedToWindow()
_inherited::AttachedToWindow();
SetViewUIColor(B_TOOL_TIP_BACKGROUND_COLOR);
SetLowUIColor(B_TOOL_TIP_TEXT_COLOR);
SetLowUIColor(B_TOOL_TIP_BACKGROUND_COLOR);
}
rgb_color
OpenWithPoseView::TextColor(bool selected) const
{
if (selected)
return ui_color(B_TOOL_TIP_BACKGROUND_COLOR);
else
return ui_color(B_TOOL_TIP_TEXT_COLOR);
}
rgb_color
OpenWithPoseView::BackColor(bool selected) const
{
if (selected)
return InvertedBackColor(ui_color(B_TOOL_TIP_BACKGROUND_COLOR));
else
return ui_color(B_TOOL_TIP_BACKGROUND_COLOR);
}
+2
View File
@@ -223,6 +223,8 @@ protected:
virtual void FinalStopWatching() {}
virtual void AttachedToWindow();
virtual rgb_color TextColor(bool selected = false) const;
virtual rgb_color BackColor(bool selected = false) const;
virtual EntryListBase* InitDirentIterator(const entry_ref* ref);
virtual void ReturnDirentIterator(EntryListBase* iterator);
+1 -32
View File
@@ -210,13 +210,6 @@ CopySelectionListToEntryRefList(const PoseList* original,
}
static rgb_color
invert_color(rgb_color color)
{
return make_color(255 - color.red, 255 - color.green, 255 - color.blue);
}
// #pragma mark - BPoseView
@@ -9115,9 +9108,6 @@ BPoseView::DrawPose(BPose* pose, int32 index, bool fullDraw)
rgb_color
BPoseView::TextColor(bool selected) const
{
if (IsDesktopWindow())
return DeskTextColor();
if (selected)
return ui_color(B_DOCUMENT_BACKGROUND_COLOR);
else
@@ -9129,14 +9119,8 @@ rgb_color
BPoseView::BackColor(bool selected) const
{
if (selected) {
if (IsDesktopWindow())
return DeskTextBackColor();
return InvertedBackColor();
return InvertedBackColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
} else {
if (IsDesktopWindow())
return BView::ViewColor();
rgb_color background = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
return tint_color(background,
TargetVolumeIsReadOnly() ? ReadOnlyTint(background) : B_NO_TINT);
@@ -9144,21 +9128,6 @@ BPoseView::BackColor(bool selected) const
}
rgb_color
BPoseView::InvertedBackColor() const
{
rgb_color background = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
rgb_color inverted = invert_color(background);
// The colors are different enough, we can use inverted
if (rgb_color::Contrast(background, inverted) > 127)
return inverted;
// use black or white
return background.IsLight() ? kBlack : kWhite;
}
void
BPoseView::Draw(BRect updateRect)
{
+2 -57
View File
@@ -213,11 +213,8 @@ public:
int32 CountItems() const;
void UpdateCount();
rgb_color DeskTextColor() const;
rgb_color DeskTextBackColor() const;
rgb_color TextColor(bool selected = false) const;
rgb_color BackColor(bool selected = false) const;
virtual rgb_color TextColor(bool selected = false) const;
virtual rgb_color BackColor(bool selected = false) const;
bool WidgetTextOutline() const;
void SetWidgetTextOutline(bool);
@@ -681,7 +678,6 @@ protected:
private:
void DrawOpenAnimation(BRect);
void ApplyBackgroundColor();
rgb_color InvertedBackColor() const;
void MoveSelectionOrEntryToTrash(const entry_ref* ref, bool selectNext);
@@ -1030,57 +1026,6 @@ BPoseView::IsDesktopView() const
}
inline rgb_color
BPoseView::DeskTextColor() const
{
// The desktop color is chosen independently for the desktop.
// The text color is chosen globally for all directories.
// It's fairly easy to get something unreadable (even with the default
// settings, it's expected that text will be black on white in Tracker
// folders, but white on blue on the desktop).
// So here we check if the colors are different enough, and otherwise,
// force the text to be either white or black.
rgb_color textColor = HighColor();
rgb_color viewColor = ViewColor();
// The colors are different enough, we can use them as is
if (rgb_color::Contrast(viewColor, textColor) > 127)
return textColor;
return viewColor.IsLight() ? kBlack : kWhite;
}
inline rgb_color
BPoseView::DeskTextBackColor() const
{
// returns black or white color depending on the desktop background
int32 thresh = 0;
rgb_color color = LowColor();
if (color.red > 150)
thresh++;
if (color.green > 150)
thresh++;
if (color.blue > 150)
thresh++;
if (thresh > 1) {
color.red = 255;
color.green = 255;
color.blue = 255;
} else {
color.red = 0;
color.green = 0;
color.blue = 0;
}
return color;
}
inline uint32
BPoseView::PrimarySort() const
{
+21
View File
@@ -95,6 +95,27 @@ ReadOnlyTint(rgb_color base)
}
rgb_color
InvertColor(rgb_color color)
{
return make_color(255 - color.red, 255 - color.green, 255 - color.blue);
}
rgb_color
InvertedBackColor(rgb_color background)
{
rgb_color inverted = InvertColor(background);
// The colors are different enough, we can use inverted
if (rgb_color::Contrast(background, inverted) > 127)
return inverted;
// use black or white
return background.IsLight() ? kBlack : kWhite;
}
bool
SecondaryMouseButtonDown(int32 modifiers, int32 buttons)
{
+2
View File
@@ -182,6 +182,8 @@ void DisallowFilenameKeys(BTextView*);
bool ValidateStream(BMallocIO*, uint32, int32 version);
float ReadOnlyTint(rgb_color base);
rgb_color InvertColor(rgb_color color);
rgb_color InvertedBackColor(rgb_color background);
bool SecondaryMouseButtonDown(int32 modifiers, int32 buttons);
uint32 HashString(const char* string, uint32 seed);