CurvesView::CurvesView(QObject *parent) :
    QGraphicsScene(parent)
{
    selectionFlag = false;
    currentSelection = NULL;
    lastSelected = NULL;
    zoomStarted = false;
    zoomFactor = 1;

    snapX = 0;
    snapY = 0;

    //add, delete
    addAction = new QAction(tr("&Add"), this);
    connect(addAction, SIGNAL(triggered()), this, SLOT(addPoint()));

    deleteAction = new QAction(tr("&Delete"), this);
    connect(deleteAction, SIGNAL(triggered()), this, SLOT(deletePoint()));

    //interpolation actions
    bezierAction = new QAction(tr("&Bezier"), this);
    bezierAction->setCheckable(true);
    connect(bezierAction, SIGNAL(triggered()), this, SLOT(setBezierInterpolation()));

    linearAction = new QAction(tr("&Linear"), this);
    linearAction->setCheckable(true);
    connect(linearAction, SIGNAL(triggered()), this, SLOT(setLinearInterpolation()));

    constantAction = new QAction(tr("&Constant"), this);
    constantAction->setCheckable(true);
    connect(constantAction, SIGNAL(triggered()), this, SLOT(setConstantInterpolation()));

    interpolationGroup = new QActionGroup(this);
    interpolationGroup->addAction(bezierAction);
    interpolationGroup->addAction(linearAction);
    interpolationGroup->addAction(constantAction);

    bezierAction->setChecked(true);

    connect(this, SIGNAL(selectionChanged()), this, SLOT(changeSelection())); 

    //display where is the current frame
    QPen frameCursorPen(Qt::SolidLine);
    frameCursorPen.setBrush(QBrush(qRgb(0,100,0), Qt::SolidPattern));
    frameCursorPen.setWidth(10);
    frameCursor = new CurveCursor(this,this,frameCursorPen);
    frameCursor->showCoord(false);

    /*
    display coordinates of points on curves,
    adding it to the scene after the frame cursor ensure that the coordinates
    will be shown on top
    */
    QPen curveCursorPen(Qt::DotLine);
    curveCursor = new CurveCursor(this,this,curveCursorPen);
    curveCursor->showHorizontal();
    connect(this, SIGNAL(scaleChanged(QPointF)), curveCursor, SLOT(counterSceneScale(QPointF)));

    connect(this, SIGNAL(scaleChanged(QPointF)), frameCursor, SLOT(counterSceneScale(QPointF)));
}
void
rce::gui::RImageMarkerScene::
deleteObject(quint32 id)
{


    deletePolygon(id);
    deletePolyline(id);
    deletePoint(id);

}
Ejemplo n.º 3
0
void DisplayObject::resize(int w, int h, int d){
    deletePoint();
    int l = w*h*d;
    cp.reserve(l);
    trfm_cp.reserve(l);
    for ( int i = 0; i<l; i++ ) {
        cp.push_back(new ColorPoint( i%w, int(i/w)%h, int(i/(w*h)) ));
        trfm_cp.push_back(new ColorPoint( i%w, int(i/w)%h, int(i/(w*h)) ));
    }
    width = w;
    height = h;
    depth = d;
}
void
rce::gui::RImageMarkerScene::
addPointObject(const QPointF &point,
         const QPen &pen,
         double size,
         quint32 id)
{
    deletePoint(id);

    rce::gui::RGraphicsCrossItem *newItem = new rce::gui::RGraphicsCrossItem(point,
                                                                             pen,
                                                                             size,
                                                                             NULL);
    addItem(newItem);

    newItem->setData(RCE_ITEM_TYPE_DATA_INDEX, PointType);
    newItem->setData(RCE_ITEM_ID_DATA_INDEX, id);
    newItem->setZValue(3);

    pointItems_[id] = newItem;
}
Ejemplo n.º 5
0
void simulatePoints(float grav_x, float grav_y) {
	int pointToDelete = -1;
	for (int i = 0; i < numPoints; i++) {
		point_buffer[i].x += point_buffer[i].vel_x;
		point_buffer[i].y += point_buffer[i].vel_y;
		point_buffer[i].rot += point_buffer[i].vel_rot;
		
		if (point_buffer[i].vel_x < 0.1f && point_buffer[i].vel_x > -0.1f && gravity_x < 0.01f && gravity_x > 0.01f) {
			point_buffer[i].vel_x = 1.0f;
		}
		
		
		point_buffer[i].vel_x += grav_x;
		point_buffer[i].vel_y += grav_y;
		
		if (point_buffer[i].y > screenHeight - radius && point_buffer[i].vel_y > 0) {
			point_buffer[i].vel_y = -point_buffer[i].vel_y * 0.9;
			point_buffer[i].vel_rot = -point_buffer[i].vel_rot * 1.05;
		}
		
		if (point_buffer[i].x < -50 || point_buffer[i].y < -50 || point_buffer[i].x > screenWidth + 50) {
			pointToDelete = i;
		}
	}
	
	if (pointToDelete > -1)
		deletePoint(pointToDelete);
	else if (numPoints < 300 && partyMode) {
		point newPoint;
		
		newPoint.x = rand() %100 + (screenWidth / 2 - 50);
		newPoint.y = rand() %50 + 10;
		newPoint.rot = 3.14f / (rand() %100);
		newPoint.vel_y = -2.0f + (rand() % 600) / 100.0f;
		newPoint.vel_x = -3.0f + (rand() % 600) / 100.0f;
		newPoint.vel_rot = -0.1f + (rand() % 1000) / 5000.0f;
		newPoint.texture_id = 4 + (rand() % 4);
		addPoint(newPoint);
	}
}
Ejemplo n.º 6
0
void mouse( int button, int state, int x, int y )
{
    if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {
        selectPoint(x,y);
        if (selected_point == -1)
        {
            addPoint(x,wY-y);
        }
    }

    if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
    {
        selectPoint(x,y);
        if (selected_point !=-1)
        {
            deletePoint(selected_point);
            selected_point = -1;
        }
    }
    glutPostRedisplay();
}
Ejemplo n.º 7
0
//==============================================================================
void PaintElementPath::setSubpathClosed (int index, const bool closed, const bool undoable)
{
    if (closed != isSubpathClosed (index))
    {
        for (int i = index + 1; i < points.size(); ++i)
        {
            PathPoint* p = points.getUnchecked (i);

            if (p->type == Path::Iterator::closePath)
            {
                jassert (! closed);

                deletePoint (i, undoable);
                return;
            }

            if (p->type == Path::Iterator::startNewSubPath)
            {
                jassert (closed);

                PathPoint* pp = addPoint (i - 1, undoable);

                PathPoint p2 (*pp);
                p2.type = Path::Iterator::closePath;
                perform (new ChangePointAction (pp, p2), "Close subpath");
                return;
            }
        }

        jassert (closed);

        PathPoint* p = addPoint (points.size() - 1, undoable);
        PathPoint p2 (*p);
        p2.type = Path::Iterator::closePath;
        perform (new ChangePointAction (p, p2), "Close subpath");
    }
}
Ejemplo n.º 8
0
int main ()
{
	//init list & set next node to NULL
	List *list;
	char i;
	int j, k;

	printf("Please choose function:\n");
	printf("(a) Create a list of points. ex: a 1 2, create a starting point (1,2).\n");
	printf("(b) Determine if a list is empty.\n");
	printf("(c) Insert a point at the end of a list. ex: c 1 2, insert a point (1,2) at the end.\n");
	printf("(d) Search for a point. ex: d 1 2, search for point (1,2).\n");
	printf("(e) Delete a point. ex: e 1 2, delete point (1,2).\n");
	printf("(f) Print out a list.\n");
	printf("(g) Count the number of points in a list.\n");
	while (1)
	{
		printf("=> ");
		do {
			scanf("%c", &i);
		} while (i == 32 || i == 10);

		if (i == 'a')
		{
			do
			{
				scanf("%d", &j);
			} while (j == 32 || j == 10);
			do
			{
				scanf("%d", &k);
			} while (k == 32 || k == 10);

			list = createList(list, j, k);
		}
		else if (i == 'b')
			isEmpty(list);
		else if (i == 'c')
		{
			do
			{
				scanf("%d", &j);
			} while (j == 32 || j == 10);
			do
			{
				scanf("%d", &k);
			} while (k == 32 || k == 10);

			insertAtTheEndOfList(list, j, k);
		}
		else if (i == 'd')
		{
			do
			{
				scanf("%d", &j);
			} while (j == 32 || j == 10);
			do
			{
				scanf("%d", &k);
			} while (k == 32 || k == 10);

			searchXY(list, j, k);
		}
		else if (i == 'e')
		{
			do
			{
				scanf("%d", &j);
			} while (j == 32 || j == 10);
			do
			{
				scanf("%d", &k);
			} while (k == 32 || k == 10);

			list = deletePoint(list, j, k);
		}
		else if (i == 'f')
			printOutList(list);
		else if (i == 'g')
			countTheNumberOfPointsInList(list);
	}

	return 0;
}
Ejemplo n.º 9
0
void FunctionEditor::constrain_in_bb(void)
{
	//if not in delete mode and something is selected
	if(selected!=-1)
	{
		//constrain start and end point at x(0) x(1) of function box
		bs.control_points[0].x = (float)delete_zone;
		bs.control_points[bs.control_points.size()-1].x = (float)delete_zone+size;

		//do not allow min 4 points to be moved to delete area (outside grey area)
		if(bs.control_points.size()==4)
		{
				//constrain points to (0,0) -> (1,1) box
				if(bs.control_points[selected].x<delete_zone) bs.control_points[selected].x= delete_zone;
				if(bs.control_points[selected].x>(size+delete_zone)) bs.control_points[selected].x= size+delete_zone;

				if(bs.control_points[selected].y<delete_zone) bs.control_points[selected].y= delete_zone;
				if(bs.control_points[selected].y>(size+delete_zone)) bs.control_points[selected].y= size+delete_zone;
		}
		//if we have more than four points these can be moved to delete area
		else
		{		
			//are we still in the delete buffer zone (grey area)
			if((bs.control_points[selected].y>(delete_zone/2))&&(bs.control_points[selected].y<(size+delete_zone+(delete_zone/2))))
			{		
				//constrain points to (0,0) -> (1,1) box
				if(bs.control_points[selected].y<delete_zone) bs.control_points[selected].y= delete_zone;
				if(bs.control_points[selected].y>size+delete_zone) bs.control_points[selected].y= size+delete_zone;
			}
			//if we moved outside delete buffer (grey area) produce a delete_event
			else
			{			
				//dont allow deletion of end points...
				if(selected==0 ||  selected==bs.control_points.size()-1)
				{
					if(bs.control_points[selected].y<delete_zone) bs.control_points[selected].y= delete_zone;
					if(bs.control_points[selected].y>size+delete_zone) bs.control_points[selected].y= size+delete_zone;
					return;
				}
				
				
				//save the point we want to delete, in case we dont really...
				v = bs.control_points[selected];

				x_min = bs.control_points[selected-1].x;
				x_max = bs.control_points[selected+1].x;

				//delete point from control po\ints (allows for delete preview)
				deletePoint();

				//generate the event
				delete_event=1;

				//select none of our cp
				selected =-1;
			}
		}
	}

	//if in delete mode
	if(delete_event==1)
	{
		//if our temp point is back to the delete buffer zone,
		//we dont want to delete it, so add it back
		if( (v.y>(delete_zone/2))&&(v.y<(size+delete_zone+(delete_zone/2))) )
		{
			//add the point back
			bs.control_points.push_back(v);
			bs.num_control_points++;

			//sort our points according to their x value
			quicksortPoints(0, bs.control_points.size()-1);			

			//find our inserted point
			for(int i=0; i<bs.control_points.size(); i++)
			{
				if(v.x==bs.control_points[i].x) selected = i;
			}

			//compute the new bspline
			bs.compute();

			//end delete event
			delete_event = 0;
		}
	}
}
Ejemplo n.º 10
0
void EditorScene::initKeyboardMouse()
{
    auto _keyboardListener = EventListenerKeyboard::create();
    _keyboardListener->onKeyPressed = [&](EventKeyboard::KeyCode code, Event* event){
        switch (code) {
            case EventKeyboard::KeyCode::KEY_SPACE:
                break;

            case EventKeyboard::KeyCode::KEY_R:
                _ks_addPoint = true;
                break;
            case EventKeyboard::KeyCode::KEY_T:
                _ks_deletePoint = true;
                break;
            case EventKeyboard::KeyCode::KEY_A:
                _ks_selection = true;
                break;
            case EventKeyboard::KeyCode::KEY_D:
                clearSelection();
                break;
            case EventKeyboard::KeyCode::KEY_W:
                moveUp(true);
                break;
            case EventKeyboard::KeyCode::KEY_S:
                moveUp(false);
                break;
            case EventKeyboard::KeyCode::KEY_F:
                _ks_shading = true;
                break;
            case EventKeyboard::KeyCode::KEY_G:
                _ks_digging = true;
                break;
            case EventKeyboard::KeyCode::KEY_X:
                _pointLayer->setVisible(!_pointLayer->isVisible());
                _rulerBg->setVisible(!_rulerBg->isVisible());
                break;

            case EventKeyboard::KeyCode::KEY_C:
                _copySrcIndex = _frameIndex;
                break;
            case EventKeyboard::KeyCode::KEY_V:
                plastFrame();
                break;

            case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
            case EventKeyboard::KeyCode::KEY_Q:
                prevFrame();
                break;

            case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
            case EventKeyboard::KeyCode::KEY_E:
                nextFrame();
                break;

            default:
                break;
        }
    };
    _keyboardListener->onKeyReleased = [&](EventKeyboard::KeyCode code, Event* event){
        switch (code) {
            case EventKeyboard::KeyCode::KEY_SPACE:
                break;

            case EventKeyboard::KeyCode::KEY_R:
                _ks_addPoint = false;
                break;
            case EventKeyboard::KeyCode::KEY_T:
                _ks_deletePoint = false;
                break;
            case EventKeyboard::KeyCode::KEY_A:
                _ks_selection = false;
                break;
            case EventKeyboard::KeyCode::KEY_F:
                _ks_shading = false;
                break;
            case EventKeyboard::KeyCode::KEY_G:
                _ks_digging = false;
                break;
            default:
                break;
        }
        
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(_keyboardListener, this);

    auto listener = EventListenerTouchOneByOne::create();

    listener->onTouchBegan = [this](Touch* touch, Event* event){
        auto rawpos = touch->getLocation();
        CCLOG("click in at %f %f", rawpos.x, rawpos.y);

        if (rawpos.y < 256) {
            diggColor(rawpos);

            return false;
        } else {

            if (_ks_addPoint) {
                addPoint(rawpos);
            } else if (_ks_deletePoint) {
                deletePoint(rawpos);
            } else if (_ks_selection) {
                selectPoint(rawpos, true);
            } else if (_ks_shading) {
                shadingTriangle(rawpos);
            } else if (_ks_digging) {
                diggColor(rawpos);
            } else {
                selectPoint(rawpos, false);
            }
        }

        return _selectedPoints.size() > 0;
    };

    listener->onTouchMoved = [this](Touch* touch, Event* event){

        auto move = touch->getDelta() ;//* 0.25;
        for (auto point : _selectedPoints) {
            point->sprite->setPosition(point->sprite->getPosition() + move);
            point->position = help_editPosition2relativePosition(point->sprite->getPosition());
        }
        this->delaunay();
        this->refreshLines();
        this->refreshTriangles();

    };

    listener->onTouchEnded = [this](Touch* touch, Event* event){
    };

    listener->onTouchCancelled = [this](Touch* touch, Event* event){
    };

    _pointLayer->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, _pointLayer);

}
Ejemplo n.º 11
0
BSplineCurveForm::BSplineCurveForm(GUIManager& guiManager, QWidget* parent)
	: Form(parent), m_guiManager(guiManager), m_currentPointIndex(-1) {

	QVBoxLayout* layout = new QVBoxLayout();
	this->setLayout(layout);

	m_controlPointInput = new VectorInput( "Next Point", false, true, false, this );
	m_controlPointInput->setValue( hpvec3(0.f, 0.f, 0.f) );
	layout->addWidget(m_controlPointInput);

	QPushButton* addPointButton  = new QPushButton("add control point");
	connect(addPointButton, SIGNAL(clicked()), this, SLOT(addPoint()));
	layout->addWidget(addPointButton);

	QPushButton* deletePointButton  = new QPushButton("delete current point");
	connect(deletePointButton, SIGNAL(clicked()), this, SLOT(deletePoint()));
	layout->addWidget(deletePointButton);

	QPushButton* interpolateButton  = new QPushButton("interpolate control points");
	connect(interpolateButton, SIGNAL(clicked()), this, SLOT(interpolate()));
	layout->addWidget(interpolateButton);

	m_periodicCheckBox = new QCheckBox("Periodic", this);
	m_periodicCheckBox->setCheckState(Qt::Unchecked);
	connect( m_periodicCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changePeriodic(int)) );
	layout->addWidget(m_periodicCheckBox);

	m_uniformCheckBox = new QCheckBox("Uniform", this);
	m_uniformCheckBox->setCheckState(Qt::Unchecked);
	connect( m_uniformCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changeUniform(int)) );
	layout->addWidget(m_uniformCheckBox);

	m_clampedCheckBox = new QCheckBox("Clamped", this);
	m_clampedCheckBox->setCheckState(Qt::Unchecked);
	connect( m_clampedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changeClamped(int)) );
	layout->addWidget(m_clampedCheckBox);

	QWidget* degreeWidget = new QWidget(this);
	m_degreeSpinBox = new QSpinBox(degreeWidget);
	m_degreeSpinBox->setMinimum(1);
	QGridLayout* degreeLayout = new QGridLayout();
	degreeLayout->addWidget( new QLabel("Degree: ", degreeWidget), 0,0 );
	degreeLayout->addWidget( m_degreeSpinBox, 0,1 );
	degreeWidget->setLayout(degreeLayout);
	connect( m_degreeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeDegree(int)) );
	layout->addWidget(degreeWidget);

	QWidget* planeWidget = new QWidget(this);
	layout->addWidget(planeWidget);
	QGridLayout* planeLayout = new QGridLayout();
	planeWidget->setLayout( planeLayout );
	m_planeLabel = new QLabel("Using standard plane", planeWidget);
	planeLayout->addWidget( m_planeLabel, 0,0 );
	/*
	QPushButton* planeButton = new QPushButton("reset", planeWidget);
	planeLayout->addWidget( planeButton, 0,1 );
	connect( planeButton, SIGNAL(clicked()), this, SLOT(resetPlane()) );
	*/
	// TODO connect to resetPlane() instead of reset()

	QPushButton* createButton  = new QPushButton("create curve");
	connect(createButton, SIGNAL(clicked()), this, SLOT(createCurve()));
	layout->addWidget(createButton);

	QPushButton* resetButton = new QPushButton("reset", this);
	layout->addWidget(resetButton);
	connect( resetButton, SIGNAL(clicked()), this, SLOT(reset()) );

	QWidget* empty = new QWidget();
	empty->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Expanding);
	layout->addWidget(empty);
	
	reset();
}