| 1 | /* |
| 2 | |
| 3 | mui.h |
| 4 | |
| 5 | Monochrome minimal user interface: Core library. |
| 6 | |
| 7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
| 8 | |
| 9 | Copyright (c) 2021, olikraus@gmail.com |
| 10 | All rights reserved. |
| 11 | |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are met: |
| 14 | |
| 15 | * Redistributions of source code must retain the above copyright notice, this |
| 16 | list of conditions and the following disclaimer. |
| 17 | |
| 18 | * Redistributions in binary form must reproduce the above copyright notice, |
| 19 | this list of conditions and the following disclaimer in the documentation |
| 20 | and/or other materials provided with the distribution. |
| 21 | |
| 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | |
| 36 | MUIF (Monochrome User Interface Functions) |
| 37 | n: A number 0 to 9 without any quotes, e.g.: 5 |
| 38 | id: Exactly two characters or numbers in double quotes, e.g. "G5". |
| 39 | cb: A callback function with the following prototype: "uint8_t muif_cb(mui_t |
| 40 | *ui, uint8_t msg)" There are MANY predefined callback functions, see separate |
| 41 | list var: Address of a variable. text: Normal text, but special characters |
| 42 | might be required for some callback functions, for example the text might |
| 43 | contain a list of selectable elements separated with the '|' symbol. |
| 44 | |
| 45 | MUIF_STYLE(n,cb) |
| 46 | Corresponding FDS command: MUI_STYLE(n) |
| 47 | Change the style of any other elements after MUI_STYLE(n), does not draw |
| 48 | anything |
| 49 | |
| 50 | MUIF_RO(id,cb) |
| 51 | Corresponding FDS command: MUI_DATA(id, text) MUI_XY(id, x, y), MUI_XYT(id, |
| 52 | x,y,text), MUI_XYA(id, x,y,a), MUI_XYAT(id, x,y,a,text) Places a read only |
| 53 | element on the form. The correct FDS command depends on the callback function. |
| 54 | |
| 55 | MUIF_LABEL(cb) |
| 56 | Corresponding FDS command: MUI_LABEL(x,y,text) |
| 57 | Places a text at the specified position, similar to MUIF_RO |
| 58 | |
| 59 | MUIF_GOTO(cb) |
| 60 | Corresponding FDS command: MUI_GOTO(x,y,n,text) |
| 61 | Places a button at the specified position, similar to MUIF_BUTTON, but does |
| 62 | not require an ID. |
| 63 | |
| 64 | MUIF_BUTTON(id,cb) |
| 65 | Corresponding FDS command: MUI_XY(id, x, y), MUI_XYT(id, x,y,text), |
| 66 | MUI_XYA(id, x,y,a), MUI_XYAT(id, x,y,a,text) Places a selectable element on |
| 67 | the form. |
| 68 | |
| 69 | MUIF_VARIABLE(id,var,cb) |
| 70 | Corresponding FDS command: MUI_XY(id, x, y), MUI_XYA(id, x,y,a) |
| 71 | Places a user input element at the specified location. |
| 72 | The correct FDS command depends on the callback function. |
| 73 | |
| 74 | |
| 75 | */ |
| 76 | |
| 77 | #ifndef MUI_H |
| 78 | #define MUI_H |
| 79 | |
| 80 | #include <stddef.h> |
| 81 | #include <stdint.h> |
| 82 | #include <string.h> |
| 83 | |
| 84 | #if defined(__GNUC__) && defined(__AVR__) |
| 85 | #include <avr/pgmspace.h> |
| 86 | #endif |
| 87 | |
| 88 | /*==========================================*/ |
| 89 | /* C++ compatible */ |
| 90 | |
| 91 | #ifdef __cplusplus |
| 92 | extern "C" { |
| 93 | #endif |
| 94 | |
| 95 | /*==========================================*/ |
| 96 | /* defines */ |
| 97 | |
| 98 | #define MUI_CHECK_EOFDS |
| 99 | |
| 100 | /*==========================================*/ |
| 101 | /* GNUC AVR PROGMEM interface */ |
| 102 | |
| 103 | #ifdef __GNUC__ |
| 104 | #define MUI_NOINLINE __attribute__((noinline)) |
| 105 | #else |
| 106 | #define MUI_NOINLINE |
| 107 | #endif |
| 108 | |
| 109 | #if defined(__GNUC__) && defined(__AVR__) |
| 110 | #define mui_pgm_read(adr) pgm_read_byte_near(adr) |
| 111 | #define mui_pgm_wread(adr) pgm_read_word_near(adr) |
| 112 | #define MUI_PROGMEM PROGMEM |
| 113 | #endif |
| 114 | |
| 115 | #ifndef mui_pgm_read |
| 116 | #ifndef CHAR_BIT |
| 117 | #define mui_pgm_read(adr) (*(const uint8_t *)(adr)) |
| 118 | #else |
| 119 | #if CHAR_BIT > 8 |
| 120 | #define mui_pgm_read(adr) ((*(const uint8_t *)(adr)) & 0x0ff) |
| 121 | #else |
| 122 | #define mui_pgm_read(adr) (*(const uint8_t *)(adr)) |
| 123 | #endif |
| 124 | #endif |
| 125 | #endif |
| 126 | |
| 127 | #ifndef mui_pgm_wread |
| 128 | #define mui_pgm_wread(adr) (*(const uint16_t *)(adr)) |
| 129 | #endif |
| 130 | |
| 131 | #ifndef MUI_PROGMEM |
| 132 | #define MUI_PROGMEM |
| 133 | #endif |
| 134 | |
| 135 | /*=== forward declarations ===*/ |
| 136 | typedef struct mui_struct mui_t; |
| 137 | typedef const struct muif_struct muif_t; |
| 138 | typedef uint8_t (*muif_cb)(mui_t *ui, uint8_t msg); |
| 139 | typedef const char fds_t MUI_PROGMEM; |
| 140 | |
| 141 | /*=== struct declarations === */ |
| 142 | |
| 143 | struct muif_struct { |
| 144 | uint8_t id0; |
| 145 | uint8_t id1; |
| 146 | uint8_t cflags; // config flags e.g. MUIF_CFLAG_IS_CURSOR_SELECTABLE, if so, |
| 147 | // then it will not receive any cursor/touch msgs |
| 148 | uint8_t extra; |
| 149 | void *data; // might be a pointer to a variable |
| 150 | muif_cb cb; // callback |
| 151 | } MUI_PROGMEM; |
| 152 | |
| 153 | /* assumes that pointers are 16 bit so encapsulate the wread i another ifdef |
| 154 | * __AVR__ */ |
| 155 | #if defined(__GNUC__) && defined(__AVR__) |
| 156 | #define muif_get_id0(muif) mui_pgm_read(&((muif)->id0)) |
| 157 | #define muif_get_id1(muif) mui_pgm_read(&((muif)->id1)) |
| 158 | #define muif_get_cflags(muif) mui_pgm_read(&((muif)->cflags)) |
| 159 | #define muif_get_extra(muif) mui_pgm_read(&((muif)->extra)) |
| 160 | #define muif_get_data(muif) ((void *)mui_pgm_wread(&((muif)->data))) |
| 161 | #define muif_get_cb(muif) ((muif_cb)mui_pgm_wread(&((muif)->cb))) |
| 162 | #else |
| 163 | #define muif_get_id0(muif) ((muif)->id0) |
| 164 | #define muif_get_id1(muif) ((muif)->id1) |
| 165 | #define muif_get_cflags(muif) ((muif)->cflags) |
| 166 | #define muif_get_extra(muif) ((muif)->extra) |
| 167 | #define muif_get_data(muif) ((muif)->data) |
| 168 | #define muif_get_cb(muif) ((muif)->cb) |
| 169 | #endif |
| 170 | |
| 171 | #define MUIF_MSG_NONE 0 |
| 172 | #define MUIF_MSG_DRAW 1 |
| 173 | #define MUIF_MSG_FORM_START 2 |
| 174 | #define MUIF_MSG_FORM_END 3 |
| 175 | /* MUIF_MSG_CURSOR_ENTER return values: 255=skip this field, <255, continue*/ |
| 176 | #define MUIF_MSG_CURSOR_ENTER 4 |
| 177 | #define MUIF_MSG_CURSOR_SELECT 5 |
| 178 | |
| 179 | /* optional VALUE messages, ignored by the mui core, but can be used inside the |
| 180 | * field functions */ |
| 181 | /* usually MUIF_MSG_VALUE_INCREMENT behaves like MUIF_MSG_CURSOR_SELECT */ |
| 182 | #define MUIF_MSG_VALUE_INCREMENT 6 |
| 183 | #define MUIF_MSG_VALUE_DECREMENT 7 |
| 184 | |
| 185 | #define MUIF_MSG_CURSOR_LEAVE 8 |
| 186 | #define MUIF_MSG_TOUCH_DOWN 9 |
| 187 | #define MUIF_MSG_TOUCH_UP 10 |
| 188 | /* MUIF_MSG_EVENT_NEXT return values: 0=not handled, 1=handled, do nothing */ |
| 189 | /* If MUIF_MSG_EVENT_NEXT/PREV are NOT handled by the field function, then this |
| 190 | * msg will change the field */ |
| 191 | #define MUIF_MSG_EVENT_NEXT 11 |
| 192 | /* MUIF_MSG_EVENT_PREV return values: 0=not handled, 1=handled, do nothing */ |
| 193 | #define MUIF_MSG_EVENT_PREV 12 |
| 194 | |
| 195 | /* dynamic flags */ |
| 196 | #define MUIF_DFLAG_IS_CURSOR_FOCUS 0x01 |
| 197 | #define MUIF_DFLAG_IS_TOUCH_FOCUS 0x02 |
| 198 | |
| 199 | /* config flags */ |
| 200 | #define MUIF_CFLAG_IS_CURSOR_SELECTABLE 0x01 |
| 201 | #define MUIF_CFLAG_IS_TOUCH_SELECTABLE 0x02 |
| 202 | #define MUIF_CFLAG_IS_EXECUTE_ON_SELECT 0x04 |
| 203 | |
| 204 | /* end user MUIF entries */ |
| 205 | #define MUIF(id, cflags, data, cb) {id[0], id[1], cflags, 0, data, cb} |
| 206 | #define MUIF_STYLE(n, cb) MUIF("S" #n, 0, 0, cb) |
| 207 | #define MUIF_RO(id, cb) MUIF(id, 0, 0, cb) |
| 208 | #define MUIF_LABEL(cb) MUIF(".L", 0, 0, cb) |
| 209 | #define MUIF_GOTO(cb) MUIF(".G", MUIF_CFLAG_IS_CURSOR_SELECTABLE, 0, cb) |
| 210 | #define MUIF_BUTTON(id, cb) MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, 0, cb) |
| 211 | #define MUIF_EXECUTE_ON_SELECT_BUTTON(id, cb) \ |
| 212 | MUIF(id, \ |
| 213 | MUIF_CFLAG_IS_CURSOR_SELECTABLE | MUIF_CFLAG_IS_EXECUTE_ON_SELECT, 0, \ |
| 214 | cb) |
| 215 | #define MUIF_VARIABLE(id, var, cb) \ |
| 216 | MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, (var), cb) |
| 217 | |
| 218 | /* must be smaller than or equal to 255 */ |
| 219 | #ifndef MUI_MAX_TEXT_LEN |
| 220 | #define MUI_MAX_TEXT_LEN 41 |
| 221 | #endif |
| 222 | |
| 223 | #define MUI_MENU_CACHE_CNT 4 |
| 224 | |
| 225 | #define MUI_MENU_LAST_FORM_STACK_SIZE 4 |
| 226 | |
| 227 | struct mui_struct { |
| 228 | void *graphics_data; |
| 229 | fds_t *root_fds; |
| 230 | |
| 231 | muif_t *muif_tlist; |
| 232 | size_t muif_tcnt; |
| 233 | |
| 234 | fds_t *current_form_fds; // the current form, NULL if the ui is not active |
| 235 | // at the moment |
| 236 | fds_t *cursor_focus_fds; // the field which has the current cursor focus, |
| 237 | // NULL if there is no current focus |
| 238 | fds_t *touch_focus_fds; // the field which has touch focus |
| 239 | |
| 240 | fds_t *token; // current token position |
| 241 | |
| 242 | uint16_t form_scroll_total; // reserved for MUIF, not used by mui |
| 243 | uint16_t form_scroll_top; // reserved for MUIF, not used by mui |
| 244 | uint8_t form_scroll_visible; // reserved for MUIF, not used by mui |
| 245 | |
| 246 | // uint8_t selected_value; // This variable is not used by the user |
| 247 | // interface but can be used by any field function |
| 248 | uint8_t tmp8; |
| 249 | |
| 250 | /* 0: mse, 1: mud */ |
| 251 | uint8_t is_mud; // a temp variable for the MUIF function to store remember |
| 252 | // up down mode. This variable will be cleared before |
| 253 | // sending MUIF_MSG_CURSOR_ENTER |
| 254 | /* current field/style variables */ |
| 255 | // uint8_t cursor_focus_position; // the index of the field which has |
| 256 | // focus, can be used as last argument for mui_EnterForm |
| 257 | |
| 258 | uint8_t delimiter; // outer delimiter of the text part of a field |
| 259 | uint8_t cmd; // current cmd or field (e.g. U or F) |
| 260 | uint8_t id0; // identifier of the field, manually provided or derived (G cmd |
| 261 | // has fixed id "FG") |
| 262 | uint8_t id1; |
| 263 | uint8_t x; // position of the field |
| 264 | uint8_t y; |
| 265 | uint8_t dflags; |
| 266 | uint8_t arg; // extra argument of the field. For example the G: form is put |
| 267 | // here, assigned by MUI_XYA or MUI_XYAT |
| 268 | int len; // length of the current command |
| 269 | fds_t *fds; // current position, *fds = cmd |
| 270 | muif_t *uif; // user interface field or style for the given id0 / id1, |
| 271 | // assigned by mui_prepare_current_field() |
| 272 | char text[MUI_MAX_TEXT_LEN + 1]; |
| 273 | |
| 274 | /* target */ |
| 275 | fds_t *tmp_fds; |
| 276 | fds_t * |
| 277 | target_fds; // used by several task functions as a return / result value |
| 278 | |
| 279 | /* last form and field, used by mui_SaveForm and mui_RestoreForm */ |
| 280 | uint8_t last_form_id[MUI_MENU_LAST_FORM_STACK_SIZE]; |
| 281 | uint8_t last_form_cursor_focus_position[MUI_MENU_LAST_FORM_STACK_SIZE]; |
| 282 | fds_t * |
| 283 | last_form_fds; // not used by mui_RestoreForm, but can be used by field |
| 284 | // functions, warning: this is the FDS of the field, from |
| 285 | // where the jump started to the child (cursor_focus_fds) |
| 286 | int8_t last_form_stack_pos; |
| 287 | |
| 288 | /* menu cursor position backup */ |
| 289 | /* idea is, to restore the cursor position if we jump to that form */ |
| 290 | uint8_t menu_form_last_added; |
| 291 | uint8_t menu_form_id[MUI_MENU_CACHE_CNT]; |
| 292 | uint8_t menu_form_cursor_focus_position[MUI_MENU_CACHE_CNT]; |
| 293 | }; |
| 294 | |
| 295 | #define mui_IsCursorFocus(mui) ((mui)->dflags & MUIF_DFLAG_IS_CURSOR_FOCUS) |
| 296 | #define mui_IsTouchFocus(mui) ((mui)->dflags & MUIF_CFLAG_IS_TOUCH_SELECTABLE) |
| 297 | |
| 298 | /*=== form string definitions ===*/ |
| 299 | |
| 300 | #define MUI_0 "\x00" |
| 301 | #define MUI_1 "\x01" |
| 302 | #define MUI_2 "\x02" |
| 303 | #define MUI_3 "\x03" |
| 304 | #define MUI_4 "\x04" |
| 305 | #define MUI_5 "\x05" |
| 306 | #define MUI_6 "\x06" |
| 307 | #define MUI_7 "\x07" |
| 308 | #define MUI_8 "\x08" |
| 309 | #define MUI_9 "\x09" |
| 310 | #define MUI_10 "\x0a" |
| 311 | #define MUI_11 "\x0b" |
| 312 | #define MUI_12 "\x0c" |
| 313 | #define MUI_13 "\x0d" |
| 314 | #define MUI_14 "\x0e" |
| 315 | #define MUI_15 "\x0f" |
| 316 | #define MUI_16 "\x10" |
| 317 | #define MUI_17 "\x11" |
| 318 | #define MUI_18 "\x12" |
| 319 | #define MUI_19 "\x13" |
| 320 | #define MUI_20 "\x14" |
| 321 | #define MUI_21 "\x15" |
| 322 | #define MUI_22 "\x16" |
| 323 | #define MUI_23 "\x17" |
| 324 | #define MUI_24 "\x18" |
| 325 | #define MUI_25 "\x19" |
| 326 | #define MUI_26 "\x1a" |
| 327 | #define MUI_27 "\x1b" |
| 328 | #define MUI_28 "\x1c" |
| 329 | #define MUI_29 "\x1d" |
| 330 | #define MUI_30 "\x1e" |
| 331 | #define MUI_31 "\x1f" |
| 332 | #define MUI_32 "\x20" |
| 333 | #define MUI_33 "\x21" |
| 334 | #define MUI_34 "\x22" |
| 335 | #define MUI_35 "\x23" |
| 336 | #define MUI_36 "\x24" |
| 337 | #define MUI_37 "\x25" |
| 338 | #define MUI_38 "\x26" |
| 339 | #define MUI_39 "\x27" |
| 340 | #define MUI_40 "\x28" |
| 341 | #define MUI_41 "\x29" |
| 342 | #define MUI_42 "\x2a" |
| 343 | #define MUI_43 "\x2b" |
| 344 | #define MUI_44 "\x2c" |
| 345 | #define MUI_45 "\x2d" |
| 346 | #define MUI_46 "\x2e" |
| 347 | #define MUI_47 "\x2f" |
| 348 | #define MUI_48 "\x30" |
| 349 | #define MUI_49 "\x31" |
| 350 | #define MUI_50 "\x32" |
| 351 | #define MUI_51 "\x33" |
| 352 | #define MUI_52 "\x34" |
| 353 | #define MUI_53 "\x35" |
| 354 | #define MUI_54 "\x36" |
| 355 | #define MUI_55 "\x37" |
| 356 | #define MUI_56 "\x38" |
| 357 | #define MUI_57 "\x39" |
| 358 | #define MUI_58 "\x3a" |
| 359 | #define MUI_59 "\x3b" |
| 360 | #define MUI_60 "\x3c" |
| 361 | #define MUI_61 "\x3d" |
| 362 | #define MUI_62 "\x3e" |
| 363 | #define MUI_63 "\x3f" |
| 364 | #define MUI_64 "\x40" |
| 365 | #define MUI_65 "\x41" |
| 366 | #define MUI_66 "\x42" |
| 367 | #define MUI_67 "\x43" |
| 368 | #define MUI_68 "\x44" |
| 369 | #define MUI_69 "\x45" |
| 370 | #define MUI_70 "\x46" |
| 371 | #define MUI_71 "\x47" |
| 372 | #define MUI_72 "\x48" |
| 373 | #define MUI_73 "\x49" |
| 374 | #define MUI_74 "\x4a" |
| 375 | #define MUI_75 "\x4b" |
| 376 | #define MUI_76 "\x4c" |
| 377 | #define MUI_77 "\x4d" |
| 378 | #define MUI_78 "\x4e" |
| 379 | #define MUI_79 "\x4f" |
| 380 | #define MUI_80 "\x50" |
| 381 | #define MUI_81 "\x51" |
| 382 | #define MUI_82 "\x52" |
| 383 | #define MUI_83 "\x53" |
| 384 | #define MUI_84 "\x54" |
| 385 | #define MUI_85 "\x55" |
| 386 | #define MUI_86 "\x56" |
| 387 | #define MUI_87 "\x57" |
| 388 | #define MUI_88 "\x58" |
| 389 | #define MUI_89 "\x59" |
| 390 | #define MUI_90 "\x5a" |
| 391 | #define MUI_91 "\x5b" |
| 392 | #define MUI_92 "\x5c" |
| 393 | #define MUI_93 "\x5d" |
| 394 | #define MUI_94 "\x5e" |
| 395 | #define MUI_95 "\x5f" |
| 396 | #define MUI_96 "\x60" |
| 397 | #define MUI_97 "\x61" |
| 398 | #define MUI_98 "\x62" |
| 399 | #define MUI_99 "\x63" |
| 400 | #define MUI_100 "\x64" |
| 401 | #define MUI_101 "\x65" |
| 402 | #define MUI_102 "\x66" |
| 403 | #define MUI_103 "\x67" |
| 404 | #define MUI_104 "\x68" |
| 405 | #define MUI_105 "\x69" |
| 406 | #define MUI_106 "\x6a" |
| 407 | #define MUI_107 "\x6b" |
| 408 | #define MUI_108 "\x6c" |
| 409 | #define MUI_109 "\x6d" |
| 410 | #define MUI_110 "\x6e" |
| 411 | #define MUI_111 "\x6f" |
| 412 | #define MUI_112 "\x70" |
| 413 | #define MUI_113 "\x71" |
| 414 | #define MUI_114 "\x72" |
| 415 | #define MUI_115 "\x73" |
| 416 | #define MUI_116 "\x74" |
| 417 | #define MUI_117 "\x75" |
| 418 | #define MUI_118 "\x76" |
| 419 | #define MUI_119 "\x77" |
| 420 | #define MUI_120 "\x78" |
| 421 | #define MUI_121 "\x79" |
| 422 | #define MUI_122 "\x7a" |
| 423 | #define MUI_123 "\x7b" |
| 424 | #define MUI_124 "\x7c" |
| 425 | #define MUI_125 "\x7d" |
| 426 | #define MUI_126 "\x7e" |
| 427 | #define MUI_127 "\x7f" |
| 428 | #define MUI_128 "\x80" |
| 429 | #define MUI_129 "\x81" |
| 430 | #define MUI_130 "\x82" |
| 431 | #define MUI_131 "\x83" |
| 432 | #define MUI_132 "\x84" |
| 433 | #define MUI_133 "\x85" |
| 434 | #define MUI_134 "\x86" |
| 435 | #define MUI_135 "\x87" |
| 436 | #define MUI_136 "\x88" |
| 437 | #define MUI_137 "\x89" |
| 438 | #define MUI_138 "\x8a" |
| 439 | #define MUI_139 "\x8b" |
| 440 | #define MUI_140 "\x8c" |
| 441 | #define MUI_141 "\x8d" |
| 442 | #define MUI_142 "\x8e" |
| 443 | #define MUI_143 "\x8f" |
| 444 | #define MUI_144 "\x90" |
| 445 | #define MUI_145 "\x91" |
| 446 | #define MUI_146 "\x92" |
| 447 | #define MUI_147 "\x93" |
| 448 | #define MUI_148 "\x94" |
| 449 | #define MUI_149 "\x95" |
| 450 | #define MUI_150 "\x96" |
| 451 | #define MUI_151 "\x97" |
| 452 | #define MUI_152 "\x98" |
| 453 | #define MUI_153 "\x99" |
| 454 | #define MUI_154 "\x9a" |
| 455 | #define MUI_155 "\x9b" |
| 456 | #define MUI_156 "\x9c" |
| 457 | #define MUI_157 "\x9d" |
| 458 | #define MUI_158 "\x9e" |
| 459 | #define MUI_159 "\x9f" |
| 460 | #define MUI_160 "\xa0" |
| 461 | #define MUI_161 "\xa1" |
| 462 | #define MUI_162 "\xa2" |
| 463 | #define MUI_163 "\xa3" |
| 464 | #define MUI_164 "\xa4" |
| 465 | #define MUI_165 "\xa5" |
| 466 | #define MUI_166 "\xa6" |
| 467 | #define MUI_167 "\xa7" |
| 468 | #define MUI_168 "\xa8" |
| 469 | #define MUI_169 "\xa9" |
| 470 | #define MUI_170 "\xaa" |
| 471 | #define MUI_171 "\xab" |
| 472 | #define MUI_172 "\xac" |
| 473 | #define MUI_173 "\xad" |
| 474 | #define MUI_174 "\xae" |
| 475 | #define MUI_175 "\xaf" |
| 476 | #define MUI_176 "\xb0" |
| 477 | #define MUI_177 "\xb1" |
| 478 | #define MUI_178 "\xb2" |
| 479 | #define MUI_179 "\xb3" |
| 480 | #define MUI_180 "\xb4" |
| 481 | #define MUI_181 "\xb5" |
| 482 | #define MUI_182 "\xb6" |
| 483 | #define MUI_183 "\xb7" |
| 484 | #define MUI_184 "\xb8" |
| 485 | #define MUI_185 "\xb9" |
| 486 | #define MUI_186 "\xba" |
| 487 | #define MUI_187 "\xbb" |
| 488 | #define MUI_188 "\xbc" |
| 489 | #define MUI_189 "\xbd" |
| 490 | #define MUI_190 "\xbe" |
| 491 | #define MUI_191 "\xbf" |
| 492 | #define MUI_192 "\xc0" |
| 493 | #define MUI_193 "\xc1" |
| 494 | #define MUI_194 "\xc2" |
| 495 | #define MUI_195 "\xc3" |
| 496 | #define MUI_196 "\xc4" |
| 497 | #define MUI_197 "\xc5" |
| 498 | #define MUI_198 "\xc6" |
| 499 | #define MUI_199 "\xc7" |
| 500 | #define MUI_200 "\xc8" |
| 501 | #define MUI_201 "\xc9" |
| 502 | #define MUI_202 "\xca" |
| 503 | #define MUI_203 "\xcb" |
| 504 | #define MUI_204 "\xcc" |
| 505 | #define MUI_205 "\xcd" |
| 506 | #define MUI_206 "\xce" |
| 507 | #define MUI_207 "\xcf" |
| 508 | #define MUI_208 "\xd0" |
| 509 | #define MUI_209 "\xd1" |
| 510 | #define MUI_210 "\xd2" |
| 511 | #define MUI_211 "\xd3" |
| 512 | #define MUI_212 "\xd4" |
| 513 | #define MUI_213 "\xd5" |
| 514 | #define MUI_214 "\xd6" |
| 515 | #define MUI_215 "\xd7" |
| 516 | #define MUI_216 "\xd8" |
| 517 | #define MUI_217 "\xd9" |
| 518 | #define MUI_218 "\xda" |
| 519 | #define MUI_219 "\xdb" |
| 520 | #define MUI_220 "\xdc" |
| 521 | #define MUI_221 "\xdd" |
| 522 | #define MUI_222 "\xde" |
| 523 | #define MUI_223 "\xdf" |
| 524 | #define MUI_224 "\xe0" |
| 525 | #define MUI_225 "\xe1" |
| 526 | #define MUI_226 "\xe2" |
| 527 | #define MUI_227 "\xe3" |
| 528 | #define MUI_228 "\xe4" |
| 529 | #define MUI_229 "\xe5" |
| 530 | #define MUI_230 "\xe6" |
| 531 | #define MUI_231 "\xe7" |
| 532 | #define MUI_232 "\xe8" |
| 533 | #define MUI_233 "\xe9" |
| 534 | #define MUI_234 "\xea" |
| 535 | #define MUI_235 "\xeb" |
| 536 | #define MUI_236 "\xec" |
| 537 | #define MUI_237 "\xed" |
| 538 | #define MUI_238 "\xee" |
| 539 | #define MUI_239 "\xef" |
| 540 | #define MUI_240 "\xf0" |
| 541 | #define MUI_241 "\xf1" |
| 542 | #define MUI_242 "\xf2" |
| 543 | #define MUI_243 "\xf3" |
| 544 | #define MUI_244 "\xf4" |
| 545 | #define MUI_245 "\xf5" |
| 546 | #define MUI_246 "\xf6" |
| 547 | #define MUI_247 "\xf7" |
| 548 | #define MUI_248 "\xf8" |
| 549 | #define MUI_249 "\xf9" |
| 550 | #define MUI_250 "\xfa" |
| 551 | #define MUI_251 "\xfb" |
| 552 | #define MUI_252 "\xfc" |
| 553 | #define MUI_253 "\xfd" |
| 554 | #define MUI_254 "\xfe" |
| 555 | #define MUI_255 "\xff" |
| 556 | |
| 557 | /* form: one id only */ |
| 558 | #define MUI_FORM(n) "U" MUI_##n |
| 559 | |
| 560 | /* style: one id only */ |
| 561 | #define MUI_STYLE(n) "S" #n |
| 562 | |
| 563 | #define MUI_AUX(id) "Z" id |
| 564 | |
| 565 | #define MUI_DATA(id, text) "D" id "\xff" text "\xff" |
| 566 | |
| 567 | #define MUI_XY(id, x, y) "F" id MUI_##x MUI_##y |
| 568 | /* button id must be two chars, but must be unique everywhere */ |
| 569 | #define MUI_XYT(id, x, y, text) "B" id MUI_##x MUI_##y "\xff" text "\xff" |
| 570 | #define MUI_XYA(id, x, y, a) "A" id MUI_##x MUI_##y MUI_##a |
| 571 | #define MUI_XYAT(id, x, y, a, text) \ |
| 572 | "T" id MUI_##x MUI_##y MUI_##a "\xff" text "\xff" |
| 573 | |
| 574 | #define MUI_LABEL(x, y, text) "L" MUI_##x MUI_##y "\xff" text "\xff" |
| 575 | #define MUI_GOTO(x, y, n, text) "G" MUI_##x MUI_##y MUI_##n "\xff" text "\xff" |
| 576 | #define MUI_goto(x, y, n, text) "g" MUI_##x MUI_##y MUI_##n "\xff" text "\xff" |
| 577 | |
| 578 | uint8_t mui_get_fds_char(fds_t *s) MUI_NOINLINE; |
| 579 | |
| 580 | uint8_t mui_fds_first_token(mui_t *ui) MUI_NOINLINE; |
| 581 | uint8_t mui_fds_next_token(mui_t *ui) MUI_NOINLINE; |
| 582 | uint8_t mui_fds_get_nth_token(mui_t *ui, uint8_t n) MUI_NOINLINE; |
| 583 | uint8_t mui_fds_get_token_cnt(mui_t *ui) MUI_NOINLINE; |
| 584 | |
| 585 | void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, |
| 586 | size_t muif_tcnt); |
| 587 | uint8_t mui_GetCurrentCursorFocusPosition(mui_t *ui); |
| 588 | void mui_Draw(mui_t *ui); |
| 589 | /* warning: The next function will overwrite the ui field variables like |
| 590 | * ui->arg, etc. 26 sep 2021: only ui->text is modified */ |
| 591 | uint8_t mui_GetSelectableFieldTextOption(mui_t *ui, fds_t *fds, |
| 592 | uint8_t nth_token); |
| 593 | /* warning: The next function will overwrite the ui field variables like |
| 594 | * ui->arg, etc 26 sep 2021: only ui->text is modified*/ |
| 595 | uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, fds_t *fds); |
| 596 | void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position); |
| 597 | void mui_LeaveForm(mui_t *ui); |
| 598 | uint8_t mui_GotoForm(mui_t *ui, uint8_t form_id, |
| 599 | uint8_t initial_cursor_position); |
| 600 | void mui_SaveFormWithCursorPosition( |
| 601 | mui_t *ui, |
| 602 | uint8_t cursor_pos); /* Save current form with manully provied cursor |
| 603 | position, Used together with mui_RestoreForm */ |
| 604 | void mui_SaveForm(mui_t *ui); /* Save current form+cursor position. Used |
| 605 | together with mui_RestoreForm */ |
| 606 | uint8_t mui_RestoreForm(mui_t *ui); /* Restore form and cursor position, |
| 607 | previously saved with mui_SaveForm */ |
| 608 | void mui_SaveCursorPosition( |
| 609 | mui_t *ui, |
| 610 | uint8_t cursor_position); /* stores a cursor position for use with |
| 611 | mui_GotoFormAutoCursorPosition */ |
| 612 | uint8_t mui_GotoFormAutoCursorPosition(mui_t *ui, uint8_t form_id); |
| 613 | |
| 614 | int mui_GetCurrentFormId( |
| 615 | mui_t *ui); /* form id or -1 if the menu system is inactive */ |
| 616 | void mui_NextField(mui_t *ui); |
| 617 | void mui_PrevField(mui_t *ui); |
| 618 | void mui_SendSelect(mui_t *ui); |
| 619 | void mui_SendSelectWithExecuteOnSelectFieldSearch( |
| 620 | mui_t *ui); /* use this if MUIF_EXECUTE_ON_SELECT_BUTTON is used */ |
| 621 | |
| 622 | void mui_SendValueIncrement(mui_t *ui); |
| 623 | void mui_SendValueDecrement(mui_t *ui); |
| 624 | |
| 625 | #define mui_IsFormActive(ui) ((ui)->current_form_fds != NULL) |
| 626 | |
| 627 | #ifdef __cplusplus |
| 628 | } |
| 629 | #endif |
| 630 | |
| 631 | #endif /* MUI_H */ |