diff --git a/src/my_wid.hpp b/src/my_wid.hpp index 1c1bbcf..bbd2d0b 100644 --- a/src/my_wid.hpp +++ b/src/my_wid.hpp @@ -41,14 +41,8 @@ int wid_get_height(Widp); int wid_get_tl_x(Widp); int wid_get_tl_y(Widp); int wid_get_width(Widp); - int wid_get_style(Widp); -std::list< Widp > wid_find_all_at(const point p); -std::list< Widp > wid_find_all_containing(const std::string &name); -std::list< Widp > wid_find_all_containing(Widp w, const std::string &name); -std::list< Widp > wid_find_all(Widp w, const std::string &name); - std::string to_string(Widp); std::string wid_get_name(Widp); std::string wid_name(Widp); @@ -106,9 +100,8 @@ int wid_get_br_y(Widp w); int wid_get_tl_x(Widp w); int wid_get_tl_y(Widp w); -int wid_count(Widp w, int depth); -int wid_get_int_context(Widp); -std::string wid_get_string_context(Widp); +int wid_count(Widp w, int depth); +int wid_get_int_context(Widp); uint8_t wid_get_do_not_lower(Widp); uint8_t wid_get_do_not_raise(Widp); @@ -230,7 +223,6 @@ void wid_set_received_input(Widp, uint8_t val); void wid_set_shape_none(Widp); void wid_set_shape_square(Widp); void wid_set_show_cursor(Widp, uint8_t val); -void wid_set_string_context(Widp w, std::string); void wid_set_style(Widp w, int style); void wid_set_tex_br(Widp, fsize val); void wid_set_text_bot(Widp, uint8_t val); @@ -263,10 +255,10 @@ typedef struct { // // Colors // - std::array< color, WID_COLOR_MAX > colors; - std::array< uint8_t, WID_COLOR_MAX > color_set; - int style; - uint8_t style_set; + color colors[ WID_COLOR_MAX ]; + uint8_t color_set[ WID_COLOR_MAX ]; + int style; + uint8_t style_set; } wid_cfg; class tree_wid_key @@ -464,14 +456,13 @@ class Wid // // Config layers: // - std::array< wid_cfg, WID_MODE_LAST > cfg {}; + wid_cfg cfg[ WID_MODE_LAST ] {}; // // Client context // - std::string string_context; - int int_context {-1}; - void *void_context {}; + int int_context {-1}; + void *void_context {}; // // Text placement. @@ -547,8 +538,6 @@ extern bool wid_mouse_two_clicks; extern const int wid_destroy_delay_ms; extern int wid_mouse_visible; -extern std::array< std::array< Widp, TERM_HEIGHT_MAX >, TERM_WIDTH_MAX > wid_on_screen_at; - extern ts_t wid_ignore_events_briefly_ts; extern ts_t wid_last_mouse_motion; extern ts_t wid_last_over_event; diff --git a/src/wid.cpp b/src/wid.cpp index 8d96b67..2a2ccc2 100644 --- a/src/wid.cpp +++ b/src/wid.cpp @@ -121,11 +121,11 @@ static int wid_lowest_priority = -1; // History for all text widgets. // #define HISTORY_MAX 16 -std::array< std::string, HISTORY_MAX > history; -uint32_t g_history_at; -uint32_t g_history_walk; +std::string history[ HISTORY_MAX ]; +uint32_t g_history_at; +uint32_t g_history_walk; -std::array< std::array< Widp, TERM_HEIGHT_MAX >, TERM_WIDTH_MAX > wid_on_screen_at {}; +Widp wid_on_screen_at[ TERM_WIDTH_MAX ][ TERM_HEIGHT_MAX ] = {{}}; static uint8_t wid_init_done; static uint8_t wid_exiting; @@ -150,7 +150,7 @@ void wid_fini(void) wid_init_done = false; wid_exiting = true; - wid_on_screen_at = {}; + memset(wid_on_screen_at, 0, sizeof(wid_on_screen_at)); wid_gc_all(); @@ -359,26 +359,6 @@ void wid_set_pos_pct(Widp w, fpoint tl, fpoint br) wid_tree_attach(w); } -void wid_set_string_context(Widp w, std::string string_context) -{ - TRACE_NO_INDENT(); - if (! w) { - ERR("NULL postringer"); - return; - } - w->string_context = string_context; -} - -std::string wid_get_string_context(Widp w) -{ - TRACE_NO_INDENT(); - if (! w) { - ERR("NULL postringer"); - return 0; - } - return (w->string_context); -} - void wid_set_int_context(Widp w, int int_context) { TRACE_NO_INDENT(); @@ -794,8 +774,7 @@ static uint8_t wid_mouse_over_begin(Widp w, uint32_t x, uint32_t y, int relx, in } if (! w->on_mouse_over_begin && ! w->on_mouse_down) { - if (get(w->cfg, WID_MODE_OVER).color_set[ WID_COLOR_BG ] - || get(w->cfg, WID_MODE_OVER).color_set[ WID_COLOR_TEXT_FG ]) { + if (w->cfg[ WID_MODE_OVER ].color_set[ WID_COLOR_BG ] || w->cfg[ WID_MODE_OVER ].color_set[ WID_COLOR_TEXT_FG ]) { // // Changes appearance on mouse over, so choose this wid even // if it has no over callback. @@ -805,7 +784,7 @@ static uint8_t wid_mouse_over_begin(Widp w, uint32_t x, uint32_t y, int relx, in // Can ignore. It doesn't really do anything when the mouse // is over. // - if (! wid_over && get(wid_on_screen_at, x, y)) { + if (! wid_over && wid_on_screen_at[ x ][ y ]) { // // But if we have nothing else, use this // @@ -1520,7 +1499,7 @@ color wid_get_color(Widp w, wid_color which) { TRACE_NO_INDENT(); uint32_t mode = (__typeof__(mode)) wid_get_mode(w); // for c++, no enum walk - wid_cfg *cfg = &getref(w->cfg, mode); + wid_cfg *cfg = &w->cfg[ mode ]; if (cfg->color_set[ which ]) { return (cfg->colors[ which ]); @@ -1528,14 +1507,14 @@ color wid_get_color(Widp w, wid_color which) if ((wid_focus == w) && (wid_over == w)) { mode = WID_MODE_OVER; - cfg = &getref(w->cfg, mode); + cfg = &w->cfg[ mode ]; if (cfg->color_set[ which ]) { return (cfg->colors[ which ]); } } mode = WID_MODE_NORMAL; - cfg = &getref(w->cfg, mode); + cfg = &w->cfg[ mode ]; if (cfg->color_set[ which ]) { return (cfg->colors[ which ]); } @@ -1547,7 +1526,7 @@ int wid_get_style(Widp w) { TRACE_NO_INDENT(); uint32_t mode = (__typeof__(mode)) wid_get_mode(w); // for c++, no enum walk - wid_cfg *cfg = &getref(w->cfg, mode); + wid_cfg *cfg = &w->cfg[ mode ]; if (cfg->style_set) { return (cfg->style); @@ -1555,14 +1534,14 @@ int wid_get_style(Widp w) if ((wid_focus == w) && (wid_over == w)) { mode = WID_MODE_OVER; - cfg = &getref(w->cfg, mode); + cfg = &w->cfg[ mode ]; if (cfg->style_set) { return (cfg->style); } } mode = WID_MODE_NORMAL; - cfg = &getref(w->cfg, mode); + cfg = &w->cfg[ mode ]; if (cfg->style_set) { return (cfg->style); } @@ -2210,8 +2189,8 @@ static void wid_destroy_immediate(Widp w) for (auto x = 0; x < TERM_WIDTH; x++) { for (auto y = 0; y < TERM_HEIGHT; y++) { - if (get(wid_on_screen_at, x, y) == w) { - set(wid_on_screen_at, x, y, static_cast< Widp >(0)); + if (wid_on_screen_at[ x ][ y ] == w) { + wid_on_screen_at[ x ][ y ] = NULL; } } } @@ -3127,13 +3106,6 @@ static void wid_find_all_(Widp w, const std::string &name, std::list< Widp > &ou } } -std::list< Widp > wid_find_all(Widp w, const std::string &name) -{ - std::list< Widp > out; - wid_find_all_(w, name, out); - return out; -} - static void wid_find_all_containing_(Widp w, const std::string &name, std::list< Widp > &out) { TRACE_NO_INDENT(); @@ -3147,27 +3119,6 @@ static void wid_find_all_containing_(Widp w, const std::string &name, std::list< } } -std::list< Widp > wid_find_all_containing(Widp w, const std::string &name) -{ - std::list< Widp > out; - wid_find_all_containing_(w, name, out); - return out; -} - -std::list< Widp > wid_find_all_containing(const std::string &name) -{ - std::list< Widp > out; - TRACE_NO_INDENT(); - for (auto &iter : wid_top_level) { - auto w = iter.second; - auto r = wid_find(w, name); - if (r) { - wid_find_all_containing_(r, name, out); - } - } - return out; -} - Widp wid_find(const std::string &name) { TRACE_NO_INDENT(); @@ -3182,37 +3133,6 @@ Widp wid_find(const std::string &name) return nullptr; } -static void wid_find_all_at(Widp w, std::list< Widp > &out, const point p) -{ - TRACE_NO_INDENT(); - - for (auto &iter : w->children_display_sorted) { - auto c = iter.second; - wid_find_all_at(c, out, p); - if ((p.x < c->abs_tl.x) || (p.y < c->abs_tl.y) || (p.x > c->abs_br.x) || (p.y > c->abs_br.y)) { - continue; - } - out.push_back(c); - } -} - -std::list< Widp > wid_find_all_at(const point p) -{ - std::list< Widp > out; - - TRACE_NO_INDENT(); - for (auto &iter : wid_top_level) { - auto w = iter.second; - if ((p.x < w->abs_tl.x) || (p.y < w->abs_tl.y) || (p.x > w->abs_br.x) || (p.y > w->abs_br.y)) { - continue; - } - - wid_find_all_at(w, out, p); - out.push_back(w); - } - return out; -} - void wid_always_hidden(Widp w, uint8_t value) { TRACE_NO_INDENT(); @@ -3781,7 +3701,7 @@ uint8_t wid_receive_input(Widp w, const SDL_Keysym *key) g_history_walk--; } - wid_set_text(w, get(history, g_history_walk)); + wid_set_text(w, history[ g_history_walk ]); w->cursor = (uint32_t) wid_get_text(w).length(); break; @@ -3791,7 +3711,7 @@ uint8_t wid_receive_input(Widp w, const SDL_Keysym *key) g_history_walk = 0; } - wid_set_text(w, get(history, g_history_walk)); + wid_set_text(w, history[ g_history_walk ]); w->cursor = (uint32_t) wid_get_text(w).length(); break; @@ -3855,7 +3775,7 @@ uint8_t wid_receive_input(Widp w, const SDL_Keysym *key) w->cursor = updatedtext.length(); } - set(history, g_history_at, updatedtext); + history[ g_history_at ] = updatedtext; g_history_at++; if (g_history_at >= HISTORY_MAX) { @@ -3892,8 +3812,8 @@ uint8_t wid_receive_input(Widp w, const SDL_Keysym *key) g_history_walk--; } - wid_set_text(w, get(history, g_history_walk)); - if (get(history, g_history_walk) == "") { + wid_set_text(w, history[ g_history_walk ]); + if (history[ g_history_walk ] == "") { continue; } @@ -3912,8 +3832,8 @@ uint8_t wid_receive_input(Widp w, const SDL_Keysym *key) g_history_walk = 0; } - wid_set_text(w, get(history, g_history_walk)); - if (get(history, g_history_walk) == "") { + wid_set_text(w, history[ g_history_walk ]); + if (history[ g_history_walk ] == "") { continue; } @@ -4050,7 +3970,7 @@ static uint8_t wid_receive_unhandled_input(const SDL_Keysym *key) Widp wid_find_at(int x, int y) { TRACE_NO_INDENT(); - auto w = get(wid_on_screen_at, x, y); + auto w = wid_on_screen_at[ x ][ y ]; if (unlikely(! w)) { return nullptr; } @@ -4901,7 +4821,7 @@ static Widp wid_mouse_motion_handler(int x, int y, int relx, int rely, int wheel TRACE_NO_INDENT(); Widp w {}; - w = get(wid_on_screen_at, x, y); + w = wid_on_screen_at[ x ][ y ]; if (w) { verify(MTYPE_WID, w); if (w->hidden) { @@ -5182,15 +5102,15 @@ void wid_joy_button(int x, int y) // // Only if there is a change in status, send an event. // - static std::array< ts_t, SDL_MAX_BUTTONS > ts; - int changed = false; - int b; + ts_t ts[ SDL_MAX_BUTTONS ]; + int changed = false; + int b; for (b = 0; b < SDL_MAX_BUTTONS; b++) { if (get(sdl.joy_buttons, b)) { - if (time_have_x_tenths_passed_since(2, get(ts, b))) { + if (time_have_x_tenths_passed_since(2, ts[ b ])) { changed = true; - set(ts, b, time_ms_cached()); + ts[ b ] = time_ms_cached(); } } } @@ -6060,19 +5980,19 @@ static void wid_display(Widp w, uint8_t disable_scissor, uint8_t *updated_scisso w_box_args.over = true; if (w->cfg[ WID_MODE_OVER ].color_set[ WID_COLOR_TEXT_FG ]) { - w_box_args.col_text = get(w->cfg, WID_MODE_OVER).colors[ WID_COLOR_TEXT_FG ]; + w_box_args.col_text = w->cfg[ WID_MODE_OVER ].colors[ WID_COLOR_TEXT_FG ]; } else { - w_box_args.col_text = get(w->cfg, WID_MODE_NORMAL).colors[ WID_COLOR_TEXT_FG ]; + w_box_args.col_text = w->cfg[ WID_MODE_NORMAL ].colors[ WID_COLOR_TEXT_FG ]; } if (w->cfg[ WID_MODE_OVER ].color_set[ WID_COLOR_BG ]) { - w_box_args.col_bg = get(w->cfg, WID_MODE_OVER).colors[ WID_COLOR_BG ]; + w_box_args.col_bg = w->cfg[ WID_MODE_OVER ].colors[ WID_COLOR_BG ]; } else { - w_box_args.col_bg = get(w->cfg, WID_MODE_NORMAL).colors[ WID_COLOR_BG ]; + w_box_args.col_bg = w->cfg[ WID_MODE_NORMAL ].colors[ WID_COLOR_BG ]; } } else { - w_box_args.col_text = get(w->cfg, WID_MODE_NORMAL).colors[ WID_COLOR_TEXT_FG ]; - w_box_args.col_bg = get(w->cfg, WID_MODE_NORMAL).colors[ WID_COLOR_BG ]; + w_box_args.col_text = w->cfg[ WID_MODE_NORMAL ].colors[ WID_COLOR_TEXT_FG ]; + w_box_args.col_bg = w->cfg[ WID_MODE_NORMAL ].colors[ WID_COLOR_BG ]; } if (w->square) { @@ -6097,7 +6017,7 @@ static void wid_display(Widp w, uint8_t disable_scissor, uint8_t *updated_scisso } if (ascii_ok_for_scissors(x, y)) { - set(wid_on_screen_at, x, y, w); + wid_on_screen_at[ x ][ y ] = w; } } } @@ -6361,7 +6281,7 @@ void wid_display_all(bool ok_to_handle_requests) // CON("---------------------------------"); - wid_on_screen_at = {}; + memset(wid_on_screen_at, 0, sizeof(wid_on_screen_at)); wid_total_count = 0;