help.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * sfnedit/help.c
  3. *
  4. * Copyright (C) 2020 bzt (bztsrc@gitlab)
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use, copy,
  10. * modify, merge, publish, distribute, sublicense, and/or sell copies
  11. * of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  21. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  22. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  24. * DEALINGS IN THE SOFTWARE.
  25. *
  26. * @brief Contextual help window
  27. *
  28. */
  29. #include <stdint.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <unistd.h>
  33. #include "libsfn.h"
  34. #include "ui.h"
  35. #include "lang.h"
  36. /**
  37. * Help window
  38. */
  39. void view_help(int idx)
  40. {
  41. int i, c;
  42. char *title, *wt, *s;
  43. ui_win_t *win = &wins[idx];
  44. i = wins[idx].tool < 0 ? 0 : wins[idx].tool;
  45. if(!idx) {
  46. title = lang[MTOOL_ABOUT + i];
  47. wt = lang[WHELP_MWIN];
  48. s = lang[MHELP_ABOUT + i];
  49. } else {
  50. title = lang[GTOOL_MEASURES + i];
  51. wt = lang[WHELP_GWIN];
  52. s = lang[GHELP_MEASURES + i];
  53. }
  54. ssfn_dst.ptr = (uint8_t*)win->data;
  55. ssfn_dst.p = win->p*4;
  56. ssfn_dst.w = win->w;
  57. ssfn_dst.h = win->h;
  58. ssfn_dst.x = 8;
  59. ssfn_dst.y = 8;
  60. ssfn_dst.fg = 0xFF000000 | ((theme[THEME_BG] >> 2) & 0x3F3F3F);
  61. ssfn_dst.bg = 0;
  62. ui_text(win, ssfn_dst.x+1, 9, lang[HELP]);
  63. ui_text(win, ssfn_dst.x+8, 9, title);
  64. ssfn_dst.x = 8;
  65. ssfn_dst.fg = 0xFF000000 | ((theme[THEME_FG] << 2) & 0xFCFCFC);
  66. ui_text(win, ssfn_dst.x, 8, lang[HELP]);
  67. ui_text(win, ssfn_dst.x+8, 8, title);
  68. ssfn_dst.fg = theme[THEME_FG];
  69. ui_text(win, 8, 32, wt);
  70. ssfn_dst.x = 8;
  71. ssfn_dst.y = 52;
  72. while(*s) {
  73. c = ssfn_utf8(&s);
  74. if(c == '[') { ssfn_dst.fg = theme[THEME_BG]; ssfn_dst.bg = theme[THEME_FG]; ssfn_putc(' '); } else
  75. if(c == ']') { ssfn_putc(' '); ssfn_dst.fg = theme[THEME_FG]; ssfn_dst.bg = theme[THEME_BG]; } else
  76. if(c == '\t') { ssfn_dst.x = 8 + 20*8; } else
  77. if(c == '\n' || ssfn_dst.x + 16 >= win->w) { ssfn_dst.x = 8; ssfn_dst.y += 18; }
  78. else ssfn_putc(c);
  79. if(ssfn_dst.fg == theme[THEME_BG]) ssfn_dst.x--;
  80. }
  81. }