display.h (2638B)
1 /** 2 * @file display.h 3 * @author Dimitrije Dobrota 4 * @date 19 June 2022 5 * @brief Methods and types for displaying UI 6 */ 7 8 #ifndef DISPLAY_H 9 #define DISPLAY_H 10 11 #include "window.h" 12 13 #ifdef _WIN32 14 #define is_term_resized(a, b) is_termresized() 15 #define HANDLE_RESIZE \ 16 { \ 17 resize_term(0, 0); \ 18 handle_winch(10); \ 19 } 20 #else 21 #define HANDLE_RESIZE \ 22 { handle_winch(10); } 23 #endif 24 25 /// Character representing dead cell 26 #define CHAR_BLANK " " 27 28 /// Character representing cursor 29 #define CHAR_CURSOR "<>" 30 31 /// Character representing a living cell with a circle 32 #define CHAR_CIRCLE "\u26AB" 33 34 /// Character representing a living cell with a square 35 #define CHAR_SQUARE "\u2B1B" 36 37 /// Active representation of a living cell 38 #define CHAR_ACTIVE CHAR_CIRCLE 39 40 /// Way of printing a cell based on Unicode support 41 #ifndef NO_UNICODE 42 #define print_cell(win, blank) \ 43 if (val) \ 44 waddstr(win, CHAR_ACTIVE); \ 45 else \ 46 waddstr(win, blank); 47 #else 48 #define print_cell(win, blank) waddstr(win, blank); 49 #endif 50 51 extern window_T MAIN_w; 52 extern mmask_t mbitmask; 53 54 typedef int (*input_f)(int); 55 56 /** 57 * @brief A item in a menu 58 * 59 * It's intended to be used with display_menu(). 60 */ 61 struct menu_T { 62 void (*callback)(char *, int); ///< function called when item is selected 63 char *name; ///< name of the menu item 64 }; 65 66 /** 67 * @brief A item in a interactive menu 68 * 69 * It's intended to be used with display_imenu(). 70 */ 71 struct imenu_T { 72 char *message; ///< prompt for the user 73 int size; ///< max number of characters required 74 input_f crit; ///< function that check the validity of a character 75 char *buffer; ///< place where read character are stored 76 }; 77 78 int input(WINDOW *win, char *buffer, int size, input_f crit); 79 80 void display_start(void); 81 void display_stop(void); 82 83 void display_menu(window_T wind, char *name, struct menu_T *items, int size, 84 int title); 85 int display_imenu(window_T wind, struct imenu_T *items, int size); 86 87 void display_patterns(window_T wind); 88 void handle_winch(int sig); 89 void display_state_set(int i, int j, int val); 90 91 #endif