README: explain further musl-specific tweaks
[rofl0r-df-libgraphics.git] / g_src / ViewBase.cpp
blob6063732832f6319d521ca6a521bf5f651bcb9fb6
1 #include <assert.h>
2 #include <iostream>
3 #include "ViewBase.h"
5 using namespace std;
6 using namespace widgets;
8 void textbox::feed(set<InterfaceKey> &input) {
9 // Backspace
10 if (input.count(INTERFACEKEY_STRING_A000) && text.size())
11 text.resize(text.size() - 1);
12 // Hopefully we'll never get multiple characters in one input set,
13 // but it's possible. We deal with this by inserting them in
14 // alphabetical order.
15 for (set<InterfaceKey>::iterator it = input.lower_bound(INTERFACEKEY_STRING_A001);
16 it != input.end() && *it <= INTERFACEKEY_STRING_A255;
17 ++it) {
18 if (keep == false) {
19 keep = true;
20 text.clear();
22 char c = *it - INTERFACEKEY_STRING_A000;
23 text += c;
27 void textbox::render(int x1, int x2, int y1, int y2) {
28 // We need to do some kind of line-breaking for multi-line text
29 // entry boxes. This shall be implemented at need, and there is none
30 // yet.
31 assert(y1 == y2);
32 gps.erasescreen_rect(x1,x2,y1,y2);
33 gps.locate(y1,x1);
34 gps.changecolor(7,0,keep);
35 int width = x2 - x1 + 1;
36 int start = text.length() - width;
37 gps.addst(text.substr(MAX(start,0)));