* Allow color drops to change the legend background color only for the
replicant. * Implemented storing and restoring the color of the data sources. * Minor style fixes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25046 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -335,6 +335,7 @@ ActivityView::ActivityView(const char* name, const BMessage* settings)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
_Init(settings);
|
_Init(settings);
|
||||||
|
|
||||||
BRect rect(Bounds());
|
BRect rect(Bounds());
|
||||||
@@ -363,7 +364,9 @@ ActivityView::~ActivityView()
|
|||||||
void
|
void
|
||||||
ActivityView::_Init(const BMessage* settings)
|
ActivityView::_Init(const BMessage* settings)
|
||||||
{
|
{
|
||||||
fBackgroundColor = (rgb_color){255, 255, 240};
|
fHistoryBackgroundColor = (rgb_color){255, 255, 240};
|
||||||
|
fLegendBackgroundColor = LowColor();
|
||||||
|
// the low color is restored by the BView unarchiving
|
||||||
fOffscreen = NULL;
|
fOffscreen = NULL;
|
||||||
#ifdef __HAIKU__
|
#ifdef __HAIKU__
|
||||||
fHistoryLayoutItem = NULL;
|
fHistoryLayoutItem = NULL;
|
||||||
@@ -388,13 +391,12 @@ ActivityView::_Init(const BMessage* settings)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t colorLength;
|
||||||
rgb_color *color;
|
rgb_color *color;
|
||||||
ssize_t colorLen;
|
if (settings->FindData("history background color", B_RGB_COLOR_TYPE,
|
||||||
if (settings->FindData("background color", B_RGB_COLOR_TYPE,
|
(const void **)&color, &colorLength) == B_OK
|
||||||
(const void **)&color, &colorLen) == B_OK &&
|
&& colorLength == sizeof(rgb_color))
|
||||||
colorLen == sizeof(rgb_color))
|
fHistoryBackgroundColor = *color;
|
||||||
fBackgroundColor = *color;
|
|
||||||
|
|
||||||
|
|
||||||
const char* name;
|
const char* name;
|
||||||
for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++) {
|
for (int32 i = 0; settings->FindString("source", i, &name) == B_OK; i++) {
|
||||||
@@ -441,7 +443,8 @@ ActivityView::SaveState(BMessage& state) const
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
status = state.AddData("background color", B_RGB_COLOR_TYPE, &fBackgroundColor, sizeof(rgb_color));
|
status = state.AddData("history background color", B_RGB_COLOR_TYPE,
|
||||||
|
&fHistoryBackgroundColor, sizeof(rgb_color));
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -453,7 +456,11 @@ ActivityView::SaveState(BMessage& state) const
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
// TODO: save and restore color as well
|
BString name = source->Name();
|
||||||
|
name << " color";
|
||||||
|
rgb_color color = source->Color();
|
||||||
|
state.AddData(name.String(), B_RGB_COLOR_TYPE, &color,
|
||||||
|
sizeof(rgb_color));
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -480,6 +487,7 @@ ActivityView::CreateLegendLayoutItem()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
DataSource*
|
DataSource*
|
||||||
ActivityView::FindDataSource(const DataSource* search)
|
ActivityView::FindDataSource(const DataSource* search)
|
||||||
{
|
{
|
||||||
@@ -494,7 +502,7 @@ ActivityView::FindDataSource(const DataSource* search)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ActivityView::AddDataSource(const DataSource* source)
|
ActivityView::AddDataSource(const DataSource* source, const BMessage* state)
|
||||||
{
|
{
|
||||||
if (source == NULL)
|
if (source == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -533,6 +541,17 @@ ActivityView::AddDataSource(const DataSource* source)
|
|||||||
else
|
else
|
||||||
copy = source->Copy();
|
copy = source->Copy();
|
||||||
|
|
||||||
|
BString colorName = source->Name();
|
||||||
|
colorName << " color";
|
||||||
|
if (state != NULL) {
|
||||||
|
const rgb_color* color = NULL;
|
||||||
|
ssize_t colorLength;
|
||||||
|
if (state->FindData(colorName.String(), B_RGB_COLOR_TYPE, i,
|
||||||
|
(const void**)&color, &colorLength) == B_OK
|
||||||
|
&& colorLength == sizeof(rgb_color))
|
||||||
|
copy->SetColor(*color);
|
||||||
|
}
|
||||||
|
|
||||||
if (!fSources.AddItem(copy, insert + i)) {
|
if (!fSources.AddItem(copy, insert + i)) {
|
||||||
fValues.RemoveItem(values);
|
fValues.RemoveItem(values);
|
||||||
delete values;
|
delete values;
|
||||||
@@ -554,6 +573,7 @@ ActivityView::RemoveDataSource(const DataSource* remove)
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
DataSource* source = FindDataSource(remove);
|
DataSource* source = FindDataSource(remove);
|
||||||
|
debug_printf("SEARCH %s, found %p\n", remove->Name(), source);
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
if (removed)
|
if (removed)
|
||||||
break;
|
break;
|
||||||
@@ -615,7 +635,7 @@ ActivityView::MinSize()
|
|||||||
{
|
{
|
||||||
BSize size(32, 32);
|
BSize size(32, 32);
|
||||||
if (fShowLegend)
|
if (fShowLegend)
|
||||||
size.height = _LegendFrame().Height();
|
size.height = _LegendHeight();
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -630,10 +650,10 @@ ActivityView::FrameResized(float /*width*/, float /*height*/)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ActivityView::_UpdateOffscreenBitmap(bool force)
|
ActivityView::_UpdateOffscreenBitmap()
|
||||||
{
|
{
|
||||||
BRect frame = _HistoryFrame();
|
BRect frame = _HistoryFrame();
|
||||||
if (!force && fOffscreen != NULL && frame == fOffscreen->Bounds())
|
if (fOffscreen != NULL && frame == fOffscreen->Bounds())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete fOffscreen;
|
delete fOffscreen;
|
||||||
@@ -649,12 +669,22 @@ ActivityView::_UpdateOffscreenBitmap(bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BView* view = new BView(frame, NULL, B_FOLLOW_NONE, B_SUBPIXEL_PRECISE);
|
BView* view = new BView(frame, NULL, B_FOLLOW_NONE, B_SUBPIXEL_PRECISE);
|
||||||
view->SetViewColor(fBackgroundColor);
|
view->SetViewColor(fHistoryBackgroundColor);
|
||||||
view->SetLowColor(view->ViewColor());
|
view->SetLowColor(view->ViewColor());
|
||||||
fOffscreen->AddChild(view);
|
fOffscreen->AddChild(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BView*
|
||||||
|
ActivityView::_OffscreenView()
|
||||||
|
{
|
||||||
|
if (fOffscreen == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return fOffscreen->ChildAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ActivityView::MouseDown(BPoint where)
|
ActivityView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
@@ -732,33 +762,37 @@ ActivityView::MessageReceived(BMessage* message)
|
|||||||
if (message->WasDropped()) {
|
if (message->WasDropped()) {
|
||||||
rgb_color *color;
|
rgb_color *color;
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
if ((message->FindData("RGBColor",
|
if ((message->FindData("RGBColor", B_RGB_COLOR_TYPE, 0,
|
||||||
B_RGB_COLOR_TYPE, 0, (const void **)&color, &size) == B_OK) &&
|
(const void **)&color, &size) == B_OK)
|
||||||
size == sizeof(rgb_color)) {
|
&& size == sizeof(rgb_color)) {
|
||||||
//message->PrintToStream();
|
BPoint dropPoint = message->DropPoint();
|
||||||
BPoint dropPoint;
|
|
||||||
dropPoint = message->DropPoint();
|
|
||||||
ConvertFromScreen(&dropPoint);
|
ConvertFromScreen(&dropPoint);
|
||||||
|
|
||||||
if (_HistoryFrame().Contains(dropPoint)) {
|
if (_HistoryFrame().Contains(dropPoint)) {
|
||||||
fBackgroundColor = *color;
|
fHistoryBackgroundColor = *color;
|
||||||
_UpdateOffscreenBitmap(true);
|
Invalidate(_HistoryFrame());
|
||||||
} else {
|
} else {
|
||||||
// check each legend color box
|
// check each legend color box
|
||||||
BRect legendFrame = _LegendFrame();
|
BRect legendFrame = _LegendFrame();
|
||||||
int32 i;
|
for (int32 i = 0; i < fSources.CountItems(); i++) {
|
||||||
for (i = 0; i < fSources.CountItems(); i++) {
|
BRect frame = _LegendFrameAt(legendFrame, i);
|
||||||
BRect r = _LegendFrameAt(legendFrame, i);
|
if (frame.Contains(dropPoint)) {
|
||||||
if (r.Contains(dropPoint)) {
|
|
||||||
fSources.ItemAt(i)->SetColor(*color);
|
fSources.ItemAt(i)->SetColor(*color);
|
||||||
|
Invalidate(_HistoryFrame());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// background
|
|
||||||
SetLowColor(*color);
|
if (dynamic_cast<ActivityMonitor*>(be_app) == NULL) {
|
||||||
|
// allow background color change in the replicant only
|
||||||
|
fLegendBackgroundColor = *color;
|
||||||
|
Invalidate(legendFrame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} // else try the switch or BView::
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case B_ABOUT_REQUESTED:
|
case B_ABOUT_REQUESTED:
|
||||||
ActivityMonitor::ShowAbout();
|
ActivityMonitor::ShowAbout();
|
||||||
@@ -937,10 +971,11 @@ ActivityView::_DrawHistory()
|
|||||||
BView* view = this;
|
BView* view = this;
|
||||||
if (fOffscreen != NULL) {
|
if (fOffscreen != NULL) {
|
||||||
fOffscreen->Lock();
|
fOffscreen->Lock();
|
||||||
view = fOffscreen->ChildAt(0);
|
view = _OffscreenView();
|
||||||
}
|
}
|
||||||
|
|
||||||
BRect frame = _HistoryFrame();
|
BRect frame = _HistoryFrame();
|
||||||
|
SetLowColor(fHistoryBackgroundColor);
|
||||||
view->FillRect(frame, B_SOLID_LOW);
|
view->FillRect(frame, B_SOLID_LOW);
|
||||||
|
|
||||||
uint32 step = 2;
|
uint32 step = 2;
|
||||||
@@ -1028,6 +1063,8 @@ ActivityView::Draw(BRect /*updateRect*/)
|
|||||||
// draw legend
|
// draw legend
|
||||||
|
|
||||||
BRect legendFrame = _LegendFrame();
|
BRect legendFrame = _LegendFrame();
|
||||||
|
|
||||||
|
SetLowColor(fLegendBackgroundColor);
|
||||||
FillRect(legendFrame, B_SOLID_LOW);
|
FillRect(legendFrame, B_SOLID_LOW);
|
||||||
|
|
||||||
font_height fontHeight;
|
font_height fontHeight;
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DataSource* FindDataSource(const DataSource* source);
|
DataSource* FindDataSource(const DataSource* source);
|
||||||
status_t AddDataSource(const DataSource* source);
|
status_t AddDataSource(const DataSource* source,
|
||||||
|
const BMessage* state = NULL);
|
||||||
status_t RemoveDataSource(const DataSource* source);
|
status_t RemoveDataSource(const DataSource* source);
|
||||||
void RemoveAllDataSources();
|
void RemoveAllDataSources();
|
||||||
|
|
||||||
@@ -86,7 +87,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void _Init(const BMessage* settings);
|
void _Init(const BMessage* settings);
|
||||||
void _Refresh();
|
void _Refresh();
|
||||||
void _UpdateOffscreenBitmap(bool force=false);
|
void _UpdateOffscreenBitmap();
|
||||||
|
BView* _OffscreenView();
|
||||||
void _UpdateFrame();
|
void _UpdateFrame();
|
||||||
BRect _HistoryFrame() const;
|
BRect _HistoryFrame() const;
|
||||||
float _LegendHeight() const;
|
float _LegendHeight() const;
|
||||||
@@ -102,7 +104,8 @@ private:
|
|||||||
friend class HistoryLayoutItem;
|
friend class HistoryLayoutItem;
|
||||||
friend class LegendLayoutItem;
|
friend class LegendLayoutItem;
|
||||||
|
|
||||||
rgb_color fBackgroundColor;
|
rgb_color fHistoryBackgroundColor;
|
||||||
|
rgb_color fLegendBackgroundColor;
|
||||||
BBitmap* fOffscreen;
|
BBitmap* fOffscreen;
|
||||||
#ifdef __HAIKU__
|
#ifdef __HAIKU__
|
||||||
BLayoutItem* fHistoryLayoutItem;
|
BLayoutItem* fHistoryLayoutItem;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class SystemInfoHandler;
|
|||||||
|
|
||||||
class SystemInfo {
|
class SystemInfo {
|
||||||
public:
|
public:
|
||||||
SystemInfo(SystemInfoHandler *handler=NULL);
|
SystemInfo(SystemInfoHandler* handler = NULL);
|
||||||
~SystemInfo();
|
~SystemInfo();
|
||||||
|
|
||||||
uint64 CachedMemory() const;
|
uint64 CachedMemory() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user