diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2015-09-05 09:32:30 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2015-09-05 09:32:30 -0400 |
commit | ea76b6988ccafaa6a4d4ed90f2489d0e49e1f180 (patch) | |
tree | b01dd19f5c53406d9d636b18bc49916bfdd6d3bc /g_src/ViewBase.cpp |
Imported Upstream version 0.40.24upstream/0.40.24upstream
Diffstat (limited to 'g_src/ViewBase.cpp')
-rwxr-xr-x | g_src/ViewBase.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/g_src/ViewBase.cpp b/g_src/ViewBase.cpp new file mode 100755 index 0000000..6063732 --- /dev/null +++ b/g_src/ViewBase.cpp @@ -0,0 +1,38 @@ +#include <assert.h> +#include <iostream> +#include "ViewBase.h" + +using namespace std; +using namespace widgets; + +void textbox::feed(set<InterfaceKey> &input) { + // Backspace + if (input.count(INTERFACEKEY_STRING_A000) && text.size()) + text.resize(text.size() - 1); + // Hopefully we'll never get multiple characters in one input set, + // but it's possible. We deal with this by inserting them in + // alphabetical order. + for (set<InterfaceKey>::iterator it = input.lower_bound(INTERFACEKEY_STRING_A001); + it != input.end() && *it <= INTERFACEKEY_STRING_A255; + ++it) { + if (keep == false) { + keep = true; + text.clear(); + } + char c = *it - INTERFACEKEY_STRING_A000; + text += c; + } +} + +void textbox::render(int x1, int x2, int y1, int y2) { + // We need to do some kind of line-breaking for multi-line text + // entry boxes. This shall be implemented at need, and there is none + // yet. + assert(y1 == y2); + gps.erasescreen_rect(x1,x2,y1,y2); + gps.locate(y1,x1); + gps.changecolor(7,0,keep); + int width = x2 - x1 + 1; + int start = text.length() - width; + gps.addst(text.substr(MAX(start,0))); +} |