Example #1
0
void Radiobutton::paintEvent(QPaintEvent *e) {
	Painter p(this);

	float64 over = a_over.current(), checked = a_checked.current();
	bool cnone = (over == 0. && checked == 0.), cover = (over == 1. && checked == 0.), cchecked = (checked == 1.);
	bool cbad = !cnone && !cover && !cchecked;
	QColor color;
	if (cbad) {
		float64 onone = (1. - over) * (1. - checked), oover = over * (1. - checked), ochecked = checked;
		color.setRedF(_st.checkFg->c.redF() * onone + _st.checkFgOver->c.redF() * oover + _st.checkFgActive->c.redF() * ochecked);
		color.setGreenF(_st.checkFg->c.greenF() * onone + _st.checkFgOver->c.greenF() * oover + _st.checkFgActive->c.greenF() * ochecked);
		color.setBlueF(_st.checkFg->c.blueF() * onone + _st.checkFgOver->c.blueF() * oover + _st.checkFgActive->c.blueF() * ochecked);
	}

	QRect r(e->rect());
	p.setClipRect(r);
	p.fillRect(r, _st.textBg->b);
	if (_checkRect.intersects(r)) {
		p.setRenderHint(QPainter::HighQualityAntialiasing);

		QPen pen;
		if (cbad) {
			pen = QPen(color);
		} else {
			pen = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->p;
		}
		pen.setWidth(_st.thickness);
		p.setPen(pen);
		p.setBrush(Qt::NoBrush);
		//int32 skip = qCeil(_st.thickness / 2);
		//p.drawEllipse(_checkRect.marginsRemoved(QMargins(skip, skip, skip, skip)));
		p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(_st.thickness / 2, _st.thickness / 2, _st.thickness / 2, _st.thickness / 2)));

		if (checked > 0) {
			p.setPen(Qt::NoPen);
			if (cbad) {
				p.setBrush(color);
			} else {
				p.setBrush(cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive));
			}
			float64 skip0 = _checkRect.width() / 2., skip1 = _st.checkSkip / 10., checkSkip = skip0 * (1. - checked) + skip1 * checked;
			p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)));
			//int32 fskip = qFloor(checkSkip), cskip = qCeil(checkSkip);
			//if (2 * fskip < _checkRect.width()) {
			//	if (fskip != cskip) {
			//		p.setOpacity(float64(cskip) - checkSkip);
			//		p.drawEllipse(_checkRect.marginsRemoved(QMargins(fskip, fskip, fskip, fskip)));
			//		p.setOpacity(1.);
			//	}
			//	if (2 * cskip < _checkRect.width()) {
			//		p.drawEllipse(_checkRect.marginsRemoved(QMargins(cskip, cskip, cskip, cskip)));
			//	}
			//}
		}

		p.setRenderHint(QPainter::HighQualityAntialiasing, false);
	}
	if (_checkRect.contains(r)) return;

	p.setPen(_st.textFg);
	p.setFont(_st.font);
	p.drawTextLeft(_st.textPosition.x(), _st.textPosition.y(), width(), _text, _textWidth);
}
Example #2
0
QVariant RelationshipView::itemChange(GraphicsItemChange change, const QVariant &value)
{
	if(change==ItemPositionChange)
	{
		this->setFlag(QGraphicsItem::ItemIsMovable, false);
	}
	else if(change==ItemSelectedHasChanged)
	{
		unsigned i, count;
		QPen pen;
		QColor color;

		//if(!this->isSelected() && value.toBool())
		//	this->sel_order=++BaseObjectView::global_sel_order;
		this->setSelectionOrder(value.toBool());

		pos_info_pol->setVisible(value.toBool());
		pos_info_txt->setVisible(value.toBool());
		obj_selection->setVisible(value.toBool());
		this->configurePositionInfo();

		for(i=0; i < 3; i++)
		{
			if(labels[i])
				labels[i]->itemChange(change, value);
		}

		//Show tha graphical points if 'value' is true
		count=graph_points.size();
		for(i=0; i < count; i++)
			graph_points[i]->setVisible(value.toBool());

		//Alter the relationship line color when it is selected
		if(value.toBool())
		{
			QColor cor1=BaseObjectView::getBorderStyle(ParsersAttributes::OBJ_SELECTION).color(),
					cor2=BaseObjectView::getBorderStyle(ParsersAttributes::RELATIONSHIP).color();

			color.setRedF((cor1.redF() + cor2.greenF())/2.0f);
			color.setGreenF((cor1.greenF() + cor2.greenF())/2.0f);
			color.setBlueF((cor1.blueF() + cor2.blueF())/2.0f);
		}
		else
			color=BaseObjectView::getBorderStyle(ParsersAttributes::RELATIONSHIP).color();

		count=lines.size();
		for(i=0; i < count; i++)
		{
			pen=lines[i]->pen();
			pen.setColor(color);
			lines[i]->setPen(pen);
		}

		//Shows/hides the attribute's selection
		count=attributes.size();
		for(i=0; i < count; i++)
			attributes[i]->children().at(3)->setVisible(value.toBool());


		emit s_objectSelected(dynamic_cast<BaseGraphicObject *>(this->getSourceObject()),
													value.toBool());
	}

	return(value);
}
Example #3
0
void ZDvidSynapse::display(ZPainter &painter, int slice, EDisplayStyle option,
                           neutube::EAxis sliceAxis) const
{
  bool visible = true;
  int z = painter.getZ(slice);

  if (slice < 0) {
    visible = isProjectionVisible();
  } else {
    visible = isSliceVisible(z, sliceAxis);
  }

  double radius = getRadius(z, sliceAxis);

  ZIntPoint center = m_position;
  center.shiftSliceAxis(sliceAxis);

  bool isFocused = (z == center.getZ());


  if (visible) {
    QPen pen;

    QColor color = getColor();

    double alpha = 1.0;
    if (option == SKELETON) {
      alpha = 0.1;
    }

    if (!isFocused) {
      alpha *= radius / m_radius;
      alpha *= alpha * 0.5;
      alpha += 0.1;  
    }
    color.setAlphaF(alpha * color.alphaF());

    pen.setColor(color);

    painter.setPen(pen);

    painter.setBrush(Qt::NoBrush);
    if (isFocused) {
      int x = center.getX();
      int y = center.getY();
      painter.drawLine(QPointF(x - 1, y), QPointF(x + 1, y));
      painter.drawLine(QPointF(x, y - 1), QPointF(x, y + 1));

      if (getStatus() == STATUS_DUPLICATED) {
        painter.drawEllipse(
              QPointF(center.getX(), center.getY()), 1, 1);
      }
    }
    if (radius > 0.0) {
      double oldWidth = pen.widthF();
      QColor oldColor = pen.color();
      if (getKind() == EKind::KIND_POST_SYN) {
        if (option != SKELETON) {
          pen.setWidthF(oldWidth + 1.0);
        }
        if (isSelected()) {
          pen.setColor(QColor(255, 0, 255, oldColor.alpha()));
        }
      } else {
        if (isSelected()) {
          pen.setWidthF(pen.widthF() + 1.0);
        }
      }

      painter.setPen(pen);
      painter.drawEllipse(QPointF(center.getX(), center.getY()),
                          radius, radius);
      pen.setWidthF(oldWidth);
      pen.setColor(oldColor);
    }
//    QString decorationText;

    if (isVerified()) {
      //        decorationText = "U";
      color.setRgb(0, 0, 0);

      if (isSelected()) {
        if (getKind() == EKind::KIND_PRE_SYN) {
          color.setRgb(0, 255, 0);
          size_t index = 0;
          for (std::vector<bool>::const_iterator iter = m_isPartnerVerified.begin();
               iter != m_isPartnerVerified.end(); ++iter, ++index) {
            bool verified = *iter;
            if (m_partnerKind[index] == EKind::KIND_POST_SYN) {
              if (!verified) {
                color.setRgb(0, 0, 0);
                break;
              }
            }
          }
        }
      }

      color.setAlphaF(alpha);
      pen.setColor(color);
      pen.setWidthF(pen.widthF() + 0.5);
      painter.setPen(pen);
      double margin = 0.5;
      painter.drawLine(QPointF(center.getX(), center.getY() + radius - margin),
                       QPointF(center.getX() + radius - margin, center.getY()));
      painter.drawLine(QPointF(center.getX(), center.getY() + radius - margin),
                       QPointF(center.getX() - radius + margin, center.getY()));
    }


    double conf  = getConfidence();
    if (conf < 1.0) {
//      double lineWidth = radius * conf * 0.5 + 1.0;
      double lineWidth = radius * 0.5;
      double red = 1.0 - conf;
      double green = conf;
      QColor color;
      color.setRedF(red);
      if (getKind() == ZDvidAnnotation::EKind::KIND_POST_SYN) {
        color.setBlueF(green);
      } else {
        color.setGreenF(green);
      }
      color.setAlphaF(alpha);
      painter.setPen(color);
      double x = center.getX();
      double y = center.getY();
      /*
      painter.drawLine(QPointF(x - lineWidth, y),
                       QPointF(x + lineWidth, y));
                       */
      int startAngle = 0;
      int spanAngle = iround((1.0 - conf) * 180) * 16;
      painter.drawArc(QRectF(QPointF(x - lineWidth, y - lineWidth),
                             QPointF(x + lineWidth, y + lineWidth)),
                      startAngle, spanAngle);
//      painter.drawEllipse(QPointF(x, y), lineWidth, lineWidth);

//      decorationText += QString(".%1").arg(iround(conf * 10.0));
    }

#if 0
    int height = iround(getRadius() * 1.5);
    int width = decorationText.size() * height;

    if (decorationText !=   m_textDecoration.text()) {
      m_textDecoration.setText(decorationText);
      m_textDecoration.setTextWidth(width);
    }

    if (!decorationText.isEmpty()) {
      QFont font;
      font.setPixelSize(height);
      font.setWeight(QFont::Light);
      font.setStyleStrategy(QFont::PreferMatch);
      painter.setFont(font);

      QColor oldColor = painter.getPen().color();
      QColor color = QColor(0, 0, 0);
      color.setAlphaF(alpha);
      QPen pen = painter.getPen();
      pen.setColor(color);
      painter.setPen(pen);
      painter.drawStaticText(center.getX() - height / 2, center.getY(),
                             m_textDecoration);
//      painter.drawText(center.getX() - height / 2, center.getY(), width, height,
//                       Qt::AlignLeft, decorationText);
      painter.setPen(oldColor);
    }
#endif
  }


  QPen pen;
  pen.setCosmetic(m_usingCosmeticPen);

  bool drawingBoundBox = false;
  bool drawingArrow = false;
  if (isSelected()) {
    if (visible) {
      drawingBoundBox = true;
    } else {
      drawingArrow = true;
    }

    QColor color;
    color.setRgb(255, 255, 0, 255);
    pen.setColor(color);
    pen.setCosmetic(true);
  } else if (hasVisualEffect(neutube::display::Sphere::VE_BOUND_BOX)) {
    drawingBoundBox = true;
    pen.setStyle(Qt::SolidLine);
    pen.setCosmetic(m_usingCosmeticPen);
  }

  if (drawingBoundBox) {
    QRectF rect;
    double halfSize = m_radius;
    if (m_usingCosmeticPen) {
      halfSize += 0.5;
    }
    rect.setLeft(center.getX() - halfSize);
    rect.setTop(center.getY() - halfSize);
    rect.setWidth(halfSize * 2);
    rect.setHeight(halfSize * 2);

    painter.setBrush(Qt::NoBrush);
    pen.setWidthF(pen.widthF() * 0.5);
    if (visible) {
      pen.setStyle(Qt::SolidLine);
    } else {
      pen.setStyle(Qt::DotLine);
    }
    painter.setPen(pen);
    painter.drawRect(rect);
  }

  if (drawingArrow) {
    painter.setPen(pen);
    QRectF rect(center.getX() - m_radius, center.getY() - m_radius,
                m_radius + m_radius, m_radius + m_radius);

//    pen.setStyle(Qt::SolidLine);
//    pen.setColor(GetArrowColor(isVerified()));
//    painter.setPen(pen);
    QPointF ptArray[4];
    //      double s = 5.0;
    if (z > center.getZ()) {
      ZFlyEmMisc::MakeTriangle(rect, ptArray, neutube::ECardinalDirection::NORTH);
      /*
        pt[0] = QPointF(rect.center().x() - rect.width() / s,
                        rect.top() + rect.height() / s);
        pt[1] = QPointF(rect.center().x(),
                        rect.top() - rect.height() / s);
        pt[2] = QPointF(rect.center().x() + rect.width() / s,
                        rect.top() + rect.height() / s);
*/
    } else {
      ZFlyEmMisc::MakeTriangle(rect, ptArray, neutube::ECardinalDirection::SOUTH);
      /*
        pt[0] = QPointF(rect.center().x() - rect.width() / s,
                        rect.bottom() - rect.height() / s);
        pt[1] = QPointF(rect.center().x(),
                        rect.bottom() + rect.height() / s);
        pt[2] = QPointF(rect.center().x() + rect.width() / s,
                        rect.bottom() - rect.height() / s);
                        */
    }
    painter.drawPolyline(ptArray, 4);
//      painter.drawLine(pt[0], pt[1]);
//      painter.drawLine(pt[1], pt[2]);
//      painter.drawLine(pt[0], pt[2]);
  }

  if (isSelected()) {
    pen.setStyle(Qt::SolidLine);

    size_t index = 0;
    if (m_isPartnerVerified.size() == m_partnerHint.size()) {
      for (std::vector<ZIntPoint>::const_iterator iter = m_partnerHint.begin();
           iter != m_partnerHint.end(); ++iter, ++index) {
        pen.setColor(GetArrowColor(m_isPartnerVerified[index]));
        painter.setPen(pen);

        const ZIntPoint &partner = *iter;
        double len = 0.0;
        if (partner.getZ() < z && getPosition().getZ() < z) {
          len = -1.0;
        } else if (partner.getZ() > z && getPosition().getZ() > z) {
          len = 1.0;
        }

        if (len != 0.0) {
          QPointF pt[3];
          pt[0].setX(partner.getX() - len);
          pt[0].setY(partner.getY() - len);

          pt[1].setX(partner.getX() + len);
          pt[1].setY(partner.getY() - len);

          pt[2].setX(partner.getX());
          pt[2].setY(partner.getY() + len);


          painter.drawLine(pt[0], pt[1]);
          painter.drawLine(pt[1], pt[2]);
          painter.drawLine(pt[0], pt[2]);
        }

        if (m_partnerKind[index] == EKind::KIND_POST_SYN) {
          ZDvidSynapse partnerSynapse;
          partnerSynapse.setKind(EKind::KIND_POST_SYN);
          partnerSynapse.setStatus(m_partnerStatus[index]);
          partnerSynapse.setPosition(partner);
          partnerSynapse.setDefaultColor();
          partnerSynapse.setDefaultRadius();
          painter.save();
          partnerSynapse.display(painter, slice, ZStackObject::NORMAL, sliceAxis);
          painter.restore();
        }
      }
    }

    index = 0;
    for (std::vector<ZIntPoint>::const_iterator iter = m_partnerHint.begin();
         iter != m_partnerHint.end(); ++iter, ++index) {
      ZLineSegmentObject line;
      line.setStartPoint(getPosition());
      line.setEndPoint(*iter);
      if (getKind() == EKind::KIND_PRE_SYN && m_partnerKind[index] == EKind::KIND_PRE_SYN) {
        line.setColor(QColor(0, 255, 255));
        line.setFocusColor(QColor(0, 255, 255));
      } else if (m_partnerKind[index] == EKind::KIND_UNKNOWN) {
        line.setColor(QColor(164, 0, 0));
        line.setFocusColor(QColor(255, 0, 0));
      } else {
        line.setColor(QColor(255, 255, 0));
        line.setFocusColor(QColor(255, 0, 255));
      }

      line.setVisualEffect(neutube::display::Line::VE_LINE_PROJ);
      line.display(painter, slice, option, sliceAxis);

      /*
      ZIntPoint pos = *iter;
      painter.drawLine(getPosition().getX(), getPosition().getY(),
                       pos.getX(), pos.getY());
                       */
    }
  }
}
void RenderThread::drawInitialAnimation()
{

    controller::GameController* controller = glw.getGameController();
    model::GameField* field = controller->getGameField();

    timeval now = timeOperator->getCurrentTime();

//    long ms = timeOperator->getTimeDifference(timestampAnimation, now);
    long ms = timeOperator->getTimeSince(timestampAnimation);

    if (ms > 3000)
    {
        initialAnimation = false;

        model::AnimationContainer container;
        container.objects = controller->getLastGeneratedBalls();
        container.timestamp = now;

        acontainerGeneratedBalls.push_back(container);
    }

    //translate into center
    int translationX = field->getDimensionX()/2;
    int translationY = field->getDimensionY()/2;

    float dist = -9;

    if (field->getDimensionX() >= field->getDimensionY())
    {
        dist = field->getDimensionX()*(-1);
    }
    else
    {
        dist=field->getDimensionY()*(-1);
    }

    int count = 0;
    //draw each field of the game
    for (int i = 0; i< field->getDimensionX(); i++)
    {
        for (int j = 0; j< field->getDimensionY();j++)
        {

            //encolor the field
            QColor c;
            if ((i % 2 == 0 && j % 2 == 0) || (i %2 == 1 && j % 2 == 1) )
            {
                c.setRedF(0.5f);
                c.setGreenF(0.5f);
                c.setBlueF(0.5f);
            }
            else
            {
                c.setRedF(0.3f);
                c.setGreenF(0.3f);
                c.setBlueF(0.3f);
            }

            int name = j*field->getDimensionX()+i;

            if (i+j < (float)ms/1000 * (float)(field->getDimensionX()+field->getDimensionY())/2)
            {

                count ++;
                //name the field
                glLoadName(name);

                //begin actual drawing of the element

                float quadcolor[4];
                qColorToQuadcolor(c, quadcolor);
                glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, quadcolor);
                glMateriali(GL_FRONT, GL_SHININESS, 96);

                glTranslatef(i+0.5-translationX,j+0.5-translationY, dist);

                float angle = (ms-(float)((i+j)*2000)/(field->getDimensionX()+field->getDimensionY()))*90/1000;

                if(angle > 90)
                    angle = 90;

                glRotatef(90-angle,1.0,-1.0,0);

                glBegin(GL_QUADS);
                glVertex3f(-0.5 , -0.5,0);
                glVertex3f(0.5, -0.5,0);
                glVertex3f(0.5, 0.5,0);
                glVertex3f(-0.5, 0.5,0);

                //end drawing
                glEnd();

                glRotatef(angle-90,1.0,-1.0,0);
                glTranslatef(-i-0.5+translationX,-j-0.5+translationY, -dist);


            }

        }
    }


