bool UITextEditor::HandleTextInput(QKeyEvent *Event) { if (!Event) return false; // For consistency with UIActions::GetActionFromKey, only handle KeyPress if (Event->type() == QEvent::KeyRelease) return false; LOG(VB_GUI, LOG_DEBUG, QString("KeyPress %1 (%2)") .arg(Event->key(), 0, 16).arg(Event->text())); // Event must produce printable text and, in the case of simulated kepresses, // must be marked as printable. For a typical basic remote, this *should* mean // that only 0-9 are handled here.. // As ever, this approach will probably need re-visiting to handle remapping // and remote input methods where printable/non-printable cannot be flagged if (Event->modifiers() == TORC_KEYEVENT_MODIFIERS) return false; QString text = Event->text(); if (text.isEmpty()) return false; QChar character = text.at(0); if (!character.isPrint()) return false; QString newtext(m_text); newtext.insert(m_cursorPosition, text); m_cursorPosition += text.size(); SetText(newtext); return true; }
virtual void Render( OverlayManager* mgr, OverlayRenderer* or ) { if( !mPassword ) { or->DrawString( mGPosition.x + 2, mGPosition.y + 2, mText, 0xFFFFFFFF, 0, mCaretPos ); } else { std::string newtext( mText.length( ), '*' ); or->DrawString( mGPosition.x + 2, mGPosition.y + 2, newtext, 0xFFFFFFFF, 0, mCaretPos ); } return Overlay::Render( mgr, or ); };
bool UITextEditor::HandleAction(int Action) { if (Action == Torc::Left) { if (m_cursorPosition > 0) { m_cursorPosition--; UpdateCursor(); } return true; } else if (Action == Torc::Right) { if (m_cursorPosition < m_text.size()) { m_cursorPosition++; UpdateCursor(); } return true; } else if (Action == Torc::BackSpace) { if (m_cursorPosition > 0 && m_text.size()) { QString newtext(m_text); newtext.remove(m_cursorPosition - 1, 1); m_cursorPosition--; SetText(newtext); } return true; } if (m_parent) return m_parent->HandleAction(Action); return false; }
int worldfactory::show_worldgen_tab_confirm(WINDOW *win, WORLDPTR world) { const int iTooltipHeight = 1; const int iContentHeight = FULL_SCREEN_HEIGHT - 3 - iTooltipHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; const char* line_of_32_underscores = "________________________________"; WINDOW *w_confirmation = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 2 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_confirmationptr( w_confirmation ); unsigned namebar_y = 1; unsigned namebar_x = 3 + utf8_width(_("World Name:")); int line = 1; bool noname = false; input_context ctxt("WORLDGEN_CONFIRM_DIALOG"); ctxt.register_action("HELP_KEYBINDINGS"); ctxt.register_action("QUIT"); ctxt.register_action("ANY_INPUT"); ctxt.register_action("NEXT_TAB"); ctxt.register_action("PREV_TAB"); ctxt.register_action("PICK_RANDOM_WORLDNAME"); std::string worldname = world->world_name; do { mvwprintz(w_confirmation, namebar_y, 2, c_white, _("World Name:")); mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores); fold_and_print(w_confirmation, 3, 2, 76, c_ltgray, _("Press <color_yellow>%s</color> to pick a random name for your world."), ctxt.get_desc("PICK_RANDOM_WORLDNAME").c_str()); fold_and_print(w_confirmation, FULL_SCREEN_HEIGHT / 2 - 2, 2, 76, c_ltgray, _("\ Press <color_yellow>%s</color> when you are satisfied with the world as it is and are ready \ to continue, or <color_yellow>%s</color> to go back and review your world."), ctxt.get_desc("NEXT_TAB").c_str(), ctxt.get_desc("PREV_TAB").c_str()); if (!noname) { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "%s", worldname.c_str()); if (line == 1) { wprintz(w_confirmation, h_ltgray, "_"); } } if (noname) { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores); noname = false; } wrefresh(win); wrefresh(w_confirmation); refresh(); const std::string action = ctxt.handle_input(); if (action == "NEXT_TAB") { #ifndef LUA MOD_INFORMATION *temp = NULL; for (std::string &mod : world->active_mod_order) { temp = mman->mod_map[mod]; if ( temp->need_lua ) { popup(_("Mod '%s' requires Lua support."), temp->name.c_str()); return -2; // Move back to modselect tab. } } #endif if (worldname.empty()) { mvwprintz(w_confirmation, namebar_y, namebar_x, h_ltgray, _("_______NO NAME ENTERED!!!!______")); noname = true; wrefresh(w_confirmation); if (!query_yn(_("Are you SURE you're finished? World name will be randomly generated."))) { continue; } else { world->world_name = pick_random_name(); if (!valid_worldname(world->world_name)) { continue; } return 1; } } else if (query_yn(_("Are you SURE you're finished?")) && valid_worldname(worldname)) { world->world_name = worldname; return 1; } else { continue; } } else if (action == "PREV_TAB") { world->world_name = worldname; return -1; } else if (action == "PICK_RANDOM_WORLDNAME") { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores); world->world_name = worldname = pick_random_name(); } else if (action == "QUIT") { // Cache the current name just in case they say No to the exit query. world->world_name = worldname; return -999; } else if (action == "ANY_INPUT") { const input_event ev = ctxt.get_raw_input(); const long ch = ev.get_first_input(); switch (line) { case 1: { utf8_wrapper wrap(worldname); utf8_wrapper newtext( ev.text ); if( ch == KEY_BACKSPACE ) { if (!wrap.empty()) { wrap.erase(wrap.length() - 1, 1); worldname = wrap.str(); } } else if(ch == KEY_F(2)) { std::string tmp = get_input_string_from_file(); int tmplen = utf8_width( tmp ); if(tmplen > 0 && tmplen + utf8_width(worldname) < 30) { worldname.append(tmp); } } else if( !newtext.empty() && is_char_allowed( newtext.at( 0 ) ) ) { // No empty string, no slash, no backslash, no control sequence wrap.append( newtext ); worldname = wrap.str(); } mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, line_of_32_underscores); mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "%s", worldname.c_str()); wprintz(w_confirmation, h_ltgray, "_"); } break; } } } while (true); return 0; }
static std::string FixShaderCode(char *text, int textLength, const UniformRules &uniformsRename, bool vertexShader) { struct ReplacePair { ReplacePair(const char *pat, const char *rep) : pattern(boost::xpressive::sregex::compile(pat, (boost::xpressive::regex_constants::ECMAScript | boost::xpressive::regex_constants::optimize))), replace(rep) { } boost::xpressive::sregex pattern; std::string replace; }; static const ReplacePair sFixPairs[] = { ReplacePair("\\.0+E\\+0+\\b", ".0"), ReplacePair("0*E\\+0+\\b", ""), ReplacePair("(\\d+)\\.([0-9][1-9])0*E\\+0+2\\b", "$1$2.0"), ReplacePair("(\\d+)\\.([1-9])0*E\\+0+1\\b", "$1$2.0"), ReplacePair("(\\d+)\\.0+E\\-0+1\\b", "0.$1"), ReplacePair("(\\d+)\\.00+E(\\+\\d+)\\b", "$1.0E$2"), ReplacePair("ATI_draw_buffers", "ARB_draw_buffers"), ReplacePair("\\:require\\n", ":enable\n"), ReplacePair("#version \\d+", ""), }; static const boost::xpressive::sregex structPattern(boost::xpressive::sregex::compile("\\bstruct\\s+(\\w+)\\s*{[^}]*};", (boost::xpressive::regex_constants::ECMAScript | boost::xpressive::regex_constants::optimize))); static const int subs[] = {1}; std::string newtext(text, textLength); // Find all the struct declarations std::list<std::string> structsList; boost::xpressive::sregex_token_iterator cur(newtext.begin(), newtext.end(), structPattern, subs); boost::xpressive::sregex_token_iterator end; for(; cur != end; ++cur ) { structsList.push_back(*cur); } // Remove unused struct declarations if (!structsList.empty()) { const std::list<std::string>::const_iterator itEnd(structsList.end()); for (std::list<std::string>::const_iterator it = structsList.begin(); it != itEnd; ++it) { const std::string &structName(*it); boost::xpressive::sregex_iterator cur(newtext.begin(), newtext.end(), (boost::xpressive::_b >> structName >> boost::xpressive::_b)); boost::xpressive::sregex_iterator end; int count = 0; for(; cur != end; ++cur, ++count) { } if (1 >= count) { const boost::xpressive::sregex removeStructPattern(boost::xpressive::sregex::compile("\\bstruct\\s+" + structName + "\\s*{[^}]*};")); newtext = regex_replace(newtext, removeStructPattern, std::string("")); } } structsList.clear(); } // Fix numbers and GLSL 'require's const size_t numPairs = sizeof(sFixPairs) / sizeof(ReplacePair); for (size_t n = 0; n < numPairs; n++) { newtext = regex_replace(newtext, sFixPairs[n].pattern, sFixPairs[n].replace); } // Fix names of uniform values const UniformRules::const_iterator itEnd(uniformsRename.end()); for (UniformRules::const_iterator it = uniformsRename.begin(); it != itEnd; ++it) { newtext = regex_replace(newtext, (it->first), (it->second)); } // Fix vertex attributes if (vertexShader) { struct AttributeReplaceRule { AttributeReplaceRule(const char *src, const char *dst, const char *tn) : re(boost::xpressive::_b >> src >> boost::xpressive::_b), replace(dst), typeName(tn) { } boost::xpressive::sregex re; std::string replace; const char *typeName; }; static const AttributeReplaceRule sAttributeReplaceRules[] = { AttributeReplaceRule("gl_Vertex", "ATTR0", "vec4"), AttributeReplaceRule("gl_Normal", "ATTR2", "vec3"), AttributeReplaceRule("gl_Color", "ATTR3", "vec4"), AttributeReplaceRule("gl_SecondaryColor", "ATTR4", "vec4"), AttributeReplaceRule("gl_FogCoord", "ATTR5", "float"), AttributeReplaceRule("gl_MultiTexCoord0", "ATTR8", "vec4"), AttributeReplaceRule("gl_MultiTexCoord1", "ATTR9", "vec4"), AttributeReplaceRule("gl_MultiTexCoord2", "ATTR10", "vec4"), AttributeReplaceRule("gl_MultiTexCoord3", "ATTR11", "vec4"), AttributeReplaceRule("gl_MultiTexCoord4", "ATTR12", "vec4"), AttributeReplaceRule("gl_MultiTexCoord5", "ATTR13", "vec4"), AttributeReplaceRule("gl_MultiTexCoord6", "ATTR14", "vec4"), AttributeReplaceRule("gl_MultiTexCoord7", "ATTR15", "vec4") }; const size_t numRules = sizeof(sAttributeReplaceRules) / sizeof(AttributeReplaceRule); for (size_t n = numRules; n--; ) { const AttributeReplaceRule &rule(sAttributeReplaceRules[n]); if (regex_search(newtext, rule.re)) { newtext = regex_replace(newtext, rule.re, rule.replace); newtext = std::string("attribute ") + rule.typeName + " " + rule.replace + ";" + newtext; } } }
int worldfactory::show_worldgen_tab_confirm(WINDOW *win, WORLDPTR world) { const int iTooltipHeight = 1; const int iContentHeight = FULL_SCREEN_HEIGHT - 3 - iTooltipHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; WINDOW *w_confirmation = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 2 + iOffsetY, 1 + iOffsetX); unsigned namebar_y = 1; unsigned namebar_x = 3 + utf8_width(_("World Name:")); int line = 1; bool noname = false; input_context ctxt("WORLDGEN_CONFIRM_DIALOG"); // Disabled because it conflicts with the "pick random world name" option, // feel free to enable it and change its keybinding in keybindings.json // ctxt.register_action("HELP_KEYBINDINGS"); ctxt.register_action("QUIT"); ctxt.register_action("ANY_INPUT"); ctxt.register_action("NEXT_TAB"); ctxt.register_action("PREV_TAB"); ctxt.register_action("PICK_RANDOM_WORLDNAME"); std::string worldname = world->world_name; do { mvwprintz(w_confirmation, namebar_y, 2, c_white, _("World Name:")); mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "______________________________"); fold_and_print(w_confirmation, 3, 2, 76, c_ltgray, _("Press <color_yellow>?</color> to pick a random name for your world.")); fold_and_print(w_confirmation, FULL_SCREEN_HEIGHT / 2 - 2, 2, 76, c_ltgray, _("\ Press <color_yellow>></color> when you are satisfied with the world as it is and are ready \ to continue, or <color_yellow><</color> to go back and review your world.")); if (!noname) { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "%s", worldname.c_str()); if (line == 1) { wprintz(w_confirmation, h_ltgray, "_"); } } if (noname) { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "______________________________"); noname = false; } wrefresh(win); wrefresh(w_confirmation); refresh(); const std::string action = ctxt.handle_input(); if (action == "NEXT_TAB") { if (worldname.empty()) { mvwprintz(w_confirmation, namebar_y, namebar_x, h_ltgray, _("______NO NAME ENTERED!!!!_____")); noname = true; wrefresh(w_confirmation); if (!query_yn(_("Are you SURE you're finished? World name will be randomly generated."))) { continue; } else { world->world_name = pick_random_name(); if (!valid_worldname(world->world_name)) { continue; } return 1; } } else if (query_yn(_("Are you SURE you're finished?")) && valid_worldname(worldname)) { world->world_name = worldname; werase(w_confirmation); delwin(w_confirmation); return 1; } else { continue; } } else if (action == "PREV_TAB") { world->world_name = worldname; werase(w_confirmation); delwin(w_confirmation); return -1; } else if (action == "PICK_RANDOM_WORLDNAME") { mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "______________________________"); world->world_name = worldname = pick_random_name(); } else if (action == "QUIT") { world->world_name = worldname; // cache the current worldname just in case they say No to the exit query return -999; } else if (action == "ANY_INPUT") { const input_event ev = ctxt.get_raw_input(); const long ch = ev.get_first_input(); switch (line) { case 1: { utf8_wrapper wrap(worldname); utf8_wrapper newtext( ev.text ); if( ch == KEY_BACKSPACE ) { if (!wrap.empty()) { wrap.erase(wrap.length() - 1, 1); worldname = wrap.str(); } } else if(ch == KEY_F(2)) { std::string tmp = get_input_string_from_file(); int tmplen = utf8_width(tmp.c_str()); if(tmplen > 0 && tmplen + utf8_width(worldname.c_str()) < 30) { worldname.append(tmp); } } else if( !newtext.empty() && is_char_allowed( newtext.at( 0 ) ) ) { // no emty string, no slash, no backslash, no control sequence wrap.append( newtext ); worldname = wrap.str(); } mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "______________________________ "); mvwprintz(w_confirmation, namebar_y, namebar_x, c_ltgray, "%s", worldname.c_str()); wprintz(w_confirmation, h_ltgray, "_"); } break; } } } while (true); return 0; }
string search_replacepre2 (void * webserver_request) { Webserver_Request * request = (Webserver_Request *) webserver_request; string siteUrl = Database_Config_General::getSiteURL (); // Get search variables from the query. string searchfor = request->query ["q"]; string replacewith = request->query ["r"]; bool casesensitive = (request->query ["c"] == "true"); string id = request->query ["id"]; bool searchplain = (request->query ["p"] == "true"); // Get the Bible and passage for this identifier. Passage details = Passage::from_text (id); string bible = details.bible; int book = details.book; int chapter = details.chapter; string verse = details.verse; // Get the plain text or the USFM. string text; if (searchplain) { text = search_logic_get_bible_verse_text (bible, book, chapter, convert_to_int (verse)); } else { text = search_logic_get_bible_verse_usfm (bible, book, chapter, convert_to_int (verse)); } // Clickable passage. string link = filter_passage_link_for_opening_editor_at (book, chapter, verse); string oldtext = filter_string_markup_words ({searchfor}, text); string newtext (text); if (casesensitive) { newtext = filter_string_str_replace (searchfor, replacewith, newtext); } else { vector <string> needles = filter_string_search_needles (searchfor, text); for (auto & needle : needles) { newtext = filter_string_str_replace (needle, replacewith, newtext); } } if (replacewith != "") newtext = filter_string_markup_words ({replacewith}, newtext); // The id sent to the browser contains bible identifier, book, chapter, and verse. int bibleID = request->database_bibles()->getID (bible); vector <string> bits = {convert_to_string (bibleID), convert_to_string (book), convert_to_string (chapter), verse}; string s_id = filter_string_implode (bits, "_"); // Check whether the user has write access to the book. string user = request->session_logic ()->currentUser (); bool write = access_bible_book_write (webserver_request, user, bible, book); // Create output. string output; output.append ("<div id=\"" + s_id + "\">\n"); output.append ("<p>"); if (write) output.append ("<a href=\"replace\"> ✔ </a> <a href=\"delete\"> ✗ </a> "); output.append (link); output.append ("</p>\n"); output.append ("<p>" + oldtext + "</p>\n"); output.append ("<p>"); if (write) output.append (newtext); else output.append (locale_logic_text_no_privileges_modify_book ()); output.append ("</p>\n"); output.append ("</div>\n"); // Output to browser. return output; }