[haiku-commits] r35084 - haiku/trunk/src/apps/activitymonitor

  • From: stpere@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 15 Jan 2010 04:08:18 +0100 (CET)

Author: stpere
Date: 2010-01-15 04:08:18 +0100 (Fri, 15 Jan 2010)
New Revision: 35084
Changeset: http://dev.haiku-os.org/changeset/35084/haiku
Ticket: http://dev.haiku-os.org/ticket/5105

Modified:
   haiku/trunk/src/apps/activitymonitor/ActivityView.cpp
   haiku/trunk/src/apps/activitymonitor/ActivityView.h
Log:
ActivityMonitor (when used as replicant) :

 * Use the "Icon Label Outline" setting to improve readability
 * It is using the same algorithm as Tracker to outline and glow the text,
   and determine the color of the text.

Implements enhancement suggestion #5105.


Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.cpp
===================================================================
--- haiku/trunk/src/apps/activitymonitor/ActivityView.cpp       2010-01-15 
02:56:39 UTC (rev 35083)
+++ haiku/trunk/src/apps/activitymonitor/ActivityView.cpp       2010-01-15 
03:08:18 UTC (rev 35084)
@@ -19,10 +19,12 @@
 #include <Autolock.h>
 #include <Bitmap.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"
@@ -174,6 +176,7 @@
 
 extern const char* kSignature;
 
+const char* kDesktopAttrName = "be:bgndimginfo";
 
 Scale::Scale(scale_type type)
        :
@@ -540,6 +543,10 @@
 //     #pragma mark -
 
 
+const rgb_color kWhite = (rgb_color){255, 255, 255, 255};
+const rgb_color kBlack = (rgb_color){0, 0, 0, 255};
+
+
 ActivityView::ActivityView(BRect frame, const char* name,
                const BMessage* settings, uint32 resizingMode)
        : BView(frame, name, resizingMode,
@@ -588,6 +595,7 @@
 
 ActivityView::~ActivityView()
 {
+       stop_watching(this);
        delete fOffscreen;
        delete fSystemInfoHandler;
 }
@@ -879,6 +887,9 @@
 void
 ActivityView::AttachedToWindow()
 {
+       if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0)
+               _LoadBackgroundInfo(true);
+
        Looper()->AddHandler(fSystemInfoHandler);
        fSystemInfoHandler->StartWatching();
 
@@ -1097,6 +1108,17 @@
                        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;
@@ -1414,6 +1436,37 @@
 
 
 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)
 {
        bool drawBackground = true;
@@ -1467,12 +1520,83 @@
                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);
-                       rgb_color c = Parent()->LowColor();
-                       if (c.red + c.green + c.blue > 128 * 3)
-                               SetHighColor(0, 0, 0);
-                       else
-                               SetHighColor(255, 255, 255);
+                       SetHighColor(textColor);
                }
                DrawString(label.String(), BPoint(6 + colorBox.right, y));
                DrawString(text.String(), BPoint(frame.right - width, y));

Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.h
===================================================================
--- haiku/trunk/src/apps/activitymonitor/ActivityView.h 2010-01-15 02:56:39 UTC 
(rev 35083)
+++ haiku/trunk/src/apps/activitymonitor/ActivityView.h 2010-01-15 03:08:18 UTC 
(rev 35084)
@@ -9,6 +9,7 @@
 #include <map>
 
 #include <Locker.h>
+#include <Message.h>
 #include <ObjectList.h>
 #include <View.h>
 
@@ -113,6 +114,7 @@
                        void            _DrawHistory(bool drawBackground);
                        void            _UpdateResolution(int32 resolution,
                                                        bool broadcast = true);
+                       void            _LoadBackgroundInfo(bool watch);
 
 private:
        class HistoryLayoutItem;
@@ -128,6 +130,11 @@
        BLayoutItem*            fHistoryLayoutItem;
        BLayoutItem*            fLegendLayoutItem;
 #endif
+
+       BMessage                        fBackgroundInfo;
+       bool                            fCachedOutline;
+       int32                           fCachedWorkspace;
+
        mutable BLocker         fSourcesLock;
        BObjectList<DataSource> fSources;
        BObjectList<DataHistory> fValues;


Other related posts: