Exemplo n.º 1
0
void SelectionTool::mouseMoveEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(m_moving){
        hud->fill(Qt::transparent);

        QPainter painter(hud);
        painter.setOpacity(.6);
        painter.drawImage(mouse.delta(), m_movingSelection);
    }
    else if(m_drawing){
        hud->fill(Qt::transparent);

        QPixmap temp(hud->size());
        temp.fill(Qt::transparent);

        QPainter painter(&temp);
        painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(GREEN_SELECTION));

        this->paintSelection(mouse, &painter);

        painter.end();
        painter.begin(hud);
        painter.setOpacity(.6);
        painter.drawPixmap(0, 0, temp);
    }
    else{
        if(*useSelection && m_selectionMode == "only" && QColor(selection->pixel(mouse.getPos())) == Qt::white)
            this->setCursor(Selection);
        else
            this->setCorrectCursor();
    }
}
Exemplo n.º 2
0
    void InputField::mouseClickListener() {
        MouseState* mouseState = getDriver()->getInput()->getMouseState();
        Box3 bb = getBoundingBox();
        Vector3 campos;
        if(getDriver()->getActiveCameras()->at(0) == nullptr)
            campos = Vector3();
        else
            campos = getDriver()->getActiveCameras()->at(0)->getPosition();

        if(bb.contains(mouseState->getPosition() + campos) && mouseState->isButtonDown(Buttons::LEFT_MOUSE)) {
            onClick(mouseState);
            mouseState->handleEvent(Buttons::LEFT_MOUSE, 0);
        } else if(mouseState->isButtonDown(Buttons::LEFT_MOUSE)) {
            onUnClicked(mouseState);
        }
    }
Exemplo n.º 3
0
void Scene::Update(float dt)
{
	MoveSheldersMatrix();
	static MouseState prevState;
	MouseState currentState;
	if (m_mouse->GetState(currentState))
	{
		if (prevState.isButtonDown(0))
			ReadKeyboard(true);
		else
			ReadKeyboard(false);
		prevState = currentState;
	}
	UpdateCamera(XMMatrixIdentity());
	m_particles->Update(m_context, dt, m_camera.GetPosition());
}
Exemplo n.º 4
0
	void MouseState::operator=(const MouseState& other)
	{
		for (sf::Mouse::Button btn = sf::Mouse::Button(0); btn < sf::Mouse::Button::ButtonCount; btn = sf::Mouse::Button(int(btn) + 1))
		{
			std::map<sf::Mouse::Button, bool>::const_iterator it = other.m_buttonState.find(btn);
			if (it != other.m_buttonState.end())
			{
				m_buttonState[btn] = it->second;
			}
			else
			{
				m_buttonState[btn] = false;
			}
		}
		m_x = other.x();
		m_y = other.y();
	}
