Exemplo n.º 1
0
// _Select
void
PathManipulator::_Select(BRect r)
{
	BPoint p;
	BPoint pIn;
	BPoint pOut;
	int32 count = fPath->CountPoints();
	Selection temp;
	for (int32 i = 0; i < count && fPath->GetPointsAt(i, p, pIn, pOut); i++) {
		if (r.Contains(p) || r.Contains(pIn) || r.Contains(pOut)) {
			temp.Add(i);
		}
	}
	// merge old and new selection
	count = fOldSelection->CountItems();
	for (int32 i = 0; i < count; i++) {
		int32 index = fOldSelection->IndexAt(i);
		if (temp.Contains(index))
			temp.Remove(index);
		else
			temp.Add(index);
	}
	if (temp != *fSelection) {
		*fSelection = temp;
		_UpdateSelection();
	}
}
Exemplo n.º 2
0
// ShowContextMenu
bool
PathManipulator::ShowContextMenu(BPoint where)
{
	// Change the selection to the current point if it isn't currently
	// selected. This could will only be chosen if the user right-clicked
	// a path point directly. 
	if (fCurrentPathPoint >= 0 && !fSelection->Contains(fCurrentPathPoint)) {
		fSelection->MakeEmpty();
		_UpdateSelection();
		*fOldSelection = *fSelection;
		_Select(fCurrentPathPoint, false);
	}

	BPopUpMenu* menu = new BPopUpMenu("context menu", false, false);
	BMessage* message;
	BMenuItem* item;

	bool hasSelection = fSelection->CountItems() > 0;

	if (fCurrentPathPoint < 0) {
		message = new BMessage(B_SELECT_ALL);
		item = new BMenuItem("Select All", message, 'A');
		menu->AddItem(item);
	
		menu->AddSeparatorItem();
	}

	message = new BMessage(MSG_TRANSFORM);
	item = new BMenuItem("Transform", message, 'T');
	item->SetEnabled(hasSelection);
	menu->AddItem(item);

	message = new BMessage(MSG_SPLIT_POINTS);
	item = new BMenuItem("Split", message);
	item->SetEnabled(hasSelection);
	menu->AddItem(item);

	message = new BMessage(MSG_FLIP_POINTS);
	item = new BMenuItem("Flip", message);
	item->SetEnabled(hasSelection);
	menu->AddItem(item);

	message = new BMessage(MSG_REMOVE_POINTS);
	item = new BMenuItem("Remove", message);
	item->SetEnabled(hasSelection);
	menu->AddItem(item);

	// go
	menu->SetTargetForItems(fCanvasView);
	menu->SetAsyncAutoDestruct(true);
	menu->SetFont(be_plain_font);
	where = fCanvasView->ConvertToScreen(where);
	BRect mouseRect(where, where);
	mouseRect.InsetBy(-10.0, -10.0);
	where += BPoint(5.0, 5.0);
	menu->Go(where, true, false, mouseRect, true);

	return true;
}
Exemplo n.º 3
0
// _Deselect
void
PathManipulator::_Deselect(int32 index)
{
	if (fSelection->Contains(index)) {
		fSelection->Remove(index);
		_UpdateSelection();
	}
}
Exemplo n.º 4
0
void
TracksCoordinator::_CleanupSelection()
{
	_UpdateSelection(-1, -1);
	InvalidateSelection();
	for (int32 i = 0; i < fSelectionQueue.CountItems(); i++)
		_RemoveFromSelection(fSelectionQueue.ItemAt(i));
}
Exemplo n.º 5
0
void
TracksCoordinator::NotifyMouseMoved(BPoint point, uint32 data,
	const BMessage* message, Render* who)
{
	if (fPrimaryButton) {
		if (!who->IsSelected())
			_AddToSelection(who);

		int64 frame = fStart+ScreenToFrame(point.x);
		if (frame < fPointer)
			_UpdateSelection(frame, fPointer);
		else
			_UpdateSelection(fPointer, frame);

		InvalidateSelection();
	}
}
Exemplo n.º 6
0
void
TracksCoordinator::NotifySelect(int64 start, int64 end, Render* who)
{
	//printf("Select all %" B_PRId64 " %" B_PRId64 "\n",
	//start, end);
	_CleanupSelection();
	_UpdateSelection(start, end);
	_AddToSelection(who);
	InvalidateTracks();
}
Exemplo n.º 7
0
// _Select
void
PathManipulator::_Select(int32 index, bool extend)
{
	if (!extend)
		fSelection->MakeEmpty();
	if (fSelection->Contains(index))
		fSelection->Remove(index);
	else
		fSelection->Add(index);
	// TODO: this can lead to unnecessary invalidation (maybe need to investigate)
	_UpdateSelection();
}
Exemplo n.º 8
0
// _ShiftSelection
void
PathManipulator::_ShiftSelection(int32 startIndex, int32 direction)
{
	int32 count = fSelection->CountItems();
	if (count > 0) {
		int32* selection = fSelection->Items();
		for (int32 i = 0; i < count; i++) {
			if (selection[i] >= startIndex) {
				selection[i] += direction;
			}
		}
	}
	_UpdateSelection();
}
Exemplo n.º 9
0
// _Select
void
PathManipulator::_Select(const int32* indices, int32 count, bool extend)
{
	if (extend) {
		for (int32 i = 0; i < count; i++) {
			if (!fSelection->Contains(indices[i]))
				fSelection->Add(indices[i]);
		}
	} else {
		fSelection->MakeEmpty();
		for (int32 i = 0; i < count; i++) {
			fSelection->Add(indices[i]);
		}
	}
	_UpdateSelection();
}
Exemplo n.º 10
0
// MouseDown
bool
PathManipulator::MouseDown(BPoint where)
{
	fMouseDown = true;

	if (fMode == TRANSFORM_POINTS) {
		if (fTransformBox) {
			fTransformBox->MouseDown(where);

//			if (!fTransformBox->IsRotating())
//				fCanvasView->SetAutoScrolling(true);
		}
		return true;
	}

	if (fMode == MOVE_POINT &&
		fSelection->CountItems() > 1 &&
		fSelection->Contains(fCurrentPathPoint)) {
		fMode = TRANSLATE_POINTS;
	}

	// apply the canvas view mouse filter depending on current mode
	if (fMode == ADD_POINT || fMode == TRANSLATE_POINTS)
		fCanvasView->FilterMouse(&where);

	BPoint canvasWhere = where;
	fCanvasView->ConvertToCanvas(&canvasWhere);

	// maybe we're changing some point, so we construct the
	// "ChangePointCommand" here so that the point is remembered
	// in its current state
	// apply the canvas view mouse filter depending on current mode
	delete fChangePointCommand;
	fChangePointCommand = NULL;
	switch (fMode) {
		case TOGGLE_SHARP:
		case TOGGLE_SHARP_IN:
		case TOGGLE_SHARP_OUT:
		case MOVE_POINT:
		case MOVE_POINT_IN:
		case MOVE_POINT_OUT:
		case REMOVE_POINT_IN:
		case REMOVE_POINT_OUT:
			fChangePointCommand = new ChangePointCommand(fPath,
														 fCurrentPathPoint,
														 fSelection->Items(),
														 fSelection->CountItems());
			_Select(fCurrentPathPoint, fShiftDown);
			break;
	}

	// at this point we init doing something
	switch (fMode) {
		case ADD_POINT:
			_AddPoint(canvasWhere);
			break;
		case INSERT_POINT:
			_InsertPoint(canvasWhere, fCurrentPathPoint);
			break;

		case TOGGLE_SHARP:
			_SetSharp(fCurrentPathPoint);
			// continue by dragging out the _connected_ in/out points
			break;
		case TOGGLE_SHARP_IN:
			_SetInOutConnected(fCurrentPathPoint, false);
			// continue by moving the "in" point
			_SetMode(MOVE_POINT_IN);
			break;
		case TOGGLE_SHARP_OUT:
			_SetInOutConnected(fCurrentPathPoint, false);
			// continue by moving the "out" point
			_SetMode(MOVE_POINT_OUT);
			break;

		case MOVE_POINT:
		case MOVE_POINT_IN:
		case MOVE_POINT_OUT:
			// the right thing happens since "fCurrentPathPoint"
			// points to the correct index
			break;

		case CLOSE_PATH:
//			SetClosed(true, true);
			break;

		case REMOVE_POINT:
			if (fPath->CountPoints() == 1) {
//				fCanvasView->Perform(new RemovePathCommand(this, fPath));
			} else {
				fCanvasView->Perform(new RemovePointsCommand(fPath,
															 fCurrentPathPoint,
															 fSelection->Items(),
															 fSelection->CountItems()));
				_RemovePoint(fCurrentPathPoint);
			}
			break;
		case REMOVE_POINT_IN:
			_RemovePointIn(fCurrentPathPoint);
			break;
		case REMOVE_POINT_OUT:
			_RemovePointOut(fCurrentPathPoint);
			break;

		case SELECT_POINTS: {
			// TODO: this works so that you can deselect all points
			// when clicking outside the path even if pressing shift
			// in case the path is open... a better way would be
			// to deselect all on mouse up, if the mouse has not moved
			bool appendSelection;
			if (fPath->IsClosed())
				appendSelection = fShiftDown;
			else
				appendSelection = fShiftDown && fCurrentPathPoint >= 0;

			if (!appendSelection) {
				fSelection->MakeEmpty();
				_UpdateSelection();
			}
			*fOldSelection = *fSelection;
			if (fCurrentPathPoint >= 0) {
				_Select(fCurrentPathPoint, appendSelection);
			}
			fCanvasView->BeginRectTracking(BRect(where, where),
				B_TRACK_RECT_CORNER);
			break;
		}
	}

	fTrackingStart = canvasWhere;
	// remember the subpixel position
	// so that MouseMoved() will work even before
	// the integer position becomes different
	fLastCanvasPos = where;
	fCanvasView->ConvertToCanvas(&fLastCanvasPos);

	// the reason to exclude the select mode
	// is that the BView rect tracking does not
	// scroll the rect starting point along with us
	// (since we're doing no real scrolling)
//	if (fMode != SELECT_POINTS)
//		fCanvasView->SetAutoScrolling(true);

	UpdateCursor();

	return true;
}