Beispiel #1
0
TEST(ColorToHex, Trivial) {
	CColor colorRed(1.0f, 0.0f, 0.0f);
	CColor colorGreen(0.0f, 1.0f, 0.0f);
	CColor colorBlue(0.0f, 0.0f, 1.0f);
	std::string redHex = utils::colorToHex(colorRed);
	std::string greenHex = utils::colorToHex(colorGreen);
	std::string blueHex = utils::colorToHex(colorBlue);
	ASSERT_EQ(redHex, "ff0000");
	ASSERT_EQ(greenHex, "00ff00");
	ASSERT_EQ(blueHex, "0000ff");
}
void playHeal() {

    //Setting all 24 LED's to Green & keeping them on

    int8_t i;

    for (i = 0; i < 24; i++) {
        colorGreen();
    }

    delay_25ms_n_times(360);
}
void playTestPassed() {
    int i;
    for ( i = 0; i < 6; i++) {
        colorRed();
    }
    for (i = 0; i < 6; i++) {
        colorYellow();
    }
    for (i = 0; i < 6; i++) {
        colorGreen();
    }
    for (i = 0; i < 6; i++) {
        colorBlue();
    }
    delay_25ms_n_times(200);

}
void NeoPixelEffects::randomColor() {
    i++;
    switch ((i / 20) % 4) {
    case 0:
        colorBlue();
        break;
    case 1:
        colorRed();
        break;
    case 2:
        colorGreen();
        break;
    case 3:
        colorYellow();
        break;
    }
}
Beispiel #5
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{     
		IWeapon* pWeapon = GetWeapon(pActInfo);

		if (!pWeapon) 
			return;
			
		switch (event)
		{
			case eFE_Initialize:
			{
				m_isFiring = false;   
				m_numShots = GetPortInt( pActInfo, IN_NUMBEROFSHOTS );
				m_actInfo = *pActInfo;
				m_numShotsDone = 0;

				pWeapon->StopFire();

				if (pActInfo->pEntity->GetId() != m_weapId)
					RemoveListener(m_weapId, this);

				m_weapId = pActInfo->pEntity->GetId();
				pWeapon->AddEventListener(this, __FUNCTION__);

#ifdef DEBUG_NODEFIREWEAPON
				pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true );
#endif
				break;
			}
		
			case eFE_Activate:
			{ 
				m_actInfo = *pActInfo;
				if (IsPortActive(pActInfo, IN_NUMBEROFSHOTS))
					m_numShots = GetPortBool( pActInfo, IN_NUMBEROFSHOTS );
				
				if (IsPortActive(pActInfo, IN_STOPFIRE))
				{
					StopFiring( pActInfo, pWeapon );
				}
				if (IsPortActive(pActInfo, IN_STARTFIRE))
				{
					m_numShotsDone = 0;
					ReplenishAmmo( pWeapon );
					pWeapon->StopFire();
					StartFiring( pActInfo, pWeapon );
				}
				break;
			}
			
			case eFE_Update:
			{
				// this fixes the problem when the entity is being externally moved/rotated, in the interval of time between when the weapon is aimed an the actual shot happens
				if (m_isFiring && GetPortBool( pActInfo, IN_ALIGNTOTARGET ))
					if (pActInfo->pEntity->GetWorldPos()!=m_lastPos || pActInfo->pEntity->GetWorldRotation()!=m_lastRotation)
						CalcFiringPosition( pActInfo, pWeapon );
			
#ifdef DEBUG_NODEFIREWEAPON
				ColorB colorRed( 255,0,0 );
				ColorB colorGreen( 0,255,0 );
				gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posOrig, colorRed, posTarget, colorRed );
				gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posTarget, colorGreen, posShot, colorGreen );
#endif
				break;
			}
		}
	}
