void MenuScene::onKeyDown(SDLKey sym, SDLMod mod, Uint16 unicode) { if (sym == SDLK_ESCAPE) { onExit(); } if( sym == SDLK_F1) enterPlayGround(); if (sym == SDLK_RETURN) { switch (menuFocus) { case LOGIN: login(); break; case NEW_ACCOUNT: #ifdef DEF_MAKEACCOUNT newAccount(); #endif break; case EXIT: onExit(); break; } } if (sym == SDLK_UP) { switch (menuFocus) { case LOGIN: menuFocus = EXIT; break; case NEW_ACCOUNT: menuFocus = LOGIN; break; case EXIT: menuFocus = NEW_ACCOUNT; break; } } if (sym == SDLK_DOWN || sym == SDLK_TAB) { switch (menuFocus) { case LOGIN: menuFocus = NEW_ACCOUNT; break; case NEW_ACCOUNT: menuFocus = EXIT; break; case EXIT: menuFocus = LOGIN; break; } } }
DialogRecepti::DialogRecepti(QWidget *parent) : QDialog(parent), ui(new Ui::DialogRecepti) { ui->setupUi(this); ui->listWidget->setSelectionMode(QAbstractItemView::SingleSelection); connect(ui->btnOpenFile,SIGNAL(clicked()),this,SLOT(onOpenFile())); connect(ui->btnExit,SIGNAL(clicked()),this,SLOT(onExit())); char * fn = new char[40]; strcpy(fn,"/sdcard/recepti/recepti.bet"); dict = iniparser_load(fn); if(dict == NULL) { QMessageBox::information(this,"iniparser library",QString("Failed to load dictionary from file:\n%1").arg(fn)); return; } int n = iniparser_getnsec(dict); //QMessageBox::information(this,QString("iniparser"),QString("%1 sections found from file: %2").arg(n).arg(fn)); if(n>0) { for(int i =0 ; i<n ; i++) { QString str(iniparser_getsecname(dict,i)); ui->listWidget->addItem(str.toUpper()); } ui->listWidget->item(0)->setSelected(true); } }
void View::exit() { onExit(); for (View* v : m_children) { v->exit(); } }
/* //////////////////////////////////////////////////////////////////////////// * Default constructor */ TTMpeg2MainWnd::TTMpeg2MainWnd() :QMainWindow() { setupUi(this); // some default values currentStreamOrder = -1; isProjectOpen = false; sliderUpdateFrame = false; enableControls(false); // Conect signals from main menu connect(actionFileOpen, SIGNAL(triggered()), videoFileInfo, SLOT(onFileOpen())); connect(actionAnalyze, SIGNAL(triggered()), SLOT(onAnalyze())); connect(actionSettings, SIGNAL(triggered()), SLOT(onSettings())); connect(actionExit, SIGNAL(triggered()), SLOT(onExit())); connect(actionWriteHeaderList, SIGNAL(triggered()), SLOT(onWriteHeaderList())); // Connect signals from video file info widget connect(videoFileInfo, SIGNAL(fileOpened(QString)), SLOT(onLoadVideoFile(QString))); // Connect signals from the step control widget connect(stepControl, SIGNAL(gotoNextFrame(int, int)), SLOT(onGotoNextFrame(int, int))); connect(stepControl, SIGNAL(gotoPrevFrame(int, int)), SLOT(onGotoPrevFrame(int, int))); // Scroller connect(scroller, SIGNAL(valueChanged(int)), SLOT(onSliderValueChanged(int))); }
static std::string FormatMessageU(IErrorReporter& reporter, HMODULE hModule, DWORD messageId, va_list* argPtr) { wchar_t* messagePtr = nullptr; ScopeExit onExit([&]() { if (messagePtr) { LocalFree(messagePtr); }} ); if (FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY, hModule, messageId, LANG_SYSTEM_DEFAULT, reinterpret_cast<LPWSTR>(&messagePtr), 0, argPtr) == 0) { reporter.ReportLastWinError("FormatMessageW"); messagePtr = nullptr; } return utf8::ToUtf8(messagePtr); }
// react to keys void keyboard(unsigned char k, int , int ) { switch(k) { case 27: onExit(); OSG::osgExit(); exit(0); break; case 'f': g_mgr->setNavigationMode(OSG::Navigator::FLY); break; case 't': g_mgr->setNavigationMode(OSG::Navigator::TRACKBALL); break; case 'q': g_mgr->setStatistics(true); break; case 'w': g_mgr->setStatistics(false); break; case 'r': { bool useTrav = !g_mgr->getUseTraversalAction(); g_mgr->setUseTraversalAction(useTrav); printf("Using %s action.\n", useTrav ? "render traversal" : "render"); } break; } }
int AppBase::run() { if (!onInit()) { return -1; } frame_timer.reset(); // game main loop begin . SDL_Event evnt; leave_main_loop = false; while (!leave_main_loop) { if (SDL_PollEvent(&evnt)) { processGlobalEvent(evnt); if (onEvent(evnt) == false) { processUnhandleEvent(evnt); } } if (!leave_main_loop) { onUpdate(); onRender(); } frame_timer.update(); } onExit(); return 0; }
void EventDispatcherBase<TDerived>::leaveStatesInExitSet(event_type event) { for (auto atomicState = derived().atomic_begin(); atomicState != derived().atomic_end(); ++atomicState) { if (!(atomicState->m_flags & state_type::InExitSet)) continue; state_type* state = &*atomicState; state_type* parent = state->parent(); while (parent && (parent->m_flags & state_type::InExitSet)) { if (parent->m_flags & (state_type::ShallowHistory | state_type::DeepHistory)) { using history_state_type = ShallowHistoryState<TDerived>; history_state_type* historyState = static_cast<history_state_type*>(parent); historyState->m_latestActiveChild = state; } state = parent; parent = state->parent(); } } for (auto iter = derived().post_order_begin(); iter != derived().post_order_end(); ++iter) { if (iter->m_flags & state_type::InExitSet) { derived().invokeStateExitCallback(&*iter); iter->m_flags &= ~state_type::StartInvoke; if (iter->m_flags & state_type::Invoked) { iter->m_flags &= ~state_type::Invoked; try { iter->exitInvoke(); } catch (...) { derived().invokeStateExceptionCallbackOrThrow(); } } iter->m_flags &= ~(state_type::Active | state_type::InExitSet); try { iter->onExit(event); } catch (...) { derived().invokeStateExceptionCallbackOrThrow(); } } } }
/*! * \brief Applies the controllers * * \param mapper Mapper containing layout information of each particle * \param particleCount Number of particles * \param elapsedTime Delta time between the previous frame */ void ParticleGroup::ApplyControllers(ParticleMapper& mapper, unsigned int particleCount, float elapsedTime) { m_processing = true; // To avoid a lock in case of exception CallOnExit onExit([this]() { m_processing = false; }); for (ParticleController* controller : m_controllers) controller->Apply(*this, mapper, 0, particleCount - 1, elapsedTime); onExit.CallAndReset(); // We only kill now the dead particles during the update if (m_dyingParticles.size() < m_particleCount) { // We kill them in reverse order, std::set sorting them via std::greater // The reason is simple, as the death of a particle means moving the last particle in the buffer, // without this solution, certain particles could avoid death for (unsigned int index : m_dyingParticles) KillParticle(index); } else KillParticles(); // Every particles are dead, this is way faster m_dyingParticles.clear(); }
bool ModuleName::Initialize() { if (s_moduleReferenceCounter > 0) { s_moduleReferenceCounter++; return true; // Already initialized } // Initialize module dependencies if (!Core::Initialize()) { NazaraError("Failed to initialize core module"); return false; } s_moduleReferenceCounter++; CallOnExit onExit(ModuleName::Uninitialize); // Initialize module here onExit.Reset(); NazaraNotice("Initialized: ModuleName module"); return true; }
bool FTP_Socket::onEnter() { std::cout << "FTP_Socket::onEnter()" << std::endl; IPaddress ip; set = SDLNet_AllocSocketSet(1); if(!set) { printf("SDLNet_AllocSocketSet: %s\n", SDLNet_GetError()); onExit(); return false; } /* Resolve the argument into an IP address type */ std::cout << "Connecting to " << host.c_str() << " on port " << port << std::endl; if(SDLNet_ResolveHost(&ip,host.c_str(),port) == -1) { printf("SDLNet_ResolveHost: %s\n",SDLNet_GetError()); onExit(); return false; } //open the socket controlSocket = SDLNet_TCP_Open(&ip); if(!controlSocket) { printf("SDLNet_TCP_Open: %s\n",SDLNet_GetError()); onExit(); return false; } if(SDLNet_TCP_AddSocket(set,controlSocket) == -1) { printf("SDLNet_TCP_AddSocket: %s\n",SDLNet_GetError()); onExit(); return false; } /* reference Only if(SDLNet_TCP_DelSocket(set,controlSocket) == -1) { printf("SDLNet_DelSocket: %s\n",SDLNet_GetError()); onExit(); return false; } */ return true; }
void GameBaseDialog::cancel() { onExit(); this->removeFromParentAndCleanup(true); if (m_pCancelCallbackTarget && m_selector) { (m_pCancelCallbackTarget->*m_selector)(NULL); } }
void SmartScene::onExit() { while( _stack.size() > 1 ) { auto layer = _stack.back(); layer->onExit(); } Scene::onExit(); }
InGameState::~InGameState() { if (m_factory) { delete m_factory; m_factory = NULL; } onExit(); }
void IGame::destroy() { if(_state != GameState::DESTROYED) { _state = GameState::DESTROYED; SDL_StopTextInput(); if(_screenManager) { delete _screenManager; } onExit(); } }
void AndroidRuntime::exit(int code) { if (mExitWithoutCleanup) { ALOGI("VM exiting with result code %d, cleanup skipped.", code); ::_exit(code); } else { ALOGI("VM exiting with result code %d.", code); onExit(code); ::exit(code); } }
void process_t::finished(childProcess_t *child,int exitStat) { QMap<Q_PID,childProcess_t *>::iterator it = processes.find(child->getpid()); if (it != processes.end()) { processes.erase(it); printf ("%s: process %lld finished\n", __PRETTY_FUNCTION__, child->getpid()); emit onExit(child->getpid(), exitStat); } else { printf ("%s: process %lld not found\n", __PRETTY_FUNCTION__, child->getpid()); } }
void SmartScene::blockTopLayer() { if( _stack.empty() == false ) { _nowBlockedTopLayer = true; auto top = _stack.back(); assert( top->isRunning() ); top->onExit(); _shadow->setLocalZOrder( top->getLocalZOrder() + 1 ); } }
R handleMethodInvocation(const typename fakeit::production_arg<arglist>::type... args) override { std::shared_ptr<Destructible> destructablePtr = _recordedActions.front(); Destructible &destructable = *destructablePtr; Action<R, arglist...> &action = dynamic_cast<Action<R, arglist...> &>(destructable); std::function<void()> finallyClause = [&]() -> void { if (action.isDone()) _recordedActions.erase(_recordedActions.begin()); }; Finally onExit(finallyClause); return action.invoke(std::forward<const typename fakeit::production_arg<arglist>::type>(args)...); }
void PhantomGame::exit(int returncode) { _running = false; vector<Composite*> components = getComponents(); for(auto component = components.begin(); component != components.end(); ++component) { (*component)->destroy(); } components.clear(); clearDisposables(); onExit(returncode); }
virtual R handleMethodInvocation(ArgumentsTuple<arglist...> & args) override { std::shared_ptr<Destructible> destructablePtr = _recordedActions.front(); Destructible &destructable = *destructablePtr; Action<R, arglist...> &action = dynamic_cast<Action<R, arglist...> &>(destructable); std::function<void()> finallyClause = [&]() -> void { if (action.isDone()) _recordedActions.erase(_recordedActions.begin()); }; Finally onExit(finallyClause); return action.invoke(args); }
/* handle Telnet better */ int FTP_Socket::recvSocket(char *message) { Uint32 result; /* get the string buffer over the socket */ result = SDLNet_TCP_Recv(controlSocket, message, 8192); // TCP Connection is broken. (because of error or closure) if(result <= 0) { onExit(); return -1; } /* return the new buffer */ return result; }
void MenuScene::onLButtonDown(int x, int y) { if (x > 385 && x < (385 + 164)) // Login Button { if (y > 178 && y < (178 + 22)) login(); #ifdef DEF_MAKEACCOUNT if (y > 216 && y < (216 + 22)) newAccount(); #endif if (y > 255 && y < (255 + 22)) onExit(); } }
void Event::eventProc(SDL_Event* e) { switch (e->type) { case SDL_WINDOWEVENT: break; case SDL_KEYDOWN: //key pressed onKeyPressed(e->key.keysym); break; case SDL_KEYUP: //key released onKeyReleased(e->key.keysym); break; case SDL_MOUSEMOTION: onMouseMove(e->motion); break; case SDL_MOUSEBUTTONDOWN: if (e->button.button == SDL_BUTTON_LEFT) onLMouseButtonPressed(e->button); else if (e->button.button == SDL_BUTTON_RIGHT) onRMouseButtonPressed(e->button); else if (e->button.button == SDL_BUTTON_MIDDLE) onMMouseButtonPressed(e->button); else ; break; case SDL_MOUSEBUTTONUP: if (e->button.button == SDL_BUTTON_LEFT) onLMouseButtonReleased(e->button); else if (e->button.button == SDL_BUTTON_RIGHT) onRMouseButtonReleased(e->button); else if (e->button.button == SDL_BUTTON_MIDDLE) onMMouseButtonReleased(e->button); else ; break; case SDL_MOUSEWHEEL: onMouseWheelMove(e->wheel); break; case SDL_QUIT: onExit(); break; default: onUser(); } }
void SmartScene::pushLayer( Layer* layer, bool exitPrevios ) { shadow_appearance(); if( layer ) { assert( _stack.empty() == false ); auto top = _stack.back(); int z = top->getLocalZOrder() + 2; _shadow->setLocalZOrder( z - 1 ); layer->setOnExitCallback( std::bind( &SmartScene::on_layerClosed, this, layer ) ); addChild( layer, z ); _stack.push_back( layer ); if( exitPrevios ) top->onExit(); } }
MyWidget::MyWidget (QWidget *parent) : QWidget(parent) { setFixedSize(350, 220); line3 = new QLineEdit (this); bExit = new QPushButton ("&Exit", this); bRnd = new QPushButton ("&RND", this); QVBoxLayout *mainLayout = new QVBoxLayout; line3->setReadOnly (true); mainLayout->addWidget(line3); mainLayout->addWidget(bRnd); mainLayout->addWidget(bExit); setLayout(mainLayout); connect (bRnd, SIGNAL(clicked ()), this, SLOT (setValue())); connect (bExit, SIGNAL(clicked ()), this, SLOT (onExit ())); }
int Application::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: update((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 1: setToZero(); break; case 2: onExit(); break; case 3: Tick(); break; case 4: Screen(); break; case 5: Hide(); break; default: ; } _id -= 6; } return _id; }
void WFrame::manageConnections() { QObject::connect(c,SIGNAL(exitProgram()),this,SLOT(onExit())); QObject::connect(c,SIGNAL(FileLoadedSignal(int)),this,SLOT(FileLoaded(int))); QObject::connect(c,SIGNAL(closeMap()),this,SLOT(onCloseMap())); QObject::connect(this,SIGNAL(closeMapButtonClicked()),c,SLOT(closeMapClicked())); QObject::connect(c,SIGNAL(loadMapSignal()),this,SLOT(loadMap())); QObject::connect(c,SIGNAL(noNodesSignal()),this,SLOT(errorNodes())); QObject::connect(c,SIGNAL(noOSMSignal()),this,SLOT(errorOSM())); QObject::connect(c,SIGNAL(multipleDropSignal()),this,SLOT(multipleDrop())); //ACTION CONNECTS QObject::connect(open,SIGNAL(triggered()),this,SLOT(getFile())); QObject::connect(exit,SIGNAL(triggered()),c,SLOT(exitClicked())); QObject::connect(closeFile,SIGNAL(triggered()),this,SLOT(checkMap())); QObject::connect(about,SIGNAL(triggered()),this,SLOT(showAbout())); QObject::connect(links,SIGNAL(triggered()),this,SLOT(showLinks())); }
//-----------------------------------------// MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent, Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint), ui_(std::unique_ptr<Ui::MainWindow>(new Ui::MainWindow)), armsManager_(std::unique_ptr<ArmsManager>(new ArmsManager())), remoteDevicesManager_(std::unique_ptr<RemoteDevicesManager>(new RemoteDevicesManager())) { ui_->setupUi(this); setWindowTitle(QApplication::applicationName()); setWindowIcon(QApplication::windowIcon()); // tray connect(&tray_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onTrayActivated(QSystemTrayIcon::ActivationReason))); menu_.addAction(tr("Открыть"),this,SLOT(onShow()))->setVisible(false); menu_.setDefaultAction(menu_.addAction(tr("Спрятать"),this,SLOT(onHide()))); menu_.addSeparator(); // menu_.addAction(tr("Лог"),this,SLOT(onShowLog())); // menu_.addAction(tr("Выход"),this,SLOT(onExit())); menu_.addSeparator(); tray_.setContextMenu(&menu_); // movia_.stop(); // movia_.setFileName(":/new/list/LAN.png"); // movia_.start(); // tray_.setIcon(QIcon(movia_.currentPixmap())); tray_.setIcon(QIcon(":/new/list/LAN.png")); tray_.show(); onHide(); assert(armsManager_); armsManager_->init(); tray_.showMessage(QApplication::applicationName(), tr("Программа запущена: порт %1").arg(Settings::value("server/port").toUInt())); }
void test_scope_guard() { { int *pi = new int; ZL::ScopeGuard onExit([&] { delete pi; pi = nullptr; }); } { SC *sc = new SC; ZL::ON_SCOPE_EXIT([&sc]{ delete sc; sc = nullptr; }); // Ok //ON_SCOPE_EXIT([&sc]{ Safe_Delete(sc) }); // Ok } std::cout << "===================\n"; { SC *sc = new SC; //ON_SCOPE_EXIT([&sc]{ Safe_Delete(sc) }); ZL::ScopeGuard rollbackIfFail([&]{ sc->RollBack(); }); do { //do something..... if (sc->Fail()) { break; } rollbackIfFail.dismiss(); //上面if失败,走不到这里,因此会导致ScopeGuard执行sc的RollBack函数 } while (0); } std::cout << "===================\n"; { SC *sc = new SC(1); ZL::ON_SCOPE_EXIT([&sc]{ Safe_Delete(sc) }); ZL::ScopeGuard rollbackIfFail([&]{ sc->RollBack(); }); do { //do something..... if (!sc->Success()) { break; } rollbackIfFail.dismiss(); //执行到这里,设置取消rollback机制,执行成功 } while (0); }