From c07e22ca5eff718d42b43b375db2bda317d65a02 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 3 Jul 2019 07:31:09 +0200 Subject: [PATCH] onscreen keyboards where applicable --- archimedean.cpp | 5 +++++ dialogs.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++-- hyper.h | 3 ++- langen.cpp | 4 ++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/archimedean.cpp b/archimedean.cpp index b4bb98c6..74378141 100644 --- a/archimedean.cpp +++ b/archimedean.cpp @@ -1067,6 +1067,11 @@ void show() { edited.compute_geometry(); dialog::addSelItem(XLAT("edge length"), fts(edited.edgelength) + (edited.get_class() == gcEuclid ? XLAT(" (arbitrary)") : ""), 0); current.compute_geometry(); + + dialog::addBreak(100); + dialog::addKeyboardItem("1234567890"); + dialog::addKeyboardItem("()[]lLhH,"); + dialog::addKeyboardItem(" \t\b\x1\x2\n"); dialog::addBreak(100); } else { diff --git a/dialogs.cpp b/dialogs.cpp index 6444cad4..866d8220 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -166,6 +166,16 @@ namespace dialog { return c; } + void addKeyboardItem(string keys) { + item it; + it.type = diKeyboard; + it.body = keys; + it.color = dialogcolor; + it.colors = 0xFF8000; + it.scale = 100; + items.push_back(it); + } + void addColorItem(string body, int value, int key) { item it; it.type = diItem; @@ -417,6 +427,38 @@ namespace dialog { } if(xthis) getcstat = I.key, inslider = true; } + else if(I.type == diKeyboard) { + int len = 0; + for(char c: I.body) + if(c == ' ' || c == '\t') len += 3; + else len++; + int sl, sr; + if(current_display->sidescreen) + sl = vid.yres + vid.fsize*2, sr = vid.xres - vid.fsize*2; + else + sl = vid.xres/4, sr = vid.xres*3/4; + int pos = 0; + for(char c: I.body) { + string s = ""; + s += c; + int nlen = 1; + if(c == ' ') s = "SPACE", nlen = 3; + if(c == '\b') s = "⌫", nlen = 1; + if(c == '\r' || c == '\n') s = "⏎", nlen = 1; + if(c == 1) s = "←", nlen = 1; + if(c == 2) s = "→", nlen = 1; + if(c == 3) s = "π"; + if(c == '\t') s = "CLEAR", nlen = 3; + int xpos = sl + (sr-sl) * (pos + nlen/2.) / len; + if(displayfr(xpos, mid, 2, dfsize * I.scale/100, s, I.color, 8)) { + displayfr(xpos, mid, 2, dfsize * I.scale/100, s, I.colors, 8); + if(c == 1) getcstat = SDLK_LEFT; + else if(c == 2) getcstat = SDLK_RIGHT; + else getcstat = c; + } + pos += nlen; + } + } } } @@ -684,6 +726,15 @@ namespace dialog { int numberdark; + void formula_keyboard(bool lr) { + addKeyboardItem("1234567890"); + addKeyboardItem(".+-*/^()\x3"); + addKeyboardItem("qwertyuiop"); + addKeyboardItem("asdfghjkl"); + addKeyboardItem("zxcvbnm,.\b"); + addKeyboardItem(lr ? " \t\x1\x2" : " \t"); + } + void drawNumberDialog() { cmode = sm::NUMBER | dialogflags; gamescreen(numberdark); @@ -712,12 +763,15 @@ namespace dialog { if(extra_options) extra_options(); + formula_keyboard(false); + display(); keyhandler = [] (int sym, int uni) { handleNavigation(sym, uni); - if((uni >= '0' && uni <= '9') || among(uni, '.', '+', '-', '*', '/', '^', '(', ')', ',') || (uni >= 'a' && uni <= 'z')) { - ne.s += uni; + if((uni >= '0' && uni <= '9') || among(uni, '.', '+', '-', '*', '/', '^', '(', ')', ',', 3) || (uni >= 'a' && uni <= 'z')) { + if(uni == 3) ne.s += "pi"; + else ne.s += uni; apply_edit(); } else if(uni == '\b' || uni == '\t') { @@ -1072,6 +1126,8 @@ namespace dialog { init(ne.title); addInfo(view_edited_string()); addBreak(100); + formula_keyboard(true); + addBreak(100); dialog::addBack(); addBreak(100); diff --git a/hyper.h b/hyper.h index 22e6e9bc..554cccfa 100644 --- a/hyper.h +++ b/hyper.h @@ -1911,7 +1911,7 @@ namespace dialog { extern color_t dialogcolor; extern int dfsize, dfspace; - enum tDialogItem {diTitle, diItem, diBreak, diHelp, diInfo, diIntSlider, diSlider, diBigItem}; + enum tDialogItem {diTitle, diItem, diBreak, diHelp, diInfo, diIntSlider, diSlider, diBigItem, diKeyboard}; struct item { tDialogItem type; @@ -1970,6 +1970,7 @@ namespace dialog { void addHelp(string body); void addInfo(string body, color_t color = dialogcolor); void addItem(string body, int key); + void addKeyboardItem(string keys); int addBreak(int val); void addTitle(string body, color_t color, int scale); diff --git a/langen.cpp b/langen.cpp index 5ef79b2d..b453c8b9 100644 --- a/langen.cpp +++ b/langen.cpp @@ -295,6 +295,10 @@ int main() { allchars.insert("π"); allchars.insert("Θ"); allchars.insert("λ"); + allchars.insert("⌫"); + allchars.insert("⏎"); + allchars.insert("←"); + allchars.insert("→"); langPL(); langCZ(); langRU(); langTR(); langDE(); langPT();