void EventBuffer::pollEvents(sf::Window& window) { sf::Event event; while (window.pollEvent(event)) pushEvent(event); }
void mainEventHandler(sf::Window &window){ sf::Event event; while (window.pollEvent(event)) { switch (event.type){ case sf::Event::Closed: window.close(); break; case sf::Event::KeyPressed: keyPressedHandler(event); break; case sf::Event::KeyReleased: keyReleasedHandler(event); break; case sf::Event::LostFocus: /* pause(); */ break; case sf::Event::GainedFocus: /* resume(); */ break; default: break; } } }
bool updatePlayer(){ vec2 pos; pos = player.pos; sf::Event event; while (window.pollEvent(event)){ while (event.type != sf::Event::KeyPressed){ switch (event.key.code){ case sf::Keyboard::W: pos.y--; break; case sf::Keyboard::A: pos.x--; break; case sf::Keyboard::S: pos.y++; break; case sf::Keyboard::D: pos.x++; break; default: return false; } } } if (arborArray[pos.x][pos.y] == '.'){ updateWolf(); player.pos = pos; arborArray[player.pos.x][player.pos.y] = '@'; return true; } return false; }
void handleEvents(WorldState & state, RenderEngine & render) { sf::Event event; while (window->pollEvent(event)) { if (event.type == sf::Event::Closed) state.setRunning(false); if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) state.setRunning(false); if((event.type == sf::Event::TextEntered) && (event.text.unicode == 'r')) state.toggleModelRotate(); if((event.type == sf::Event::TextEntered) && (event.text.unicode == 'q')) state.toggleIncreaseVelocity(); if(event.type == sf::Event::Resized) { resize(event.size.width, event.size.height); } if(event.type == sf::Event::MouseButtonPressed) { state.lastClickPos[0] = event.mouseButton.x; state.lastClickPos[1] = (state.currentRes[1]-event.mouseButton.y); state.lastFrameDragPos[0] = event.mouseButton.x; state.lastFrameDragPos[1] = (state.currentRes[1]-event.mouseButton.y); state.mouseButtonDown = true; } if(event.type == sf::Event::MouseButtonReleased) state.mouseButtonDown = false; if(event.type == sf::Event::MouseMoved && state.mouseButtonDown) { state.cursorDragAmount[0] += state.lastFrameDragPos[0] - event.mouseMove.x; state.cursorDragAmount[1] += state.lastFrameDragPos[1] - (state.currentRes[1]-event.mouseMove.y); state.lastFrameDragPos[0] = event.mouseMove.x; state.lastFrameDragPos[1] = (state.currentRes[1]-event.mouseMove.y); } if(event.type == sf::Event::MouseWheelMoved) { state.zoomCamera(event.mouseWheel.delta); state.cursorScrollAmount += event.mouseWheel.delta; } if(event.type == sf::Event::MouseMoved) { state.cursorAbsolutePos[0] = event.mouseMove.x; state.cursorAbsolutePos[1] = (state.currentRes[1]-event.mouseMove.y); } if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Up)) state.zoomCamera(1); if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Down)) state.zoomCamera(-1); } }
void start() { std::chrono::time_point<std::chrono::system_clock> startTime=std::chrono::system_clock::now(); //Event thread (main thread) bool running = true; while (running) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::KeyPressed) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { window.close(); running=false; } } else if (event.type == sf::Event::Closed) { window.close(); running = false; } } std::chrono::duration<double> elapsed_seconds = std::chrono::system_clock::now() - startTime; double time=elapsed_seconds.count(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0.0, 30.0, -65.0, //Camera position in World Space 0.0, 5.0, 0.0, //Camera looks towards this position 0.0, 1.0, 0.0); //Up glPushMatrix(); glRotatef(-time*50.0, 0.0, 1.0, 0.0); glTranslatef(20.0, 0.0, 0.0); unanimatedAstroBoy.draw(); glPopMatrix(); glPushMatrix(); glRotatef(-time*50.0+90.0, 0.0, 1.0, 0.0); glTranslatef(20.0, 0.0, 0.0); astroBoy.drawFrame(time); glPopMatrix(); glPushMatrix(); glRotatef(-time*50.0+180.0, 0.0, 1.0, 0.0); glTranslatef(20.0, 0.0, 0.0); astroBoyMovingGlasses.drawFrame(time); glPopMatrix(); glRotatef(-time*50.0+270.0, 0.0, 1.0, 0.0); glTranslatef(20.0, 0.0, 0.0); astroBoyHeadBanging.drawFrame(time); //Swap buffer (show result) window.display(); } }
//!----------------------------------------------------------------------------- //! FUNCTION IMPLEMENTATIONS //!----------------------------------------------------------------------------- int treatEvents(sf::Window &window) { static sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) return STOP; } return CONTINUE; }
void windowEvents ( sf::Window& window) { sf::Event e; while ( window.pollEvent ( e ) ) { if ( e.type == sf::Event::Closed ) { window.close(); } } }
void pollEvents() { sf::Event windowEvent; while (window.pollEvent(windowEvent)) { switch (windowEvent.type) { case sf::Event::Closed: window.close(); break; } } }
bool handleEvents(sf::Window& window, sf::View& view) { sf::Event event; bool continueRunning = true; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { continueRunning = false; } if (event.type == sf::Event::Resized) { view.setSize(event.size.width, event.size.height); } } return continueRunning; }
void EventHandler::Listen(sf::Window& Window){ event_queue_t& queue = Object()->m_event_queue; listener_map_pair_t ptr_range; sf::Event nextEvent; while (Window.pollEvent(nextEvent)) { queue.push(nextEvent); } while(!queue.empty()){ Object()->doCallEvent(queue.front(), Object()->m_listener_map.equal_range(queue.front().type)); queue.pop(); } }
void handleEvents(sf::Window & window, WorldState & state) { sf::Event event; while (window.pollEvent(event)) { // Close window : exit if (event.type == sf::Event::Closed) state.setRunning(false); // Escape key : exit if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) state.setRunning(false); if (event.type == sf::Event::MouseMoved) { state.updateMousePos(event.mouseMove.x, event.mouseMove.y); } } }
void InputHandler::processEvents(sf::Window& window) { reset(); sf::Event event; while (window.pollEvent(event)) { switch (event.type) { case sf::Event::KeyPressed: if (key_press_callback_func != nullptr) key_press_callback_func(event.key); break; case sf::Event::KeyReleased: if (key_release_callback_func != nullptr) key_release_callback_func(event.key); break; case sf::Event::MouseMoved: m_NewMousePosition.x = event.mouseMove.x; m_NewMousePosition.y = event.mouseMove.y; if (mouse_moved_callback_func != nullptr) mouse_moved_callback_func(event.mouseMove); m_LastMousePosition.x = event.mouseMove.x; m_LastMousePosition.y = event.mouseMove.y; break; case sf::Event::MouseWheelScrolled: if (mouse_wheel_scroll_callback_func != nullptr) mouse_wheel_scroll_callback_func(event.mouseWheelScroll); break; case sf::Event::MouseButtonPressed: if (mouse_button_pressed_callback_func != nullptr) mouse_button_pressed_callback_func(event.mouseButton); StartDrag(event.mouseButton); break; case sf::Event::MouseButtonReleased: StopDrag(event.mouseButton); if (mouse_button_released_callback_func != nullptr) mouse_button_released_callback_func(event.mouseButton); break; case sf::Event::Closed: window.close(); break; } } }
void handleEvents(WorldState & state, RenderEngine & render) { sf::Event event; while (App->pollEvent(event)) { if (event.type == sf::Event::Closed) state.setRunning(false); if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) state.setRunning(false); if((event.type == sf::Event::TextEntered) && (event.text.unicode == 'q')) state.setShadingMode(0); if((event.type == sf::Event::TextEntered) && (event.text.unicode == 'w')) state.setShadingMode(1); if((event.type == sf::Event::TextEntered) && (event.text.unicode == 'e')) state.setShadingMode(2); if((event.type == sf::Event::TextEntered) && (event.text.unicode == 'r')) state.toggleModelRotate(); if((event.type == sf::Event::TextEntered) && (event.text.unicode == 't')) state.toggleLightRotate(); } }
void handleEvents(sf::Window & window, WorldState & state) { sf::Event event; while (window.pollEvent(event)) { // Close window : exit if (event.type == sf::Event::Closed) state.setRunning(false); // Escape key : exit if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) state.setRunning(false); if (event.type == sf::Event::TextEntered) { Model const & model = state.getModel(); float time = state.getCurrentTime(); RenderEngine render = RenderEngine(render); switch (static_cast<char>(event.key.code)) { case 'q': printf("'q' should scale\n"); // scale = true. //if(!state.scaleEnabled()) state.toggleScale(); break; case 'w': printf("'w' should enable bouncing\n"); state.toggleTranslate(); break; case 'e': printf("'e' should enable z rotation\n"); // rotZ = true. state.toggleRotZ(); break; case 'r': printf("'r' should enable y rotation\n"); // rotY = true. state.toggleRotY(); break; default: printf("nothing\n"); break; } } // std::cout << "Your Input: " << static_cast<char>(event.key.code) << std::endl; //TODO add event handlers for qwer //'q' should scale //'w' should enable bouncing //'e' should enable z rotation //'r' should enable y rotation } }
void handleEvents(WorldState & state, RenderEngine & render) { bool shiftDown = sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) ||sf::Keyboard::isKeyPressed(sf::Keyboard::RShift); sf::Event Event; while (App->pollEvent(Event)) { if (Event.type == sf::Event::Closed) state.setRunning(false); if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) state.setRunning(false); if (Event.type == sf::Event::MouseButtonPressed) { previousPos = glm::vec2(Event.mouseButton.x, Event.mouseButton.y); if(Event.mouseButton.button == sf::Mouse::Left && !shiftDown) buttonDown[0] = 1; if(Event.mouseButton.button == sf::Mouse::Right) buttonDown[1] = true; if(Event.mouseButton.button == sf::Mouse::Middle) buttonDown[2] = true; if(Event.mouseButton.button == sf::Mouse::Left && shiftDown) buttonDown[2] = true; } if (Event.type == sf::Event::MouseButtonReleased) { if(Event.mouseButton.button == sf::Mouse::Left && !shiftDown) buttonDown[0] = false; if(Event.mouseButton.button == sf::Mouse::Right) buttonDown[1] = false; if(Event.mouseButton.button == sf::Mouse::Middle) buttonDown[2] = false; if(Event.mouseButton.button == sf::Mouse::Left && shiftDown) buttonDown[2] = false; lastUpdate = timer.getElapsedTime().asSeconds(); } if (Event.type == sf::Event::Resized) { render.reshape( Event.size.width, Event.size.height ); state.setSize( Event.size.width, Event.size.height ); } } lastUpdate = timer.getElapsedTime().asSeconds(); bool needsUpdate = lastUpdate > TIME_BETWEEN_UPDATES; if (needsUpdate) { glm::ivec2 newPos = glm::ivec2(sf::Mouse::getPosition(*App).x, sf::Mouse::getPosition(*App).y); if(buttonDown[0]) state.updateRotate(previousPos, newPos); if(buttonDown[1]) state.updateXYTranslate(previousPos, newPos); if(buttonDown[2]) state.updateZTranslate(previousPos, newPos); lastUpdate = timer.restart().asSeconds(); previousPos = newPos; } }
void InputSystem::update( sf::Window &window ) { sf::Event lEvent; while (window.pollEvent( lEvent )) { switch (lEvent.type) { case sf::Event::KeyPressed: { KeyboardEvent* e = new KeyboardEvent(); e->mKeyCode = lEvent.key.code; e->mkeyPressed = true; e->setID(E_KeyboardPressed); EventSystem::ptr()->dispatchEvent(e); break; } case sf::Event::KeyReleased: { KeyboardEvent* e = new KeyboardEvent(); e->mKeyCode = lEvent.key.code; e->mKeyReleased = true; e->setID(E_KeyboardReleased); EventSystem::ptr()->dispatchEvent(e); break; } case sf::Event::MouseButtonPressed: { MouseEvent* e = new MouseEvent(); e->mMouseButton = static_cast<int>(lEvent.mouseButton.button); e->mMousePressed = true; e->setID(E_MouseButtonPressed); EventSystem::ptr()->dispatchEvent(e); break; } case sf::Event::MouseButtonReleased: { MouseEvent* e = new MouseEvent(); e->mMouseButton = lEvent.mouseButton.button; e->mMouseReleased = true; e->setID(E_MouseButtonReleased); EventSystem::ptr()->dispatchEvent(e); break; } case sf::Event::MouseMoved: { MouseEvent* e = new MouseEvent(); e->mMouseMoved = true; e->mMouseMoveX = lEvent.mouseMove.x; e->mMouseMoveY = lEvent.mouseMove.y; e->mMouseMoveZ = lEvent.mouseWheel.delta; e->setID(E_MouseMoved); EventSystem::ptr()->dispatchEvent(e); break; } case sf::Event::Closed: { Event* e = new Event( E_INPUT ); e->setID(E_WindowClosed); EventSystem::ptr()->dispatchEvent(e); break; } case sf::Event::Resized: { Event* e = new Event(E_INPUT); e->setID(E_WindowResized); EventSystem::ptr()->dispatchEvent(e); break; } } } }