Exemplo n.º 5
0
void Ellipse::process(Canvas &canvasMain, Canvas &canvasTemp,
    const MouseState &mouse, const PaintParameters &param)
{
    canvasTemp.clear();
    if (!m_leftClicked && mouse.isLeftPressed())
    {
        if (mouse.isOnCanvas())
        {
            m_ellipseStart = mouse.getPos();
            m_ellipseStart -= canvasMain.getPos();
            m_startOnCanvas = true;
        }
        else
        {
            m_startOnCanvas = false;
        }
    }
    else if (m_leftClicked && mouse.isLeftPressed() && m_startOnCanvas)
    {
        m_ellipseEnd = mouse.getPos();
        m_ellipseEnd -= canvasMain.getPos();
        drawEllipse(*canvasTemp.ptr(), m_ellipseStart, m_ellipseEnd, param);
    }
    else if (m_leftClicked && !mouse.isLeftPressed() && m_startOnCanvas)
    {
        drawEllipse(*canvasMain.ptr(), m_ellipseStart, m_ellipseEnd, param);
    }
    m_leftClicked = mouse.isLeftPressed();
}
Exemplo n.º 6
0
void SelectionTool::mousePressEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(*useSelection && m_selectionMode == "only" && QColor(selection->pixel(mouse.getPos())) == Qt::white){
        m_moving = true;

        m_movingSelection = QImage(layer->size(), layer->format());
        m_movingSelection.fill(GREEN_SELECTION);
        QPainter painter(&m_movingSelection);
        painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        painter.drawImage(0, 0, *selection);
    }
    else if(mouse.button() == Qt::LeftButton){
        m_drawing = true;
        m_noKeyReleased = true;
        m_keysDown.remove(Qt::Key_Shift);
        m_keysDown.remove(Qt::Key_Alt);
    }
}
Exemplo n.º 7
0
void SelectionTool::mouseReleaseEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(m_moving){
        m_moving = false;

        selection->fill(Qt::transparent);
        hud->fill(Qt::transparent);

        QPainter painter(selection);
        painter.drawImage(mouse.delta(), m_movingSelection);
        painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(Qt::white));
        painter.drawRect(0, 0, layer->width(), layer->height());
    }
    else if(m_drawing){
        m_drawing = false;

        if(m_selectionMode == "only" || *useSelection == false)
            selection->fill(Qt::transparent);

        *useSelection = true;
        hud->fill(Qt::transparent);

        QPixmap temp(layer->size());
        temp.fill(Qt::transparent);

        QPainter painter(&temp);
        painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(Qt::white));

        this->paintSelection(mouse, &painter);

        painter.end();
        painter.begin(selection);

        if(m_selectionMode == "not")
            painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);

        if(m_selectionMode == "and")
            painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);

        painter.drawPixmap(0, 0, temp);

        if(m_noKeyReleased && m_unmodifiedMode != 0){
            if(m_selectionMode == "or" || m_selectionMode == "and")
                m_keysDown.insert(Qt::Key_Shift);
            if(m_selectionMode == "not" || m_selectionMode == "and")
                m_keysDown.insert(Qt::Key_Alt);
        }

        this->updateMode();
    }

    emit selectionChanged(true);
}
Exemplo n.º 8
0
void BrushTool::mouseReleaseEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(mouse.button() == Qt::LeftButton){
        hud->fill(Qt::transparent);

        QImage temp(layer->size(), layer->format());
        temp.fill(Qt::transparent);

        QPainter *painter = this->getPainter(&temp);

        if(m_brushSize->value() == 1)
            Tool::drawPerfectLine(painter, mouse.getPos(), m_last);
        else
            painter->drawLine(mouse.getPos(), m_last);

        delete painter;

        this->drawInSelection(layer, &temp, selection, useSelection);
    }
}
Exemplo n.º 9
0
void GradientTool::mouseMoveEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(mouse.isButtonDown(Qt::LeftButton)){
        hud->fill(Qt::transparent);

        QImage temp(layer->size(), layer->format());
        temp.fill(Qt::transparent);

        this->drawGradient(mouse, &temp, this->getColor(m_from->currentText()), this->getColor(m_to->currentText()));
        this->drawInSelection(hud, &temp, selection, useSelection);
    }
}
Exemplo n.º 10
0
void Room::Update(float dt)
{
	UpdateLamp(dt);
	static MouseState prevState;
	MouseState currentState;
	if (m_mouse->GetState(currentState))
	{
		bool change = true;
		if (prevState.isButtonDown(0))
		{
			auto d = currentState.getMousePositionChange();
			m_camera.Rotate(d.y/300.f, d.x/300.f);
		}
		else if (prevState.isButtonDown(1))
		{
			auto d = currentState.getMousePositionChange();
			m_camera.Zoom(d.y/10.0f);
		}
		else
			change = false;
		prevState = currentState;
		if (change)
			UpdateCamera();
	}
	m_particles->Update(m_context, dt, m_camera.GetPosition());
}
Exemplo n.º 11
0
void Scene::Update(float dt)
{
	UpdateInput();
	static MouseState prevState;
	MouseState currentState;
	if (!m_mouse->GetState(currentState))
		return;
	bool change = true;
	if (prevState.isButtonDown(0))
	{
		POINT d = currentState.getMousePositionChange();
		m_camera.Rotate(d.x / 300.f, d.y / 300.f);
	}
	else
		change = false;
	prevState = currentState;
	//if (change)
	UpdateCamera(m_camera.GetViewMatrix());
	//UpdateScene(dt);
	if (m_menu->animationPending)
		UpdateCube(dt);

	//m_particles->Update(m_context, dt, m_camera.GetPosition());
}
Exemplo n.º 12
0
void MouseHandler::updateMouseState(MouseState& mouseState)
{
	mouseState.resetMouseMoved();
	mouseState.resetKeyReleased();

	mouseState.setMousePosition(getMousePosition());

	SHORT buttonState = 0;
	buttonState = GetAsyncKeyState(VK_LBUTTON);
	mouseState.setKeyDown(MouseState::KEY_LEFT, getKeyStateDown(buttonState));

	buttonState = GetAsyncKeyState(VK_RBUTTON);
	mouseState.setKeyDown(MouseState::KEY_RIGHT, getKeyStateDown(buttonState));

	buttonState = GetAsyncKeyState(VK_MBUTTON);
	mouseState.setKeyDown(MouseState::KEY_CENTER, getKeyStateDown(buttonState));
}
Exemplo n.º 13
0
//main
int main() {
    //install allegro as needed
    al_init();
    al_install_keyboard();
    al_install_mouse();
    al_init_image_addon();

    //resources
    Display display(640, 480);
    EventQueue eventQueue;
    Timer timer(1./60);
    UserEventSource ues;

    //bind the resources to the event queue
    eventQueue << Keyboard::getEventSource() << Mouse::getEventSource() << display << timer << ues;

    //bitmaps
    Bitmap paddleBmp("data/paddle.bmp");
    paddleBmp.convertMaskToAlpha(Color(0xFFFFFFFF));
    Bitmap ballBmp("data/ball.bmp");
    ballBmp.convertMaskToAlpha(Color(0xFFFFFFFF));
    std::vector<Bitmap> stones;
    for(int i = 1; i <= 23; ++i) {
        stones.push_back(Bitmap(String("data/stone") + i + ".jpg"));
    }

    //blocks
    std::vector<SpritePtr> blocks;
    int stoneWidth = stones[0].getWidth();
    int stoneHeight = stones[0].getHeight();
    int blockCols = display.getWidth() / stoneWidth;
    int blockRows = 2 * display.getHeight() / 3 / stoneHeight;
    for(int j = 0; j < blockRows; ++j) {
        for(int i = 0; i < blockCols; ++i) {
            blocks.push_back(SpritePtr(new Sprite(makePoint(i * stoneWidth, j * stoneHeight), stones[rnd(stones.size())])));
        }
    }

    //paddle and ball sprites
    auto paddleStartPos = makePoint(display.getWidth()/2 - paddleBmp.getWidth()/2, display.getHeight() - paddleBmp.getHeight());
    Sprite paddle(paddleStartPos, paddleBmp);
    auto ballStartPos = makePoint(paddle.position.getX() + paddleBmp.getWidth()/2 - ballBmp.getWidth()/2, paddle.position.getY() - ballBmp.getHeight());
    Sprite ball(ballStartPos, ballBmp);

    NativeTextLog textLog("ALX Example Debug Window");

    //the reset function
    auto reset = [&]() {
        paddle.position = paddleStartPos;
        ball.position = ballStartPos;
        ball.velocity.set(0, 0);
        MouseState mouseState;
        mouseState.retrieve();
        display.setMousePosition(display.getWidth()/2, mouseState.getMouseY());
    };


    //the update logic function
    auto updateLogic = [&]() {
        //update the ball position
        ball.position += ball.velocity;

        //invert the ball's horizontal velocity if it hits the screen horizontal end
        if (ball.position.getX() == 0 || ball.position.getX() == display.getWidth() - ball.bitmap.getWidth()) {
            ball.velocity.setX(-ball.velocity.getX());
        }

        //invert the ball's vertical velocity if it hits the screen top
        if (ball.position.getY() == 0) {
            ball.velocity.setY(1);
        }

        //reset the game if the ball reaches the bottom of the screen
        if (ball.position.getY() == display.getHeight()) {
            reset();
            return;
        }

        //check if the ball collides with a block
        for(auto &block : blocks) {
            if (block && collision(ball, *block)) {
                deflectBall(ball, *block);
                block.reset();
            }
        }

        //check if the ball collides with the paddle
        if (collision(ball, paddle)) {
            textLog << "collision between ball and paddle\n";
            if (ball.getRect().getCenterX() < paddle.getRect().getCenterX()) {
                ball.velocity.setX(-1);
            }
            else {
                ball.velocity.setX(1);
            }
            ball.velocity.setY(-1);
        }
    };

    //the function to use for drawing the current frame
    auto drawFrame = [&]() {
        //draw black background
        al_clear_to_color(Color(0));

        //draw the blocks
        for(auto &blockPtr : blocks) {
            if (blockPtr) blockPtr->draw();
        }

        //draw the paddle and ball
        paddle.draw();
        ball.draw();
    };

    //test fclose issue.
    {
        File test("text.txt", "r");
        test.close();
    }

    //event loop
    timer.start();
    bool loop = true;
    bool redraw = false;
    while (loop) {
        //time for redraw
        if (redraw && eventQueue.isEmpty()) {
            redraw = false;
            drawFrame();
            al_flip_display();
        }

        //wait for event
        Event event = eventQueue.waitForEvent();

        //process event
        switch (event.getType()) {
            //key down
            case ALLEGRO_EVENT_KEY_DOWN:
                switch (event.getKeyboardKeycode()) {

                    //end the loop
                    case ALLEGRO_KEY_ESCAPE:
                        loop = false;
                        break;
                }
                break;

            //mouse
            case ALLEGRO_EVENT_MOUSE_AXES:
                paddle.position.setX(std::max(0, std::min(event.getMouseX() - paddle.bitmap.getWidth()/2, display.getWidth() - paddle.bitmap.getWidth())));
                if (ball.velocity == Point<int>(0, 0)) {
                    ball.position.setX(paddle.position.getX() + paddle.bitmap.getWidth()/2 - ball.bitmap.getWidth()/2);
                }
                break;

            //button down
            case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
                if (ball.velocity == Point<int>(0, 0)) {
                    ball.velocity.set(1, -1);
                }
                break;

            //timer
            case ALLEGRO_EVENT_TIMER:
                if (event.getTimer() == timer) {
                    redraw = true;
                    updateLogic();
                }
                break;

            //display close
            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                loop = false;
                break;
        }
    }

	return 0;
}
Exemplo n.º 14
0
void BrushTool::mousePressEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(mouse.button() == Qt::LeftButton){
        m_last = mouse.getPos();
    }
}