diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-06-07 10:58:01 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-06-07 10:58:01 +0200 |
commit | 0b246d96f4928755b50a005dd954f051c717ed02 (patch) | |
tree | d6763257d11f79beb1f6c10bfc0fd7fa6ee0072d | |
parent | 9256315371ad5a67eaee80cf7453d2885a59f5c3 (diff) |
implemented tab key handlers
-rw-r--r-- | client/ui.c | 17 | ||||
-rw-r--r-- | client/ui.h | 5 | ||||
-rw-r--r-- | client/ui_dirc.c | 44 | ||||
-rw-r--r-- | client/ui_errcatch.c | 4 | ||||
-rw-r--r-- | client/ui_tabbar.c | 16 |
5 files changed, 53 insertions, 33 deletions
diff --git a/client/ui.c b/client/ui.c index 41a392f..5f649e0 100644 --- a/client/ui.c +++ b/client/ui.c @@ -29,10 +29,26 @@ void w2_wmvaddnstr(WINDOW *win, unsigned int y, unsigned int x, char *str, unsig waddnstr(win, str, len); } +void w2_ui_switch_tab(w2_e_ui_tabs next_tab) { + g_w2_ui_current_tab = next_tab % W2_UI_TAB_COUNT; + wclear(g_w2_ui_pad_body); +} + +void w2_ui_key_handler() { + int ch; + void (*current_mode_key_handler)() = g_w2_keyhndl_ptrs[g_w2_ui_current_tab]; + return; + while ((ch = getch()) != -1) { + if (ch == '\t') w2_ui_switch_tab(g_w2_ui_current_tab + 1); + else if (current_mode_key_handler != NULL) (*current_mode_key_handler)(ch); + } +} + void w2_ui_main() { g_w2_ui_width = getmaxx(g_w2_ui_win); g_w2_ui_height = getmaxy(g_w2_ui_win); + w2_ui_key_handler(); w2_ui_paint(); } @@ -46,7 +62,6 @@ void w2_ui_paint() { prefresh(g_w2_ui_pad_tabbar, 0, 0, 2, 0, 2, g_w2_ui_width - 1); prefresh(g_w2_ui_pad_body, W2_MAX(0, g_w2_ui_pad_body_scroll), 0, 4 - W2_MIN(0, g_w2_ui_pad_body_scroll), 0, g_w2_ui_height - 2, g_w2_ui_width - 1); - // wrefresh(g_w2_ui_win); } void w2_ui_paint_statusbar() { diff --git a/client/ui.h b/client/ui.h index bc74144..eb09739 100644 --- a/client/ui.h +++ b/client/ui.h @@ -19,8 +19,11 @@ extern int g_w2_ui_pad_body_scroll; extern unsigned int g_w2_ui_width; extern unsigned int g_w2_ui_height; extern void (*g_w2_tab_ptrs[W2_UI_TAB_COUNT])(bool first); +extern void (*g_w2_keyhndl_ptrs[W2_UI_TAB_COUNT])(int key); extern w2_e_ui_tabs g_w2_ui_current_tab; +void w2_ui_switch_tab(w2_e_ui_tabs next_tab); + /** update terminal props */ void w2_ui_update(); /** clear screen */ @@ -40,6 +43,8 @@ void w2_ui_tabbar_init(); void w2_ui_tab_dirc(bool first); void w2_ui_tab_start(bool first); void w2_ui_tab_errcatch(bool first); +void w2_ui_onkey_dirc(int ch); +void w2_ui_onkey_errcatch(int ch); void w2_wmvaddstr(WINDOW *win, unsigned int y, unsigned int x, char *str); void w2_wmvaddnstr(WINDOW *win, unsigned int y, unsigned int x, char *str, unsigned int len); diff --git a/client/ui_dirc.c b/client/ui_dirc.c index 63adad1..72e57d0 100644 --- a/client/ui_dirc.c +++ b/client/ui_dirc.c @@ -2,6 +2,12 @@ #include "../shared/util.h" #include "commands.h" #include "ui.h" +#include "errcatch.h" + +unsigned int g_w2_lb = 0; +unsigned int g_w2_lf = 0; +unsigned int g_w2_rb = 0; +unsigned int g_w2_rf = 0; /** decay modifier */ #define W2_DIRC_MOD ((double)0.95) @@ -86,33 +92,33 @@ void w2_ui_dirc_paint(int left, int right) { "<space> send dirc mode command"); } +void w2_ui_onkey_dirc(int ch) { + if (ch == 'e' || ch == 'w') g_w2_lf++; + if (ch == 'd' || ch == 's') g_w2_lb++; + if (ch == 'q' || ch == 'w') g_w2_rf++; + if (ch == 'a' || ch == 's') g_w2_rb++; + if (ch == ' ') w2_send_mode(W2_M_DIRC); + + char buf[32]; + sprintf(buf, "er is iets fout, %02x", ch); + w2_errcatch_throw_msg(0x69, 32, buf); +} + void w2_ui_tab_dirc(bool first) { g_w2_ui_pad_body_scroll = 0; if (first) w2_ui_dirc_init(); - int ch = 0; - unsigned int lb = 0; - unsigned int lf = 0; - unsigned int rb = 0; - unsigned int rf = 0; - while ((ch = getch()) != -1) { - if (ch == 'e' || ch == 'w') - lf++; - else if (ch == 'd' || ch == 's') - lb++; - else if (ch == 'q' || ch == 'w') - rf++; - else if (ch == 'a' || ch == 's') - rb++; - else if (ch == ' ') - w2_send_mode(W2_M_DIRC); - } - int drive_l = w2_dirc_motor_l(lf, lb); - int drive_r = w2_dirc_motor_r(rf, rb); + int drive_l = w2_dirc_motor_l(g_w2_lf, g_w2_lb); + int drive_r = w2_dirc_motor_r(g_w2_rf, g_w2_rb); drive_l += drive_r * W2_DIRC_STP; drive_r += drive_l * W2_DIRC_STP; w2_send_dirc(drive_l, drive_r); w2_ui_dirc_paint(drive_l, drive_r); + + g_w2_lb = 0; + g_w2_lf = 0; + g_w2_rb = 0; + g_w2_rf = 0; } diff --git a/client/ui_errcatch.c b/client/ui_errcatch.c index abfbe22..2d695aa 100644 --- a/client/ui_errcatch.c +++ b/client/ui_errcatch.c @@ -35,6 +35,10 @@ char *w2_err_format(w2_s_error *error) { return ret_str; } +void w2_ui_onkey_errcatch(int ch) { + +} + void w2_ui_tab_errcatch(bool first) { g_w2_errcatch_log_line = 0; g_w2_ui_pad_body_scroll = 5 - g_w2_ui_height; diff --git a/client/ui_tabbar.c b/client/ui_tabbar.c index 91d476f..f11d1a5 100644 --- a/client/ui_tabbar.c +++ b/client/ui_tabbar.c @@ -7,27 +7,17 @@ unsigned int g_w2_ui_tabbar_scroll = 0; unsigned int g_w2_ui_tabbar_lengths[W2_UI_TAB_COUNT]; void (*g_w2_tab_ptrs[W2_UI_TAB_COUNT])(bool first); +void (*g_w2_keyhndl_ptrs[W2_UI_TAB_COUNT])(int key); void w2_ui_tabbar_init() { g_w2_tab_ptrs[W2_UI_TAB_START] = &w2_ui_tab_start; g_w2_tab_ptrs[W2_UI_TAB_ERRCATCH] = &w2_ui_tab_errcatch; + g_w2_keyhndl_ptrs[W2_UI_TAB_START] = &w2_ui_onkey_errcatch; g_w2_tab_ptrs[W2_UI_TAB_DIRC] = &w2_ui_tab_dirc; -} - -void w2_ui_switch_tab(w2_e_ui_tabs next_tab) { - g_w2_ui_current_tab = next_tab % W2_UI_TAB_COUNT; - wclear(g_w2_ui_pad_body); -} - -void w2_ui_tabbar_logic() { - int ch; - while ((ch = getch()) != -1) { - if (ch == '\t') w2_ui_switch_tab(g_w2_ui_current_tab + 1); - } + g_w2_keyhndl_ptrs[W2_UI_TAB_DIRC] = &w2_ui_onkey_dirc; } void w2_ui_paint_tabbar() { - w2_ui_tabbar_logic(); wmove(g_w2_ui_pad_tabbar, 0, 0); for (unsigned int i = 0; i < W2_UI_TAB_COUNT; i++) { g_w2_ui_tabbar_lengths[i] += 2 + strlen(g_w2_tab_strings[i]); |