Example #1
0
void refreshConnectState(TS_StateTypeDef ts_event) {

    uint32_t color_back_pushed, color_back_normal;

    if (!isConnected) {
        memcpy(buttons[BUTTON_CONNECT].title, "Conn.\0", 6);
        color_back_pushed = LCD_COLOR_DARKGREEN;
        color_back_normal = LCD_COLOR_LIGHTGREEN;
    }
    else {
        memcpy(buttons[BUTTON_CONNECT].title, "Disc.\0", 6);
        color_back_pushed = LCD_COLOR_DARKRED;
        color_back_normal = LCD_COLOR_LIGHTRED;
    }

    if (isTouched(ts_event, &buttons[BUTTON_CONNECT], BUTTON_WIDTH, BUTTON_HEIGTH)) {

        if (!buttons[BUTTON_CONNECT].hasBeenAcknowledged)
            buttons[BUTTON_CONNECT].buttonEventHandler((void*) &buttons[BUTTON_CONNECT]);

        if (!buttons[BUTTON_CONNECT].isPushed)
            placeButton(buttons[BUTTON_CONNECT], color_back_pushed, LCD_COLOR_WHITE, BUTTON_WIDTH, BUTTON_HEIGTH);
        buttons[BUTTON_CONNECT].isPushed = 1;
    }
    else {

        if (buttons[BUTTON_CONNECT].isPushed)
            placeButton(buttons[BUTTON_CONNECT], color_back_normal, LCD_COLOR_BLACK, BUTTON_WIDTH, BUTTON_HEIGTH);

        buttons[BUTTON_CONNECT].isPushed = 0;
        buttons[BUTTON_CONNECT].hasBeenAcknowledged = 0;
    }
}
Example #2
0
    //% help=input/on-pin-released weight=6 blockGap=8
    //% blockId=device_pin_released block="on pin %NAME|released"
    //% advanced=true
    void onPinReleased(TouchPin name, Action body) {
        auto pin = getPin((int)name);
        if (!pin) return;

        // Forces the PIN to switch to makey-makey style detection.
        pin->isTouched();
        registerWithDal((int)name, MICROBIT_BUTTON_EVT_UP, body);
    }
