From ed1b27536bc03e0a594e114846d84c5b32cb0fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 7 Apr 2009 16:09:00 +0000 Subject: [PATCH] * Some beautification, mostly for when the replicant is embedded on the Desktop. * Fall back to a shorter legend label when the room is too small (before truncating). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30001 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/activitymonitor/ActivityView.cpp | 75 ++++++++++++++++------- src/apps/activitymonitor/ActivityView.h | 2 +- src/apps/activitymonitor/DataSource.cpp | 72 ++++++++++++++++++++++ src/apps/activitymonitor/DataSource.h | 11 ++++ 4 files changed, 138 insertions(+), 22 deletions(-) diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp index c82eb31b7c..73947ce6d1 100644 --- a/src/apps/activitymonitor/ActivityView.cpp +++ b/src/apps/activitymonitor/ActivityView.cpp @@ -13,6 +13,7 @@ #ifdef __HAIKU__ # include +# include #endif #include #include @@ -920,6 +921,8 @@ void ActivityView::_UpdateOffscreenBitmap() { BRect frame = _HistoryFrame(); + frame.OffsetTo(B_ORIGIN); + if (fOffscreen != NULL && frame == fOffscreen->Bounds()) return; @@ -1183,13 +1186,14 @@ ActivityView::_UpdateFrame() BRect ActivityView::_HistoryFrame() const { - if (!fShowLegend) - return Bounds(); - BRect frame = Bounds(); - BRect legendFrame = _LegendFrame(); - frame.bottom = legendFrame.top - 1; + if (fShowLegend) { + BRect legendFrame = _LegendFrame(); + frame.bottom = legendFrame.top - 1; + } + + frame.InsetBy(2, 2); return frame; } @@ -1283,7 +1287,7 @@ ActivityView::_PositionForValue(DataSource* source, DataHistory* values, void -ActivityView::_DrawHistory() +ActivityView::_DrawHistory(bool drawBackground) { _UpdateOffscreenBitmap(); @@ -1294,6 +1298,19 @@ ActivityView::_DrawHistory() } BRect frame = _HistoryFrame(); + BRect outerFrame = frame.InsetByCopy(-2, -2); + + // draw the outer frame + uint32 flags = 0; + if (!drawBackground) + flags |= BControlLook::B_BLEND_FRAME; + be_control_look->DrawTextControlBorder(this, outerFrame, + outerFrame, fLegendBackgroundColor, flags); + + // convert to offscreen view if necessary + if (view != this) + frame.OffsetTo(B_ORIGIN); + view->SetLowColor(fHistoryBackgroundColor); view->FillRect(frame, B_SOLID_LOW); @@ -1322,7 +1339,6 @@ ActivityView::_DrawHistory() scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT); view->SetHighColor(scaleColor); - view->StrokeRect(frame); view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2), BPoint(frame.right, frame.top + frame.Height() / 2)); @@ -1364,7 +1380,7 @@ ActivityView::_DrawHistory() view->Sync(); if (fOffscreen != NULL) { fOffscreen->Unlock(); - DrawBitmap(fOffscreen, B_ORIGIN); + DrawBitmap(fOffscreen, outerFrame.LeftTop()); } } @@ -1393,20 +1409,24 @@ ActivityView::_UpdateResolution(int32 resolution, bool broadcast) void -ActivityView::Draw(BRect /*updateRect*/) +ActivityView::Draw(BRect updateRect) { - _DrawHistory(); + bool drawBackground = true; + if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0) + drawBackground = false; + + _DrawHistory(drawBackground); if (!fShowLegend) return; // draw legend + BRect legendFrame = _LegendFrame(); + SetLowColor(fLegendBackgroundColor); + if (drawBackground) + FillRect(legendFrame, B_SOLID_LOW); BAutolock _(fSourcesLock); - BRect legendFrame = _LegendFrame(); - - SetLowColor(fLegendBackgroundColor); - FillRect(legendFrame, B_SOLID_LOW); font_height fontHeight; GetFontHeight(&fontHeight); @@ -1418,11 +1438,12 @@ ActivityView::Draw(BRect /*updateRect*/) // draw color box BRect colorBox = _LegendColorFrameAt(legendFrame, i); - SetHighColor(tint_color(source->Color(), B_DARKEN_1_TINT)); - StrokeRect(colorBox); + BRect rect = colorBox; + uint32 flags = BControlLook::B_BLEND_FRAME; + be_control_look->DrawTextControlBorder(this, rect, + rect, fLegendBackgroundColor, flags); SetHighColor(source->Color()); - colorBox.InsetBy(1, 1); - FillRect(colorBox); + FillRect(rect); // show current value and label float y = frame.top + ceilf(fontHeight.ascent); @@ -1432,10 +1453,22 @@ ActivityView::Draw(BRect /*updateRect*/) float width = StringWidth(text.String()); BString label = source->Label(); - TruncateString(&label, B_TRUNCATE_MIDDLE, - frame.right - colorBox.right - 12 - width); + float possibleLabelWidth = frame.right - colorBox.right - 12 - width; + // TODO: TruncateString() is broken... remove + 5 when fixed! + if (ceilf(StringWidth(label.String()) + 5) > possibleLabelWidth) + label = source->ShortLabel(); + TruncateString(&label, B_TRUNCATE_MIDDLE, possibleLabelWidth); - SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); + if (drawBackground) + SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); + else { + 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); + } DrawString(label.String(), BPoint(6 + colorBox.right, y)); DrawString(text.String(), BPoint(frame.right - width, y)); } diff --git a/src/apps/activitymonitor/ActivityView.h b/src/apps/activitymonitor/ActivityView.h index e4444da9ef..9a712626df 100644 --- a/src/apps/activitymonitor/ActivityView.h +++ b/src/apps/activitymonitor/ActivityView.h @@ -110,7 +110,7 @@ private: BRect _LegendColorFrameAt(BRect frame, int32 index) const; float _PositionForValue(DataSource* source, DataHistory* values, int64 value); - void _DrawHistory(); + void _DrawHistory(bool drawBackground); void _UpdateResolution(int32 resolution, bool broadcast = true); diff --git a/src/apps/activitymonitor/DataSource.cpp b/src/apps/activitymonitor/DataSource.cpp index dfbdfb11b9..65096e4232 100644 --- a/src/apps/activitymonitor/DataSource.cpp +++ b/src/apps/activitymonitor/DataSource.cpp @@ -150,6 +150,13 @@ DataSource::Name() const } +const char* +DataSource::ShortLabel() const +{ + return Label(); +} + + const char* DataSource::Label() const { @@ -325,6 +332,13 @@ UsedMemoryDataSource::Label() const } +const char* +UsedMemoryDataSource::ShortLabel() const +{ + return "Memory"; +} + + bool UsedMemoryDataSource::Primary() const { @@ -367,6 +381,13 @@ CachedMemoryDataSource::Label() const } +const char* +CachedMemoryDataSource::ShortLabel() const +{ + return "Cache"; +} + + bool CachedMemoryDataSource::Primary() const { @@ -412,6 +433,13 @@ SwapSpaceDataSource::Label() const } +const char* +SwapSpaceDataSource::ShortLabel() const +{ + return "Swap"; +} + + bool SwapSpaceDataSource::Primary() const { @@ -459,6 +487,13 @@ SemaphoresDataSource::Label() const } +const char* +SemaphoresDataSource::ShortLabel() const +{ + return "Sems"; +} + + bool SemaphoresDataSource::AdaptiveScale() const { @@ -647,6 +682,13 @@ RunningAppsDataSource::Label() const } +const char* +RunningAppsDataSource::ShortLabel() const +{ + return "Apps"; +} + + bool RunningAppsDataSource::AdaptiveScale() const { @@ -676,6 +718,7 @@ CPUUsageDataSource::CPUUsageDataSource(const CPUUsageDataSource& other) fPreviousTime = other.fPreviousTime; fCPU = other.fCPU; fLabel = other.fLabel; + fShortLabel = other.fShortLabel; } @@ -737,6 +780,13 @@ CPUUsageDataSource::Label() const } +const char* +CPUUsageDataSource::ShortLabel() const +{ + return fShortLabel.String(); +} + + const char* CPUUsageDataSource::Name() const { @@ -773,6 +823,7 @@ CPUUsageDataSource::_SetCPU(int32 cpu) if (SystemInfo().CPUCount() > 1) fLabel << " " << cpu; + fShortLabel = fLabel; fLabel << " Usage"; const rgb_color kColors[] = { @@ -867,6 +918,13 @@ CPUCombinedUsageDataSource::Label() const } +const char* +CPUCombinedUsageDataSource::ShortLabel() const +{ + return "CPU"; +} + + const char* CPUCombinedUsageDataSource::Name() const { @@ -958,6 +1016,13 @@ PageFaultsDataSource::Label() const } +const char* +PageFaultsDataSource::ShortLabel() const +{ + return "P-Faults"; +} + + const char* PageFaultsDataSource::Name() const { @@ -1052,6 +1117,13 @@ NetworkUsageDataSource::Label() const } +const char* +NetworkUsageDataSource::ShortLabel() const +{ + return fIn ? "RX" : "TX"; +} + + const char* NetworkUsageDataSource::Name() const { diff --git a/src/apps/activitymonitor/DataSource.h b/src/apps/activitymonitor/DataSource.h index 965b8bddd1..d4d1e91cdc 100644 --- a/src/apps/activitymonitor/DataSource.h +++ b/src/apps/activitymonitor/DataSource.h @@ -40,6 +40,7 @@ public: virtual const char* Name() const; virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual const char* Unit() const; virtual rgb_color Color() const; virtual bool AdaptiveScale() const; @@ -81,6 +82,7 @@ public: virtual int64 NextValue(SystemInfo& info); virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool Primary() const; }; @@ -94,6 +96,7 @@ public: virtual int64 NextValue(SystemInfo& info); virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool Primary() const; }; @@ -107,6 +110,7 @@ public: virtual int64 NextValue(SystemInfo& info); virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool Primary() const; }; @@ -120,6 +124,7 @@ public: virtual int64 NextValue(SystemInfo& info); virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool AdaptiveScale() const; }; @@ -172,6 +177,7 @@ public: virtual int64 NextValue(SystemInfo& info); virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool AdaptiveScale() const; }; @@ -190,6 +196,7 @@ public: virtual const char* Name() const; virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual int32 CPU() const; virtual bool PerCPU() const; @@ -202,6 +209,7 @@ private: bigtime_t fPreviousTime; int32 fCPU; BString fLabel; + BString fShortLabel; }; @@ -219,6 +227,7 @@ public: virtual const char* Name() const; virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool MultiCPUOnly() const; virtual bool Primary() const; @@ -243,6 +252,7 @@ public: virtual const char* Name() const; virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool AdaptiveScale() const; virtual bool Primary() const; @@ -266,6 +276,7 @@ public: virtual const char* Name() const; virtual const char* Label() const; + virtual const char* ShortLabel() const; virtual bool AdaptiveScale() const; virtual scale_type ScaleType() const; virtual bool Primary() const;