Exemplo n.º 1
0
void Container::mergeAnimation(Shape*& s1, Shape*& s2) {

	double s1speed = s1->animation()->getSpeedX();
	double s2speed = s2->animation()->getSpeedX();
	int s1size = s1->getSize();
	int s2size = s2->getSize();

	// both squares
	if (s1->getID() == SQUARE && s2->getID() == SQUARE) {

		if (s1speed >= s2speed && s1size <= s2size) {
			deleteShape(s1);
		}
		else {
			deleteShape(s2);
		}
	}
	// both diamonds
	else if (s1->getID() == DIAMOND && s1->getID() == DIAMOND) {
		if (s1speed >= s2speed && s1size >= s2size) {
			deleteShape(s2);
		}
		else {
			deleteShape(s1);
		}
	}
	// different shapes
	else {
		Shape* slowerShape = (s1speed <= s2speed) ? s1 : s2;
		deleteShape(slowerShape);
	}
}
Exemplo n.º 2
0
static void deleteShape(KShape *shape)
{
    KShapeContainer *container = dynamic_cast<KShapeContainer*>(shape);
    if (container) {
        foreach(KShape *shape, container->shapes())
            deleteShape(shape);
    }
    delete shape;
}
Exemplo n.º 3
0
void view::createAction()
{
	m_newAction = new QAction(tr("&New"), this);
	m_newAction->setIcon(QIcon(":/images/new.png"));
	m_newAction->setShortcut(QKeySequence::New);
	connect(m_newAction, SIGNAL(triggered()), this, SLOT(newFile()));

 	m_exitAction = new QAction(tr("&Exit"), this);
 	m_exitAction->setShortcut(tr("Ctrl+Q"));
	connect(m_exitAction, SIGNAL(triggered()), this, SLOT(close()));

	m_groupAction = new QAction(tr("&Group"), this);
	m_groupAction->setShortcut(tr("Ctrl+G"));
	connect(m_groupAction, SIGNAL(triggered()), this, SLOT(createGroupShape()));

	m_splitAction = new QAction(tr("&Split"), this);
	m_splitAction->setShortcut(tr("Ctrl+U"));
	connect(m_splitAction, SIGNAL(triggered()), this, SLOT(splitGroupShape()));

	m_deleteAction = new QAction(tr("&Delete"), this);
	m_deleteAction->setShortcut(tr("Delete"));
	connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteShape()));

	m_basicShapeAction = new QAction(tr("&BasicShape"), this);
	m_basicShapeAction->setShortcut(tr("Ctrl+Shift+B"));
	connect(m_basicShapeAction, SIGNAL(triggered()), this, SLOT(basicShapeToolBar()));

	m_complexShapeAction = new QAction(tr("&ComplexShape"), this);
	m_complexShapeAction->setShortcut(tr("Ctrl+Shift+C"));
	connect(m_complexShapeAction, SIGNAL(triggered()), this, SLOT(complexShapeToolBar()));

	m_showGrid = new QAction(tr("&Show"), this);
	m_showGrid->setShortcut(tr("Ctrl+Alt+S"));
	connect(m_showGrid, SIGNAL(triggered()), this, SLOT(drawGrid()));

	m_aboutAction = new QAction(tr("About"), this);
	connect(m_aboutAction, SIGNAL(triggered()), this, SLOT(about()));

	m_aboutQtAction = new QAction(tr("About &Qt"), this);
	m_aboutQtAction->setShortcut(tr("Ctrl+Shift+Q"));
	connect(m_aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));

	m_rectAction = new QAction(tr("Rect"), this);
	m_rectAction->setIcon(QIcon(":/images/rect.png"));
	connect(m_rectAction, SIGNAL(triggered()), this, SLOT(createRectShape()));

	m_circleAction = new QAction(tr("Circle"), this);
	m_circleAction->setIcon(QIcon(":/images/circle.png"));
	connect(m_circleAction, SIGNAL(triggered()), this, SLOT(createCircleShape()));

	m_triangleAction = new QAction(tr("Triangle"), this);
	m_triangleAction->setIcon(QIcon(":/images/triangle.png"));
	connect(m_triangleAction, SIGNAL(triggered()), this, SLOT(createTriangleShape()));
}
Exemplo n.º 4
0
void BulletShape::deleteShape(btCollisionShape* shape)
{
    if(shape!=NULL)
    {
        if(shape->isCompound())
        {
            btCompoundShape* ms = static_cast<btCompoundShape*>(shape);
            int a = ms->getNumChildShapes();
            for(int i=0; i <a;i++)
                deleteShape(ms->getChildShape(i));
        }
        delete shape;
    }
}
Exemplo n.º 5
0
bool handleButtons(float x, float y)
{
	if(translateButton.contains(x,y))
		transM = TRANS_TRANSLATION;
	else if(rotateButton.contains(x,y))
		transM = TRANS_ROTATION;
	else if(scaleButton.contains(x,y))
		transM = TRANS_SCALE;
	else if(XButton.contains(x,y))
		axisM = X_AXIS;
	else if(YButton.contains(x,y))
		axisM = Y_AXIS;
	else if(ZButton.contains(x,y))
		axisM = Z_AXIS;
	else if(tetraButton.contains(x,y))
		createShape(SHAPE_TETRAHEDRON);
	else if(cubeButton.contains(x,y))
		createShape(SHAPE_CUBE);
	else if(octButton.contains(x,y))
		createShape(SHAPE_OCTAHEDRON);
	else if(sphereButton.contains(x,y))
		createShape(SHAPE_SPHERE);
	else if(cylinderButton.contains(x,y))
		createShape(SHAPE_CYLINDER);
	else if(planeButton.contains(x,y))
		createShape(SHAPE_PLANE);
	else if(deleteButton.contains(x,y))
		deleteShape();
	else if(RButton.contains(x,y))
		colorM = COLOR_R;
	else if(GButton.contains(x,y))
		colorM = COLOR_G;
	else if(BButton.contains(x,y))
		colorM = COLOR_B;
	else if(loadButton.contains(x,y))
	{	
		idCounter = load("default.mcg", &listOfShapes);
		if(idCounter <= 0)
		{
			idCounter = 1;
			listOfShapes.clear();
		}
	}
	else if(saveButton.contains(x,y))
		save("default", listOfShapes);
	else return false;
	buttonCheck();
	return true;
}
Exemplo n.º 6
0
void MyPainter::mouseReleaseEvent(QMouseEvent* event)
{
    if(event->button() == Qt::LeftButton){
        qDebug("Mouse release");

        if( _shape )
        {
            _buffer2.fill( Qt::transparent );
            _shape->draw( _buffer2 );

            _shape->mouseReleaseEvent( event );
            qDebug("Mouse released sended to the shape");
        }

        // We call the paintEvent method
        update();

        deleteShape();
    }
}
Exemplo n.º 7
0
// destroy
void MBulletContext::clear(void)
{
	unsigned int i;
	unsigned int id;

	// delete constraints
	for(i=0; i<m_constraints.size(); i++){
		id = i;
		deleteConstraint(&id);
	}

	// remove the rigidbodies from the dynamics world and delete them
	for(i=0; i<m_collisionObjects.size(); i++){
		id = i;
		deleteObject(&id);
	}

	// delete collision shapes
	for(i=0; i<m_collisionShapes.size(); i++){
		id = i;
		deleteShape(&id);
	}

	m_collisionObjects.clear();
	m_collisionShapes.clear();
	m_constraints.clear();
	
	SAFE_DELETE(m_dynamicsWorld);
	SAFE_DELETE(m_solver);
	SAFE_DELETE(m_overlappingPairCache);
	SAFE_DELETE(m_dispatcher);
	SAFE_DELETE(m_collisionConfiguration);

	// create NULL id 0
	m_collisionShapes.push_back(NULL);
	m_collisionObjects.push_back(NULL);
	m_constraints.push_back(NULL);
}
Exemplo n.º 8
0
void MyPainter::mousePressEvent(QMouseEvent* event)
{
    if(event->button() == Qt::LeftButton){
        qDebug("Mouse pressed");

        // We check if the fill out color it's the same like background color to disable brush (fill out it's transparent)
        _brush.setStyle(Qt::NoBrush);
        if(_windowBackgroundColor != _brush.color()){
            _brush.setStyle(_brushStyle);
        }

        deleteShape();

        if ( !_shape )
        {
            // Create the shape to draw
            _shape = ShapeFactory::createShape(_shapeToDraw, _pen, _brush);

            if( _shape )
            {
                qDebug() << "Shape " << _shapeToDraw << " created";
                connect( _shape, SIGNAL(drawed()), this, SLOT(shapeDrawed()));
            }
        }
        else
        {
            qDebug() << "A shape already exist";
        }

        // Generate the mouse event to the shape
        if( _shape )
        {
            _shape->mousePressEvent( event );
            qDebug("Mouse press sended to the shape");
        }
    }
}
Exemplo n.º 9
0
// *********************************************************************************************************
void CDisplayerVisualShape::setActive(bool active)
{
	//H_AUTO(R2_CDisplayerVisualShape_setActive)
	if (active == _Active) return;
	if (!active)
	{
		deleteShape();
	}
	else
	{
		if (!_MapDeco.isAddedToMap() && _WorldMapDisplay)
		{
			CGroupMap *gm = CTool::getWorldMap();
			if (gm)
			{
				_MapDeco.setDisplayedInstance(getDisplayedInstance(), false);
				gm->addDeco(&_MapDeco);
				_MapDeco.invalidateCoords();
			}
		}
	}
	_Touched = true;
	_Active = active;
}
Exemplo n.º 10
0
void handleEvents()
{
	sf::Event Event;
	const sf::Input& Input = App->GetInput();
	bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
	while (App->GetEvent(Event))
	{
		// Close window : exit
		if (Event.Type == sf::Event::Closed)
			App->Close();
		//
		// Escape key : exit
		if (Event.Type == sf::Event::KeyPressed)
		{
			if(Event.Key.Code == sf::Key::Escape)
				App->Close();
			else if(Event.Key.Code == sf::Key::Delete)
				deleteShape();
			else if(Event.Key.Code == sf::Key::Up && selected != 0)
			{
				Shape* s = findShape(selected);
				switch(colorM)
				{
					case COLOR_R:
						s->color[0] = ffmin(1.0, s->color[0]+0.05); break;
					case COLOR_G:
						s->color[1] = ffmin(1.0, s->color[1]+0.05); break;
					case COLOR_B:
						s->color[2] = ffmin(1.0, s->color[2]+0.05); break;
				}	
			}
			else if(Event.Key.Code == sf::Key::Down && selected != 0)
			{
				Shape* s = findShape(selected);
				switch(colorM)
				{
					case COLOR_R:
						s->color[0] = ffmax(0.0, s->color[0]-0.05); break;
					case COLOR_G:
						s->color[1] = ffmax(0.0, s->color[1]-0.05); break;
					case COLOR_B:
						s->color[2] = ffmax(0.0, s->color[2]-0.05); break;
				}	
			}
		}

		// Resize event : adjust viewport
		if (Event.Type == sf::Event::Resized)
		{
			glViewport(0, 0, Event.Size.Width, Event.Size.Height);
			currentRes[0] = Event.Size.Width;
			currentRes[1] = Event.Size.Height;	
			update_perspective();
		}

		if (Event.Type == sf::Event::MouseButtonPressed)
		{	
			lastPos[0] = Event.MouseButton.X;
			lastPos[1] = Event.MouseButton.Y;
			float x = Event.MouseButton.X;
			float y = currentRes[1]-Event.MouseButton.Y;
			if(Event.MouseButton.Button == sf::Mouse::Left)
			{
				if(!handleButtons(x,y))
				{
					handleSelection(Event.MouseButton.X, Event.MouseButton.Y);
				}
			}

			if(Event.MouseButton.Button == sf::Mouse::Left && !shiftDown)
			{
				buttonDown[0] = 1;
			}
			if(Event.MouseButton.Button == sf::Mouse::Right)
				buttonDown[1] = 1;
			if(Event.MouseButton.Button == sf::Mouse::Middle)
				buttonDown[2] = 1;
			if(Event.MouseButton.Button == sf::Mouse::Left && shiftDown)
				buttonDown[2] = 1;
		}

		if (Event.Type == sf::Event::MouseButtonReleased)
		{
			if(Event.MouseButton.Button == sf::Mouse::Left && !shiftDown)
				buttonDown[0] = 0;
			if(Event.MouseButton.Button == sf::Mouse::Right)
				buttonDown[1] = 0;
			if(Event.MouseButton.Button == sf::Mouse::Middle)
				buttonDown[2] = 0;
			if(Event.MouseButton.Button == sf::Mouse::Left && shiftDown)
				buttonDown[2] = 0;
		}

		if (Event.Type == sf::Event::MouseMoved && (buttonDown[0] || buttonDown[1] || buttonDown[2]) )
		{
			int x = Event.MouseMove.X;
			int y = Event.MouseMove.Y;
			if(selected == 0)
			{
				if(buttonDown[0])
					camera.trackball_rotate(lastPos[0], lastPos[1], x, y, currentRes[0], currentRes[1]);
				if(buttonDown[1])
					camera.trackball_translate(lastPos[0], lastPos[1], x, y);
				if(buttonDown[2])
					camera.trackball_translate_z(lastPos[0], lastPos[1], x, y);
			}
			else
			{
				Shape* s = findShape(selected);
				float diff = (x-lastPos[0])-(y-lastPos[1]);
				vec3 v;
				switch(axisM)
				{
					case X_AXIS:
						v = vec3(diff,0.0,0.0); break;
					case Y_AXIS:
						v = vec3(0.0,diff,0.0); break;
					case Z_AXIS:
						v = vec3(0.0,0.0,diff); break;
				}
				switch(transM)
				{
					case TRANS_TRANSLATION:
						s->trans.trans += v*0.01; break;
					case TRANS_ROTATION:
						s->rot.trans += v*0.1; break;
					case TRANS_SCALE:
						s->scale.trans += v*0.01; break;
				}
			}
			lastPos[0] = x;
			lastPos[1] = y;
		}
	}
}
Exemplo n.º 11
0
ClipboardProxyShape::~ClipboardProxyShape()
{
    deleteShape(m_child);
}
Exemplo n.º 12
0
void BulletShape::unloadImpl()
{
    deleteShape(Shape);
}
Exemplo n.º 13
0
// *********************************************************************************************************
CDisplayerVisualShape::~CDisplayerVisualShape()
{
	deleteShape();
	deleteVisualCollisionEntity();
}
Exemplo n.º 14
0
void MapTool::
buttonCallback(int buttonSlotIndex,
               Vrui::InputDevice::ButtonCallbackData* cbData)
{
statsMan.start(StatsManager::EDITLINE);

    Geometry::Point<double,3> pos = getPosition();
    pos        = crusta->mapToUnscaledGlobe(pos);

    Shape*& curShape = crusta->getMapManager()->getActiveShape(toolId);

    if (cbData->newButtonState)
    {
        if (buttonSlotIndex==0)
        {
            switch (mode)
            {
                case MODE_IDLE:
                {
                    createShape(curShape, curControl, pos);
                    crusta->getMapManager()->updateActiveShape(toolId);
                    mode = MODE_DRAGGING;
                    break;
                }

                case MODE_SELECTING_CONTROL:
                {
                    selectControl(pos);
                    addControlPoint(curShape, curControl, pos);
                    mode = MODE_DRAGGING;
                    break;
                }

                case MODE_SELECTING_SHAPE:
                {
                    if (curShape != NULL)
                    {
                        deleteShape(curShape, curControl);
                    }
                    break;
                }

                default:
                    break;
            }
        }
        else
        {
            switch (mode)
            {
                case MODE_DRAGGING:
                {
                    removeControl(curShape, curControl);
                    //destroy empty shapes
                    if (curShape->getControlPoints().size()==0)
                    {
                        deleteShape(curShape, curControl);
                        mode = MODE_IDLE;
                    }
                    else
                        mode = MODE_SELECTING_CONTROL;
                    break;
                }

                case MODE_IDLE:
                case MODE_SELECTING_CONTROL:
                {
                    selectShape(pos);
                    mode = MODE_SELECTING_SHAPE;
                   break;
                }

                default:
                    break;
            }
        }
    }
    else
    {
        if (buttonSlotIndex==0)
        {
            switch (mode)
            {
                case MODE_DRAGGING:
                {
                    mode = MODE_SELECTING_CONTROL;
                    break;
                }

                default:
                    break;
            }
        }
        else
        {
            switch (mode)
            {
                case MODE_SELECTING_SHAPE:
                {
                    if (curShape != NULL)
                    {
                        mode = MODE_SELECTING_CONTROL;
                    }
                    else
                    {
                        mode = MODE_IDLE;
                    }
                    break;
                }

                default:
                    break;
            }
        }
    }

statsMan.stop(StatsManager::EDITLINE);
}
Exemplo n.º 15
0
BulletShape::~BulletShape()
{
    deleteShape(mCollisionShape);
}
Exemplo n.º 16
0
//--------------------------------------------------------------
void ofxMtlMapping2D::keyPressed(int key)
{
    // ----
    switch (key) {
        case 9:  // TAB
            //ofToggleFullscreen();
            break;
            
        case 'l':
            loadShapesList();
            break;
            
        case 'm':
            //ofxMtlMapping2DControls::mapping2DControls()->toggle();
            break;
            
        case 's':
            ofxMtlMapping2DControls::mapping2DControls()->save();
            saveShapesList();
            break;
            
        case 356:
            //left
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->left();
                }
            }
            break;
                
        case 357: //up
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->up();
                }
            }
            break;
        
        case 358: //right
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->right();
                }
            }
            break;
                
        case 359: //down
            if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape && ofxMtlMapping2DShape::activeVertexId >=0) {
                    ofxMtlMapping2DVertex::activeVertex->down();
                }
            }
            break;
            
        case 127:
            deleteShape();
            break;
            
        case 8:
            //deleteShape();
            break;
            