Example #3
0
// dieses Rect relativ zum anderen...
eTouchType Rect::getTouchType(const Rect& rect) const
{
	if(!isTouched(rect)) {
		return TOUCHES_NO_TOUCH;
	}

	// ist 'rect' innerhalb dieses Rects?
	if(isRectInside(rect)) {
		return TOUCHES_IS_COMPLETELY_INSIDE;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_RIGHT_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_LOWER_BORDER;
	} else if(isTopRightCornerInside(rect.getTopRight()) && isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_LEFT_BORDER;
	} else if(isBottomRightCornerInside(rect.getBottomRight()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_UPPER_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft())) {
		return TOUCHES_CROSSES_BOTTOM_RIGHT_CORNER;
	} else if(isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_BOTTOM_LEFT_CORNER;
	} else if(isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_TOP_LEFT_CORNER;
	} else if(isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_TOP_RIGHT_CORNER;
	}

	else if((rect.getLeft() < getLeft()) && (rect.getRight() > getRight()) && (rect.getTop() >= getTop()) && (rect.getBottom() <= getBottom())) { // ? = 
		return TOUCHES_CROSSES_LEFT_AND_RIGHT_BORDER;
	} else if((rect.getTop() < getTop()) && (rect.getBottom() > getBottom()) && (rect.getLeft() >= getLeft()) && (rect.getRight() <= getRight())) {
		return TOUCHES_CROSSES_TOP_AND_BOTTOM_BORDER;
	}

	else if((rect.getLeft() == getRight()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_RIGHT_BORDER;
	} else if((rect.getTop() == getBottom()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_LOWER_BORDER;
	} else if((rect.getRight() == getLeft()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_LEFT_BORDER;
	} else if((rect.getBottom() == getTop()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_UPPER_BORDER;
	}

	else if((rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_UPPER_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_RIGHT_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LOWER_AREA;
	} else if((rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LEFT_AREA;
	}

	else { 
		return TOUCHES_NO_TOUCH;
	}
}
void BitmapTextButton::draw()
{
	if (bDrawBackground) {
		ofSetColor(bgColor * (isTouched()?0.5:1));
		ofFill();
		ofDrawRectangle(0, 0, getWidth(), getHeight());
	}

	ofSetColor(labelColor);
	ofDrawBitmapString(label, 5, getHeight()-5);

	if (bDrawBorder) {
		ofSetColor(borderColor);
		ofNoFill();
		ofSetLineWidth(1);
		ofDrawRectangle(0, 0, getWidth(), getHeight());
	}
}
bool ADS7843AsyncTouchScreen::getCoordinates(Point& point) {

    uint16_t xvalues[7],yvalues[7];
    Point p;
    TouchScreenPostProcessor::PostProcessAction ppa;
    int16_t sequenceNumber;

    sequenceNumber=0;

    do {

        // get the samples

        getSamples(xvalues,yvalues,7);

        // the panel must have been touched all this time

        if(!isTouched())
            return errorProvider.set(ErrorProvider::ERROR_PROVIDER_TOUCH_SCREEN,E_NO_TOUCH,0);

        // get the median values

        p.X=fastMedian(xvalues);
        p.Y=fastMedian(yvalues);

        // translate the co-ordinates using the calibration routine

        point=_calibration->translate(p);

        // pass the co-ordinate to the post processor and abort if it fails

        if((ppa=_postProcessor->postProcess(point,sequenceNumber++))==TouchScreenPostProcessor::Error)
            return false;

        // keep going until the post processor signals it's finished

    } while(ppa==TouchScreenPostProcessor::MoreSamplesRequired);

    return true;
}
Example #6
0
void refreshButtonState (TS_StateTypeDef ts_event,  button_t *button, uint16_t width, uint16_t heigth) {

    if (isTouched(ts_event, button, width, heigth)) {

        if (!button->isPushed)
            paintPushedButton(*button, width, heigth);

        if (!button->hasBeenAcknowledged)
            button->buttonEventHandler((void*) button);

        button->isPushed = 1;
    }
    else {

        if (button->isPushed)
            unpaintPushedButton(*button, width, heigth);

        button->hasBeenAcknowledged = 0;
        button->isPushed = 0;
    }

}
Example #7
0
 //% help=input/pin-is-pressed weight=58
 //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
 //% blockGap=8
 bool pinIsPressed(TouchPin name) {
     auto pin = getPin((int)name);
     return pin && pin->isTouched();
 }
Example #8
0
// ***************************************************************************
void	CAnimatedMaterial::update()
{
    if(isTouched(OwnerBit) && _Material!=NULL /*&& _Material->isLighted()*/)
    {

        // well, just update all...  :)

        // diffuse part.
        CRGBA	diff= _Diffuse.Value;
        sint c= (sint)(_Opacity.Value*255);
        clamp(c, 0, 255);
        diff.A= c;

        // setup material.
        if (_Material->isLighted())
        {
            _Material->setLighting(true, _Emissive.Value, _Ambient.Value, diff, _Specular.Value, _Shininess.Value);
        }
        else
        {
            _Material->setColor(diff);
        }

        // clear flags.
        clearFlag(AmbientValue);
        clearFlag(DiffuseValue);
        clearFlag(SpecularValue);
        clearFlag(ShininessValue);
        clearFlag(EmissiveValue);
        clearFlag(OpacityValue);


        // Texture Anim.
        if(isTouched(TextureValue))
        {
            nlassert(_MaterialBase);

            uint32	id= _Texture.Value;
            if(_MaterialBase->validAnimatedTexture(id))
            {
                _Material->setTexture(0, _MaterialBase->getAnimatedTexture(id) );
            }
            clearFlag(TextureValue);
        }

        // Get texture matrix from animated value to setup the material
        for (uint k = 0; k < IDRV_MAT_MAXTEXTURES; ++k)
        {
            if (_Material->isUserTexMatEnabled(k))
            {
                const CTexAnimatedMatValues &texMatAV = _TexAnimatedMatValues[k];

                CMatrix convMat; // exported v are already inverted (todo : optim this if needed, this matrix shouldn't be necessary)
                convMat.setRot(CVector::I, -CVector::J, CVector::K);
                convMat.setPos(CVector::J);
                float fCos = cosf(texMatAV._WRot.Value);
                float fSin = sinf(texMatAV._WRot.Value);
                CMatrix SR;
                SR.setRot(CVector(texMatAV._UScale.Value * fCos, texMatAV._VScale.Value * fSin, 0.f),
                          CVector(- texMatAV._UScale.Value * fSin, texMatAV._VScale.Value * fCos, 0.f),
                          CVector::K);
                CVector half(0.5f, 0.5f, 0.f);
                SR.setPos(SR.mulVector(- half - CVector(texMatAV._UTrans.Value, texMatAV._VTrans.Value, 0.f)) + half);
                _Material->setUserTexMat(k, convMat * SR * convMat);
            }
        }

        // We are OK!
        IAnimatable::clearFlag(OwnerBit);
    }
}
Example #9
0
void Bullet::Move()
{
	int bulletX = m_pLocation.getX();
	int bulletY = m_pLocation.getY();
	int collideX;
	int collideY;
	int bulletFlySpeed = m_iMoveSpeed+m_tOwner->MoveSpeed();
	switch (m_dDirection)                     //ÅÚµ¯µÄ·ÉÐÐ
	{
	case RETREAT:
		m_pLocation.setY(bulletY+bulletFlySpeed);
		collideX = m_pLocation.getX();
		collideY = m_pLocation.getY()+7;
		break;
	case LEFT:
		m_pLocation.setX(bulletX-bulletFlySpeed);
		collideX = m_pLocation.getX()-7;
		collideY = m_pLocation.getY();
		break;
	case RIGHT:
		m_pLocation.setX(bulletX+bulletFlySpeed);
		collideX = m_pLocation.getX()+7;
		collideY = m_pLocation.getY();
		break;
	case FRONT:
		m_pLocation.setY(bulletY-bulletFlySpeed);
		collideX = m_pLocation.getX();
		collideY = m_pLocation.getY()-7;
		break;
	default:
		break;
	}
	int map_value = map[(g_roundNumber-1)%5][collideY/64][collideX/64];// »ñÈ¡µØÐÎ
	if (map_value==101||map_value==102||(map_value>=109&&map_value!=111&&map_value!=112&&map_value<=116))     //Óöµ½Ç½±Ú
	{
		m_bIsFly = false;
	}
	else if (bulletX<0||bulletX>g_rect.right||bulletY<0||bulletY>g_rect.bottom)  //³ö½ç
	{
		m_bIsFly = false;
	}
	else if (m_tOwner->getID()==0)       //²Ù¿Ø̹¿Ë   ÅÚµ¯´¦Àí
	{
		if (isTouched(this,enemys[0])&&enemys[0]->getIsAlive()&&enemys[0]->getHP()>0&&!enemys[0]->getIsInvincible())   //»÷ÖÐAssassin
		{
			ShootedPlace.push_back(APoint(this->Location().getX()/64+1,this->Location().getY()/64+1));
			enemys[0]->decreaseHP();
			m_bIsFly = false;
			g_score+=30;
		}
		else
		{
			for (int i=0;i<g_enemyNumber;i++)
			{
				if (isTouched(this,newEnemy[i])&&newEnemy[i]->getIsAlive()&&newEnemy[i]->getHP()>0&&!newEnemy[i]->getIsInvincible())            //²Ù¿ØÅÚµ¯»÷Öез½Ì¹¿Ë
				{
					ShootedPlace.push_back(APoint(this->Location().getX()/64+1,this->Location().getY()/64+1));
					newEnemy[i]->decreaseHP();
					m_bIsFly = false;
			        if (newEnemy[i]->getFitness()<30)
			        {
						g_score+=20;   ////////////////////////////////////////////////////////////////////////////////////////////////////
			        }
					else if (newEnemy[i]->getFitness()<50)
					{
						g_score+=35;
					}
					else
					{
						g_score+=50;
					}
					break;
				}
				else if (newEnemy[i]->getBullet().getIsFly()&&isTouched(&(newEnemy[i]->getBullet()),this))//²Ù¿ØÅÚµ¯ÓëµÐ·½ÅÚµ¯ÏàÅö
				{
					newEnemy[i]->m_pBullet.setIsFly(false);
					m_bIsFly = false;
					break;
				}
			}
		}
		
	}
	else if (m_tOwner->getID()==2)   //ÒÔºóÐ޸ģ¡£¡£¡£¡£¡£¡£¡£¡£¡£¡
	{
		if (pLTank->getIsAlive()&&pLTank->getHP()&&isTouched(this,pLTank))
		{
			pLTank->decreaseHP();
			this->m_tOwner->increaseShoot();
			this->m_tOwner->setFitness(this->m_tOwner->getFitness()+25);
			m_bIsFly = false;
		}
	}

}