//    glDisable(GL_LIGHTING);
//    glColor3f(1.0f, 1.0f, 1.0f);
//    glRasterPos3f(-3, 3, -5);

//    std::ostringstream ostream;
//    ostream << "t: " << ms << " count:" << count;
//    std::string pr(ostream.str());

//    glutBitmapString(GLUT_BITMAP_HELVETICA_12, reinterpret_cast<const unsigned char*>(pr.c_str()));

//    glEnable(GL_LIGHTING);

}
void RenderThread::drawNormalFieldWithAnimation()
{

    controller::GameController* controller = glw.getGameController();
    model::GameField* field = controller->getGameField();

    if (field == 0)
    {
        drawIdleSequence();
        return;
    }

    //now

    //get path between selected and hovered field
    std::vector<model::FieldPosition> path;
    if (hoveredField != selectedField && selectedField != -1 && hoveredField != -1)
    {
        model::FieldPosition pos1;
        pos1.posX = selectedField%field->getDimensionX();
        pos1.posY = selectedField / field->getDimensionX();

        model::FieldPosition pos2;
        pos2.posX = hoveredField % field->getDimensionX();
        pos2.posY = hoveredField / field->getDimensionX();

        path = field->getPath(pos1,pos2);
    }


    //translate into center
    int translationX = field->getDimensionX()/2;
    int translationY = field->getDimensionY()/2;

    GLfloat dist = -9;

    if (field->getDimensionX() >= field->getDimensionY())
    {
        dist = field->getDimensionX()*(-1);
    }
    else
    {
        dist=field->getDimensionY()*(-1);
    }

    //GLfloat dist = -9;

    glRotatef(rotationX, 1.0, 0.0, 0.0);
    glRotatef(rotationY, 0.0, 1.0, 0.0);
    glRotatef(rotationZ, 0.0, 0.0, 1.0);
    glTranslatef(((rotationZ*dist*(-1))/90)*(-rotationX/70),(rotationX*dist)/90, (rotationX*dist)/90);

    //draw each field of the game
    for (int i = 0; i< field->getDimensionX(); i++)
    {
        for (int j = 0; j< field->getDimensionY();j++)
        {

            GLfloat anima_x = 0;
            GLfloat anima_y = 0;
            GLfloat anima_z = 0;
            GLfloat anima_size = 1;
            GLfloat anima_color = 0;

            calcAnimationTranslation(field,i,j,dist, &anima_x,&anima_y, &anima_z, &anima_color, &anima_size);


            //encolor the field
            QColor c;
            if ((i % 2 == 0 && j % 2 == 0) || (i %2 == 1 && j % 2 == 1) )
            {
                anima_color += 0.5;
            }
            else
            {
                anima_color += 0.3;
            }

            c.setRedF(anima_color);
            c.setGreenF(anima_color);
            c.setBlueF(anima_color);

            int name = j*field->getDimensionX()+i;


            // highlight selected and hovered field
            if(name == selectedField)
            {
                c = Qt::white;
            }
            else
            {
                if ((name == hoveredField && path.size() > 1) || (selectedField == -1 && hoveredField == name))
                {
                    c=Qt::lightGray;
                }
                else
                {
                    if (name == hoveredField && path.size() <= 1)
                    {
                        c=Qt::magenta;
                    }
                    else
                    {
//                        if (!field->getBallAt(i,j).isNull && !field->getBallAt(i,j).outOfField)
//                        {
//                            model::Ball b = field->getBallAt(i,j);
//                            c.setRed(b.color.getColorR());
//                            c.setGreen(b.color.getColorG());
//                            c.setBlue(b.color.getColorB());
//                            c.setAlpha(b.color.getColorA());
//                        }
//                        else
//                        {
                            if (path.size() > 1)
                            {
                                for (unsigned int k = 0; k < path.size() ; k++)
                                {
                                    if (path[k].posX == i && path[k].posY == j)
                                    {
                                        c = Qt::lightGray;
                                    }
                                }
                            }
                    }
                }
            }


            //name the field
            glLoadName(name);

            //begin actual drawing of the element
            glBegin(GL_QUADS);

            float quadcolor[4];
            qColorToQuadcolor(c, quadcolor);
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, quadcolor);
            glMateriali(GL_FRONT, GL_SHININESS, 96);

            //glw.qglColor(c);
            glVertex3f(0+i-translationX , 0+j-translationY,dist);
            glVertex3f(1+i-translationX, 0+j-translationY,dist);
            glVertex3f(1+i - translationX, 1+j-translationY,dist);
            glVertex3f(0+i-translationX, 1+j-translationY,dist);

            //end drawing
            glEnd();



            if ((!field->getBallAt(i,j).isNull && !field->getBallAt(i,j).outOfField) || (anima_size != 1 && field->getBallAt(i,j).isNull && !field->getBallAt(i,j).outOfField))
            {

//                GLfloat anima_z = 0;

//                std::vector<int> toRemove;
//                //check for animation pos
//                for(int k = 0; k< acontainerGeneratedBalls.size(); k++)
//                    for (int l = 0; l< acontainerGeneratedBalls[k].objects.size(); l++)
//                        if (acontainerGeneratedBalls[k].objects[l].posX == i && acontainerGeneratedBalls[k].objects[l].posY == j){
//                            long ms = timeOperator->getTimeDifference(acontainerGeneratedBalls[k].timestamp, now);

//                            if (ms < 2000)
//                                anima_z = quadraticNewBallFunction(dist,ms);//(float)(2000-ms)/2000*(-dist);
//                            else{
//                                toRemove.push_back(k);
//                                break;
//                            }
//                        }

//                for (int k = 0; k < toRemove.size();k++)
//                    acontainerGeneratedBalls.erase(acontainerGeneratedBalls.begin()+toRemove[k]);


                if (anima_size != 1)
                {
                    float ball_color = 0.4;
                    c.setRedF(ball_color);
                    c.setGreenF(ball_color);
                    c.setBlueF(ball_color);
                    c.setAlphaF(1.0f);
                }
                else
                {
                    model::Ball b = field->getBallAt(i,j);
                    c.setRed(b.color.getColorR());
                    c.setGreen(b.color.getColorG());
                    c.setBlue(b.color.getColorB());
                    c.setAlpha(b.color.getColorA());
                }

                glTranslatef(anima_x, anima_y,anima_z);
                glTranslatef(0.5+i-translationX,0.5+j-translationY,dist+0.5);
                glRotatef(180,1.0,0,0);
                glBegin(GL_QUADS);

                //convert color
                qColorToQuadcolor(c, quadcolor);
                glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, quadcolor);
                glMateriali(GL_FRONT, GL_SHININESS, 96);
                glutSolidSphere(0.5*anima_size, 50, 50);

                glEnd();
                glRotatef(-180,1.0,0,0);
                glTranslatef(-0.5-i+translationX,-0.5-j+translationY,(-1)*(dist+0.5));
                glTranslatef(-anima_x,-anima_y,-anima_z);


            }
        }
    }

    //draw the score
    glDisable(GL_LIGHTING);
    glColor3f(1.0f, 1.0f, 1.0f);
    glRasterPos3f(field->getDimensionX()-translationX+1, field->getDimensionY()-translationY-0.5,dist);

    std::ostringstream ostream;
    ostream << "Score: " << controller->getTheScore();
    std::string score(ostream.str());

    glutBitmapString(GLUT_BITMAP_HELVETICA_12, reinterpret_cast<const unsigned char*>(score.c_str()));

    if (controller->isGameOver()){
        glRasterPos3f(0, 0,-5);
        glutBitmapString(GLUT_BITMAP_HELVETICA_18, reinterpret_cast<const unsigned char*>("Game Over!"));
    }

    //frames
    glColor3f(0.3f, 0.3f, 0.3f);
    glRasterPos3f(field->getDimensionX()-translationX+1, 0-translationY,dist);

    std::ostringstream ostream2;
    ostream2 << "Frames/s: " << framerate;
    std::string frames(ostream2.str());

    glutBitmapString(GLUT_BITMAP_HELVETICA_12, reinterpret_cast<const unsigned char*>(frames.c_str()));

    glEnable(GL_LIGHTING);
}
void RenderThread::drawNormalField()
{

    controller::GameController* controller = glw.getGameController();
    model::GameField* field = controller->getGameField();

    if (field == 0)
    {
        drawIdleSequence();
        return;
    }

    //get path between selected and hovered field
    std::vector<model::FieldPosition> path;
    if (hoveredField != selectedField && selectedField != -1 && hoveredField != -1)
    {

        model::FieldPosition pos1;
        pos1.posX = selectedField%field->getDimensionX();
        pos1.posY = selectedField / field->getDimensionX();

        model::FieldPosition pos2;
        pos2.posX = hoveredField % field->getDimensionX();
        pos2.posY = hoveredField / field->getDimensionX();

        path = field->getPath(pos1,pos2);

    }


    //translate into center
    int translationX = field->getDimensionX()/2;
    int translationY = field->getDimensionY()/2;

    GLfloat dist = -9;

    if (field->getDimensionX() >= field->getDimensionY())
    {
        dist = field->getDimensionX()*(-1);
    }
    else
    {
        dist=field->getDimensionY()*(-1);
    }

    //GLfloat dist = -9;

    glRotatef(rotationX, 1.0, 0.0, 0.0);
    glRotatef(rotationY, 0.0, 1.0, 0.0);
    glRotatef(rotationZ, 0.0, 0.0, 1.0);
    glTranslatef(((rotationZ*dist*(-1))/90)*(-rotationX/70),(rotationX*dist)/90, (rotationX*dist)/90);

    //draw each field of the game
    for (int i = 0; i< field->getDimensionX(); i++)
    {
        for (int j = 0; j< field->getDimensionY();j++)
        {

            //encolor the field
            QColor c;
            if ((i % 2 == 0 && j % 2 == 0) || (i %2 == 1 && j % 2 == 1) )
            {
                c.setRedF(0.5f);
                c.setGreenF(0.5f);
                c.setBlueF(0.5f);
            }
            else
            {
                c.setRedF(0.3f);
                c.setGreenF(0.3f);
                c.setBlueF(0.3f);
            }

            int name = j*field->getDimensionX()+i;


            // highlight selected and hovered field
            if(name == selectedField)
            {
                c = Qt::white;
            }
            else
            {
                if ((name == hoveredField && path.size() > 1) || (selectedField == -1 && hoveredField == name))
                {
                    c=Qt::lightGray;
                }
                else
                {
                    if (name == hoveredField && path.size() <= 1)
                    {
                        c=Qt::magenta;
                    }
                    else
                    {
//                        if (!field->getBallAt(i,j).isNull && !field->getBallAt(i,j).outOfField){
//                            model::Ball b = field->getBallAt(i,j);
//                            c.setRed(b.color.getColorR());
//                            c.setGreen(b.color.getColorG());
//                            c.setBlue(b.color.getColorB());
//                            c.setAlpha(b.color.getColorA());
//                        }
//                        else
                            if (path.size() > 1)
                            {
                                for (unsigned int k = 0; k < path.size() ; k++)
                                {
                                    if (path[k].posX == i && path[k].posY == j)
                                    {
                                        c = Qt::lightGray;
                                    }
                                }
                            }
                    }
                }
            }


            //name the field
            glLoadName(name);

            //begin actual drawing of the element
            glBegin(GL_QUADS);

            float quadcolor[4];
            qColorToQuadcolor(c, quadcolor);
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, quadcolor);
            glMateriali(GL_FRONT, GL_SHININESS, 96);

            //glw.qglColor(c);
            glVertex3f(0+i-translationX , 0+j-translationY,dist);
            glVertex3f(1+i-translationX, 0+j-translationY,dist);
            glVertex3f(1+i - translationX, 1+j-translationY,dist);
            glVertex3f(0+i-translationX, 1+j-translationY,dist);
            glEnd();//end drawing

            if (!field->getBallAt(i,j).isNull && !field->getBallAt(i,j).outOfField)
            {

                model::Ball b = field->getBallAt(i,j);
                c.setRed(b.color.getColorR());
                c.setGreen(b.color.getColorG());
                c.setBlue(b.color.getColorB());
                c.setAlpha(b.color.getColorA());

                glTranslatef(0.5+i-translationX,0.5+j-translationY,dist+0.5);
                glRotatef(100,1.0,0,0);
                glBegin(GL_QUADS);
                //convert colors
                qColorToQuadcolor(c, quadcolor);
                glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, quadcolor);
                glMateriali(GL_FRONT, GL_SHININESS, 96);
                glutSolidSphere(0.5, 50, 50);
                glEnd();
                glRotatef(-100,1.0,0,0);
                glTranslatef(-0.5-i+translationX,-0.5-j+translationY,(-1)*(dist+0.5));

            }
        }
    }

    //draw the score
    glDisable(GL_LIGHTING);
    glColor3f(1.0f, 1.0f, 1.0f);
    glRasterPos3f(field->getDimensionX()-translationX+1, field->getDimensionY()-translationY-0.5,dist);

    std::ostringstream ostream;
    ostream << "Score: " << controller->getTheScore();
    std::string score(ostream.str());

    glutBitmapString(GLUT_BITMAP_HELVETICA_12, reinterpret_cast<const unsigned char*>(score.c_str()));

    if (controller->isGameOver())
    {
        glRasterPos3f(0, 0,-5);
        glutBitmapString(GLUT_BITMAP_HELVETICA_18, reinterpret_cast<const unsigned char*>("Game Over!"));
    }

    //frames
    glColor3f(0.3f, 0.3f, 0.3f);
    glRasterPos3f(field->getDimensionX()-translationX+1, 0-translationY,dist);

    std::ostringstream ostream2;
    ostream2 << "Frames/s: " << framerate;
    std::string frames(ostream2.str());

    glutBitmapString(GLUT_BITMAP_HELVETICA_12, reinterpret_cast<const unsigned char*>(frames.c_str()));

    glEnable(GL_LIGHTING);
}
void VisualClusterTree::SetNodeColorStyle(const QString& style, const QColor& color)
{
	Log::Inst().Debug("VisualClusterTree::SetNodeColorStyle(...)");

	if(!m_activeSystem || !m_tree)
		return;

	if(style == "Single colour")
	{
		m_nodeColorStyle = VisualNode::SINGLE_COLOR;
		SetNodeColor(color);
		return;
	}
	else if(style == "Propogate continuous")
		m_nodeColorStyle = VisualNode::PROPOGATE_CONTINUOUS_COLOR;
	else if(style == "Propogate weighted")
		m_nodeColorStyle = VisualNode::PROPOGATE_WEIGHTED_COLOR;
	else if(style == "Propogate discrete")
		m_nodeColorStyle = VisualNode::PROPOGATE_DISCRETE_COLOR;

	// set node colors
	QList<VisualNode*> postOrderNodes = m_tree->PostOrder();
	if(postOrderNodes.size() == 1)
		return;	// there is only a root node

	foreach(VisualNode* node, postOrderNodes)
	{
		QColor nodeColor;
		if(node->IsLeaf())
		{
			// set color of node based on legend
			Sample sample;
			if(!m_activeSystem->GetSamples()->GetSample(node->GetName(), sample))
				Log::Inst().Error("Invalid sample specified setting node colour: " + node->GetName());

			nodeColor = sample.GetColor();
		}
		else
		{
			// set color of node based on color of children
			QList<VisualNode*> children = node->GetChildren();
			
			if(m_nodeColorStyle == VisualNode::PROPOGATE_DISCRETE_COLOR)
			{
				nodeColor = children.at(0)->GetColor();
				for(int j = 0; j < children.size(); ++j)
				{
					if(children.at(j)->GetColor() != nodeColor)
						nodeColor = Qt::black;
				}
			}
			else if(m_nodeColorStyle == VisualNode::PROPOGATE_CONTINUOUS_COLOR)
			{
				float red = 0.0f, green = 0.0f, blue = 0.0f;
				for(int j = 0; j < children.size(); ++j)
				{
					QColor color = children.at(j)->GetColor();
					red += color.redF();
					green += color.greenF();
					blue += color.blueF();
				}

				nodeColor.setRedF(red / children.size());
				nodeColor.setGreenF(green / children.size());
				nodeColor.setBlueF(blue / children.size());
			}
			else // m_nodeColorStyle == VisualNode::PROPOGATE_WEIGHTED_COLOR
			{
				float red = 0.0f, green = 0.0f, blue = 0.0f;
				uint totalWeight = 0;
				for(int j = 0; j < children.size(); ++j)
				{
					uint weight = children.at(j)->GetWeightedNumberOfSeqs();
					totalWeight += weight;

					QColor color = children.at(j)->GetColor();
					red += color.redF() * weight;
					green += color.greenF() * weight;
					blue += color.blueF() * weight;
				}

				nodeColor.setRedF(red / totalWeight);
				nodeColor.setGreenF(green / totalWeight);
				nodeColor.setBlueF(blue / totalWeight);
			}
		}

		node->SetColor(nodeColor);
		node->update();
	}