void TetrisBoard::timerEvent(QTimerEvent *event){ if (event->timerId() == timer.timerId()) { if(!tetris.isPaused()){ if(lineDownTimeoutEnabled)tetris.timeoutElapsed(); timer.start(tetris.getTimeoutTime(), this); if(!invisible)refreshGUI(); } } else if (event->timerId() == borisTimer.timerId()) { if(tetris.hasStarted() && !tetris.isGameOver() && !tetris.isPaused() && borisIsPlaying){ boris.tick(); if(!invisible)refreshGUI(); } if (!tetris.hasStarted() && autoPlay){ start(); } } else { QFrame::timerEvent(event); } if(tetris.isGameOver() && !gameOver){ gameOver = true; onGameOver(); if (autoPlay && !(autoStopEnabled && gamesPlayed >= autoStopGames)){ start(); } } }
void TetrisBoard::start(){ gameOver = false; tetris.startNewGame(); timer.start(tetris.getTimeoutTime(), this); borisTimer.start(borisInterval, this); refreshGUI(); }
void TetrisBoard::keyPressEvent(QKeyEvent *event) { if (!tetris.hasStarted() || tetris.isPaused()) { QFrame::keyPressEvent(event); return; } switch (event->key()) { case Qt::Key_Left: tetris.moveLeft(); break; case Qt::Key_Right: tetris.moveRight(); break; case Qt::Key_Down: tetris.moveDown(); break; case Qt::Key_Up: tetris.rotateCCW(); break; case Qt::Key_Space: tetris.drop(); break; default: QFrame::keyPressEvent(event); } refreshGUI(); }
void Viewer::initializeGUI() { _window = new nanogui::Window(this, "Settings"); _window->setPosition(Vector2i(15, 15)); _window->setLayout(new nanogui::GroupLayout()); new nanogui::Label(_window, "Actions", "sans-bold"); nanogui::Button *createMeshButton = new nanogui::Button(_window, "Create Mesh"); createMeshButton->setCallback([&] () { createMesh(); refreshGUI(); }); nanogui::Button *clearMeshButton = new nanogui::Button(_window, "Clear Mesh"); clearMeshButton->setCallback([&] () { clearMesh(); refreshGUI(); }); nanogui::Button *cameraJsonButton = new nanogui::Button(_window, "Camera JSON"); cameraJsonButton->setCallback([&] () { createCameraJson(); refreshGUI(); }); new nanogui::Label(_window, "Display", "sans-bold"); _showDomainCheckBox = new nanogui::CheckBox(_window, "Show Domain (G)"); _showDomainCheckBox->setCallback([&] (bool b) { _engine.viewOptions().showDomain = b; refreshGUI(); }); _showFluidParticlesCheckBox = new nanogui::CheckBox(_window, "Show Fluid Particles (F)"); _showFluidParticlesCheckBox->setCallback([&] (bool b) { _engine.viewOptions().showFluidParticles = b; refreshGUI(); }); _showFluidMeshCheckBox = new nanogui::CheckBox(_window, "Show Fluid Mesh (Shift+F)"); _showFluidMeshCheckBox->setCallback([&] (bool b) { _engine.viewOptions().showFluidMesh = b; refreshGUI(); }); _showBoundaryParticlesCheckBox = new nanogui::CheckBox(_window, "Show Boundary Particles (B)"); _showBoundaryParticlesCheckBox->setCallback([&] (bool b) { _engine.viewOptions().showBoundaryParticles = b; refreshGUI(); }); _showBoundaryMeshesCheckBox = new nanogui::CheckBox(_window, "Show Boundary Meshes (Shift+B)"); _showBoundaryMeshesCheckBox->setCallback([&] (bool b) { _engine.viewOptions().showBoundaryMeshes = b; refreshGUI(); }); _showDebugCheckBox = new nanogui::CheckBox(_window, "Show Debug (D)"); _showDebugCheckBox->setCallback([&] (bool b) { _engine.viewOptions().showDebug = b; refreshGUI(); }); _showCacheCheckBox = new nanogui::CheckBox(_window, "Show Cache (C)"); _showCacheCheckBox->setCallback([&] (bool b) { _engine.viewOptions().showCache = b; refreshGUI(); }); new nanogui::Label(_window, "Options", "sans-bold"); nanogui::CheckBox *anisotropicMeshCheckBox = new nanogui::CheckBox(_window, "Anisotropic Mesh"); anisotropicMeshCheckBox->setChecked(_anisotropicMesh); anisotropicMeshCheckBox->setCallback([&] (bool b) { _anisotropicMesh = b; refreshGUI(); }); _transportPanel = new nanogui::Panel(this); _transportPanel->setPosition(nanogui::Vector2i(0, mSize.y() - 50)); _transportPanel->setFixedSize(nanogui::Vector2i(mSize.x(), 50)); _transportPanel->setLayout(new nanogui::GroupLayout()); _transportSlider = new nanogui::Slider(_transportPanel); _transportSlider->setCallback([&] (float value) { _engine.setCachePosition(value); }); performLayout(mNVGContext); setVisible(true); }
Viewer::Viewer(const ViewerSettings &settings) : Screen(nanogui::Vector2i(1280, 720), "Fluid Simulator"), _engine(mNVGContext, mSize, mSize) { initializeGUI(); refreshGUI(); loadScene(settings.filename); }
bool Viewer::keyboardEvent(int key, int scancode, int action, int modifiers) { if (!Screen::keyboardEvent(key, scancode, action, modifiers)) { if (action == GLFW_PRESS) { switch (key) { case GLFW_KEY_ESCAPE: setVisible(false); break; case GLFW_KEY_TAB: _window->setVisible(!_window->visible()); break; case GLFW_KEY_HOME: //_sph->reset(); break; case GLFW_KEY_SPACE: _isRunning = !_isRunning; break; case GLFW_KEY_G: _engine.viewOptions().showDomain = !_engine.viewOptions().showDomain; break; case GLFW_KEY_F: if (modifiers & GLFW_MOD_SHIFT) { _engine.viewOptions().showFluidMesh = !_engine.viewOptions().showFluidMesh; } else { _engine.viewOptions().showFluidParticles = !_engine.viewOptions().showFluidParticles; } break; case GLFW_KEY_B: if (modifiers & GLFW_MOD_SHIFT) { _engine.viewOptions().showBoundaryMeshes = !_engine.viewOptions().showBoundaryMeshes; } else { _engine.viewOptions().showBoundaryParticles = !_engine.viewOptions().showBoundaryParticles; } break; case GLFW_KEY_D: _engine.viewOptions().showDebug = !_engine.viewOptions().showDebug; break; case GLFW_KEY_C: _engine.viewOptions().showCache = !_engine.viewOptions().showCache; break; case GLFW_KEY_S: _engine.updateStep(); break; } } refreshGUI(); } return true; }