void Console::processCommand() { QString inputString = document()->lastBlock().text(); if (!inputString.startsWith(m_prefix)) { std::cerr << "Error: last block of console did not start with prefix" << std::endl; } inputString.remove(0, m_prefix.length()); if (!inputString.trimmed().isEmpty()) { if (m_history.size() == 0 || m_history.back() != inputString) { m_history.append(inputString); } } m_historyPos = -1; inputString = inputString.trimmed(); prepareCommandLine(); emit command(inputString.toUtf8()); }
Console::Console(QWidget *parent) : QPlainTextEdit(parent) , m_commandLineReady(false) , m_historyPos(-1) , m_completer(0) { QFont f; #ifdef Q_OS_LINUX f.setFamily("Monospace"); f.setPointSize(12); #elif defined(Q_OS_MAC) f.setFamily("Menlo"); f.setPointSize(12); #else f.setFamily("Consolas"); f.setPointSize(12); #endif setFont(f); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setUndoRedoEnabled(false); //setLineWrapMode(QPlainTextEdit::NoWrap); //setWordWrapMode(QTextOption::NoWrap); setBackgroundVisible(false); setFrameStyle(QFrame::NoFrame); setTabStopWidth(40); setAcceptDrops(false); setPrefix("Nexpo> "); setPrefixColor(QColor(30, 128, 50)); f.setBold(true); setPrefixFont(f); m_errorColor = QColor(200, 0, 0); // Restore saved history from last session QSettings settings; m_history = settings.value("consoleCommandHistory").toStringList(); prepareCommandLine(); }
void Console::cls() { clear(); prepareCommandLine(); }
BOOL CXEvilApp::InitInstance() { // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. int t_argc; char **t_argv; prepareCommandLine(m_lpCmdLine,t_argc,t_argv); int t_fullscreencmdlineindex=-1; BOOL t_fullscreenmode=TRUE; int t_reducedrawindex=-1; if (FAILED(CoInitialize(NULL))) { AfxMessageBox("Error loading COM"); return FALSE; } for (int i=0;i<t_argc;i++) { if (!strcmp(t_argv[i],"-full_screen")) { t_fullscreencmdlineindex=i; } else if (!strcmp(t_argv[i],"-window_screen")) { t_fullscreenmode=FALSE; } else if (!strcmp(t_argv[i],"-reduce_draw")) { t_reducedrawindex=i;; } } CXEvilApp::StartSDL(); AboutDialog t_dlg; t_dlg.enableFullScreenButton(TRUE); t_dlg.setFullScreenMode(t_fullscreenmode); t_dlg.enableReduceDraw(TRUE); t_dlg.setReduceDraw(t_reducedrawindex != -1); t_dlg.setVersionString(Game::get_version_string()); t_dlg.setLicenseText(LAgreement::get_text()); if (t_dlg.DoModal()!= IDOK) { exit(0); } t_fullscreenmode=t_dlg.getFullScreenMode(); if (t_fullscreenmode&&(t_fullscreencmdlineindex== -1)) { t_argv[t_argc++]=_strdup("-full_screen"); } if (!t_fullscreenmode&&(t_fullscreencmdlineindex!= -1)) { t_argv[t_fullscreencmdlineindex]=_strdup("-window_screen"); } if (t_dlg.getReduceDraw() && t_reducedrawindex == -1) { t_argv[t_argc++]=_strdup("-reduce_draw"); } if (!t_dlg.getReduceDraw() && t_reducedrawindex != -1) { t_argv[t_reducedrawindex]=_strdup("-dummy_arg"); } BOOL t_timecheck=timeStampcheck(); if (!t_timecheck) { TimeStampFailedDlg t_timefailed; t_timefailed.DoModal(); return FALSE; } #ifdef _AFXDLL //Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif LoadStdProfileSettings(0); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CTypedPtrList<CPtrList,CWnd *> t_wndlist; srand((unsigned int)time(NULL)); WORD wVersionRequested; WSADATA wsaData; int err; wVersionRequested = MAKEWORD(2, 0); err = WSAStartup(wVersionRequested, &wsaData); // Ui::check_num_lock(); m_game = new Game(&t_argc,t_argv); m_game->getWindowList(t_wndlist); if (clock()== -1) assert (FALSE); long total = 0; long events = 0; CMN_EVENTDATA t_event;//for messasge reception int t_timer; BOOL t_gameover=FALSE; // TurnStarter exists so Game::yield() can decide when to start timing the next turn. TurnStarter turnStarter(t_timer); // Start the first turn. turnStarter.start_turn(); // Main loop while (!t_gameover) { // wait till it's time to wake up int t_wndCount = m_game->getWindowList(t_wndlist); Quanta quanta = m_game->get_quanta(); // Clock the game total++; POSITION t_pos; m_game->pre_clock(); // If there is no UI at all, don't check for events. if (t_wndCount != -1) { for( t_pos = t_wndlist.GetHeadPosition(); t_pos != NULL; ) { CWnd *t_wnd=t_wndlist.GetNext(t_pos); assert(t_wnd); t_event.m_parent=t_wnd->m_hWnd; while (PeekMessage(&t_event.m_event,t_wnd->m_hWnd,NULL,NULL,PM_REMOVE)) { if (TranslateMessage(&t_event.m_event)) break; if (!m_game->process_event(0,t_event)) break; } } } m_game->post_clock(); if (m_game->show_stats() && !(total % Game::REPORT_TIME)) { std::cout << "total:" << total << " events:" << events << " percent:" << ((float)events / (float) total) << std::endl; } if (m_game->quit_game()) { t_gameover = TRUE; break; } m_game->yield(t_timer,quanta,&turnStarter); } for (int i=1;i<t_argc;i++) { delete t_argv[i]; } delete t_argv; return FALSE; }