//        case 'b':
//            if ((ofxMtlMapping2DShape::activeShapeId + 1) >= ofxMtlMapping2DShapes::pmShapes.size()) {
//                ofxMtlMapping2DShapes::pmShapes[0]->setAsActiveShape();
//            } else {
//                ofxMtlMapping2DShapes::pmShapes[(ofxMtlMapping2DShape::activeShapeId + 1)]->setAsActiveShape();
//            }
//        break;

            
        case 'n':
            /*if (ofxMtlMapping2DControls::mapping2DControls()->editShapes()) {
                if(ofxMtlMapping2DShape::activeShape) {
                    ofxMtlMapping2DShape::activeVertexId++;
                    ofxMtlMapping2DShape::activeVertexId %= ofxMtlMapping2DShape::activeShape->vertices.size();
                    
                    //-----
                    if (ofxMtlMapping2DShape::activeShape->vertices.size() > ofxMtlMapping2DShape::activeVertexId)
                    {
                        list<ofxMtlMapping2DVertex*>::iterator it = ofxMtlMapping2DShape::activeShape->vertices.begin();
                        advance(it, ofxMtlMapping2DShape::activeVertexId);
                        ofxMtlMapping2DVertex* vertex = *it;
                        vertex->setAsActive();
                    }
                }
            }*/
            break;
    }
}
Exemplo n.º 17
0
BulletShape::~BulletShape()
{
    deleteShape(Shape);
}