本文整理汇总了C++中sf::Window::pollEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ Window::pollEvent方法的具体用法?C++ Window::pollEvent怎么用?C++ Window::pollEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Window
的用法示例。
在下文中一共展示了Window::pollEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pollEvents
void EventBuffer::pollEvents(sf::Window& window)
{
sf::Event event;
while (window.pollEvent(event))
pushEvent(event);
}
示例2: mainEventHandler
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;
}
}
}
示例3: updatePlayer
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;
}
示例4: handleEvents
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);
}
}
示例5: start
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();
}
}
示例6: treatEvents
//!-----------------------------------------------------------------------------
//! 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;
}
示例7: while
void
windowEvents ( sf::Window& window)
{
sf::Event e;
while ( window.pollEvent ( e ) ) {
if ( e.type == sf::Event::Closed ) {
window.close();
}
}
}
示例8: pollEvents
void pollEvents()
{
sf::Event windowEvent;
while (window.pollEvent(windowEvent))
{
switch (windowEvent.type)
{
case sf::Event::Closed:
window.close();
break;
}
}
}
示例9: handleEvents
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;
}
示例10: Listen
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();
}
}
示例11: handleEvents
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);
}
}
}
示例12: processEvents
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;
}
}
}
示例13: handleEvents
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();
}
}
示例14: handleEvents
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
}
}
示例15: handleEvents
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;
}
}