示例#1
0
void
ActivityView::MouseDown(BPoint where)
{
	int32 buttons = B_SECONDARY_MOUSE_BUTTON;
	if (Looper() != NULL && Looper()->CurrentMessage() != NULL)
		Looper()->CurrentMessage()->FindInt32("buttons", &buttons);

	if (buttons == B_PRIMARY_MOUSE_BUTTON) {
		fZoomPoint = where;
		fOriginalResolution = fDrawResolution;
		fZooming = true;
		SetMouseEventMask(B_POINTER_EVENTS);
		return;
	}

	BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
	menu->SetFont(be_plain_font);

	BMenu* additionalMenu = new BMenu(B_TRANSLATE("Additional items"));
	additionalMenu->SetFont(be_plain_font);

	SystemInfo info;
	BMenuItem* item;

	for (int32 i = 0; i < DataSource::CountSources(); i++) {
		const DataSource* source = DataSource::SourceAt(i);

		if (source->MultiCPUOnly() && info.CPUCount() == 1)
			continue;

		BMessage* message = new BMessage(kMsgToggleDataSource);
		message->AddInt32("index", i);

		item = new BMenuItem(source->Name(), message);
		if (FindDataSource(source))
			item->SetMarked(true);

		if (source->Primary())
			menu->AddItem(item);
		else
			additionalMenu->AddItem(item);
	}

	menu->AddItem(new BMenuItem(additionalMenu));
	menu->AddSeparatorItem();
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Show legend"),
		new BMessage(kMsgToggleLegend)));
	item->SetMarked(fShowLegend);

	menu->SetTargetForItems(this);
	additionalMenu->SetTargetForItems(this);

	ActivityWindow* window = dynamic_cast<ActivityWindow*>(Window());
	if (window != NULL && window->ActivityViewCount() > 1) {
		menu->AddSeparatorItem();
		BMessage* message = new BMessage(kMsgRemoveView);
		message->AddPointer("view", this);
		menu->AddItem(item = new BMenuItem(B_TRANSLATE("Remove graph"),
			message));
		item->SetTarget(window);
	}

	ConvertToScreen(&where);
	menu->Go(where, true, false, true);
}
示例#2
0
status_t
ActivityView::AddDataSource(const DataSource* source, const BMessage* state)
{
	if (source == NULL)
		return B_BAD_VALUE;

	BAutolock _(fSourcesLock);

	// Search for the correct insert spot to maintain the order of the sources
	int32 insert = DataSource::IndexOf(source);
	for (int32 i = 0; i < fSources.CountItems() && i < insert; i++) {
		DataSource* before = fSources.ItemAt(i);
		if (DataSource::IndexOf(before) > insert) {
			insert = i;
			break;
		}
	}
	if (insert > fSources.CountItems())
		insert = fSources.CountItems();

	// Generate DataHistory and ViewHistory objects for the source
	// (one might need one history per CPU)

	uint32 count = 1;
	if (source->PerCPU()) {
		SystemInfo info;
		count = info.CPUCount();
	}

	for (uint32 i = 0; i < count; i++) {
		DataHistory* values = new(std::nothrow) DataHistory(10 * 60000000LL,
			RefreshInterval());
		ListAddDeleter<DataHistory> valuesDeleter(fValues, values, insert);

		ViewHistory* viewValues = new(std::nothrow) ViewHistory;
		ListAddDeleter<ViewHistory> viewValuesDeleter(fViewValues, viewValues,
			insert);

		if (valuesDeleter.Failed() || viewValuesDeleter.Failed())
			return B_NO_MEMORY;

		values->SetScale(_ScaleFor(source->ScaleType()));

		DataSource* copy;
		if (source->PerCPU())
			copy = source->CopyForCPU(i);
		else
			copy = source->Copy();

		ListAddDeleter<DataSource> sourceDeleter(fSources, copy, insert);
		if (sourceDeleter.Failed())
			return B_NO_MEMORY;

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

		valuesDeleter.Detach();
		viewValuesDeleter.Detach();
		sourceDeleter.Detach();
		insert++;
	}

#ifdef __HAIKU__
	InvalidateLayout();
#endif
	return B_OK;
}