void Field::update(sf::Event ev) { sf::Vector2i pos_mouse(sf::Mouse::getPosition(*win)); int x,y; x = (int)((float)pos_mouse.x/(float)draw_size); y = (int)((float)pos_mouse.y/(float)draw_size); if (x < 0 || x > (int)size.x || y < 0 || y > (int)size.y) { return; } int i = y*size.x+x; if (ev.type == sf::Event::MouseButtonPressed && ev.key.code == sf::Mouse::Left) { if (!field[i].is_revealed) setPressedState(i,true); } if (ev.type == sf::Event::MouseButtonReleased) { if (ev.key.code == sf::Mouse::Left) { if (field[i].is_pressed && !field[i].is_flagged && !field[i].is_revealed) { setRevealState(i,true); // check win/lose state if (field[i].type == Tile::BOMB) is_lost = true; } setAllPressedState(false); } if (ev.key.code == sf::Mouse::Right) { if (!field[i].is_revealed) { changeFlag(i); } } } updateAllVertex(); }
void Field::setAllPressedState(bool state) { bool was_debugging = is_debugging; is_debugging = false; for (uint i = 0; i < field.size(); ++i) { setPressedState(i,state); } is_debugging = was_debugging; if (is_debugging) cout << "All tiles pressed state set to " << state << endl; }
void ButtonWidget::handleMouseDown(int x, int y, int button, int clickCount) { _duringPress = true; setPressedState(); }