m_test.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * sfnedit/m_test.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 Main window test font tool
  27. *
  28. */
  29. #include <stdint.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include "libsfn.h"
  33. #include "ui.h"
  34. #include "lang.h"
  35. #define FONTMAXSIZE 256
  36. static char teststr[256] = { 0 };
  37. int fontsize = 24;
  38. /**
  39. * Font test window
  40. */
  41. void view_test()
  42. {
  43. ui_win_t *win = &wins[0];
  44. int r, x = 32, y = 80;
  45. char *str = teststr;
  46. ui_box(win, 19, 40, 20, 20, theme[wins[0].field == 7 ? THEME_CURSOR : (selfield == 0 ? THEME_DARKER : THEME_LIGHT)],
  47. theme[wins[0].field == 7 ? THEME_LIGHT : THEME_BG], theme[wins[0].field == 7 ? THEME_CURSOR :
  48. (selfield == 0 ? THEME_LIGHT : THEME_DARKER)]);
  49. ui_icon(win, 21, 42, ICON_ZOOMOUT, 0);
  50. ui_box(win, 41, 40, 20, 20, theme[wins[0].field == 8 ? THEME_CURSOR : (selfield == 1 ? THEME_DARKER : THEME_LIGHT)],
  51. theme[wins[0].field == 8 ? THEME_LIGHT : THEME_BG], theme[wins[0].field == 8 ? THEME_CURSOR :
  52. (selfield == 1 ? THEME_LIGHT : THEME_DARKER)]);
  53. ui_icon(win, 43, 42, ICON_ZOOMIN, 0);
  54. if(!teststr[0]) strcpy(teststr, "Lorem ipsum sic dolor amet");
  55. ui_input(win, 64, 40, win->w - 84, teststr, wins[0].field == 9, 255, 0);
  56. ssfn_dst.fg = theme[THEME_FG];
  57. ssfn_dst.w = win->w - 16;
  58. ssfn_dst.h = win->h;
  59. ui_box(win, 16, 76, win->w - 32, fontsize + 8, theme[THEME_BG], theme[THEME_BG], theme[THEME_BG]);
  60. do { r = ui_render(win, &x, &y, fontsize, str); str += r; } while(r > 0);
  61. ssfn_dst.w = win->w;
  62. }
  63. /**
  64. * On enter handler
  65. */
  66. void ctrl_test_onenter()
  67. {
  68. switch(wins[0].field) {
  69. case 7:
  70. if(fontsize > 8) fontsize--;
  71. break;
  72. case 8:
  73. if(fontsize < FONTMAXSIZE) fontsize++;
  74. break;
  75. }
  76. }
  77. /**
  78. * On key handler
  79. */
  80. void ctrl_test_onkey()
  81. {
  82. if(event.x == K_UP && fontsize < FONTMAXSIZE) fontsize++;
  83. if(event.x == K_DOWN && fontsize > 8) fontsize--;
  84. if(event.x >= ' ') {
  85. strcpy(teststr, (char*)&event.x);
  86. wins[0].field = 9;
  87. input_refresh = 1;
  88. input_maxlen = 0;
  89. input_str = NULL;
  90. }
  91. ui_refreshwin(0, 0, 0, wins[0].w, wins[0].h);
  92. }
  93. /**
  94. * On button press handler
  95. */
  96. void ctrl_test_onbtnpress()
  97. {
  98. ui_win_t *win = &wins[0];
  99. if(event.w & 24) {
  100. if(event.w & 8 && fontsize > 8) fontsize--;
  101. if(event.w & 16 && fontsize < FONTMAXSIZE) fontsize++;
  102. } else {
  103. selfield = wins[0].field = -1;
  104. if(event.y > 40 && event.y < 60) {
  105. if(event.x >= 19 && event.x < 39) selfield = 0; else
  106. if(event.x >= 41 && event.x < 61) selfield = 1; else
  107. if(event.x >= 64 && event.x < win->w - 20) wins[0].field = 9;
  108. }
  109. }
  110. }
  111. /**
  112. * On click (button release) handler
  113. */
  114. void ctrl_test_onclick()
  115. {
  116. if(event.y > 40 && event.y < 60) {
  117. if(event.x >= 19 && event.x < 39 && selfield == 0 && fontsize > 8) fontsize--;
  118. if(event.x >= 41 && event.x < 61 && selfield == 1 && fontsize < FONTMAXSIZE) fontsize++;
  119. }
  120. else wins[0].field = -1;
  121. selfield = -1;
  122. }