void AllegroShell::run(){ // run the loop unsigned num = 0; ALLEGRO_EVENT ev; al_start_timer(timer); unsigned keyboard_count = 0; unsigned mouse_count = 0; unsigned timer_count = 0; while( run_flag ){ al_wait_for_event(queue,&ev); num++; printf("\r%d",num); if( ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){ run_flag = false; }else if( isKeyboardEvent(&ev)){ // handle keyboard input ++keyboard_count; al_get_keyboard_state(&(keyboard)); handle_keyboard(&ev); }else if( isMouseEvent(&ev) ){ // handle mouse input ++mouse_count; mouse->update(&ev); handle_mouse(&ev); }else if( ev.type == ALLEGRO_EVENT_TIMER){ ++timer_count; // Update the model only if we haven't drawn the scene if(draw_flag == false){ if(step_once_flag){ // always step once if the user requests it model->step(); step_once_flag = false; }else if(step_flag) { model->step(); } } draw_flag = true; }else if (ev.type == USER_VIEW_EVENT){ // handling user events al_unref_user_event(&ev.user); } if( draw_flag && al_event_queue_is_empty(queue)){ draw(); draw_flag = false; } } // end while(run_flag) Textlog::get().log("\nkeyboard_count = %u\n",keyboard_count); Textlog::get().log("mouse_count = %u\n",mouse_count); Textlog::get().log("timer_count = %u\n",timer_count); }
bool Event::composed() const { if (m_composed) return true; // http://w3c.github.io/webcomponents/spec/shadow/#scoped-flag if (!isTrusted()) return false; return m_type == eventNames().inputEvent || m_type == eventNames().textInputEvent || m_type == eventNames().DOMActivateEvent || isCompositionEvent() || isClipboardEvent() || isFocusEvent() || isKeyboardEvent() || isMouseEvent() || isTouchEvent(); }
void assignKeyFromWaitEvent(int player_num, int key_enum) { SDL_Event event; event = wait_for_key_event(); quit_if_quit_event(event); if(isKeyboardEvent(event)) { if(event.key.keysym.sym != SDLK_ESCAPE) { player_keys[player_num][key_enum] = event.key.keysym.sym; } } else if(isJoystickEvent(event)) player_joy[player_num].setKeyFromEvent(key_enum, event); SDL_Delay(400); clear_events(); }
void render::run(rawTexture* imageList, int size){ // variables Timer timer(1000 / 30); SDL_Renderer* ren; SDL_Window* win; int win_x = 200; int win_y = 200; int win_w = 400; int win_h = 400; // Create the window Uint32 window_flags = SDL_WINDOW_SHOWN; win = SDL_CreateWindow( "binPackerTest", win_x, win_y, win_w, win_h, window_flags ); if(win == NULL){ printf("Failed to create window\n"); return; } // create the renderer Uint32 ren_flags = SDL_RENDERER_ACCELERATED; ren_flags = SDL_RENDERER_PRESENTVSYNC; ren = SDL_CreateRenderer(win, -1, ren_flags); if(ren == NULL){ SDL_DestroyWindow(win); printf("Failed to create renderer\n"); return; } // main loop SDL_Event e; bool exit_flag = false; bool draw_flag = false; timer.start(); for(;;){ while(SDL_PollEvent(&e) && exit_flag == false){ if(e.type == SDL_QUIT){ exit_flag = true; } else if(isKeyboardEvent(e)){ const Uint8* keyboard = SDL_GetKeyboardState(NULL); if(keyboard[SDL_SCANCODE_ESCAPE]){ SDL_Event ev; SDL_zero(ev); ev.type = SDL_QUIT; ev.quit.type = SDL_QUIT; ev.quit.timestamp = SDL_GetTicks(); SDL_PushEvent(&ev); } } else if(isMouseEvent(e)){ // do nothing } else if(e.type >= SDL_USEREVENT){ if(e.user.type == timer.type){ draw_flag = true; } // do nothing } } if(exit_flag){ break; } if(draw_flag){ // draw the shit here. SDL_RenderClear(ren); SDL_Rect rect; SDL_Color color = { 90, 90, 120, 140 }; for(int i = 0; i < size; ++i){ rect.x = imageList[i].extent.x(); rect.y = imageList[i].extent.y(); rect.w = imageList[i].extent.w(); rect.h = imageList[i].extent.h(); render_rectangle(ren, &rect, color); } SDL_RenderPresent(ren); } } // destruction timer.stop(); SDL_DestroyRenderer(ren); SDL_DestroyWindow(win); }