static void udp_recv(const struct sa *src, struct mbuf *mb, void *arg) { struct ui_st *st = arg; struct mbuf *mbr = mbuf_alloc(64); struct re_printf pf; st->udp_peer = *src; pf.vph = print_handler; pf.arg = mbr; while (mbuf_get_left(mb)) { char ch = mbuf_read_u8(mb); if (ch == '\r') ch = '\n'; ui_input_key(ch, &pf); } if (mbr->end > 0) { mbr->pos = 0; (void)udp_send(st->us, src, mbr); } mem_deref(mbr); }
static void report_key(struct ui_st *ui, char key) { static struct re_printf pf_stderr = {print_handler, NULL}; (void)ui; ui_input_key(key, &pf_stderr); }
int ui_input(int x0, int y0, int x1, int y1, struct input *input) { float px, qx; char *p, *q; int state; if (ui.x >= x0 && ui.x < x1 && ui.y >= y0 && ui.y < y1) { ui.hot = input; if (!ui.active && ui.down) { input->p = find_string_location(input->text, input->end, x0 + 2, ui.x); ui.active = input; } } if (ui.active == input) { input->q = find_string_location(input->text, input->end, x0 + 2, ui.x); ui.focus = input; } if (!ui.focus) ui.focus = input; if (ui.focus == input) state = ui_input_key(input); else state = 0; glColor4f(0, 0, 0, 1); glRectf(x0, y0, x1, y1); glColor4f(1, 1, 1, 1); glRectf(x0+1, y0+1, x1-1, y1-1); p = input->p < input->q ? input->p : input->q; q = input->p > input->q ? input->p : input->q; px = x0 + 2 + measure_string_part(input->text, p); qx = px + measure_string_part(p, q); if (ui.focus) { glColor4f(0.6f, 0.6f, 1.0f, 1.0f); glRectf(px, y0 + 2, qx+1, y1 - 2); } glColor4f(0, 0, 0, 1); draw_string_part(x0 + 2, y0 + 2, input->text, input->end); return state; }
static void tcp_recv_handler(struct mbuf *mb, void *arg) { struct ui_st *st = arg; struct re_printf pf; pf.vph = tcp_write_handler; pf.arg = st->tc; while (mbuf_get_left(mb) > 0) { char ch = mbuf_read_u8(mb); if (ch == '\r') ch = '\n'; ui_input_key(ch, &pf); } }