* 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
This commit is contained in:
Stephan Aßmus
2009-04-07 16:09:00 +00:00
parent 1111232758
commit ed1b27536b
4 changed files with 138 additions and 22 deletions
+54 -21
View File
@@ -13,6 +13,7 @@
#ifdef __HAIKU__ #ifdef __HAIKU__
# include <AbstractLayoutItem.h> # include <AbstractLayoutItem.h>
# include <ControlLook.h>
#endif #endif
#include <Application.h> #include <Application.h>
#include <Autolock.h> #include <Autolock.h>
@@ -920,6 +921,8 @@ void
ActivityView::_UpdateOffscreenBitmap() ActivityView::_UpdateOffscreenBitmap()
{ {
BRect frame = _HistoryFrame(); BRect frame = _HistoryFrame();
frame.OffsetTo(B_ORIGIN);
if (fOffscreen != NULL && frame == fOffscreen->Bounds()) if (fOffscreen != NULL && frame == fOffscreen->Bounds())
return; return;
@@ -1183,13 +1186,14 @@ ActivityView::_UpdateFrame()
BRect BRect
ActivityView::_HistoryFrame() const ActivityView::_HistoryFrame() const
{ {
if (!fShowLegend)
return Bounds();
BRect frame = 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; return frame;
} }
@@ -1283,7 +1287,7 @@ ActivityView::_PositionForValue(DataSource* source, DataHistory* values,
void void
ActivityView::_DrawHistory() ActivityView::_DrawHistory(bool drawBackground)
{ {
_UpdateOffscreenBitmap(); _UpdateOffscreenBitmap();
@@ -1294,6 +1298,19 @@ ActivityView::_DrawHistory()
} }
BRect frame = _HistoryFrame(); 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->SetLowColor(fHistoryBackgroundColor);
view->FillRect(frame, B_SOLID_LOW); view->FillRect(frame, B_SOLID_LOW);
@@ -1322,7 +1339,6 @@ ActivityView::_DrawHistory()
scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT); scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT);
view->SetHighColor(scaleColor); view->SetHighColor(scaleColor);
view->StrokeRect(frame);
view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2), view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2),
BPoint(frame.right, frame.top + frame.Height() / 2)); BPoint(frame.right, frame.top + frame.Height() / 2));
@@ -1364,7 +1380,7 @@ ActivityView::_DrawHistory()
view->Sync(); view->Sync();
if (fOffscreen != NULL) { if (fOffscreen != NULL) {
fOffscreen->Unlock(); fOffscreen->Unlock();
DrawBitmap(fOffscreen, B_ORIGIN); DrawBitmap(fOffscreen, outerFrame.LeftTop());
} }
} }
@@ -1393,20 +1409,24 @@ ActivityView::_UpdateResolution(int32 resolution, bool broadcast)
void 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) if (!fShowLegend)
return; return;
// draw legend // draw legend
BRect legendFrame = _LegendFrame();
SetLowColor(fLegendBackgroundColor);
if (drawBackground)
FillRect(legendFrame, B_SOLID_LOW);
BAutolock _(fSourcesLock); BAutolock _(fSourcesLock);
BRect legendFrame = _LegendFrame();
SetLowColor(fLegendBackgroundColor);
FillRect(legendFrame, B_SOLID_LOW);
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
@@ -1418,11 +1438,12 @@ ActivityView::Draw(BRect /*updateRect*/)
// draw color box // draw color box
BRect colorBox = _LegendColorFrameAt(legendFrame, i); BRect colorBox = _LegendColorFrameAt(legendFrame, i);
SetHighColor(tint_color(source->Color(), B_DARKEN_1_TINT)); BRect rect = colorBox;
StrokeRect(colorBox); uint32 flags = BControlLook::B_BLEND_FRAME;
be_control_look->DrawTextControlBorder(this, rect,
rect, fLegendBackgroundColor, flags);
SetHighColor(source->Color()); SetHighColor(source->Color());
colorBox.InsetBy(1, 1); FillRect(rect);
FillRect(colorBox);
// show current value and label // show current value and label
float y = frame.top + ceilf(fontHeight.ascent); float y = frame.top + ceilf(fontHeight.ascent);
@@ -1432,10 +1453,22 @@ ActivityView::Draw(BRect /*updateRect*/)
float width = StringWidth(text.String()); float width = StringWidth(text.String());
BString label = source->Label(); BString label = source->Label();
TruncateString(&label, B_TRUNCATE_MIDDLE, float possibleLabelWidth = frame.right - colorBox.right - 12 - width;
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(label.String(), BPoint(6 + colorBox.right, y));
DrawString(text.String(), BPoint(frame.right - width, y)); DrawString(text.String(), BPoint(frame.right - width, y));
} }
+1 -1
View File
@@ -110,7 +110,7 @@ private:
BRect _LegendColorFrameAt(BRect frame, int32 index) const; BRect _LegendColorFrameAt(BRect frame, int32 index) const;
float _PositionForValue(DataSource* source, float _PositionForValue(DataSource* source,
DataHistory* values, int64 value); DataHistory* values, int64 value);
void _DrawHistory(); void _DrawHistory(bool drawBackground);
void _UpdateResolution(int32 resolution, void _UpdateResolution(int32 resolution,
bool broadcast = true); bool broadcast = true);
+72
View File
@@ -150,6 +150,13 @@ DataSource::Name() const
} }
const char*
DataSource::ShortLabel() const
{
return Label();
}
const char* const char*
DataSource::Label() const DataSource::Label() const
{ {
@@ -325,6 +332,13 @@ UsedMemoryDataSource::Label() const
} }
const char*
UsedMemoryDataSource::ShortLabel() const
{
return "Memory";
}
bool bool
UsedMemoryDataSource::Primary() const UsedMemoryDataSource::Primary() const
{ {
@@ -367,6 +381,13 @@ CachedMemoryDataSource::Label() const
} }
const char*
CachedMemoryDataSource::ShortLabel() const
{
return "Cache";
}
bool bool
CachedMemoryDataSource::Primary() const CachedMemoryDataSource::Primary() const
{ {
@@ -412,6 +433,13 @@ SwapSpaceDataSource::Label() const
} }
const char*
SwapSpaceDataSource::ShortLabel() const
{
return "Swap";
}
bool bool
SwapSpaceDataSource::Primary() const SwapSpaceDataSource::Primary() const
{ {
@@ -459,6 +487,13 @@ SemaphoresDataSource::Label() const
} }
const char*
SemaphoresDataSource::ShortLabel() const
{
return "Sems";
}
bool bool
SemaphoresDataSource::AdaptiveScale() const SemaphoresDataSource::AdaptiveScale() const
{ {
@@ -647,6 +682,13 @@ RunningAppsDataSource::Label() const
} }
const char*
RunningAppsDataSource::ShortLabel() const
{
return "Apps";
}
bool bool
RunningAppsDataSource::AdaptiveScale() const RunningAppsDataSource::AdaptiveScale() const
{ {
@@ -676,6 +718,7 @@ CPUUsageDataSource::CPUUsageDataSource(const CPUUsageDataSource& other)
fPreviousTime = other.fPreviousTime; fPreviousTime = other.fPreviousTime;
fCPU = other.fCPU; fCPU = other.fCPU;
fLabel = other.fLabel; fLabel = other.fLabel;
fShortLabel = other.fShortLabel;
} }
@@ -737,6 +780,13 @@ CPUUsageDataSource::Label() const
} }
const char*
CPUUsageDataSource::ShortLabel() const
{
return fShortLabel.String();
}
const char* const char*
CPUUsageDataSource::Name() const CPUUsageDataSource::Name() const
{ {
@@ -773,6 +823,7 @@ CPUUsageDataSource::_SetCPU(int32 cpu)
if (SystemInfo().CPUCount() > 1) if (SystemInfo().CPUCount() > 1)
fLabel << " " << cpu; fLabel << " " << cpu;
fShortLabel = fLabel;
fLabel << " Usage"; fLabel << " Usage";
const rgb_color kColors[] = { const rgb_color kColors[] = {
@@ -867,6 +918,13 @@ CPUCombinedUsageDataSource::Label() const
} }
const char*
CPUCombinedUsageDataSource::ShortLabel() const
{
return "CPU";
}
const char* const char*
CPUCombinedUsageDataSource::Name() const CPUCombinedUsageDataSource::Name() const
{ {
@@ -958,6 +1016,13 @@ PageFaultsDataSource::Label() const
} }
const char*
PageFaultsDataSource::ShortLabel() const
{
return "P-Faults";
}
const char* const char*
PageFaultsDataSource::Name() const PageFaultsDataSource::Name() const
{ {
@@ -1052,6 +1117,13 @@ NetworkUsageDataSource::Label() const
} }
const char*
NetworkUsageDataSource::ShortLabel() const
{
return fIn ? "RX" : "TX";
}
const char* const char*
NetworkUsageDataSource::Name() const NetworkUsageDataSource::Name() const
{ {
+11
View File
@@ -40,6 +40,7 @@ public:
virtual const char* Name() const; virtual const char* Name() const;
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual const char* Unit() const; virtual const char* Unit() const;
virtual rgb_color Color() const; virtual rgb_color Color() const;
virtual bool AdaptiveScale() const; virtual bool AdaptiveScale() const;
@@ -81,6 +82,7 @@ public:
virtual int64 NextValue(SystemInfo& info); virtual int64 NextValue(SystemInfo& info);
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool Primary() const; virtual bool Primary() const;
}; };
@@ -94,6 +96,7 @@ public:
virtual int64 NextValue(SystemInfo& info); virtual int64 NextValue(SystemInfo& info);
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool Primary() const; virtual bool Primary() const;
}; };
@@ -107,6 +110,7 @@ public:
virtual int64 NextValue(SystemInfo& info); virtual int64 NextValue(SystemInfo& info);
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool Primary() const; virtual bool Primary() const;
}; };
@@ -120,6 +124,7 @@ public:
virtual int64 NextValue(SystemInfo& info); virtual int64 NextValue(SystemInfo& info);
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool AdaptiveScale() const; virtual bool AdaptiveScale() const;
}; };
@@ -172,6 +177,7 @@ public:
virtual int64 NextValue(SystemInfo& info); virtual int64 NextValue(SystemInfo& info);
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool AdaptiveScale() const; virtual bool AdaptiveScale() const;
}; };
@@ -190,6 +196,7 @@ public:
virtual const char* Name() const; virtual const char* Name() const;
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual int32 CPU() const; virtual int32 CPU() const;
virtual bool PerCPU() const; virtual bool PerCPU() const;
@@ -202,6 +209,7 @@ private:
bigtime_t fPreviousTime; bigtime_t fPreviousTime;
int32 fCPU; int32 fCPU;
BString fLabel; BString fLabel;
BString fShortLabel;
}; };
@@ -219,6 +227,7 @@ public:
virtual const char* Name() const; virtual const char* Name() const;
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool MultiCPUOnly() const; virtual bool MultiCPUOnly() const;
virtual bool Primary() const; virtual bool Primary() const;
@@ -243,6 +252,7 @@ public:
virtual const char* Name() const; virtual const char* Name() const;
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool AdaptiveScale() const; virtual bool AdaptiveScale() const;
virtual bool Primary() const; virtual bool Primary() const;
@@ -266,6 +276,7 @@ public:
virtual const char* Name() const; virtual const char* Name() const;
virtual const char* Label() const; virtual const char* Label() const;
virtual const char* ShortLabel() const;
virtual bool AdaptiveScale() const; virtual bool AdaptiveScale() const;
virtual scale_type ScaleType() const; virtual scale_type ScaleType() const;
virtual bool Primary() const; virtual bool Primary() const;