// removes control point near (x, y) if it exists
void GLWidget::removeControlPoint(float x, float y) {
    int selectIndex = getSelectedPoint(x, y);
    if (selectIndex != -1) {
        controlPoints.remove(selectIndex);
        updateCatmullRomSpline();
    }
}
Beispiel #2
0
void Controller::dragAnchorPoint(double x, double y){
	if(getPolygon(x,y) != NULL){
		deselectAllPoints();
		getSelectedPoint(x,y)->setSelection(true);
		glfwSetMousePosCallback(MousePosCallback);
	}
}
/* Selected control point to move using mouse */
GLvoid mouse_callback(GLint button, GLint state, GLint x, GLint y)
{
    if ((GLUT_LEFT_BUTTON == button) && (GLUT_DOWN == state))
    {
        leftBtnDown = GL_TRUE;
        //Select a control point
        selectedPointIndex = getSelectedPoint(x, y);
    }
    else if ((GLUT_LEFT_BUTTON == button) && (GLUT_UP == state))
    {
        leftBtnDown = GL_FALSE;
        selectedPointIndex = -1;
    }
    glutPostRedisplay();
}
void SplineEditorWidget::mousePressEvent(QMouseEvent *event)
{
    QGraphicsView::mousePressEvent(event);
    QList<QGraphicsItem *> items = _scene->selectedItems();
    if(items.size() > 0)
    {
        SplinePointWidget *splinePoint = dynamic_cast<SplinePointWidget*>( items.at(0) );
        emit pressedPoint( _spline->pointAt( splinePoint->pointIndex ) );

    }

    if(_is_shift_pressed)
    {
        std::cout << mapToScene(event->pos()).x() << "|" << mapToScene(event->pos()).y() << std::endl;

        if(event->buttons() == Qt::LeftButton)
        {
            if( isSplineExist() )
            {
                Spline &spline = getSpline();
                spline.push_back( QVector2D( mapToScene(event->pos()).x(), mapToScene(event->pos()).y() ) );
                setSpline( spline );

            }

        }

        if(event->buttons() == Qt::RightButton)
        {
            if( isSplineExist() )
            {
                if( isPointSelected() )
                {
                    Spline &spline = getSpline();
                    SplinePoint& selectedPoint = getSelectedPoint();
                    spline.remove( selectedPoint );
                    setSpline( spline );

                }
            }

        }
    }

}
void GLWidget::mousePressEvent(QMouseEvent *event)
{
    // right click to remove points
    if (event->button() == Qt::RightButton) {
        QPoint mpos = event->pos();
        removeControlPoint((float)mpos.x(), (float)mpos.y());
    }

    // left click and drag to to move points
    if (event->button() == Qt::LeftButton) {
        QPoint mpos = event->pos();
        int selectIndex = getSelectedPoint((float)mpos.x(), (float)mpos.y());
        if (selectIndex != -1) {
            selectedPointIndex = selectIndex;
            isPointSelected = true;
        } else {
            isPointSelected = false;
        }
    }
}
void PointEditor::mouseDown (const MouseEvent& e)
{
    int verticalPoint = getVerticalPoint(e.x);
    
    if (verticalPoint > -1)
    {
        points[verticalPoint].y = e.y;
        selectedPoint = verticalPoint;
    }
    else
    {
        selectedPoint = getSelectedPoint(e.x, e.y);
        
        if (selectedPoint == -1)
        {
            addPoint (e.x, e.y);
            sortPoints();
            
            sendChangeMessage();
        }
    }
    
    repaint();
}
Beispiel #7
0
void Controller::releaseDraggedAnchorPoint(void){
	if(getSelectedPoint() != NULL){
		getSelectedPoint()->setSelection(false);
	}
}
Beispiel #8
0
void Controller::setPointPosition(double x, double y){
	getSelectedPoint()->setPosition(x,y);
}
Beispiel #9
0
int gMuteChannel::handle(int e) {

	int ret = 0;
	int mouseX = Fl::event_x()-x();

	switch (e) {

		case FL_ENTER: {
			ret = 1;
			break;
		}

		case FL_MOVE: {
			selectedPoint = getSelectedPoint();
			redraw();
			ret = 1;
			break;
		}

		case FL_LEAVE: {
			draggedPoint  = -1;
			selectedPoint = -1;
			redraw();
			ret = 1;
			break;
		}

		case FL_PUSH: {

			/* left click on point: drag
			 * right click on point: delete
			 * left click on void: add */

			if (Fl::event_button1())  {

				if (selectedPoint != -1) {
					draggedPoint   = selectedPoint;
					previousXPoint = points.at(selectedPoint).x;
				}
				else {

					/* click on the grey area leads to nowhere */

					if (mouseX > pParent->coverX) {
						ret = 1;
						break;
					}

					/* click in the middle of a long mute_on (between two points): new actions
					 * must be added in reverse: first mute_off then mute_on. Let's find the
					 * next point from here. */

					unsigned nextPoint = points.size;
					for (unsigned i=0; i<points.size; i++) {
						if (mouseX < points.at(i).x) {
							nextPoint = i;
							break;
						}
					}

					/* next point odd = mute_on [click here] mute_off
					 * next point even = mute_off [click here] mute_on */

					int frame_a = mouseX * pParent->zoom;
					int frame_b = frame_a+2048;

					if (pParent->gridTool->isOn()) {
						frame_a = pParent->gridTool->getSnapFrame(mouseX);
						frame_b = pParent->gridTool->getSnapFrame(mouseX + pParent->gridTool->getCellSize());

						/* with snap=on a point can fall onto another */

						if (pointCollides(frame_a) || pointCollides(frame_b)) {
							ret = 1;
							break;
						}
					}

					/* ensure frame parity */

					if (frame_a % 2 != 0) frame_a++;
					if (frame_b % 2 != 0) frame_b++;

					/* avoid overflow: frame_b must be within the sequencer range. In that
					 * case shift the ON-OFF block */

					if (frame_b >= G_Mixer.totalFrames) {
						frame_b = G_Mixer.totalFrames;
						frame_a = frame_b-2048;
					}

					if (nextPoint % 2 != 0) {
						recorder::rec(pParent->chan->index, ACTION_MUTEOFF, frame_a);
						recorder::rec(pParent->chan->index, ACTION_MUTEON,  frame_b);
					}
					else {
						recorder::rec(pParent->chan->index, ACTION_MUTEON,  frame_a);
						recorder::rec(pParent->chan->index, ACTION_MUTEOFF, frame_b);
					}
					recorder::sortActions();

					mainWin->keyboard->setChannelWithActions((gSampleChannel*)pParent->chan->guiChannel); // update mainWindow
					extractPoints();
					redraw();
				}
			}
			else {

				/* delete points pair */

				if (selectedPoint != -1) {

					unsigned a;
					unsigned b;

					if (points.at(selectedPoint).type == ACTION_MUTEOFF) {
						a = selectedPoint-1;
						b = selectedPoint;
					}
					else {
						a = selectedPoint;
						b = selectedPoint+1;
					}

					//gLog("selected: a=%d, b=%d >>> frame_a=%d, frame_b=%d\n",
					//		a, b, points.at(a).frame, points.at(b).frame);

					recorder::deleteAction(pParent->chan->index, points.at(a).frame,	points.at(a).type, false); // false = don't check vals
					recorder::deleteAction(pParent->chan->index,	points.at(b).frame,	points.at(b).type, false); // false = don't check vals
					recorder::sortActions();

					mainWin->keyboard->setChannelWithActions((gSampleChannel*)pParent->chan->guiChannel); // update mainWindow
					extractPoints();
					redraw();
				}
			}
			ret = 1;
			break;
		}

		case FL_RELEASE: {

			if (draggedPoint != -1) {

				if (points.at(draggedPoint).x == previousXPoint) {
					//gLog("nothing to do\n");
				}
				else {

					int newFrame = points.at(draggedPoint).x * pParent->zoom;

					recorder::deleteAction(
							pParent->chan->index,
							points.at(draggedPoint).frame,
							points.at(draggedPoint).type,
							false);  // don't check values

					recorder::rec(
							pParent->chan->index,
							points.at(draggedPoint).type,
							newFrame);

					recorder::sortActions();

					points.at(draggedPoint).frame = newFrame;
				}
			}
			draggedPoint  = -1;
			selectedPoint = -1;

			ret = 1;
			break;
		}

		case FL_DRAG: {

			if (draggedPoint != -1) {

				/* constrain the point between two ends (leftBorder-point,
				 * point-point, point-rightBorder) */

				int prevPoint;
				int nextPoint;

				if (draggedPoint == 0) {
					prevPoint = 0;
					nextPoint = points.at(draggedPoint+1).x - 1;
					if (pParent->gridTool->isOn())
						nextPoint -= pParent->gridTool->getCellSize();
				}
				else
				if ((unsigned) draggedPoint == points.size-1) {
					prevPoint = points.at(draggedPoint-1).x + 1;
					nextPoint = pParent->coverX-x();
					if (pParent->gridTool->isOn())
						prevPoint += pParent->gridTool->getCellSize();
				}
				else {
					prevPoint = points.at(draggedPoint-1).x + 1;
					nextPoint = points.at(draggedPoint+1).x - 1;
					if (pParent->gridTool->isOn()) {
						prevPoint += pParent->gridTool->getCellSize();
						nextPoint -= pParent->gridTool->getCellSize();
					}
				}

				if (mouseX <= prevPoint)
					points.at(draggedPoint).x = prevPoint;
				else
				if (mouseX >= nextPoint)
					points.at(draggedPoint).x = nextPoint;
				else
				if (pParent->gridTool->isOn())
					points.at(draggedPoint).x = pParent->gridTool->getSnapPoint(mouseX)-1;
				else
					points.at(draggedPoint).x = mouseX;

				redraw();
			}
			ret = 1;
			break;
		}
	}


	return ret;
}
Beispiel #10
0
int gEnvelopeChannel::handle(int e) {

	/* Adding an action: no further checks required, just record it on frame
	 * mx*pParent->zoom. Deleting action is trickier: find the active
	 * point and derive from it the corresponding frame. */

	int ret = 0;
	int mx  = Fl::event_x()-x();  // mouse x
	int my  = Fl::event_y()-y();  // mouse y

	switch (e) {

		case FL_ENTER: {
			ret = 1;
			break;
		}

		case FL_MOVE: {
			selectedPoint = getSelectedPoint();
			redraw();
			ret = 1;
			break;
		}

		case FL_LEAVE: {
			draggedPoint  = -1;
			selectedPoint = -1;
			redraw();
			ret = 1;
			break;
		}

		case FL_PUSH: {

			/* left click on point: drag
			 * right click on point: delete
			 * left click on void: add */

			if (Fl::event_button1()) {

				if (selectedPoint != -1) {
					draggedPoint = selectedPoint;
				}
				else {

					/* top & border fix */

					if (my > h()-8) my = h()-8;
					if (mx > pParent->coverX-x()) mx = pParent->coverX-x();

					if (range == RANGE_FLOAT) {

						/* if this is the first point ever, add other two points at the beginning
						 * and the end of the range */

						if (points.size() == 0) {
							addPoint(0, 0, 1.0f, 0, 1);
							recorder::rec(pParent->chan->index, type, 0, 0, 1.0f);
							addPoint(G_Mixer.totalFrames, 0, 1.0f, pParent->coverX, 1);
							recorder::rec(pParent->chan->index, type, G_Mixer.totalFrames, 0, 1.0f);
						}

						/* line between 2 points y = (x-a) / (b-a); a = h() - 8; b = 1 */

						int frame   = mx * pParent->zoom;
						float value = (my - h() + 8) / (float) (1 - h() + 8);
						addPoint(frame, 0, value, mx, my);
						recorder::rec(pParent->chan->index, type, frame, 0, value);
						recorder::sortActions();
						sortPoints();
					}
					else {
						/// TODO
					}
					mainWin->keyboard->setChannelWithActions((gSampleChannel*)pParent->chan->guiChannel); // update mainWindow
					redraw();
				}
			}
			else {

				/* right click on point 0 or point size-1 deletes the entire envelope */

				if (selectedPoint != -1) {
					if (selectedPoint == 0 || (unsigned) selectedPoint == points.size()-1) {
						recorder::clearAction(pParent->chan->index, type);
						points.clear();
					}
					else {
						recorder::deleteAction(pParent->chan->index, points.at(selectedPoint).frame, type, false);
						recorder::sortActions();
						points.erase(points.begin() + selectedPoint);
					}
					mainWin->keyboard->setChannelWithActions((gSampleChannel*)pParent->chan->guiChannel); // update mainWindow
					redraw();
				}
			}

			ret = 1;
			break;
		}

		case FL_RELEASE: {
			if (draggedPoint != -1) {

				if (points.at(draggedPoint).x == previousXPoint) {
					//gLog("nothing to do\n");
				}
				else {
					int newFrame = points.at(draggedPoint).x * pParent->zoom;

					/* x edge correction */

					if (newFrame < 0)
						newFrame = 0;
					else if (newFrame > G_Mixer.totalFrames)
						newFrame = G_Mixer.totalFrames;

					/* vertical line check */

					int vp = verticalPoint(points.at(draggedPoint));
					if (vp == 1) 			 newFrame -= 256;
					else if (vp == -1) newFrame += 256;

					/*  delete previous point and record a new one */

					recorder::deleteAction(pParent->chan->index,	points.at(draggedPoint).frame, type, false);

					if (range == RANGE_FLOAT) {
						float value = (points.at(draggedPoint).y - h() + 8) / (float) (1 - h() + 8);
						recorder::rec(pParent->chan->index, type, newFrame, 0, value);
					}
					else {
						/// TODO
					}

					recorder::sortActions();
					points.at(draggedPoint).frame = newFrame;
					draggedPoint  = -1;
					selectedPoint = -1;
				}
			}
			ret = 1;
			break;
		}

		case FL_DRAG: {

			if (draggedPoint != -1) {

				/* y constraint */

				if (my > h()-8)
					points.at(draggedPoint).y = h()-8;
				else
				if (my < 1)
					points.at(draggedPoint).y = 1;
				else
					points.at(draggedPoint).y = my;

				/* x constraint
				 * constrain the point between two ends (leftBorder-point, point-point,
				 * point-rightBorder). First & last points cannot be shifted on x */

				if (draggedPoint == 0)
					points.at(draggedPoint).x = x()-8;
				else
				if ((unsigned) draggedPoint == points.size()-1)
					points.at(draggedPoint).x = pParent->coverX;
				else {
					int prevPoint = points.at(draggedPoint-1).x;
					int nextPoint = points.at(draggedPoint+1).x;
					if (mx <= prevPoint)
						points.at(draggedPoint).x = prevPoint;
					else
					if (mx >= nextPoint)
						points.at(draggedPoint).x = nextPoint;
					//else
					//	points.at(draggedPoint).x = mx;
					else {
						if (pParent->gridTool->isOn())
							points.at(draggedPoint).x = pParent->gridTool->getSnapPoint(mx)-1;
						else
							points.at(draggedPoint).x = mx;
					}
				}
				redraw();
			}

			ret = 1;
			break;
		}
	}

	return ret;
}