Outline of labels/strings drawn to desktop

* Rather than duplicating the decision taking logic involving wheter or not to draw
the outline or glow in every replicant, update be_control_look to make it more
generic.
* The Monitoring of the background preferences is now only done in Tracker (where it
was already being done).
* Add a BControlLook::B_IGNORE_OUTLINE flag to avoid this new behaviour.
* Remove that said logic from ActivityMonitor and use be_control_look.
* Use the ignore flag in DeskCalc to avoid the outline in its case.

Should fix #7716, #7291.
This commit is contained in:
Philippe Saint-Pierre
2012-02-22 19:06:22 -05:00
parent f1553a0fc4
commit d63b75faf8
7 changed files with 136 additions and 142 deletions
+8 -128
View File
@@ -20,12 +20,10 @@
#include <Bitmap.h>
#include <Catalog.h>
#include <Dragger.h>
#include <fs_attr.h>
#include <MenuItem.h>
#include <MessageRunner.h>
#include <PopUpMenu.h>
#include <Shape.h>
#include <StorageKit.h>
#include <String.h>
#include "ActivityMonitor.h"
@@ -179,7 +177,6 @@ const uint32 kMsgUpdateResolution = 'ures';
extern const char* kSignature;
const char* kDesktopAttrName = "be:bgndimginfo";
Scale::Scale(scale_type type)
:
@@ -599,7 +596,6 @@ ActivityView::ActivityView(BMessage* archive)
ActivityView::~ActivityView()
{
stop_watching(this);
delete fOffscreen;
delete fSystemInfoHandler;
}
@@ -891,9 +887,6 @@ ActivityView::RemoveAllDataSources()
void
ActivityView::AttachedToWindow()
{
if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0)
_LoadBackgroundInfo(true);
Looper()->AddHandler(fSystemInfoHandler);
fSystemInfoHandler->StartWatching();
@@ -1114,17 +1107,6 @@ ActivityView::MessageReceived(BMessage* message)
ActivityMonitor::ShowAbout();
break;
case B_NODE_MONITOR:
{
BString attrName;
if (message->FindString("attr", &attrName) == B_OK) {
if (attrName == kDesktopAttrName)
_LoadBackgroundInfo(false);
} else
_LoadBackgroundInfo(false);
break;
}
case kMsgUpdateResolution:
{
int32 resolution;
@@ -1446,37 +1428,6 @@ ActivityView::_UpdateResolution(int32 resolution, bool broadcast)
}
void
ActivityView::_LoadBackgroundInfo(bool watch)
{
fCachedOutline = false;
fCachedWorkspace = -1;
BPath path;
if (find_directory(B_DESKTOP_DIRECTORY, &path) == B_OK) {
BNode desktopNode = BNode(path.Path());
attr_info info;
if (desktopNode.GetAttrInfo(kDesktopAttrName, &info) != B_OK)
return;
char* buffer = new char[info.size];
if (desktopNode.ReadAttr(kDesktopAttrName, B_MESSAGE_TYPE, 0,
buffer, (size_t)info.size) == info.size) {
BMessage message;
if (message.Unflatten(buffer) == B_OK)
fBackgroundInfo = message;
}
delete[] buffer;
if (watch) {
node_ref nref;
desktopNode.GetNodeRef(&nref);
watch_node(&nref, B_WATCH_ATTR, this);
}
}
}
void
ActivityView::Draw(BRect updateRect)
{
@@ -1533,87 +1484,16 @@ ActivityView::Draw(BRect updateRect)
if (drawBackground)
SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
else {
rgb_color c = Parent()->ViewColor();
rgb_color textColor = c.red + c.green * 1.5f + c.blue * 0.50f
>= 300 ? kBlack : kWhite;
int32 mask;
bool tmpOutline = false;
bool outline = fCachedOutline;
int8 indice = 0;
if (fCachedWorkspace != current_workspace()) {
while (fBackgroundInfo.FindInt32("be:bgndimginfoworkspaces",
indice, &mask) == B_OK
&& fBackgroundInfo.FindBool("be:bgndimginfoerasetext",
indice, &tmpOutline) == B_OK) {
if (((1 << current_workspace()) & mask) != 0) {
outline = tmpOutline;
fCachedWorkspace = current_workspace();
fCachedOutline = outline;
break;
}
indice++;
}
}
if (outline) {
SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
BFont font;
GetFont(&font);
if (textColor == kBlack) {
// Black text with white halo/glow
rgb_color glowColor = kWhite;
font.SetFalseBoldWidth(2.0);
SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
glowColor.alpha = 30;
SetHighColor(glowColor);
DrawString(label.String(), BPoint(6 + colorBox.right, y));
DrawString(text.String(), BPoint(frame.right - width, y));
font.SetFalseBoldWidth(1.0);
SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
glowColor.alpha = 65;
SetHighColor(glowColor);
DrawString(label.String(), BPoint(6 + colorBox.right, y));
DrawString(text.String(), BPoint(frame.right - width, y));
font.SetFalseBoldWidth(0.0);
SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
} else {
// white text with black outline
rgb_color outlineColor = kBlack;
font.SetFalseBoldWidth(1.0);
SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
outlineColor.alpha = 30;
SetHighColor(outlineColor);
DrawString(label.String(), BPoint(6 + colorBox.right, y));
DrawString(text.String(), BPoint(frame.right - width, y));
font.SetFalseBoldWidth(0.0);
SetFont(&font, B_FONT_FALSE_BOLD_WIDTH);
outlineColor.alpha = 200;
SetHighColor(outlineColor);
DrawString(label.String(), BPoint(6 + colorBox.right + 1,
y + 1));
DrawString(text.String(), BPoint(frame.right - width + 1,
y + 1));
}
}
SetDrawingMode(B_OP_OVER);
SetHighColor(textColor);
if (be_control_look == NULL) {
DrawString(label.String(), BPoint(6 + colorBox.right, y));
DrawString(text.String(), BPoint(frame.right - width, y));
} else {
be_control_look->DrawLabel(this, label.String(),
Parent()->ViewColor(), 0, BPoint(6 + colorBox.right, y));
be_control_look->DrawLabel(this, text.String(),
Parent()->ViewColor(), 0, BPoint(frame.right - width, y));
}
DrawString(label.String(), BPoint(6 + colorBox.right, y));
DrawString(text.String(), BPoint(frame.right - width, y));
}
}