Esempio n. 1
0
void GameLayer::createPips() {
    // Create the pips
    for (int i = 0; i < PIP_COUNT; i++) {
        Size visibleSize = Director::getInstance()->getVisibleSize();
        Sprite *pipUp = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("pipe_up"));
        Sprite *pipDown = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("pipe_down"));
        Node *singlePip = Node::create();
        
        // bind to pair
        pipDown->setPosition(0, PIP_HEIGHT + PIP_DISTANCE);
		singlePip->addChild(pipDown, 0, DOWN_PIP);
        singlePip->addChild(pipUp, 0, UP_PIP);
        singlePip->setPosition(visibleSize.width + i*PIP_INTERVAL + WAIT_DISTANCE, this->getRandomHeight());
		auto body = PhysicsBody::create();
		auto shapeBoxDown = PhysicsShapeBox::create(pipDown->getContentSize(),PHYSICSSHAPE_MATERIAL_DEFAULT, Point(0, PIP_HEIGHT + PIP_DISTANCE));
		body->addShape(shapeBoxDown);
		body->addShape(PhysicsShapeBox::create(pipUp->getContentSize()));
		body->setDynamic(false);
		
		//ÉèÖÃÅöײ
		body->setCategoryBitmask(ColliderTypePip);  
		body->setCollisionBitmask(ColliderTypeBird);  
		body->setContactTestBitmask(ColliderTypeBird);  
		
		singlePip->setPhysicsBody(body);
        singlePip->setTag(PIP_NEW);
        
        this->addChild(singlePip);
        this->pips.push_back(singlePip);
    }
}
Esempio n. 2
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setupUi(this);

    QWidget *w = documentTabs->widget(0);
    documentTabs->removeTab(0);
    delete w;

    connect(actionOpen, SIGNAL(triggered()), this, SLOT(openDocument()));
    connect(actionClose, SIGNAL(triggered()), this, SLOT(closeDocument()));
    connect(actionNew, SIGNAL(triggered()), this, SLOT(newDocument()));
    connect(actionSave, SIGNAL(triggered()), this, SLOT(saveDocument()));
    connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
    connect(actionRed, SIGNAL(triggered()), this, SLOT(setShapeColor()));
    connect(actionGreen, SIGNAL(triggered()), this, SLOT(setShapeColor()));
    connect(actionBlue, SIGNAL(triggered()), this, SLOT(setShapeColor()));
    connect(actionAddCircle, SIGNAL(triggered()), this, SLOT(addShape()));
    connect(actionAddRectangle, SIGNAL(triggered()), this, SLOT(addShape()));
    connect(actionAddTriangle, SIGNAL(triggered()), this, SLOT(addShape()));
    connect(actionRemoveShape, SIGNAL(triggered()), this, SLOT(removeShape()));
    connect(actionAddRobot, SIGNAL(triggered()), this, SLOT(addRobot()));
    connect(actionAddSnowman, SIGNAL(triggered()), this, SLOT(addSnowman()));
    connect(actionAbout, SIGNAL(triggered()), this, SLOT(about()));
    connect(actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt()));

    connect(undoLimit, SIGNAL(valueChanged(int)), this, SLOT(updateActions()));
    connect(documentTabs, SIGNAL(currentChanged(int)), this, SLOT(updateActions()));

    actionOpen->setShortcut(QString("Ctrl+O"));
    actionClose->setShortcut(QString("Ctrl+W"));
    actionNew->setShortcut(QString("Ctrl+N"));
    actionSave->setShortcut(QString("Ctrl+S"));
    actionExit->setShortcut(QString("Ctrl+Q"));
    actionRemoveShape->setShortcut(QString("Del"));
    actionRed->setShortcut(QString("Alt+R"));
    actionGreen->setShortcut(QString("Alt+G"));
    actionBlue->setShortcut(QString("Alt+B"));
    actionAddCircle->setShortcut(QString("Alt+C"));
    actionAddRectangle->setShortcut(QString("Alt+L"));
    actionAddTriangle->setShortcut(QString("Alt+T"));

    m_undoGroup = new QUndoGroup(this);
    undoView->setGroup(m_undoGroup);
    undoView->setCleanIcon(QIcon(":/icons/ok.png"));

    QAction *undoAction = m_undoGroup->createUndoAction(this);
    QAction *redoAction = m_undoGroup->createRedoAction(this);
    undoAction->setIcon(QIcon(":/icons/undo.png"));
    redoAction->setIcon(QIcon(":/icons/redo.png"));
    menuShape->insertAction(menuShape->actions().at(0), undoAction);
    menuShape->insertAction(undoAction, redoAction);

    toolBar->addAction(undoAction);
    toolBar->addAction(redoAction);

    newDocument();
    updateActions();
};
void TestPACopyPastePage::copyPasteSinglePage()
{
    MockDocument doc;

    KoPAMasterPage * master1 = new KoPAMasterPage();
    doc.insertPage( master1, 0 );

    KoPAPage * page1 = new KoPAPage( master1 );
    doc.insertPage( page1, 0 );

    addShape( page1 );

    QList<KoPAPageBase *> pages;
    pages.append( page1 );
    copyAndPaste( &doc, pages, page1 );

    QCOMPARE( doc.pages( true ).size(), 1 );
    QCOMPARE( doc.pages( false ).size(), 2 );
    QVERIFY( doc.pages( false ).front() == page1 );

    KoPAPageBase * page2 = doc.pages( false ).last();
    QVERIFY( dynamic_cast<KoPAPage*>( page2 )->masterPage() == master1 );

    copyAndPaste( &doc, pages, page1 );

    QCOMPARE( doc.pages( true ).size(), 1 );
    QCOMPARE( doc.pages( false ).size(), 3 );
    QVERIFY( doc.pages( false )[0] == page1 );
    QVERIFY( doc.pages( false )[2] == page2 );

    KoPAPageBase * page3 = doc.pages( false )[1];
    QVERIFY( dynamic_cast<KoPAPage*>( page3 )->masterPage() == master1 );

    QVERIFY( page1 != page2 );
    QVERIFY( page1 != page3 );
    QVERIFY( page2 != page3 );

    copyAndPaste( &doc, pages, 0 );

    QCOMPARE( doc.pages( true ).size(), 1 );
    QCOMPARE( doc.pages( false ).size(), 4 );
    QVERIFY( doc.pages( false )[1] == page1 );
    QVERIFY( doc.pages( false )[2] == page3 );
    QVERIFY( doc.pages( false )[3] == page2 );

    QMimeData * data = copy( &doc, pages );
    addShape( master1 );
    paste( &doc, data, page1 );

    QCOMPARE( doc.pages( true ).size(), 2 );
    QVERIFY( doc.pages( true )[0] == master1 );
    QCOMPARE( doc.pages( false ).size(), 5 );
    QVERIFY( doc.pages( false )[1] == page1 );
    QVERIFY( doc.pages( false )[3] == page3 );
    QVERIFY( doc.pages( false )[4] == page2 );
}
/// KoTextOnShapeContainer
KoTextOnShapeContainer::KoTextOnShapeContainer(KoShape *childShape, KoResourceManager *documentResources)
    : KoShapeContainer(*(new KoTextOnShapeContainerPrivate(this)))
{
    Q_D(KoTextOnShapeContainer);
    Q_ASSERT(childShape);
    d->content = childShape;

    setSize(childShape->size());
    setZIndex(childShape->zIndex());
    setTransformation(childShape->transformation());
    if (childShape->parent()) {
        childShape->parent()->addShape(this);
        childShape->setParent(0);
    }

    childShape->setPosition(QPointF()); // since its relative to my position, this won't move it
    childShape->setSelectable(false);

    d->model = new KoTextOnShapeContainerModel(this, d);
    addShape(childShape);

    QSet<KoShape*> delegates;
    delegates << childShape;
    KoShapeFactoryBase *factory = KoShapeRegistry::instance()->get("TextShapeID");
    if (factory) { // not installed, thats too bad, but allowed
        d->textShape = factory->createDefaultShape(documentResources);
        Q_ASSERT(d->textShape); // would be a bug in the text shape;
        if (d->resizeBehavior == TextFollowsPreferredTextRect) {
            d->textShape->setSize(d->preferredTextRect.size());
        } else {
            d->textShape->setSize(size());
        }
        d->textShape->setTransformation(childShape->transformation());
        if (d->resizeBehavior == TextFollowsPreferredTextRect) {
            d->textShape->setPosition(d->preferredTextRect.topLeft());
        }
        KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(d->textShape->userData());
        Q_ASSERT(shapeData); // would be a bug in kotext
        shapeData->setVerticalAlignment(Qt::AlignVCenter);
        addShape(d->textShape);
        d->textShape->setZIndex(childShape->zIndex() + 1);
        d->textShape->setSelectable(false);
        delegates << d->textShape;
    } else {
        kWarning(30006) << "Text shape factory not found";
    }

    static_cast<KoTextOnShapeContainerModel*>(d->model)->lock = false;

    setToolDelegates(delegates);
}
Esempio n. 5
0
KoPAPageBase::KoPAPageBase()
: KoShapeContainer( new KoPAPageContainerModel() )
{
    // Add a default layer
    KoShapeLayer* layer = new KoShapeLayer;
    addShape(layer);
}
Esempio n. 6
0
Handle <Device::RTShape> Renderer::addShape(Device::RTMaterial material, Device::RTShape shape, const ofMatrix4x4 & t) {
    AffineSpace3f space = AffineSpace3f( LinearSpace3f(t(0,0), t(1,0), t(2,0),
                                         t(0,1), t(1,1), t(2,1),
                                         t(0,2), t(1,2), t(2,2)),
                                         Vec3f(t(3,0), t(3,1), t(3,2)));
    return addShape(material, shape, space);
}
Esempio n. 7
0
void PhysicsWorld::addChild(PhysicsBody* body)
{
    auto shapes = body->getShapes();
    
    // add body to space
    if (body->isDynamic())
    {
        cpSpaceAddBody(_info->space, body->_info->body);
    }
    
    // add shapes to space
    for (auto it = shapes.begin(); it != shapes.end(); it++)
    {
        addShape(*it);
    }
    
    if (_bodys == nullptr)
    {
        _bodys = Array::create(body, NULL);
        _bodys->retain();
    }else
    {
        _bodys->addObject(body);
    }
}
Esempio n. 8
0
bool MgCmdDrawLines::touchEnded(const MgMotion* sender)
{
    Point2d pnt(snapPoint(sender));
    dynshape()->shape()->setPoint(m_index, pnt);
    
    bool closed = checkClosed(sender, pnt);
    MgBaseLines* lines = (MgBaseLines*)dynshape()->shape();
    
    dynshape()->shape()->update();
    
    if (canAddPoint(sender, pnt)) {
        if (closed || needEnded()) {
            if (closed) {
                lines->removePoint(m_step);
            }
            addShape(sender);
            m_step = 0;
            _lastClicked = false;
        }
        else if (m_step <= dynshape()->shape()->getPointCount()) {
            m_step++;
        }
    }
    else if (m_step > 1) {
        if (m_step >= dynshape()->shape()->getPointCount()) {
            m_step--;
        }
        lines->removePoint(m_index);
    }
    
    return MgCommandDraw::touchEnded(sender);
}
Esempio n. 9
0
// handle events
void Controller::handleEvents(const sf::Event& event)
{
	switch (event.type)
	{
	case sf::Event::Closed: // X button has been pressed
		exit(EXIT_SUCCESS);
		break;

	case sf::Event::MouseButtonPressed: // Mouse Button pressed:
		// on canvas
		if (_canvas.is_in_canvas(event.mouseButton.x, event.mouseButton.y))
			addShape(event.mouseButton.x, event.mouseButton.y);

		else // on menu
			for (unsigned i = 0; i < _menus.size(); i++)
				_menus[i]->execute(event.mouseButton.x, event.mouseButton.y); // execute button command
		break;

	case sf::Event::MouseMoved: // moving mouse. save mouse position and display coordinates if on canvas
		if (_canvas.is_in_canvas(event.mouseMove.x, event.mouseMove.y))
		{
			_mouse_pos.x = event.mouseMove.x;
			_mouse_pos.y = event.mouseMove.y;
		}
		else // not on canvas
		{
			_mouse_pos.x = BAD;
			_mouse_pos.y = BAD;
		}

		break;
	}
}
Esempio n. 10
0
void MeshEditorInstance::deserializeShapes(const RJNode& data)
{
    lock();

    SPhysVolume* firstVolume = nullptr;

    for(const RJNode& volumeJson : data)
    {
        std::string name = si::read(volumeJson, "name", DV_STRING);
        std::string shapeStr = si::read(volumeJson, "shape", DV_STRING);
        EPhysShape shape = physShape::fromString(shapeStr);

        if(SPhysVolume* volume = addShape(name, shape))
        {
            volume->color = si::read(volumeJson, "color", DV_COLOR);
            volume->location = si::read(volumeJson, "location", DV_GLMVEC3);
            volume->rotation = si::read(volumeJson, "rotation", DV_GLMVEC3);
            volume->scale = si::read(volumeJson, "scale", DV_GLMVEC3);

            if(!volume)
            {
                firstVolume = volume;
            }
        }
    }

    // This also resets cursor to volume properties so it won't override deserialized data.
    setSelectedShapeInternal(firstVolume);

    unlock();
}
Esempio n. 11
0
bool MgCmdDrawFreeLines::touchEnded(const MgMotion* sender)
{
    MgBaseLines* lines = (MgBaseLines*)dynshape()->shape();
    
    float closelen  = sender->displayMmToModel(5.f);
    float closedist = sender->pointM.distanceTo(dynshape()->shape()->getPoint(0));
    bool  closed    = (m_step > 2 && closedist < closelen
        && dynshape()->shape()->getExtent().width() > closedist * 1.5f
        && dynshape()->shape()->getExtent().height() > closedist * 1.5f);
    
    if (m_step > 2 && dynshape()->shape()->isClosed() != closed) {
        lines->setClosed(closed);
        if (closed)
            lines->removePoint(m_step);
        else
            lines->addPoint(sender->pointM);
    }
    if (!closed) {
        dynshape()->shape()->setPoint(m_step, sender->pointM);
        if (m_step > 0 && !canAddPoint(sender, true))
            lines->removePoint(m_step);
    }
    dynshape()->shape()->update();
    
    if (m_step > 1) {
        addShape(sender);
    }
    else {
        click(sender);  // add a point
    }
    delayClear(sender);

    return MgCommandDraw::touchEnded(sender);
}
Esempio n. 12
0
bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/)
{
    cpVect* vec = nullptr;
    do
    {
        _type = Type::EDGECHAIN;
        
        vec = new (std::nothrow) cpVect[count];
        PhysicsHelper::points2cpvs(points, vec, count);
        
        int i = 0;
        for (; i < count - 1; ++i)
        {
            auto shape = cpSegmentShapeNew(s_sharedBody, vec[i], vec[i + 1], border);
            CC_BREAK_IF(shape == nullptr);
            cpShapeSetUserData(shape, this);
            cpShapeSetElasticity(shape, 1.0f);
            cpShapeSetFriction(shape, 1.0f);
            addShape(shape);
        }
        CC_SAFE_DELETE_ARRAY(vec);
        CC_BREAK_IF(i < count - 1);
        
        _mass = PHYSICS_INFINITY;
        _moment = PHYSICS_INFINITY;
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    CC_SAFE_DELETE_ARRAY(vec);
    
    return false;
}
Esempio n. 13
0
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: openDocument(); break;
        case 1: saveDocument(); break;
        case 2: closeDocument(); break;
        case 3: newDocument(); break;
        case 4: addShape(); break;
        case 5: removeShape(); break;
        case 6: setShapeColor(); break;
        case 7: addSnowman(); break;
        case 8: addRobot(); break;
        case 9: about(); break;
        case 10: aboutQt(); break;
        case 11: updateActions(); break;
        default: ;
        }
        _id -= 12;
    }
    return _id;
}
Esempio n. 14
0
bool PhysicsShapeEdgeSegment::init(const Vec2& a, const Vec2& b, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/)
{
    do
    {
        _type = Type::EDGESEGMENT;
        
        auto shape = cpSegmentShapeNew(s_sharedBody,
                                           PhysicsHelper::point2cpv(a),
                                           PhysicsHelper::point2cpv(b),
                                           border);
        CC_BREAK_IF(shape == nullptr);
        cpShapeSetUserData(shape, this);
        
        addShape(shape);
        
        _mass = PHYSICS_INFINITY;
        _moment = PHYSICS_INFINITY;
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    return false;
}
Esempio n. 15
0
bool PhysicsShapePolygon::init(const Vec2* points, int count, const PhysicsMaterial& material/* = MaterialDefault*/, const Vec2& offset/* = Vec2(0, 0)*/)
{
    do
    {
        _type = Type::POLYGEN;
        
        auto vecs = new cpVect[count];
        PhysicsHelper::points2cpvs(points, vecs, count);
        auto shape = cpPolyShapeNew(s_sharedBody, count, vecs, PhysicsHelper::point2cpv(offset));
        CC_SAFE_DELETE_ARRAY(vecs);
        
        CC_BREAK_IF(shape == nullptr);
        
        addShape(shape);
        
        _area = calculateArea();
        _mass = material.density == PHYSICS_INFINITY ? PHYSICS_INFINITY : material.density * _area;
        _moment = calculateDefaultMoment();
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    return false;
}
Esempio n. 16
0
bool PhysicsShapeBox::init(const Size& size, const PhysicsMaterial& material/* = MaterialDefault*/, const Vec2& offset /*= Vec2(0, 0)*/, float radius/* = 0.0f*/)
{
    do
    {
        _type = Type::BOX;
        
        auto wh = PhysicsHelper::size2cpv(size);
        cpVect vec[4] =
        {
            {-wh.x/2.0f, -wh.y/2.0f}, {-wh.x/2.0f, wh.y/2.0f}, {wh.x/2.0f, wh.y/2.0f}, {wh.x/2.0f, -wh.y/2.0f}
        };
        
        cpTransform transform = cpTransformTranslate(PhysicsHelper::point2cpv(offset));
        
        auto shape = cpPolyShapeNew(s_sharedBody, 4, vec, transform, radius);
        CC_BREAK_IF(shape == nullptr);
        cpShapeSetUserData(shape, this);
        
        addShape(shape);
        
        _area = calculateArea();
        _mass = material.density == PHYSICS_INFINITY ? PHYSICS_INFINITY : material.density * _area;
        _moment = calculateDefaultMoment();
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    return false;
}
Esempio n. 17
0
bool PhysicsShapePolygon::init(const Vec2* points, int count, const PhysicsMaterial& material/* = MaterialDefault*/, const Vec2& offset/* = Vec2(0, 0)*/, float radius/* = 0.0f*/)
{
    do
    {
        _type = Type::POLYGEN;
        
        auto vecs = new (std::nothrow) cpVect[count];
        PhysicsHelper::points2cpvs(points, vecs, count);        //count = cpConvexHull((int)count, vecs, nullptr, nullptr, 0);
        cpTransform transform = cpTransformTranslate(PhysicsHelper::point2cpv(offset));
        auto shape = cpPolyShapeNew(s_sharedBody, count, vecs, transform, radius);
        CC_SAFE_DELETE_ARRAY(vecs);
        
        CC_BREAK_IF(shape == nullptr);
        cpShapeSetUserData(shape, this);
        
        addShape(shape);
        
        _area = calculateArea();
        _mass = material.density == PHYSICS_INFINITY ? PHYSICS_INFINITY : material.density * _area;
        _moment = calculateDefaultMoment();
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    return false;
}
Esempio n. 18
0
bool PhysicsShapeEdgeBox::init(const Size& size, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/, const Vec2& offset/*= Vec2(0, 0)*/)
{
    do
    {
        _type = Type::EDGEBOX;
        
        cpVect vec[4] = {};
        vec[0] = PhysicsHelper::point2cpv(Vec2(-size.width/2+offset.x, -size.height/2+offset.y));
        vec[1] = PhysicsHelper::point2cpv(Vec2(+size.width/2+offset.x, -size.height/2+offset.y));
        vec[2] = PhysicsHelper::point2cpv(Vec2(+size.width/2+offset.x, +size.height/2+offset.y));
        vec[3] = PhysicsHelper::point2cpv(Vec2(-size.width/2+offset.x, +size.height/2+offset.y));
        
        int i = 0;
        for (; i < 4; ++i)
        {
            auto shape = cpSegmentShapeNew(s_sharedBody, vec[i], vec[(i + 1) % 4], border);
            CC_BREAK_IF(shape == nullptr);
            cpShapeSetUserData(shape, this);
            addShape(shape);
        }
        CC_BREAK_IF(i < 4);
        
        _mass = PHYSICS_INFINITY;
        _moment = PHYSICS_INFINITY;
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    return false;
}
Esempio n. 19
0
ShrinkToFitShapeContainer::ShrinkToFitShapeContainer(KoShape *childShape, KoDocumentResourceManager *documentResources)
    : KoShapeContainer(*(new ShrinkToFitShapeContainerPrivate(this, childShape)))
{
    Q_UNUSED(documentResources);
    Q_D(ShrinkToFitShapeContainer);

    setPosition(childShape->position());
    setSize(childShape->size());
    setZIndex(childShape->zIndex());
    setRunThrough(childShape->runThrough());
    rotate(childShape->rotation());
    //setTransformation(childShape->transformation());

    if (childShape->parent()) {
        childShape->parent()->addShape(this);
        childShape->setParent(0);
    }

    childShape->setPosition(QPointF(0.0,0.0)); // since its relative to my position, this won't move it
    childShape->setSelectable(false); // our ShrinkToFitShapeContainer will handle that from now on

    d->model = new ShrinkToFitShapeContainerModel(this, d);
    addShape(childShape);

    QSet<KoShape*> delegates;
    delegates << childShape;
    setToolDelegates(delegates);

    KoTextShapeData* data = dynamic_cast<KoTextShapeData*>(childShape->userData());
    Q_ASSERT(data);
    KoTextDocumentLayout *lay = qobject_cast<KoTextDocumentLayout*>(data->document()->documentLayout());
    Q_ASSERT(lay);
    QObject::connect(lay, SIGNAL(finishedLayout()), static_cast<ShrinkToFitShapeContainerModel*>(d->model), SLOT(finishedLayout()));
}
Esempio n. 20
0
PyShape *PyLink::addCube(double x, double y, double z)
{
    PyShape *shape = new PyShape();
    loadCube(shape, x,y,z);
    addShape(shape);
    return shape;
}
void TestPACopyPastePage::copyPasteMixedPages()
{
    MockDocument doc;

    KoPAMasterPage * master1 = new KoPAMasterPage();
    doc.insertPage( master1, 0 );

    KoPAPage * page1 = new KoPAPage( master1 );
    doc.insertPage( page1, 0 );

    KoPAMasterPage * master2 = new KoPAMasterPage();
    doc.insertPage( master2, master1 );

    QList<KoPAPageBase *> pages;
    pages.append( page1 );
    pages.append( master2 );
    QMimeData * data = copy( &doc, pages );
    addShape( master2 );
    paste( &doc, data, page1 );

    QVERIFY( doc.pages( false ).size() == 2 );
    QVERIFY( doc.pages( true ).size() == 2 );
    QVERIFY( doc.pages( true )[0] == master1 );
    QVERIFY( doc.pages( true )[1] == master2 );
}
Esempio n. 22
0
void RenderArea::mousePressEvent(QMouseEvent *e){


    setCursor(Qt::PointingHandCursor);
    startPnt = e->pos();
    endPnt = e->pos();
    
	if(e->button() == Qt::RightButton){
    	if(shapePtr->shapeName == "HollowPolygon" || shapePtr->shapeName == "SolidPolygon"){
    		SolidPolygon* pShapePtr = dynamic_cast<SolidPolygon*>(shapePtr);
    		pShapePtr->points.clear();
    		update();
    	}
        return;
    }
    
    isPressed = true;
        if(shapePtr->shapeName == "BezierPath"){
        if(shapePtr->points.size()<=2){
            shapePtr->points.push_back(startPnt);
        }else{
            addShape();
        }
        return;
    }
    if(shapePtr->shapeName == "HollowPolygon" || shapePtr->shapeName == "SolidPolygon"){
        SolidPolygon* pShapePtr = dynamic_cast<SolidPolygon*>(shapePtr);
        if(!pShapePtr->initialized()){
            pShapePtr->initialize(startPnt,endPnt);
        }else{
            if(pShapePtr->isTooClose(endPnt)){
                if(pShapePtr->points.size()<=3){
                    shapePtr->points.clear();
                    update();
                    return;
                }
                pShapePtr->points.pop_back();
                pShapePtr->finished = true;
                addShape();
            }else{
                pShapePtr->updateAdd(endPnt);
            }
        }
        update();
        return;
    }
}
Esempio n. 23
0
void BoySprite::changeShape(){
	if(this->getPhysicsBody() == nullptr){
		return;
	}

	auto body = this->getPhysicsBody();
	body->removeAllShapes();
	if(this->getCurrentState() == ACTION_STATE_RUN) {
		body->addShape(NORMAL_SHAPE);
	}else if(this->getCurrentState() == ACTION_STATE_SLIDE){
		body->addShape(SLIDE_SHAPE);
	}else if(this->getCurrentState() == ACTION_STATE_JUMP_UP){
		body->addShape(NORMAL_SHAPE);
	}else if(this->getCurrentState() == ACTION_STATE_JUMP_DOWN){
		body->addShape(NORMAL_SHAPE);
	}
}
Esempio n. 24
0
bool MgCmdDrawSplines::cancel(const MgMotion* sender)
{
    if (!m_freehand && m_step > 1) {
        MgBaseLines* lines = (MgBaseLines*)dynshape()->shape();
        lines->removePoint(m_step--);
        addShape(sender);
    }
    return MgCommandDraw::cancel(sender);
}
Esempio n. 25
0
void WFillGrid::fillGrid() {
  if (!_winged_edge || !_grid)
    return;

  vector<WShape*> &	wshapes = _winged_edge->getWShapes();

  for (vector<WShape*>::const_iterator it = wshapes.begin();it != wshapes.end(); ++it)
    addShape(*it);
}
Esempio n. 26
0
//===========================================================================//
void Body::addCircle(double radius,
                     const math::Vector2F& offset)
{
    b2CircleShape shape;
    shape.m_radius = radius * mWorld.PIXELS_TO_METERS;
    shape.m_p.x = offset.x * mWorld.PIXELS_TO_METERS;
    shape.m_p.y = offset.y * mWorld.PIXELS_TO_METERS;
    addShape(shape);
}
Esempio n. 27
0
Shape *ShapeSpace::newShape( Shape::Type type )
{
    Shape *shape = 0;
    if( m_factoryMap.contains(type) ){
        shape = m_factoryMap[type]->newInstance();
    }
    addShape( shape );
    return shape;

}
Esempio n. 28
0
bool MgCmdDrawDot::touchEnded(const MgMotion* sender)
{
    dynshape()->shape()->setPoint(0, snapPoint(sender));
    dynshape()->shape()->update();
    
    addShape(sender);
    m_step = 0;
    
    return MgCommandDraw::touchEnded(sender);
}
Esempio n. 29
0
	Actor::Actor() {
		bActive = true;
		parentScene = nullptr;
		bRemoveMe = false;
		// Add our AABB
		AxisBox *b = new AxisBox();
		b->setExtents(glm::vec3(1.0f));
		addShape(b);
		fMass = 0.01f;
	}
Esempio n. 30
0
//===========================================================================//
void Body::addBox(const math::Vector2F& size,
                  const math::Vector2F& offset)
{
    b2PolygonShape shape;
    b2Vec2 center(offset.x * mWorld.PIXELS_TO_METERS,
                  offset.y * mWorld.PIXELS_TO_METERS);
    shape.SetAsBox(size.x / 2.0 * mWorld.PIXELS_TO_METERS,
                   size.y / 2.0 * mWorld.PIXELS_TO_METERS,
                   center, 0.0f);
    addShape(shape);
}