ATTRIBUTES_DECLARE_ALL MainWindow::MainWindow() { QWidget::installEventFilter(this); menu = NULL; gameWidget = NULL; // Create console //#ifdef XKILL_DEBUG AllocConsole(); SetConsoleTitle(L"Debug console"); int hConHandle; long lStdHandle; FILE *fp; // redirect unbuffered STDOUT to the console lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); fp = _fdopen( hConHandle, "w" ); *stdout = *fp; setvbuf( stdout, NULL, _IONBF, 0 ); //#endif // Init iterators ATTRIBUTES_INIT_ALL; // subscribe to events SUBSCRIBE_TO_EVENT(this, EVENT_SHOW_FULLSCREEN); SUBSCRIBE_TO_EVENT(this, EVENT_SHOW_MESSAGEBOX); SUBSCRIBE_TO_EVENT(this, EVENT_QUIT_TO_DESKTOP); // create UI generated from XML file ui.setupUi(this); ui.mainToolBar->hide(); MainWindow::setWindowTitle("XKILL"); resize(1000, 600); QWidget::setAttribute(Qt::WA_PaintOnScreen); // init game gameWidget = new GameWidget(this); this->setCentralWidget(gameWidget); // init tools new Menu_Editor(ui, this); menu = new Menu_Main(this); // setup signals and slots connect(ui.actionFullscreen, SIGNAL(triggered()), this, SLOT(slot_toggleFullScreen())); connect(ui.actionCap_FPS, SIGNAL(toggled(bool)), gameWidget, SLOT(slot_toggleCapFPS(bool))); ui.actionCap_FPS->setChecked(true); connect(ui.actionQuit, SIGNAL(triggered()), this, SLOT(close())); connect(gameWidget, SIGNAL(signal_fpsChanged(QString)), this, SLOT(slot_setTitle(QString))); connect(gameWidget, SIGNAL(signal_fpsChanged(QString)), this, SLOT(slot_setTitle(QString))); // Listen to incomming event this->installEventFilter(this); slot_toggleFullScreen(); //Fullscreen // DEBUG build specific settings (setAlwaysOnTopAndShow(false) is set in Menu_Main2::Menu_Main2() if DEBUG) #if defined(DEBUG) || defined(_DEBUG) slot_toggleFullScreen(); //Windowed SEND_EVENT(&Event(EVENT_STARTGAME));//Skips menu in DEBUG #endif }
void Java_org_xcsoar_EventBridge_onKeyUp(JNIEnv *env, jclass cls, jint key_code) { event_queue->push(Event(Event::KEY_UP, TranslateKeyCode(key_code))); }
int DefaultEventManager<Platform::POLL>::isRegistered( const SocketHandle::Handle& handle, const EventType::Type event) const { return d_callbacks.end() != d_callbacks.find(Event(handle, event)); }
bool CButton::EventProcess(const Event &event) { if ( (m_state & STATE_VISIBLE) == 0 ) return true; if ( m_state & STATE_DEAD ) return true; CControl::EventProcess(event); if ( event.type == EVENT_FRAME ) { if ( m_bRepeat && m_repeat != 0.0f ) { m_repeat -= event.rTime; if ( m_repeat <= 0.0f ) { m_repeat = DELAY2; m_event->AddEvent(Event(m_eventType)); return false; } } } if ( event.type == EVENT_MOUSE_BUTTON_DOWN && event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT && (m_state & STATE_VISIBLE) && (m_state & STATE_ENABLE) ) { if ( CControl::Detect(event.mousePos) ) { m_bCapture = true; m_repeat = DELAY1; if ( m_bImmediat || m_bRepeat ) { m_event->AddEvent(Event(m_eventType)); } return false; } } if ( event.type == EVENT_MOUSE_MOVE && m_bCapture ) { } if ( event.type == EVENT_MOUSE_BUTTON_UP && //left event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT && m_bCapture ) { if ( CControl::Detect(event.mousePos) ) { if ( !m_bImmediat && !m_bRepeat ) { m_event->AddEvent(Event(m_eventType)); } } m_bCapture = false; m_repeat = 0.0f; } return true; }
int Edit::processEvent (const Event& event) { if (event.key > 0 && event.key < 256 && isprint (event.key)) { processText (event); return 1; } switch (event.key) { case KB_UP: case KB_KP_UP: up (); break; case KB_DOWN: case KB_KP_DOWN: down (); break; case KB_LEFT: case KB_KP_LEFT: left (); break; case KB_RIGHT: case KB_KP_RIGHT: right (); break; case KB_BKSPACE: backSpace (); break; case KB_TAB: tab (); break; case KB_HOME: case KB_KP_HOME: home (); break; case KB_END: case KB_KP_END: end (); break; case KB_INS: case KB_KP_INS: ins (); break; case KB_DEL: case KB_KP_DEL: del (); break; case KB_ESC: mExitKey = KB_ESC; postEvent (Event (EV_QUIT)); break; case KB_ENTER: strncpy (mpRealText, mpText, mLength); mpRealText[mLength] = '\0'; if (mpHist != 0) mpHist->add (mpText); mExitKey = KB_ENTER; postEvent (Event (EV_QUIT)); break; case EV_COLOR_CHANGE: draw (); return Popup::processEvent (event); default: return Popup::processEvent (event); } return 1; }
Event DiscreteTimeLayer::getNextEvent() { return Event(this,time + event_frequency); }
bool CAutoResearch::EventProcess(const Event &event) { CPowerContainerObject* power; Math::Vector pos, speed; Error message; Math::Point dim; float angle; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( event.type == EVENT_UPDINTERFACE ) { if ( m_object->GetSelect() ) CreateInterface(true); } if ( m_object->GetSelect() ) // center selected? { Error err = ERR_UNKNOWN; if ( event.type == EVENT_OBJECT_RTANK ) err = StartAction(RESEARCH_TANK); if ( event.type == EVENT_OBJECT_RFLY ) err = StartAction(RESEARCH_FLY); if ( event.type == EVENT_OBJECT_RTHUMP ) err = StartAction(RESEARCH_THUMP); if ( event.type == EVENT_OBJECT_RCANON ) err = StartAction(RESEARCH_CANON); if ( event.type == EVENT_OBJECT_RTOWER ) err = StartAction(RESEARCH_TOWER); if ( event.type == EVENT_OBJECT_RPHAZER ) err = StartAction(RESEARCH_PHAZER); if ( event.type == EVENT_OBJECT_RSHIELD ) err = StartAction(RESEARCH_SHIELD); if ( event.type == EVENT_OBJECT_RATOMIC ) err = StartAction(RESEARCH_ATOMIC); if( err != ERR_OK && err != ERR_UNKNOWN ) m_main->DisplayError(err, m_object); if( err != ERR_UNKNOWN ) return false; } if ( event.type != EVENT_FRAME ) return true; m_progress += event.rTime*m_speed; m_timeVirus -= event.rTime; if ( m_object->GetVirusMode() ) // contaminated by a virus? { if ( m_timeVirus <= 0.0f ) { m_timeVirus = 0.1f+Math::Rand()*0.3f; } return true; } UpdateInterface(event.rTime); EventProgress(event.rTime); angle = m_time*0.1f; m_object->SetPartRotationY(1, angle); // rotates the antenna angle = (30.0f+sinf(m_time*0.3f)*20.0f)*Math::PI/180.0f; m_object->SetPartRotationZ(2, angle); // directs the antenna if ( m_phase == ALP_WAIT ) { FireStopUpdate(m_progress, false); // extinguished return true; } if ( m_phase == ALP_SEARCH ) { FireStopUpdate(m_progress, true); // flashes if ( m_progress < 1.0f ) { if ( m_object->GetPower() == nullptr || !m_object->GetPower()->Implements(ObjectInterfaceType::PowerContainer) ) // more battery? { SetBusy(false); UpdateInterface(); m_phase = ALP_WAIT; m_progress = 0.0f; m_speed = 1.0f/1.0f; return true; } power = dynamic_cast<CPowerContainerObject*>(m_object->GetPower()); power->SetEnergyLevel(1.0f-m_progress); if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; pos = m_object->GetPosition(); pos.x += (Math::Rand()-0.5f)*6.0f; pos.z += (Math::Rand()-0.5f)*6.0f; pos.y += 11.0f; speed.x = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f; speed.y = Math::Rand()*20.0f; dim.x = Math::Rand()*1.0f+1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIVAPOR); } } else { m_main->MarkResearchDone(m_research, m_object->GetTeam()); // research done m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); UpdateInterface(); m_main->DisplayError(INFO_RESEARCH, m_object); message = ERR_OK; if ( m_research == RESEARCH_TANK ) message = INFO_RESEARCHTANK; if ( m_research == RESEARCH_FLY ) message = INFO_RESEARCHFLY; if ( m_research == RESEARCH_THUMP ) message = INFO_RESEARCHTHUMP; if ( m_research == RESEARCH_CANON ) message = INFO_RESEARCHCANON; if ( m_research == RESEARCH_TOWER ) message = INFO_RESEARCHTOWER; if ( m_research == RESEARCH_PHAZER ) message = INFO_RESEARCHPHAZER; if ( m_research == RESEARCH_SHIELD ) message = INFO_RESEARCHSHIELD; if ( m_research == RESEARCH_ATOMIC ) message = INFO_RESEARCHATOMIC; if ( message != ERR_OK ) { m_main->DisplayError(message, m_object); } SetBusy(false); UpdateInterface(); m_phase = ALP_WAIT; m_progress = 0.0f; m_speed = 1.0f/1.0f; } } return true; }
void Agent::sendEvent(std::string name, folly::dynamic params) { if (!channel_) { return; } channel_->sendMessage(Event(getDomain(), std::move(name), std::move(params))); }
//---------------------------------------------------------------------------- //! @brief フィルタグラフの構築 //! @param callbackwin : メッセージを送信するウィンドウ //! @param stream : 読み込み元ストリーム //! @param streamname : ストリームの名前 //! @param type : メディアタイプ(拡張子) //! @param size : メディアサイズ //---------------------------------------------------------------------------- void __stdcall tTVPDSVideoOverlay::BuildGraph( HWND callbackwin, IStream *stream, const wchar_t * streamname, const wchar_t *type, unsigned __int64 size ) { HRESULT hr; // CoInitialize(NULL); // detect CMediaType from stream's extension ('type') try { if( FAILED(hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)) ) ThrowDShowException(L"Failed to call CoInitializeEx.", hr); // create IFilterGraph instance if( FAILED(hr = m_GraphBuilder.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC)) ) ThrowDShowException(L"Failed to create FilterGraph.", hr); // Register to ROT if(GetShouldRegisterToROT()) { AddToROT(m_dwROTReg); } if( IsWindowsMediaFile(type) ) { CComPtr<IBaseFilter> pVRender; // for video renderer filter if( FAILED(hr = pVRender.CoCreateInstance(CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER)) ) ThrowDShowException(L"Failed to create video renderer filter object.", hr); if( FAILED(hr = GraphBuilder()->AddFilter(pVRender, L"Video Renderer")) ) ThrowDShowException(L"Failed to call IFilterGraph::AddFilter.", hr); BuildWMVGraph( pVRender, stream ); } else { CMediaType mt; mt.majortype = MEDIATYPE_Stream; ParseVideoType( mt, type ); // may throw an exception // create proxy filter m_Proxy = new CIStreamProxy( stream, size ); hr = S_OK; m_Reader = new CIStreamReader( m_Proxy, &mt, &hr ); if( FAILED(hr) || m_Reader == NULL ) ThrowDShowException(L"Failed to create proxy filter object.", hr); m_Reader->AddRef(); // add fliter if( FAILED(hr = GraphBuilder()->AddFilter( m_Reader, NULL)) ) ThrowDShowException(L"Failed to call IFilterGraph::AddFilter.", hr); // AddFilterしたのでRelease m_Reader->Release(); if( mt.subtype == MEDIASUBTYPE_Avi || mt.subtype == MEDIASUBTYPE_QTMovie ) { // render output pin if( FAILED(hr = GraphBuilder()->Render(m_Reader->GetPin(0))) ) ThrowDShowException(L"Failed to call IGraphBuilder::Render.", hr); } else { CComPtr<IBaseFilter> pVRender; // for video renderer filter if( FAILED(hr = pVRender.CoCreateInstance(CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER)) ) ThrowDShowException(L"Failed to create video renderer filter object.", hr); if( FAILED(hr = GraphBuilder()->AddFilter(pVRender, L"Video Renderer")) ) ThrowDShowException(L"Failed to call IFilterGraph::AddFilter.", hr); BuildMPEGGraph( pVRender, m_Reader); // may throw an exception } } // query each interfaces if( FAILED(hr = m_GraphBuilder.QueryInterface( &m_MediaControl )) ) ThrowDShowException(L"Failed to query IMediaControl", hr); if( FAILED(hr = m_GraphBuilder.QueryInterface( &m_MediaPosition )) ) ThrowDShowException(L"Failed to query IMediaPosition", hr); if( FAILED(hr = m_GraphBuilder.QueryInterface( &m_MediaSeeking )) ) ThrowDShowException(L"Failed to query IMediaSeeking", hr); if( FAILED(hr = m_GraphBuilder.QueryInterface( &m_MediaEventEx )) ) ThrowDShowException(L"Failed to query IMediaEventEx", hr); if( FAILED(hr = m_GraphBuilder.QueryInterface( &m_BasicVideo )) ) ThrowDShowException(L"Failed to query IBasicVideo", hr); if( FAILED(hr = m_GraphBuilder.QueryInterface( &m_VideoWindow )) ) ThrowDShowException(L"Failed to query IVideoWindow", hr); if( FAILED(hr = m_GraphBuilder.QueryInterface( &m_BasicAudio )) ) ThrowDShowException(L"Failed to query IBasicAudio", hr); // check whether the stream has video if(!m_VideoWindow || !m_BasicVideo ) TVPThrowExceptionMessage(L"The stream has no video components."); { long visible; if(FAILED(hr = VideoWindow()->get_Visible(&visible))) ThrowDShowException(L"The stream has no video components or has unsupported video format.", hr); } // disable AutoShow VideoWindow()->put_AutoShow(OAFALSE); // set notify event if(callbackwin) { if(FAILED(hr = Event()->SetNotifyWindow((OAHWND)callbackwin, WM_GRAPHNOTIFY, (long)(this)))) ThrowDShowException(L"Failed to set IMediaEventEx::SetNotifyWindow.", hr); } } catch(const wchar_t *msg) { MakeAPause(true); ReleaseAll(); CoUninitialize(); TVPThrowExceptionMessage(msg); } catch(...) { MakeAPause(true); ReleaseAll(); CoUninitialize(); throw; } MakeAPause(false); CoUninitialize(); // ここでこれを呼ぶとまずそうな気がするけど、大丈夫なのかなぁ }
void PortableTaskBarReceiver::quit() { m_events->addEvent(Event(Event::kQuit)); }
MainState Game::run() { SDL_Event event; running = true; Uint32 fpsTicks = SDL_GetTicks(); Uint32 lastticks = fpsTicks; Desktop* desktop = dynamic_cast<Desktop*> (gui.get()); if(!desktop) { throw std::runtime_error("Toplevel component is not a Desktop");} gui->resize(getConfig()->videoX, getConfig()->videoY); int frame = 0; while(running) { getGameView()->scroll(); while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_VIDEORESIZE: initVideo(event.resize.w, event.resize.h); gui->resize(event.resize.w, event.resize.h); getConfig()->videoX = event.resize.w; getConfig()->videoY = event.resize.h; break; case SDL_KEYUP: { Event gui_event(event); if( gui_event.keysym.sym == SDLK_ESCAPE ){ getButtonPanel()->selectQueryTool(); break; } if( gui_event.keysym.sym == SDLK_b ){ getButtonPanel()->toggleBulldozeTool(); break; } /* //FIXME hack for monitoring constructionCount if( gui_event.keysym.sym == SDLK_c ){ std::cout << "ConstructionCount.size() = " << constructionCount.size() << std::endl; int i, j; for (i = 0, j = 0; i < constructionCount.size(); i++) {constructionCount[i]?j++:j;} std::cout << "for a total of " << j << " active constructions" << std::endl; break; } */ if( gui_event.keysym.sym == SDLK_p ){ static int i = 0; while(i < constructionCount.size() && !constructionCount[i]) {i++;} if (i < constructionCount.size()) { main_screen_originx = constructionCount[i]->x; main_screen_originy = constructionCount[i]->y; getGameView()->readOrigin(true); mps_set( main_screen_originx, main_screen_originy, MPS_MAP); mps_update(); mps_refresh(); i++; } else { i = 0; } break; } if( gui_event.keysym.sym == SDLK_F1 ){ helpWindow->showTopic("help"); break; } if( gui_event.keysym.sym == SDLK_F12 ){ quickSave(); break; } if( gui_event.keysym.sym == SDLK_F9 ){ quickLoad(); break; } #ifdef DEBUG if( gui_event.keysym.sym == SDLK_F5 ){ testAllHelpFiles(); break; } #endif int need_break=true; switch(gui_event.keysym.sym) { case SDLK_BACKQUOTE: getMiniMap()->mapViewChangeDisplayMode(MiniMap::NORMAL); break; case SDLK_1: getMiniMap()->mapViewChangeDisplayMode(MiniMap::STARVE); break; case SDLK_2: getMiniMap()->mapViewChangeDisplayMode(MiniMap::UB40); break; case SDLK_3: getMiniMap()->mapViewChangeDisplayMode(MiniMap::POWER); break; case SDLK_4: getMiniMap()->mapViewChangeDisplayMode(MiniMap::FIRE); break; case SDLK_5: getMiniMap()->mapViewChangeDisplayMode(MiniMap::CRICKET); break; case SDLK_6: getMiniMap()->mapViewChangeDisplayMode(MiniMap::HEALTH); break; case SDLK_7: getMiniMap()->mapViewChangeDisplayMode(MiniMap::TRAFFIC); break; case SDLK_8: getMiniMap()->mapViewChangeDisplayMode(MiniMap::POLLUTION); break; case SDLK_9: getMiniMap()->mapViewChangeDisplayMode(MiniMap::COAL); break; case SDLK_0: getMiniMap()->mapViewChangeDisplayMode(MiniMap::COMMODITIES); break; default: need_break=false; } if (need_break) break; gui->event(gui_event); break; } case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_KEYDOWN: { Event gui_event(event); gui->event(gui_event); break; } case SDL_ACTIVEEVENT: if( event.active.gain == 1 ){ gui->resize( gui->getWidth(), gui->getHeight() ); } break; case SDL_VIDEOEXPOSE: gui->resize( gui->getWidth(), gui->getHeight() ); break; case SDL_QUIT: saveCityNG( "9_currentGameNG.scn" ); running = false; quitState = QUIT; break; default: break; } } // create update Event Uint32 ticks = SDL_GetTicks(); float elapsedTime = ((float) (ticks - lastticks)) / 1000.0; gui->event(Event(elapsedTime)); lastticks = ticks; helpWindow->update(); if(desktop->needsRedraw()) { desktop->draw(*painter); flipScreenBuffer(); } frame++; // Slow down cpu consumption in pause mode if(ticks - fpsTicks > 1000 && lincitySpeed) { #ifdef DEBUG_FPS printf("FPS: %d.\n", (frame*1000) / (ticks - fpsTicks)); #endif getEconomyGraph()->newFPS( frame ); frame = 0; fpsTicks = ticks; } else if(!lincitySpeed) { frame = 0;} /* SDL_Delay is done in execute_timestep */ execute_timestep (); } return quitState; }
void LinuxInputDevice::Read() { struct input_event buffer[64]; const ssize_t nbytes = fd.Read(buffer, sizeof(buffer)); if (nbytes < 0) { /* device has failed or was unplugged - bail out */ if (errno != EAGAIN && errno != EINTR) Close(); return; } unsigned n = size_t(nbytes) / sizeof(buffer[0]); for (unsigned i = 0; i < n; ++i) { const struct input_event &e = buffer[i]; switch (e.type) { case EV_SYN: if (e.code == SYN_REPORT) { /* commit the finger movement */ const bool pressed = pressing; const bool released = releasing; pressing = releasing = false; if (pressed) merge.SetDown(true); if (released) merge.SetDown(false); if (IsKobo() && released) { /* workaround: on the Kobo Touch N905B, releasing the touch screen reliably produces a finger position that is way off; in that case, ignore finger movement */ moving = false; edit_position = public_position; } if (moving) { moving = false; public_position = edit_position; merge.MoveAbsolute(public_position.x, public_position.y); } else if (rel_x != 0 || rel_y != 0) { merge.MoveRelative(rel_x, rel_y); rel_x = rel_y = 0; } } break; case EV_KEY: if (e.code == BTN_TOUCH || e.code == BTN_MOUSE) { bool new_down = e.value; if (new_down != down) { down = new_down; if (new_down) pressing = true; else releasing = true; } } else queue.Push(Event(e.value ? Event::KEY_DOWN : Event::KEY_UP, TranslateKeyCode(e.code))); break; case EV_ABS: moving = true; switch (e.code) { case ABS_X: edit_position.x = e.value; break; case ABS_Y: edit_position.y = e.value; break; } break; case EV_REL: switch (e.code) { case REL_X: rel_x += e.value; break; case ABS_Y: rel_y += e.value; break; } break; } } }
void ServerApp::handleScreenError(const Event&, void*) { LOG((CLOG_CRIT "error on screen")); m_events->addEvent(Event(Event::kQuit)); }
void ServerApp::handleClientsDisconnected(const Event&, void*) { m_events->addEvent(Event(Event::kQuit)); }
MainState MainMenu::run() { SDL_Event event; running = true; quitState = QUIT; Uint32 fpsTicks = SDL_GetTicks(); Uint32 lastticks = fpsTicks; int frame = 0; while(running) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_VIDEORESIZE: initVideo(event.resize.w, event.resize.h); currentMenu->resize(event.resize.w, event.resize.h); getConfig()->videoX = event.resize.w; getConfig()->videoY = event.resize.h; if(currentMenu == optionsMenu.get())//update resolution display { std::stringstream mode; mode.str(""); mode << event.resize.w << "x" << event.resize.h; getParagraph( *optionsMenu, "resolutionParagraph")->setText(mode.str()); } break; case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_KEYDOWN:{ Event gui_event(event); currentMenu->event(gui_event); break; } case SDL_KEYUP: { Event gui_event(event); //In menu ESC as well as ^c exits the game. //might come in handy if video-mode is not working as expected. if( ( gui_event.keysym.sym == SDLK_ESCAPE ) || ( gui_event.keysym.sym == SDLK_c && ( gui_event.keysym.mod & KMOD_CTRL) ) ){ running = false; quitState = QUIT; break; } currentMenu->event(gui_event); break; } case SDL_VIDEOEXPOSE: currentMenu->resize( currentMenu->getWidth(), currentMenu->getHeight() ); break; case SDL_ACTIVEEVENT: if( event.active.gain == 1 ){ currentMenu->resize( currentMenu->getWidth(), currentMenu->getHeight() ); } break; case SDL_QUIT: running = false; quitState = QUIT; break; default: break; } } SDL_Delay(100); // give the CPU time to relax... (we are in main menu) // create update Event Uint32 ticks = SDL_GetTicks(); float elapsedTime = ((float) (ticks - lastticks)) / 1000.0; currentMenu->event(Event(elapsedTime)); lastticks = ticks; if(currentMenu->needsRedraw()) { currentMenu->draw(*painter); flipScreenBuffer(); } frame++; if(ticks - fpsTicks > 1000) { #ifdef DEBUG_FPS printf("MainMenu FPS: %d.\n", (frame*1000) / (ticks - fpsTicks)); #endif frame = 0; fpsTicks = ticks; } } return quitState; }
Event Device::popIO(int id) { if (ioDevices[id].empty()) { return Event(Event::NO_OP, 0.0, 0.0, -1, id); } auto item = ioDevices[id].front(); ioDevices[id].pop(); return item; }
void Push(Event::Callback callback, void *ctx) { Push(Event(callback, ctx)); }
virtual inline void MouseEnter() { Dispatch(Event(UIElement::EvtMouseEnter)); }
// Calculate and return features about the percussiveness of the key press KeyPositionTracker::PercussivenessFeatures KeyPositionTracker::pressPercussiveness() { PercussivenessFeatures features; key_buffer_index index; key_velocity maximumVelocity, largestVelocityDifference; key_buffer_index maximumVelocityIndex, largestVelocityDifferenceIndex; // Check that we have a valid start point from which to calculate if(missing_value<timestamp_type>::isMissing(startTimestamp_) || keyBuffer_.beginIndex() > startIndex_ - 1) { std::cout << "*** no start time\n"; features.percussiveness = missing_value<float>::missing(); return features; } // From the start of the key press, look for an initial maximum in velocity index = startIndex_; maximumVelocity = scale_key_velocity(0); maximumVelocityIndex = startIndex_; largestVelocityDifference = scale_key_velocity(0); largestVelocityDifferenceIndex = startIndex_; std::cout << "*** start index " << index << std::endl; while(index < keyBuffer_.endIndex()) { if(pressIndex_ != 0 && index >= pressIndex_) break; key_position diffPosition = keyBuffer_[index] - keyBuffer_[index - 1]; timestamp_diff_type diffTimestamp = keyBuffer_.timestampAt(index) - keyBuffer_.timestampAt(index - 1); key_velocity velocity = calculate_key_velocity(diffPosition, diffTimestamp); // Look for maximum of velocity if(velocity > maximumVelocity) { maximumVelocity = velocity; maximumVelocityIndex = index; std::cout << "*** found new max velocity " << maximumVelocity << " at index " << index << std::endl; } // And given the difference between the max and the current sample, // look for the largest rebound (velocity hitting a peak and falling) if(maximumVelocity - velocity > largestVelocityDifference) { largestVelocityDifference = maximumVelocity - velocity; largestVelocityDifferenceIndex = index; std::cout << "*** found new diff velocity " << largestVelocityDifference << " at index " << index << std::endl; } // Only look at the early part of the key press: if the key position // makes it more than a certain amount down, assume the initial spike // has passed and finish up. But always allow at least 5 points for the // fastest key presses to be considered. if(index - startIndex_ >= 4 && keyBuffer_[index] > kPositionTrackerPositionThresholdForPercussivenessCalculation) { break; } index++; } // Now transfer what we've found to the data structure features.velocitySpikeMaximum = Event(maximumVelocityIndex, maximumVelocity, keyBuffer_.timestampAt(maximumVelocityIndex)); features.velocitySpikeMinimum = Event(largestVelocityDifferenceIndex, maximumVelocity - largestVelocityDifference, keyBuffer_.timestampAt(largestVelocityDifferenceIndex)); features.timeFromStartToSpike = keyBuffer_.timestampAt(maximumVelocityIndex) - keyBuffer_.timestampAt(startIndex_); // Check if we found a meaningful difference. If not, percussiveness is set to 0 if(largestVelocityDifference == scale_key_velocity(0)) { features.percussiveness = 0.0; features.areaPrecedingSpike = scale_key_velocity(0); features.areaFollowingSpike = scale_key_velocity(0); return features; } // Calculate the area under the velocity curve before and after the maximum features.areaPrecedingSpike = scale_key_velocity(0); for(index = startIndex_; index < maximumVelocityIndex; index++) { key_position diffPosition = keyBuffer_[index] - keyBuffer_[index - 1]; timestamp_diff_type diffTimestamp = keyBuffer_.timestampAt(index) - keyBuffer_.timestampAt(index - 1); features.areaPrecedingSpike += calculate_key_velocity(diffPosition, diffTimestamp); } features.areaFollowingSpike = scale_key_velocity(0); for(index = maximumVelocityIndex; index < largestVelocityDifferenceIndex; index++) { key_position diffPosition = keyBuffer_[index] - keyBuffer_[index - 1]; timestamp_diff_type diffTimestamp = keyBuffer_.timestampAt(index) - keyBuffer_.timestampAt(index - 1); features.areaFollowingSpike += calculate_key_velocity(diffPosition, diffTimestamp); } std::cout << "area before = " << features.areaPrecedingSpike << " after = " << features.areaFollowingSpike << std::endl; features.percussiveness = features.velocitySpikeMaximum.position; return features; }
virtual inline void MouseLeave() { Dispatch(Event(UIElement::EvtMouseLeave)); }
/*-----------------------------------------------*/ void VillagerC::onTrigger() { Event ev = Event(Event::ET_COLLISION_START, "dialog", "villager_grumble"); eventQueue->queueEvent(ev); }
virtual inline void MouseUp() { Dispatch(Event(UIElement::EvtMouseUp)); }
void Edit::tab () { processText (Event (' ')); }
virtual inline void MouseDown() { Dispatch(Event(UIElement::EvtMouseDown)); }
Event Event::mid(unsigned a, unsigned b) { return Event(ev->mid(a, b)); }
bool CEditValue::EventProcess(const Event &event) { CControl::EventProcess(event); if ( (m_state & STATE_VISIBLE) == 0 ) return true; if ( (m_state & STATE_ENABLE) == 0 ) return true; if ( m_state & STATE_DEAD ) return true; if (m_edit != nullptr) { if ( m_edit->GetFocus() && event.type == EVENT_KEY_DOWN && event.GetData<KeyEventData>()->key == KEY(RETURN) ) { float value = GetValue(); if ( value > m_maxValue ) value = m_maxValue; if ( value < m_minValue ) value = m_minValue; SetValue(value, true); HiliteValue(event); } if ( !m_edit->EventProcess(event) ) return false; if ( event.type == m_edit->GetEventType() ) { m_event->AddEvent(Event(m_eventType)); } } if (m_buttonUp != nullptr) { if ( event.type == m_buttonUp->GetEventType() ) { float value = GetValue()+m_stepValue; if ( value > m_maxValue ) value = m_maxValue; SetValue(value, true); HiliteValue(event); } if ( !m_buttonUp->EventProcess(event) ) return false; } if (m_buttonDown != nullptr) { if ( event.type == m_buttonDown->GetEventType() ) { float value = GetValue()-m_stepValue; if ( value < m_minValue ) value = m_minValue; SetValue(value, true); HiliteValue(event); } if ( !m_buttonDown->EventProcess(event) ) return false; } if (event.type == EVENT_MOUSE_WHEEL && Detect(event.mousePos)) { float value = GetValue() + (m_stepValue * event.GetData<MouseWheelEventData>()->y); if ( value < m_minValue ) value = m_minValue; if ( value > m_maxValue ) value = m_maxValue; SetValue(value, true); HiliteValue(event); } return true; }
void Java_org_xcsoar_EventBridge_onMouseUp(JNIEnv *env, jclass cls, jint x, jint y) { event_queue->push(Event(Event::MOUSE_UP, x, y)); }
void Connection::ReadPacket() { if(Errors()) return; /** Handle Reading Packet Type Header. **/ if (!SOCKET) { return; } if(SOCKET->get()->available() > 0 && INCOMING->GetHeader() == 255) { std::vector<unsigned char> HEADER(1, 255); if(Read(HEADER, 1) == 1) INCOMING->SetHeader(HEADER[0]); return; } if(INCOMING->GetHeader() != 255 && !INCOMING->Complete()) { /** Handle Reading Packet Length Header. **/ if (SOCKET->get()->available() >= 4 && INCOMING->GetLength() == 0) { std::vector<unsigned char> BYTES(4, 0); if(Read(BYTES, 4) == 4) { INCOMING->SetLength(BYTES); Event(0); } return; } /** Handle Reading Packet Data. **/ unsigned int nAvailable = (unsigned int)SOCKET->get()->available(); if(nAvailable > 0 && INCOMING->GetLength() > 0 && INCOMING->GetData().size() < INCOMING->GetLength()) { std::vector<unsigned char> DATA( std::min(nAvailable, (unsigned int)(INCOMING->GetLength() - INCOMING->GetData().size())), 0); unsigned int nRead = (unsigned int)Read(DATA, DATA.size()); if(nRead == DATA.size()) { std::vector<unsigned char> dta = INCOMING->GetData(); try { dta.insert(dta.end(), DATA.begin(), DATA.end()); } catch(const std::exception e) { return; } INCOMING->SetData(dta); Event(nRead); } return; } } }
static inline int dispatchCallbacks(bsl::vector<struct ::pollfd> *tmp, bsl::vector<struct ::pollfd>& pollFds, CallbackMap *callbacks) { BSLS_ASSERT(tmp); BSLS_ASSERT(0 == tmp->size()); // Internal invariant int numCallbacks = 0; // Implementation note: We need to make a local copy of signaled the // sockets because an invoked callback can potentially modify 'pollFds' // array thereby corrupting the iteration order. In the worst case, a // full copy of 'pollFds' is made. typedef bsl::vector<struct ::pollfd>::size_type size_type; size_type numSockets = pollFds.size(); for (size_type i = 0; i < numSockets; ++i) { const struct ::pollfd& data = pollFds[i]; if (0 != data.revents) { tmp->push_back(data); } } numSockets = tmp->size(); for (size_type i = 0; i < numSockets; ++i) { const struct ::pollfd& currData = (*tmp)[i]; // READ/ACCEPT. enum { DEFAULT_MASK = POLLERR | POLLHUP | POLLNVAL }; if (currData.revents & (POLLIN | DEFAULT_MASK)) { CallbackMap::iterator callbackIt, cbEnd = callbacks->end(); if (cbEnd != (callbackIt = callbacks->find( Event(currData.fd, EventType::e_READ))) || cbEnd != (callbackIt = callbacks->find( Event(currData.fd, btlso::EventType::e_ACCEPT)))) { (callbackIt->second)(); ++numCallbacks; } } // WRITE/CONNECT. if (currData.revents & (POLLOUT | DEFAULT_MASK)) { CallbackMap::iterator callbackIt, cbEnd = callbacks->end(); if (cbEnd != (callbackIt = callbacks->find( Event(currData.fd, EventType::e_WRITE))) || cbEnd != (callbackIt = callbacks->find( Event(currData.fd, EventType::e_CONNECT)))) { (callbackIt->second)(); ++numCallbacks; } } } tmp->clear(); return numCallbacks; }
void MainWindow::keyPressEvent( QKeyEvent* e ) { // Toggle mouselock if(e->key() == Qt::Key_Alt) SEND_EVENT(&Event_SetMouseLock(false)); // Toggle full screen if((e->key()==Qt::Key_Return) && (e->modifiers()==Qt::AltModifier)) slot_toggleFullScreen(); // Exit program if((e->key()==Qt::Key_F4) && (e->modifiers()==Qt::AltModifier)) SEND_EVENT(&Event(EVENT_QUIT_TO_DESKTOP)); // Toggle editor if((e->key()==Qt::Key_F1)) ui.dockWidget->toggleViewAction()->activate(QAction::Trigger); // Skip menu if((e->key()==Qt::Key_F2)) SEND_EVENT(&Event(EVENT_STARTGAME)); // Toggle cap fps if((e->key()==Qt::Key_F3)) { if(!ui.actionCap_FPS->isChecked()) ui.actionCap_FPS->setChecked(true); else ui.actionCap_FPS->setChecked(false); } // Show debug out print if((e->key()==Qt::Key_F5)) { SEND_EVENT(&Event(EVENT_TOGGLE_DEBUG_MESSAGES)); } if((e->key()==Qt::Key_F6)) { SETTINGS->showDebugPhysics = !SETTINGS->showDebugPhysics; } if((e->key()==Qt::Key_1)) { {Event_PostHudMessage e("Punish them all"); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setStyle(Event_PostHudMessage::STYLE_WARNING); SEND_EVENT(&e);} {Event_PostHudMessage e(""); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setHtmlMessage("","NullProcess", "is executing"); SEND_EVENT(&e);} } if((e->key()==Qt::Key_2)) { // Post hud messages {Event_PostHudMessage e(""); e.receiver = Event_PostHudMessage::RECEIVER_ALL;e.setHtmlMessage("Now running in", "Kernel Mode"); SEND_EVENT(&e);} {Event_PostHudMessage e(""); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setHtmlMessage("Chosen by Scheduler"); SEND_EVENT(&e);} {Event_PostHudMessage e(""); e.receiver = Event_PostHudMessage::RECEIVER_ALL;e.setHtmlMessage("","Blarrghh", "is executing"); e.receiver = Event_PostHudMessage::RECEIVER_ALL_BUT_SUBJECT; SEND_EVENT(&e);} } if((e->key()==Qt::Key_3)) { Event_PostHudMessage e(""); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setStyle(Event_PostHudMessage::STYLE_WARNING); e.message = "Punish them all"; SEND_EVENT(&e); } if((e->key()==Qt::Key_4)) { Event_PostHudMessage e(""); e.setHtmlMessage("You terminated", "Blarrhgh", "", "+2 priority"); e.receiver = Event_PostHudMessage::RECEIVER_ALL; SEND_EVENT(&e); } // // Menu controls during in-game // if(GET_STATE() == STATE_DEATHMATCH) { switch (e->key()) { case Qt::Key_Escape: SEND_EVENT(&Event(EVENT_ENDGAME)); break; case Qt::Key_F11: { static bool hideHud = false; hideHud = !hideHud; SEND_EVENT(&Event_EnableHud(!hideHud)); } break; default: break; } } if(GET_STATE() == STATE_MAINMENU) { //switch(e->key()) //{ //case Qt::Key_Escape: // menu->setAlwaysOnTopAndShow(false); //check // SEND_EVENT(&Event_EnableMenu(false)); //check // break; //default: // break; //} } if(GET_STATE() == STATE_GAMEOVER) { switch (e->key()) { case Qt::Key_Escape: SEND_EVENT(&Event(EVENT_ENDGAME)); break; default: break; } } // Inform about key press SEND_EVENT(&Event_KeyPress(e->key(), true, (e->key() == Qt::Key::Key_Shift), (e->key() == Qt::Key::Key_Tab))); }