commit 2c59a66
uint
·
2026-06-12 16:43:36 +0000 UTC
parent 657d974
basic-window: type user input
2 files changed,
+20,
-5
M
TODO
+0,
-1
1@@ -1,6 +1,5 @@
2 Maus:
3 [?] Cursor warping
4-[?] Input text buffer
5 [?] Custom cursor
6
7 MausFont:
+20,
-4
1@@ -9,6 +9,8 @@ int mx, my;
2 bool cur_visible = true;
3 bool cur_locked = false;
4 bool mb1_pressed = false;
5+char txtbuf[4096] = {'\0'};
6+int current_char = 0;
7
8 void handle_ev(Maus* mw, MausEvent* ev)
9 {
10@@ -21,18 +23,18 @@ void handle_ev(Maus* mw, MausEvent* ev)
11 (void)0;
12
13 bool* keys = mw->key_syms;
14- if (keys[MAUS_KEY_Q]) {
15+ if (keys[MAUS_KEY_CONTROL_L] && keys[MAUS_KEY_Q]) {
16 maus_close(mw);
17 exit(EXIT_SUCCESS);
18 };
19- if (keys[MAUS_KEY_P]) {
20+ if (keys[MAUS_KEY_CONTROL_L] && keys[MAUS_KEY_P]) {
21 cur_visible ?
22 maus_cur_set_mode(mw, MAUS_CURSOR_STATE_HIDDEN) :
23 maus_cur_set_mode(mw, MAUS_CURSOR_STATE_VISIBLE);
24
25 cur_visible = !cur_visible;
26 }
27- if (keys[MAUS_KEY_L]) {
28+ if (keys[MAUS_KEY_CONTROL_L] && keys[MAUS_KEY_L]) {
29 cur_locked ?
30 maus_cur_set_mode(mw, MAUS_CURSOR_STATE_FREE) :
31 maus_cur_set_mode(mw, MAUS_CURSOR_STATE_LOCKED);
32@@ -40,6 +42,17 @@ void handle_ev(Maus* mw, MausEvent* ev)
33 cur_locked = !cur_locked;
34 }
35
36+ if (ev->key.pressed == false)
37+ break;
38+
39+ if (!((ev->key.key >= 32 && ev->key.key <= 126) || ev->key.key == '\n'))
40+ break;
41+
42+ if (current_char + 1 < 4095 && current_char >= 0)
43+ txtbuf[current_char++] = ev->key.key;
44+ else
45+ maus_log(stderr, "txtbuf full");
46+
47 break;
48 }
49 case MAUS_EV_MOUSE_BUTTON: {
50@@ -92,11 +105,14 @@ int main(void)
51 }
52 }
53
54- maus_draw_text(mw, font, 700, 50, "maus font\nloading example", red);
55+ /* maus_draw_text(mw, font, 700, 50, "maus font\nloading example", red); */
56
57 /* char buf[512] = {0}; */
58 /* snprintf(buf, 512, "maus' basic-window has been running for %lld ticks!", ticks); */
59 /* maus_clipboard_set_text(mw, buf); */
60+
61+ maus_draw_text(mw, font, 700, 50, txtbuf, red);
62+
63 maus_target_fps(mw, 60);
64 maus_present(mw);
65 }