void WorkPlaceWidget::drawEntitie(Entitie* e, bool focus, bool isAbstract){
    this->calculateEntitie(e);
    int x = ((IntField*)e->fieldByID("X"))->getValue();
    int y = ((IntField*)e->fieldByID("Y"))->getValue();
    int w = ((IntField*)e->fieldByID("W"))->getValue();
    int h = ((IntField*)e->fieldByID("H"))->getValue();
    int t = ((IntField*)e->fieldByID("T"))->getValue();

    bool mov = true;
    for(int i=0; i<this->core->getEntitieCount(); i++){
       Entitie* e0 = this->core->getEntitieAt(i);
       int xe = ((IntField*)e0->fieldByID("X"))->getValue();
       int ye = ((IntField*)e0->fieldByID("Y"))->getValue();
       int we = ((IntField*)e0->fieldByID("W"))->getValue();
       int he = ((IntField*)e0->fieldByID("H"))->getValue();
       if((xe-w-15<x)&&(ye-h-15<y)&&(we+xe+15>x)&&(he+ye+15>y)&&(e0!=e)){
           mov = false;
       }
    }
    int alpha =  (((isAbstract)||(!mov)) ? 20 : 250);
    int alpha0 = (((isAbstract)||(!mov)) ? 0 : 25);
    int alpha1 = (((isAbstract)||(!mov)) ? 0 : 100);
    if(isAbstract){
        ((IntField*)e->fieldByID("X"))->setValue(this->curX);
        ((IntField*)e->fieldByID("Y"))->setValue(this->curY);
    }
    QPainter painter(this);
    QColor color(255,200,125,alpha);
    QColor color1(255,170,100,alpha);
    QColor color2(215,215,255,alpha);
    QColor colorRed(252,139,130,alpha);
    QColor colorGreen(125,220,125,alpha);
    QColor colorGreenAlpha(55,155,55,alpha0);
    QColor colorBlackAlpha(0,0,0,alpha1);
    QPen pen1 = QPen(Qt::black, 1, Qt::SolidLine);
    QPen pen2 = QPen(colorBlackAlpha, 1, Qt::SolidLine);
    painter.setPen(pen1);

    if(this->core->getState()==10 && this->core->getWeightOfSolution()!=-1){
        bool green = false;
        for(int i=0; i<this->core->getBestWay()->size(); i++){
            if(e->getID()==this->core->getBestWay()->at(i)){
                green = true;
            }
        }
        if(t!=1){
            if(green){
                painter.setBrush(QBrush(colorGreen));
            }else{
                painter.setBrush(QBrush(colorRed));
            }
        }else{
           painter.setBrush(QBrush(color2));
        }
    }else{
        if(t==0){
            painter.setBrush(QBrush(color1));
        }else if(t==1){
            painter.setBrush(QBrush(color2));
        }else{
            painter.setBrush(QBrush(color));
        }
    }

    if(x>max_width-w-5){
        ((IntField*)e->fieldByID("X"))->setValue(max_width-w-5);
        x=max_width-w-5;
    }
    if(y>max_height-h-5){
        ((IntField*)e->fieldByID("Y"))->setValue(max_height-h-5);
        y=max_height-h-5;
    }
    if(x<5){
        ((IntField*)e->fieldByID("X"))->setValue(5);
        x=5;
    }
    if(y<5){
        ((IntField*)e->fieldByID("Y"))->setValue(5);
        y=5;
    }
    string label = e->getID();
    QRect r1(x,y,w,h);
    QRect r12(x+5,y+5,w-10,h-10);
    QRect r2(x,y,w,20);
    if(focus){
        QRect rf(x-2,y-2,w+4,h+4);
        painter.drawRect(rf);
    }
    painter.drawRect(r1);
    painter.drawRect(r2);
    painter.drawText(r12,label.c_str());
    for(int i=work_count; i<e->fieldCount(); i++){
       string field = e->fieldAt(i)->getID();
       QRect tr(x+5,y+5+(i+1-work_count)*24,w-10,h-10);
       painter.drawText(tr,field.c_str());
    }
    if(t!=1){
        double distance = this->core->getDistanceOf(e);
        painter.setBrush(QBrush(Qt::black));
        painter.drawEllipse(QPoint(x-1,y-1), 2, 2);
        if(focus){
            painter.setBrush(QBrush(colorGreenAlpha));
            painter.setPen(pen2);
            painter.drawEllipse(QPoint(x-1,y-1), (int)qRound(distance), (int)qRound(distance));
        }
    }
}
Beispiel #7
0
void PixmapDial::paintEvent(QPaintEvent*)
{
    QPainter painter(this);

    if (! m_label.isEmpty())
    {
        painter.setPen(m_color2);
        painter.setBrush(m_label_gradient);
        painter.drawRect(m_label_gradient_rect);

        painter.setPen(m_colorT[isEnabled() ? 0 : 1]);
        painter.drawText(m_label_pos, m_label);
    }

    if (isEnabled())
    {
        float current = value()-minimum();
        float divider = maximum()-minimum();

        if (divider == 0.0f)
            return;

        float value = current/divider;
        QRectF source, target(0.0f, 0.0f, p_size, p_size);

        int xpos, ypos, per = (p_count-1)*value;

        if (m_orientation == HORIZONTAL)
        {
            xpos = p_size*per;
            ypos = 0.0f;
        }
        else
        {
            xpos = 0.0f;
            ypos = p_size*per;
        }

        source = QRectF(xpos, ypos, p_size, p_size);
        painter.drawPixmap(target, m_pixmap, source);

        // Custom knobs (Dry/Wet and Volume)
        if (m_custom_paint == CUSTOM_PAINT_CARLA_WET || m_custom_paint == CUSTOM_PAINT_CARLA_VOL)
        {
            // knob color
            QColor colorGreen(0x5D, 0xE7, 0x3D, 191 + m_hover_step*7);
            QColor colorBlue(0x3E, 0xB8, 0xBE, 191 + m_hover_step*7);

            // draw small circle
            QRectF ballRect(8.0, 8.0, 15.0, 15.0);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - floorf(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            // draw arc
            int startAngle = 216*16;
            int spanAngle  = -252*16*value;

            if (m_custom_paint == CUSTOM_PAINT_CARLA_WET)
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2));

                QConicalGradient gradient(15.5, 15.5, -45);
                gradient.setColorAt(0.0,   colorBlue);
                gradient.setColorAt(0.125, colorBlue);
                gradient.setColorAt(0.625, colorGreen);
                gradient.setColorAt(0.75,  colorGreen);
                gradient.setColorAt(0.76,  colorGreen);
                gradient.setColorAt(1.0,   colorGreen);
                painter.setBrush(gradient);
                painter.setPen(QPen(gradient, 3));
            }
            else
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2, 2.2));

                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 3));
            }

            painter.drawArc(4.0, 4.0, 26.0, 26.0, startAngle, spanAngle);
        }
        // Custom knobs (L and R)
        else if (m_custom_paint == CUSTOM_PAINT_CARLA_L || m_custom_paint == CUSTOM_PAINT_CARLA_R)
        {
            // knob color
            QColor color(0xAD + m_hover_step*5, 0xD5 + m_hover_step*4, 0x4B + m_hover_step*5);

            // draw small circle
            QRectF ballRect(7.0, 8.0, 11.0, 12.0);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - floorf(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            painter.setBrush(color);
            painter.setPen(QPen(color, 0));
            painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0f, 2.0f));

            int startAngle, spanAngle;

            // draw arc
            if (m_custom_paint == CUSTOM_PAINT_CARLA_L)
            {
                startAngle = 216*16;
                spanAngle  = -252.0*16*value;
            }
            else if (m_custom_paint == CUSTOM_PAINT_CARLA_R)
            {
                startAngle = 324.0*16;
                spanAngle  = 252.0*16*(1.0-value);
            }
            else
                return;

            painter.setPen(QPen(color, 2));
            painter.drawArc(3.5, 4.5, 22.0, 22.0, startAngle, spanAngle);

            if (HOVER_MIN < m_hover_step && m_hover_step < HOVER_MAX)
            {
                m_hover_step += m_hovered ? 1 : -1;
                QTimer::singleShot(20, this, SLOT(update()));
            }
        }

        if (HOVER_MIN < m_hover_step && m_hover_step < HOVER_MAX)
        {
            m_hover_step += m_hovered ? 1 : -1;
            QTimer::singleShot(20, this, SLOT(update()));
        }
    }
    else
    {
        QRectF target(0.0, 0.0, p_size, p_size);
        painter.drawPixmap(target, m_pixmap, target);
    }
}
Beispiel #8
0
void PixmapDial::paintEvent(QPaintEvent* event)
{
    event->accept();

    QPainter painter(this);
    painter.save();
    painter.setRenderHint(QPainter::Antialiasing, true);

    if (! fLabel.isEmpty())
    {
        if (fCustomPaint == CUSTOM_PAINT_NULL)
        {
            painter.setPen(fColor2);
            painter.setBrush(fLabelGradient);
            painter.drawRect(fLabelGradientRect);
        }

        painter.setFont(fLabelFont);
        painter.setPen(fColorT[isEnabled() ? 0 : 1]);
        painter.drawText(fLabelPos, fLabel);
    }

    if (isEnabled())
    {
        float current = value()-minimum();
        float divider = maximum()-minimum();

        if (divider == 0.0f)
            return;

        float value = current/divider;
        QRectF source, target(0.0f, 0.0f, fSize, fSize);

        int xpos, ypos, per = (fCount-1)*value;

        if (fOrientation == HORIZONTAL)
        {
            xpos = fSize*per;
            ypos = 0.0f;
        }
        else
        {
            xpos = 0.0f;
            ypos = fSize*per;
        }

        source = QRectF(xpos, ypos, fSize, fSize);
        painter.drawPixmap(target, fPixmap, source);

        // Custom knobs (Dry/Wet and Volume)
        if (fCustomPaint == CUSTOM_PAINT_CARLA_WET || fCustomPaint == CUSTOM_PAINT_CARLA_VOL)
        {
            // knob color
            QColor colorGreen(0x5D, 0xE7, 0x3D, 191 + fHoverStep*7);
            QColor colorBlue(0x3E, 0xB8, 0xBE, 191 + fHoverStep*7);

            // draw small circle
            QRectF ballRect(8.0f, 8.0f, 15.0f, 15.0f);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - std::floor(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            // draw arc
            int startAngle = 216*16;
            int spanAngle  = -252*16*value;

            if (fCustomPaint == CUSTOM_PAINT_CARLA_WET)
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2f, 2.2f));

                QConicalGradient gradient(15.5f, 15.5f, -45);
                gradient.setColorAt(0.0f,   colorBlue);
                gradient.setColorAt(0.125f, colorBlue);
                gradient.setColorAt(0.625f, colorGreen);
                gradient.setColorAt(0.75f,  colorGreen);
                gradient.setColorAt(0.76f,  colorGreen);
                gradient.setColorAt(1.0f,   colorGreen);
                painter.setBrush(gradient);
                painter.setPen(QPen(gradient, 3));
            }
            else
            {
                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 0));
                painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.2f, 2.2f));

                painter.setBrush(colorBlue);
                painter.setPen(QPen(colorBlue, 3));
            }

            painter.drawArc(4.0f, 4.0f, 26.0f, 26.0f, startAngle, spanAngle);
        }
        // Custom knobs (L and R)
        else if (fCustomPaint == CUSTOM_PAINT_CARLA_L || fCustomPaint == CUSTOM_PAINT_CARLA_R)
        {
            // knob color
            QColor color(0xAD + fHoverStep*5, 0xD5 + fHoverStep*4, 0x4B + fHoverStep*5);

            // draw small circle
            QRectF ballRect(7.0f, 8.0f, 11.0f, 12.0f);
            QPainterPath ballPath;
            ballPath.addEllipse(ballRect);
            //painter.drawRect(ballRect);
            float tmpValue  = (0.375f + 0.75f*value);
            float ballValue = tmpValue - std::floor(tmpValue);
            QPointF ballPoint(ballPath.pointAtPercent(ballValue));

            painter.setBrush(color);
            painter.setPen(QPen(color, 0));
            painter.drawEllipse(QRectF(ballPoint.x(), ballPoint.y(), 2.0f, 2.0f));

            int startAngle, spanAngle;

            // draw arc
            if (fCustomPaint == CUSTOM_PAINT_CARLA_L)
            {
                startAngle = 216*16;
                spanAngle  = -252.0*16*value;
            }
            else if (fCustomPaint == CUSTOM_PAINT_CARLA_R)
            {
                startAngle = 324.0*16;
                spanAngle  = 252.0*16*(1.0-value);
            }
            else
                return;

            painter.setPen(QPen(color, 2));
            painter.drawArc(3.5f, 4.5f, 22.0f, 22.0f, startAngle, spanAngle);

            if (HOVER_MIN < fHoverStep && fHoverStep < HOVER_MAX)
            {
                fHoverStep += fHovered ? 1 : -1;
                QTimer::singleShot(20, this, SLOT(update()));
            }
        }

        if (HOVER_MIN < fHoverStep && fHoverStep < HOVER_MAX)
        {
            fHoverStep += fHovered ? 1 : -1;
            QTimer::singleShot(20, this, SLOT(update()));
        }
    }
    else
    {
        QRectF target(0.0f, 0.0f, fSize, fSize);
        painter.drawPixmap(target, fPixmap, target);
    }

    painter.restore();
}