示例#1
0
status_t
ActivityView::SaveState(BMessage& state) const
{
	status_t status = state.AddBool("show legend", fShowLegend);
	if (status != B_OK)
		return status;

	status = state.AddInt64("refresh interval", fRefreshInterval);
	if (status != B_OK)
		return status;

	status = state.AddData("history background color", B_RGB_COLOR_TYPE,
		&fHistoryBackgroundColor, sizeof(rgb_color));
	if (status != B_OK)
		return status;

	for (int32 i = 0; i < fSources.CountItems(); i++) {
		DataSource* source = fSources.ItemAt(i);

		if (!source->PerCPU() || source->CPU() == 0)
			status = state.AddString("source", source->InternalName());
		if (status != B_OK)
			return status;

		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;
}
示例#2
0
void
ActivityView::Draw(BRect updateRect)
{
	bool drawBackground = true;
	if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0)
		drawBackground = false;

	_DrawHistory(drawBackground);

	if (!fShowLegend)
		return;

	// draw legend
	BRect legendFrame = _LegendFrame();
	if (LowUIColor() == B_NO_COLOR)
		SetLowColor(fLegendBackgroundColor);

	if (drawBackground) {
		BRect backgroundFrame(legendFrame);
		backgroundFrame.bottom += kDraggerSize;
		FillRect(backgroundFrame, B_SOLID_LOW);
	}

	BAutolock _(fSourcesLock);

	font_height fontHeight;
	GetFontHeight(&fontHeight);

	for (int32 i = 0; i < fSources.CountItems(); i++) {
		DataSource* source = fSources.ItemAt(i);
		DataHistory* values = fValues.ItemAt(i);
		BRect frame = _LegendFrameAt(legendFrame, i);

		// draw color box
		BRect colorBox = _LegendColorFrameAt(legendFrame, i);
		BRect rect = colorBox;
		uint32 flags = BControlLook::B_BLEND_FRAME;
		be_control_look->DrawTextControlBorder(this, rect,
			rect, fLegendBackgroundColor, flags);
		SetHighColor(source->Color());
		FillRect(rect);

		// show current value and label
		float y = frame.top + ceilf(fontHeight.ascent);
		int64 value = values->ValueAt(values->End());
		BString text;
		source->Print(text, value);
		float width = StringWidth(text.String());

		BString label = source->Label();
		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);

		if (drawBackground)
			SetHighColor(ui_color(B_PANEL_TEXT_COLOR));

		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));
		}
	}
}
void
ActivityView::_DrawHistory(bool drawBackground)
{
	_UpdateOffscreenBitmap();

	BView* view = this;
	if (fOffscreen != NULL) {
		fOffscreen->Lock();
		view = _OffscreenView();
	}

	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);

	uint32 step = 2;
	uint32 resolution = fDrawResolution;
	if (fDrawResolution > 1) {
		step = 1;
		resolution--;
	}

	uint32 width = frame.IntegerWidth() - 10;
	uint32 steps = width / step;
	bigtime_t timeStep = RefreshInterval() * resolution;
	bigtime_t now = system_time();

	// Draw scale
	// TODO: add second markers?

	view->SetPenSize(1);

	rgb_color scaleColor = view->LowColor();
	uint32 average = (scaleColor.red + scaleColor.green + scaleColor.blue) / 3;
	if (average < 96)
		scaleColor = tint_color(scaleColor, B_LIGHTEN_2_TINT);
	else
		scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT);

	view->SetHighColor(scaleColor);
	view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2),
		BPoint(frame.right, frame.top + frame.Height() / 2));

	// Draw values

	view->SetPenSize(1.5);
	BAutolock _(fSourcesLock);

	for (uint32 i = fSources.CountItems(); i-- > 0;) {
		ViewHistory* viewValues = fViewValues.ItemAt(i);
		DataSource* source = fSources.ItemAt(i);
		DataHistory* values = fValues.ItemAt(i);

		viewValues->Update(values, steps, fDrawResolution, now, timeStep,
			RefreshInterval());

		uint32 x = viewValues->Start() * step;
		BShape shape;
		bool first = true;

		for (uint32 i = viewValues->Start(); i < steps; x += step, i++) {
			float y = _PositionForValue(source, values,
				viewValues->ValueAt(i));

			if (first) {
				shape.MoveTo(BPoint(x, y));
				first = false;
			} else
				shape.LineTo(BPoint(x, y));
		}

		view->SetHighColor(source->Color());
		view->SetLineMode(B_BUTT_CAP, B_ROUND_JOIN);
		view->MovePenTo(B_ORIGIN);
		view->StrokeShape(&shape);
	}

	// TODO: add marks when an app started or quit
	view->Sync();
	if (fOffscreen != NULL) {
		fOffscreen->Unlock();
		DrawBitmap(fOffscreen, outerFrame.LeftTop());
	}
}
示例#4
0
void
ActivityView::_DrawHistory(bool drawBackground)
{
	_UpdateOffscreenBitmap();

	BView* view = this;
	if (fOffscreen != NULL) {
		fOffscreen->Lock();
		view = _OffscreenView();
	}

	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);

	uint32 step = 2;
	uint32 resolution = fDrawResolution;
	if (fDrawResolution > 1) {
		step = 1;
		resolution--;
	}

	// We would get a negative number of steps which isn't a good idea.
	if (frame.IntegerWidth() <= 10)
		return;

	uint32 width = frame.IntegerWidth() - 10;
	uint32 steps = width / step;
	bigtime_t timeStep = RefreshInterval() * resolution;
	bigtime_t now = system_time();

	// Draw scale
	// TODO: add second markers?

	view->SetPenSize(1);

	rgb_color scaleColor = view->LowColor();
	uint32 average = (scaleColor.red + scaleColor.green + scaleColor.blue) / 3;
	if (average < 96)
		scaleColor = tint_color(scaleColor, B_LIGHTEN_2_TINT);
	else
		scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT);

	view->SetHighColor(scaleColor);
	view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2),
		BPoint(frame.right, frame.top + frame.Height() / 2));

	// Draw values

	view->SetPenSize(1.5);
	BAutolock _(fSourcesLock);

	for (uint32 i = fSources.CountItems(); i-- > 0;) {
		ViewHistory* viewValues = fViewValues.ItemAt(i);
		DataSource* source = fSources.ItemAt(i);
		DataHistory* values = fValues.ItemAt(i);

		viewValues->Update(values, steps, fDrawResolution, now, timeStep,
			RefreshInterval());

		if (viewValues->Start() >= (int32)steps - 1)
			continue;

		uint32 x = viewValues->Start() * step;

		bool first = true;

		view->SetHighColor(source->Color());
		view->SetLineMode(B_BUTT_CAP, B_ROUND_JOIN);
		view->MovePenTo(B_ORIGIN);

		try {
			view->BeginLineArray(steps - viewValues->Start() - 1);

			BPoint prev;

			for (uint32 j = viewValues->Start(); j < steps; x += step, j++) {
				float y = _PositionForValue(source, values,
					viewValues->ValueAt(j));

				if (first) {
					first = false;
				} else
					view->AddLine(prev, BPoint(x, y), source->Color());

				prev.Set(x, y);
			}

		} catch (std::bad_alloc) {
			// Not enough memory to allocate the line array.
			// TODO we could try to draw using the slower but less memory
			// consuming solution using StrokeLine.
		}

		view->EndLineArray();
	}

	// TODO: add marks when an app started or quit
	view->Sync();
	if (fOffscreen != NULL) {
		fOffscreen->Unlock();
		DrawBitmap(fOffscreen, outerFrame.LeftTop());
	}
}
示例#5
0
void
ActivityView::Draw(BRect updateRect)
{
	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) {
		BRect backgroundFrame(legendFrame);
		backgroundFrame.bottom += kDraggerSize;
		FillRect(backgroundFrame, B_SOLID_LOW);
	}

	BAutolock _(fSourcesLock);

	font_height fontHeight;
	GetFontHeight(&fontHeight);

	for (int32 i = 0; i < fSources.CountItems(); i++) {
		DataSource* source = fSources.ItemAt(i);
		DataHistory* values = fValues.ItemAt(i);
		BRect frame = _LegendFrameAt(legendFrame, i);

		// draw color box
		BRect colorBox = _LegendColorFrameAt(legendFrame, i);
		BRect rect = colorBox;
		uint32 flags = BControlLook::B_BLEND_FRAME;
		be_control_look->DrawTextControlBorder(this, rect,
			rect, fLegendBackgroundColor, flags);
		SetHighColor(source->Color());
		FillRect(rect);

		// show current value and label
		float y = frame.top + ceilf(fontHeight.ascent);
		int64 value = values->ValueAt(values->End());
		BString text;
		source->Print(text, value);
		float width = StringWidth(text.String());

		BString label = source->Label();
		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);

		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);
		}
		DrawString(label.String(), BPoint(6 + colorBox.right, y));
		DrawString(text.String(), BPoint(frame.right - width, y));
	}
}