コード例 #1
0
void
ActivityView::MessageReceived(BMessage* message)
{
	// if a color is dropped, use it as background
	if (message->WasDropped()) {
		rgb_color* color;
		ssize_t size;
		if (message->FindData("RGBColor", B_RGB_COLOR_TYPE, 0,
				(const void**)&color, &size) == B_OK
			&& size == sizeof(rgb_color)) {
			BPoint dropPoint = message->DropPoint();
			ConvertFromScreen(&dropPoint);

			if (_HistoryFrame().Contains(dropPoint)) {
				fHistoryBackgroundColor = *color;
				Invalidate(_HistoryFrame());
			} else {
				// check each legend color box
				BAutolock _(fSourcesLock);

				BRect legendFrame = _LegendFrame();
				for (int32 i = 0; i < fSources.CountItems(); i++) {
					BRect frame = _LegendColorFrameAt(legendFrame, i);
					if (frame.Contains(dropPoint)) {
						fSources.ItemAt(i)->SetColor(*color);
						Invalidate(_HistoryFrame());
						Invalidate(frame);
						return;
					}
				}

				if (dynamic_cast<ActivityMonitor*>(be_app) == NULL) {
					// allow background color change in the replicant only
					fLegendBackgroundColor = *color;
					SetLowColor(fLegendBackgroundColor);
					Invalidate(legendFrame);
				}
			}
			return;
		}
	}

	switch (message->what) {
		case B_ABOUT_REQUESTED:
		{
			BAboutWindow* window = new BAboutWindow(kAppName, kSignature);

			const char* authors[] = {
				"Axel Dörfler",
				NULL
			};

			window->AddCopyright(2008, "Haiku, Inc.");
			window->AddAuthors(authors);

			window->Show();

			break;
		}
		case kMsgUpdateResolution:
		{
			int32 resolution;
			if (message->FindInt32("resolution", &resolution) != B_OK)
				break;

			_UpdateResolution(resolution, false);
			break;
		}

		case kMsgTimeIntervalUpdated:
			bigtime_t interval;
			if (message->FindInt64("interval", &interval) != B_OK)
				break;

			if (interval < 10000)
				interval = 10000;

			atomic_set64(&fRefreshInterval, interval);
			break;

		case kMsgToggleDataSource:
		{
			int32 index;
			if (message->FindInt32("index", &index) != B_OK)
				break;

			const DataSource* baseSource = DataSource::SourceAt(index);
			if (baseSource == NULL)
				break;

			DataSource* source = FindDataSource(baseSource);
			if (source == NULL)
				AddDataSource(baseSource);
			else
				RemoveDataSource(baseSource);

			Invalidate();
			break;
		}

		case kMsgToggleLegend:
			fShowLegend = !fShowLegend;
			Invalidate();
			break;

		case B_MOUSE_WHEEL_CHANGED:
		{
			float deltaY = 0.0f;
			if (message->FindFloat("be:wheel_delta_y", &deltaY) != B_OK
				|| deltaY == 0.0f)
				break;

			int32 resolution = fDrawResolution;
			if (deltaY > 0)
				resolution *= 2;
			else
				resolution /= 2;

			_UpdateResolution(resolution);
			break;
		}

		default:
			BView::MessageReceived(message);
			break;
	}
}
コード例 #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));
		}
	}
}
コード例 #3
0
ファイル: ActivityView.cpp プロジェクト: mariuz/haiku
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));
	}
}