Example #1
0
    void Button::update(const sf::RenderWindow& window)
    {
        if (!isFocusable())
        {
            onLock();
            updateAppearance();
            return;
        }

        sf::Vector2i mousePos = sf::Mouse::getPosition(window);
        bool isMouseOn = mousePos.x >= (getGlobalPosition().x - getWidth() * .5f)
                        && mousePos.x <= (getGlobalPosition().x + getWidth() * .5f)
                        && mousePos.y >= (getGlobalPosition().y - getHeight() * .5f)
                        && mousePos.y <= (getGlobalPosition().y + getHeight() * .5f);
        if (isMouseOn)
        {
            if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
            {
                onPress();
            }
            else
            {
                if(mState == Button::OnPressed) { onClick(); }
                onFocus();
            }
        }
        else
        {
            lostFocus();
        }
        updateAppearance();
    }
Example #2
0
void Matrix::next()
{
	Ruleset::Piece piece = _next.dequeue();
	_rules->populateSequence(_next);

	Pair position = _rules->getStartPosition(piece);

	if (_tetromino)
		_tetromino->deleteLater();

	_tetromino = new Tetromino(piece, this);
	_tetromino->setPosition(position);
	QObject::connect(_tetromino, SIGNAL(evMove(int)), this, SLOT(onMove(int)));
	QObject::connect(_tetromino, SIGNAL(evMoveFail()), this, SLOT(onMoveFail()));
	QObject::connect(_tetromino, SIGNAL(evTurn(int)), this, SLOT(onTurn(int)));
	QObject::connect(_tetromino, SIGNAL(evTurnFail()), this, SLOT(onTurnFail()));
	QObject::connect(_tetromino, SIGNAL(evFall(int)), this, SLOT(onFall(int)));
	QObject::connect(_tetromino, SIGNAL(evDrop(int)), this, SLOT(onDrop(int)));
	QObject::connect(_tetromino, SIGNAL(evLand()), this, SLOT(onLand()));
	QObject::connect(_tetromino, SIGNAL(evLock()), this, SLOT(onLock()));

	if (_ghost)
		_ghost->deleteLater();

	_ghost = new Tetromino(piece, this);
	_ghost->setPosition(position);
	_ghost->drop();
	_ghost->setLocked(false);

	emit evTetromino(_tetromino);
	emit evGhost(_ghost);

	if (overlapped())
	{
		emit evTopOut();
		setState(STATE_OVER, true);
	}
}