Ejemplo n.º 1
0
void drawCollider(CircleCollider &c)
{
	Vec2 blerg = c.getParent()->getPosition();
	drawCircle(blerg.x, blerg.y, c.getRadius(), 15, color);
}
Ejemplo n.º 2
0
void ItemElement::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{

    QGraphicsPixmapItem::paint(painter,option,widget);
    if(qobject_cast<MainScene*>(scene())){
        showColliders = qobject_cast<MainScene*>(scene())->showColliders();
        if(this->isSelected()){
           mRotateEnabled = qobject_cast<MainScene*>(scene())->rotate();
        }
    } else {
        mRotateEnabled = false;
     }

    if(qobject_cast<SplitScene*>(scene())){
        showColliders = true;
    }

    if(showColliders){
        QRectF tmpRect;
       QList<QGraphicsItem*> colliders = mTemplate->getColliderRoot()->childItems();


       foreach(QGraphicsItem* col, colliders){
           if(col->type() == QGraphicsItem::UserType+1){

               BoxCollider* boxCol = static_cast<BoxCollider*>(col);
               tmpRect = tmpRect.united(boxCol->getRectToDraw().boundingRect());

               QPen pen(QColor(Qt::cyan));
               pen.setWidth (1);
               painter->setPen (pen);

               painter->drawPolygon(boxCol->getRectToDraw());

               painter->setBrush (QColor(Qt::green));
               painter->setOpacity (0.3);
               painter->drawPolygon(boxCol->getRectToDraw());
           }
           if(col->type() == QGraphicsItem::UserType+2){

               MeshCollider* meshCol = static_cast<MeshCollider*>(col);
               tmpRect = tmpRect.united(meshCol->getPolyToDraw().boundingRect());

               QPen pen(QColor(Qt::cyan));
               pen.setWidth (1);
               painter->setPen (pen);

               painter->drawPolygon(meshCol->getPolyToDraw());

               painter->setBrush (QColor(Qt::green));
               painter->setOpacity (0.3);
               painter->drawPolygon(meshCol->getPolyToDraw());
           }
           if(col->type() == QGraphicsItem::UserType+3){

               CircleCollider* cirCol = static_cast<CircleCollider*>(col);
               int rad = (int)cirCol->getRadius();
               QPointF center = cirCol->getCenter();

               QPointF topLeft = QPointF(center.x() - rad,center.y() - rad);
                QPointF bottomRight = QPointF((center.x() + rad),(center.y() + rad));

               tmpRect = tmpRect.united(QRectF(topLeft,bottomRight));

               QPen pen(QColor(Qt::cyan));
               pen.setWidth (1);
               painter->setPen (pen);

               painter->drawEllipse(center,rad,rad);

               painter->setBrush (QColor(Qt::green));
               painter->setOpacity (0.3);
               painter->drawEllipse(center,rad,rad);
           }


           updateColliderRect(tmpRect);

       }
       if(mRotateEnabled){
          painter->drawEllipse(boundingRect().center(),50,50);
          if(mItemDragged){
              painter->setPen(QColor(Qt::darkGreen));
              painter->setBrush(QColor(Qt::darkGreen));
             // painter->drawPie(QRectF(boundingRect().center()-QPointF(50,-50),boundingRect().center()+QPointF(50,-50)),mRotationStartAngle*16,mRotationSpanAngle*16);
          }
       }
    }
}