m_props.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * sfnedit/m_props.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 font properties tool
  27. *
  28. */
  29. #include <stdint.h>
  30. #include <stdio.h>
  31. #include "libsfn.h"
  32. #include "ui.h"
  33. #include "lang.h"
  34. int fieldtexts = 0, typetexts = 0;
  35. /**
  36. * Font properties window
  37. */
  38. void view_props()
  39. {
  40. int i, j, k;
  41. ui_win_t *win = &wins[0];
  42. if(!fieldtexts) {
  43. for(i = PROP_TYPE; i <= PROP_LICENSE; i++) {
  44. j = ui_textwidth(lang[i]) + 36;
  45. if(j > fieldtexts) fieldtexts = j;
  46. }
  47. for(i = PROP_SERIF; i <= PROP_HAND; i++) {
  48. j = ui_textwidth(lang[i]) + 8;
  49. if(j > typetexts) typetexts = j;
  50. }
  51. }
  52. if(wins[0].field != 7) {
  53. ui_box(win, fieldtexts, 40, typetexts + 19, (PROP_HAND - PROP_SERIF + 1) * 18 + 4, theme[THEME_BG],
  54. theme[THEME_BG], theme[THEME_BG]);
  55. }
  56. j = win->w - fieldtexts - 20;
  57. ui_text(win, 20, 40, lang[PROP_TYPE]);
  58. ui_input(win, fieldtexts, 40, typetexts + 15, lang[PROP_SERIF + ctx.family], 0, 16, 0);
  59. ui_box(win, fieldtexts + typetexts + 3, 41, 15, 18, theme[selfield == 6 ? THEME_DARKER : THEME_LIGHT], theme[THEME_BG],
  60. theme[selfield == 7 ? THEME_LIGHT : THEME_DARKER]);
  61. ui_tri(win, fieldtexts + typetexts + 7, 48, 0);
  62. k = fieldtexts + typetexts + 32;
  63. i = (win->w - k - 20) / 4;
  64. ssfn_dst.w = k+i-2;
  65. ui_bool(win, k, 40, lang[PROP_BOLD], ctx.style & SSFN_STYLE_BOLD, wins[0].field == 8);
  66. ssfn_dst.w = k+2*i-2;
  67. ui_bool(win, k+i, 40, lang[PROP_ITALIC], ctx.style & SSFN_STYLE_ITALIC, wins[0].field == 9);
  68. ssfn_dst.w = k+3*i-2;
  69. ui_bool(win, k+2*i, 40, lang[PROP_USRDEF1], ctx.style & SSFN_STYLE_USRDEF1, wins[0].field == 10);
  70. ssfn_dst.w = win->w - 1;
  71. ui_bool(win, k+3*i, 40, lang[PROP_USRDEF2], ctx.style & SSFN_STYLE_USRDEF2, wins[0].field == 11);
  72. ui_text(win, 20, 64, lang[PROP_NAME]);
  73. ui_input(win, fieldtexts, 64, j, ctx.name, wins[0].field == 12, 255, 3);
  74. ui_text(win, 20, 88, lang[PROP_FAMILY]);
  75. ui_input(win, fieldtexts, 88, j, ctx.familyname, wins[0].field == 13, 255, 4);
  76. ui_text(win, 20,112, lang[PROP_SUBFAM]);
  77. ui_input(win, fieldtexts,112, j, ctx.subname, wins[0].field == 14, 255, 5);
  78. ui_text(win, 20,136, lang[PROP_REVISION]);
  79. ui_input(win, fieldtexts,136, j, ctx.revision, wins[0].field == 15, 255, 6);
  80. ui_text(win, 20,160, lang[PROP_MANUFACTURER]);
  81. ui_input(win, fieldtexts,160, j, ctx.manufacturer, wins[0].field == 16, 255, 7);
  82. ui_text(win, 20,184, lang[PROP_LICENSE]);
  83. ui_input(win, fieldtexts,184, j, ctx.license, wins[0].field == 17, 255, 8);
  84. if(wins[0].field == 7) {
  85. ui_box(win, fieldtexts, 40, typetexts + 19, (PROP_HAND - PROP_SERIF + 1) * 18 + 4, theme[THEME_DARKER],
  86. theme[THEME_INPBG], theme[THEME_LIGHT]);
  87. for(i = 0; i <= PROP_HAND - PROP_SERIF; i++) {
  88. if(i == ctx.family)
  89. ui_box(win, fieldtexts + 1, 41 + i * 18, typetexts + 17, 20, theme[THEME_SELBG],
  90. theme[THEME_SELBG], theme[THEME_SELBG]);
  91. ui_text(win, fieldtexts + 2, 41 + i * 18, lang[i + PROP_SERIF]);
  92. }
  93. ui_box(win, fieldtexts + typetexts + 3, 41, 15, 18, theme[THEME_DARKER], theme[THEME_BG], theme[THEME_LIGHT]);
  94. ui_tri(win, fieldtexts + typetexts + 7, 48, 0);
  95. }
  96. }
  97. /**
  98. * On enter handler
  99. */
  100. void ctrl_props_onenter()
  101. {
  102. if(wins[0].field == 8) ctx.style ^= SSFN_STYLE_BOLD; else
  103. if(wins[0].field == 9) ctx.style ^= SSFN_STYLE_ITALIC; else
  104. if(wins[0].field ==10) ctx.style ^= SSFN_STYLE_USRDEF1; else
  105. if(wins[0].field ==11) ctx.style ^= SSFN_STYLE_USRDEF2; else
  106. if(wins[0].field == 7) wins[0].field = 8;
  107. ui_refreshwin(0, 0, 0, wins[0].w, wins[0].h);
  108. }
  109. /**
  110. * On key handler
  111. */
  112. void ctrl_props_onkey()
  113. {
  114. if(wins[0].field == 7) {
  115. if(event.x == K_UP) {
  116. if(ctx.family > 0) {
  117. ctx.family--;
  118. ui_refreshwin(0, 0, 0, wins[0].w, wins[0].h);
  119. }
  120. } else
  121. if(event.x == K_DOWN) {
  122. if(ctx.family < PROP_HAND - PROP_SERIF + 1) {
  123. ctx.family++;
  124. ui_refreshwin(0, 0, 0, wins[0].w, wins[0].h);
  125. }
  126. }
  127. }
  128. }
  129. /**
  130. * On button press handler
  131. */
  132. void ctrl_props_onbtnpress()
  133. {
  134. int i, k;
  135. ui_win_t *win = &wins[0];
  136. selfield = -1;
  137. if(wins[0].field == 7) {
  138. if(event.y > 40 && event.y < 41 + (PROP_HAND - PROP_SERIF + 1) * 18 && event.x > fieldtexts &&
  139. event.x < fieldtexts + typetexts + 2) ctx.family = (event.y - 41) / 18;
  140. } else
  141. if(event.y > 40 && event.y < 60) {
  142. k = fieldtexts + typetexts + 32;
  143. i = (win->w - k - 20) / 4;
  144. if(event.x >= fieldtexts && event.x < fieldtexts + typetexts + 18) selfield = 7; else
  145. if(event.x >= k && event.x <= k + i - 1) ctx.style ^= SSFN_STYLE_BOLD; else
  146. if(event.x >= k + i && event.x <= k + 2*i - 1) ctx.style ^= SSFN_STYLE_ITALIC; else
  147. if(event.x >= k + 2*i && event.x <= k + 3*i - 1) ctx.style ^= SSFN_STYLE_USRDEF1; else
  148. if(event.x >= k + 3*i && event.x <= k + 4*i - 1) ctx.style ^= SSFN_STYLE_USRDEF2;
  149. } else
  150. if(event.x > fieldtexts && event.y >= 64 && event.y < 208) wins[0].field = (event.y - 64) / 24 + 12;
  151. else wins[0].field = -1;
  152. }
  153. /**
  154. * On click (button release) handler
  155. */
  156. void ctrl_props_onclick()
  157. {
  158. if(wins[0].field == 7) {
  159. wins[0].field = -1;
  160. } else {
  161. if(event.y > 40 && event.y < 60 && event.x >= fieldtexts && event.x < fieldtexts + typetexts + 18 && selfield == 7)
  162. wins[0].field = 7;
  163. }
  164. selfield = -1;
  165. }