Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
void
BListView::Select(int32 start, int32 finish, bool extend)
{
	if (_Select(start, finish, extend)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 3
0
void
BListView::Select(int32 index, bool extend)
{
	if (_Select(index, extend)) {
		SelectionChanged();
		InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
	}
}
Ejemplo n.º 4
0
void CPanelHistory::SetOriginal()
{
  int nCount = m_pComboHistory->GetCount();
  if(nCount)
  {
    nCount--;
    _Select(nCount);
  }
}
Ejemplo n.º 5
0
// _AddPoint
void
PathManipulator::_AddPoint(BPoint where)
{
	if (fPath->AddPoint(where)) {
		fCurrentPathPoint = fPath->CountPoints() - 1;

		delete fAddPointCommand;
		fAddPointCommand = new AddPointCommand(fPath, fCurrentPathPoint,
											   fSelection->Items(),
											   fSelection->CountItems());

		_Select(fCurrentPathPoint, fShiftDown);
	}
}
Ejemplo n.º 6
0
// _InsertPoint
void
PathManipulator::_InsertPoint(BPoint where, int32 index)
{
	double scale;

	BPoint point;
	BPoint pointIn;
	BPoint pointOut;

	BPoint previous;
	BPoint previousOut;
	BPoint next;
	BPoint nextIn;

	if (fPath->FindBezierScale(index - 1, where, &scale)
		&& scale >= 0.0 && scale <= 1.0
		&& fPath->GetPoint(index - 1, scale, point)) {

		fPath->GetPointAt(index - 1, previous);
		fPath->GetPointOutAt(index - 1, previousOut);
		fPath->GetPointAt(index, next);
		fPath->GetPointInAt(index, nextIn);

		where = scale_point(previousOut, nextIn, scale);

		previousOut = scale_point(previous, previousOut, scale);
		nextIn = scale_point(next, nextIn, 1 - scale);
		pointIn = scale_point(previousOut, where, scale);
		pointOut = scale_point(nextIn, where, 1 - scale);
		
		if (fPath->AddPoint(point, index)) {

			fPath->SetPointIn(index, pointIn);
			fPath->SetPointOut(index, pointOut);

			delete fInsertPointCommand;
			fInsertPointCommand = new InsertPointCommand(fPath, index,
														 fSelection->Items(),
														 fSelection->CountItems());

			fPath->SetPointOut(index - 1, previousOut);
			fPath->SetPointIn(index + 1, nextIn);

			fCurrentPathPoint = index;
			_ShiftSelection(fCurrentPathPoint, 1);
			_Select(fCurrentPathPoint, fShiftDown);
		}
	}
}
Ejemplo n.º 7
0
int connect_nonb(int sock_fd, const struct sockaddr *sa_ptr, socklen_t sa_len, int n_sec){
	int flags, n, error_;
	socklen_t len;
	fd_set rset, wset;
	struct timeval tval;

	flags = _Fcntl(sock_fd, F_GETFL, 0);
	_Fcntl(sock_fd, F_SETFL, flags | O_NONBLOCK);

	error_ = 0;

	n = connect(sock_fd, sa_ptr, sa_len);
	if(n < 0)
		if(errno != EINPROGRESS)
			return -1;

	if(n == 0)
		goto done;

	FD_ZERO(&rset);
	FD_SET(sock_fd, &rset);
	wset = rset;
	tval.tv_sec = n_sec;
	tval.tv_usec = 0;
	n = _Select(sock_fd+1, &rset, &wset, NULL, n_sec? &tval: NULL);
	printf("n=%d\n",n );
	if(n == 0){
		close(sock_fd);
		errno = ETIMEDOUT;
		return -1;
	}

	if(FD_ISSET(sock_fd, &rset) || FD_ISSET(sock_fd, &wset)){
		len = sizeof(error_);
		if(getsockopt(sock_fd, SOL_SOCKET, SO_ERROR, &error_, &len))
			return -1;
	}else{
		error("Select error: sock_fd not set");
	}
	done:
		_Fcntl(sock_fd, F_SETFL, flags);
		if(error_){
			close(sock_fd);
			errno = error_;
			return -1;
		}
		return 0;
}
Ejemplo n.º 8
0
// MessageReceived
bool
PathManipulator::MessageReceived(BMessage* message, Command** _command)
{
	bool result = true;
	switch (message->what) {
		case MSG_TRANSFORM:
			if (!fSelection->IsEmpty())
				_SetMode(TRANSFORM_POINTS);
			break;
		case MSG_REMOVE_POINTS:
			*_command = _Delete();
			break;
		case MSG_SPLIT_POINTS:
			*_command = new SplitPointsCommand(fPath,
											   fSelection->Items(),
											   fSelection->CountItems());
			break;
		case MSG_FLIP_POINTS:
			*_command = new FlipPointsCommand(fPath,
											  fSelection->Items(),
											  fSelection->CountItems());
			break;
		case B_SELECT_ALL: {
			*fOldSelection = *fSelection;
			fSelection->MakeEmpty();
			int32 count = fPath->CountPoints();
			for (int32 i = 0; i < count; i++)
				fSelection->Add(i);
			if (*fOldSelection != *fSelection) {
//				*_command = new SelectPointsCommand(this, fPath,
//												   fOldSelection->Items(),
//												   fOldSelection->CountItems(),
//												   fSelection->Items(),
//												   fSelection->CountItems()));
				count = fSelection->CountItems();
				int32 indices[count];
				memcpy(indices, fSelection->Items(), count * sizeof(int32));
				_Select(indices, count);
			}
			break;
		}
		default:
			result = false;
			break;
	}
	return result;
}
Ejemplo n.º 9
0
// MouseUp
Command*
PathManipulator::MouseUp()
{
	// prevent carrying out actions more than once by only
	// doing it if "fMouseDown" is true at the point of
	// entering this function
	if (!fMouseDown)
		return NULL;
	fMouseDown = false;

	if (fMode == TRANSFORM_POINTS) {
		if (fTransformBox) {
			return fTransformBox->MouseUp();
		}
		return NULL;
	}

	Command* command = NULL;

	switch (fMode) {

		case ADD_POINT:
			command = fAddPointCommand;
			fAddPointCommand = NULL;
			_SetMode(MOVE_POINT_OUT);
			break;

		case INSERT_POINT:
			command = fInsertPointCommand;
			fInsertPointCommand = NULL;
			break;

		case SELECT_POINTS:
			if (*fSelection != *fOldSelection) {
//				command = new SelectPointsCommand(this, fPath,
//												  fOldSelection->Items(),
//												  fOldSelection->CountItems(),
//												  fSelection->Items(),
//												  fSelection->CountItems()));
			}
			fCanvasView->EndRectTracking();
			break;

		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:
			command = fChangePointCommand;
			fChangePointCommand = NULL;
			break;

		case TRANSLATE_POINTS:
			if (!fNudgeCommand) {
				// select just the point that was clicked
				*fOldSelection = *fSelection;
				if (fCurrentPathPoint >= 0) {
					_Select(fCurrentPathPoint, fShiftDown);
				}
				if (*fSelection != *fOldSelection) {
//					command = new SelectPointsCommand(this, fPath,
//													  fOldSelection->Items(),
//													  fOldSelection->CountItems(),
//													  fSelection->Items(),
//													  fSelection->CountItems()));
				}
			} else {
				command = _FinishNudging();
			}
			break;
	}

	return command;
}
Ejemplo n.º 10
0
// MouseMoved
void
PathManipulator::MouseMoved(BPoint where)
{
	fCanvasView->FilterMouse(&where);
		// NOTE: only filter mouse coords in mouse moved, no other
		// mouse function
	BPoint canvasWhere = where;
	fCanvasView->ConvertToCanvas(&canvasWhere);

	// since the tablet is generating mouse moved messages
	// even if only the pressure changes (and not the actual mouse position)
	// we insert this additional check to prevent too much calculation
	if (fLastCanvasPos == canvasWhere)
		return;

	fLastCanvasPos = canvasWhere;

	if (fMode == TRANSFORM_POINTS) {
		if (fTransformBox) {
			fTransformBox->MouseMoved(where);
		}
		return;
	}

	if (fMode == CLOSE_PATH) {
		// continue by moving the point
		_SetMode(MOVE_POINT);
		delete fChangePointCommand;
		fChangePointCommand = new ChangePointCommand(fPath,
													 fCurrentPathPoint,
													 fSelection->Items(),
													 fSelection->CountItems());
	}

//	if (!fPrecise) {
//		float offset = fmod(fOutlineWidth, 2.0) / 2.0;
//		canvasWhere.point += BPoint(offset, offset);
//	}

	switch (fMode) {
		case ADD_POINT:
		case INSERT_POINT:
		case TOGGLE_SHARP:
			// drag the "out" control point, mirror the "in" control point
			fPath->SetPointOut(fCurrentPathPoint, canvasWhere, true);
			break;
		case MOVE_POINT:
			// drag all three control points at once
			fPath->SetPoint(fCurrentPathPoint, canvasWhere);
			break;
		case MOVE_POINT_IN:
			// drag in control point
			fPath->SetPointIn(fCurrentPathPoint, canvasWhere);
			break;
		case MOVE_POINT_OUT:
			// drag out control point
			fPath->SetPointOut(fCurrentPathPoint, canvasWhere);
			break;
		
		case SELECT_POINTS: {
			// change the selection
			BRect r;
			r.left = min_c(fTrackingStart.x, canvasWhere.x);
			r.top = min_c(fTrackingStart.y, canvasWhere.y);
			r.right = max_c(fTrackingStart.x, canvasWhere.x);
			r.bottom = max_c(fTrackingStart.y, canvasWhere.y);
			_Select(r);
			break;
		}

		case TRANSLATE_POINTS: {
			BPoint offset = canvasWhere - fTrackingStart;
			_Nudge(offset);
			fTrackingStart = canvasWhere;
			break;
		}
	}
}
Ejemplo n.º 11
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;
}