m_about.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * sfnedit/m_about.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 About
  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. #ifdef __WIN32__
  37. #include <windows.h>
  38. #include <shellapi.h>
  39. #endif
  40. #ifdef __MACOSX__
  41. #define OPEN "open"
  42. #else
  43. #define OPEN "xdg-open"
  44. #endif
  45. extern ssfn_t logofnt;
  46. char repo_url[] = "https://gitlab.com/bztsrc/scalable-font2";
  47. /**
  48. * Open the repository in the default browser
  49. */
  50. void about_open_repo()
  51. {
  52. #ifdef __WIN32__
  53. ShellExecuteA(0, 0, repo_url, 0, 0, SW_SHOW);
  54. #else
  55. char cmd[256];
  56. if(!fork()) {
  57. fclose(stdin);
  58. fclose(stdout);
  59. fclose(stderr);
  60. sprintf(cmd, OPEN " %s", repo_url);
  61. exit(system(cmd));
  62. }
  63. #endif
  64. wins[0].field = -1;
  65. ui_refreshwin(0, 0, 0, wins[0].w, wins[0].h);
  66. }
  67. /**
  68. * The about window
  69. */
  70. void view_about()
  71. {
  72. int i, j, m, p;
  73. char *s = "Scalable Screen Font Editor", *ptr = ((char*)ssfn_src + 32);
  74. ui_win_t *win = &wins[0];
  75. uint8_t *a, *b, *c = (uint8_t*)&theme[THEME_BG];
  76. if(win->w > 64 && win->h > 58) {
  77. for(p = 40*win->p + (win->w - 64) / 2, m = 0, j = 0; j < 64 && 58 + j < win->h; j++, p += win->p, m += 64 * 4) {
  78. for(i = 0; i < 64; i++) {
  79. if(icon64[m + (i<<2)+3]) {
  80. a = (uint8_t*)&win->data[p + i];
  81. b = (uint8_t*)&icon64[m + (i<<2)];
  82. a[2] = (b[0]*b[3] + (256 - b[3])*c[2]) >> 8;
  83. a[1] = (b[1]*b[3] + (256 - b[3])*c[1]) >> 8;
  84. a[0] = (b[2]*b[3] + (256 - b[3])*c[0]) >> 8;
  85. }
  86. }
  87. }
  88. }
  89. ssfn_dst.ptr = (uint8_t*)win->data;
  90. ssfn_dst.p = win->p*4;
  91. ssfn_dst.w = win->w;
  92. ssfn_dst.h = win->h;
  93. ssfn_dst.x = (win->w - 620) / 2;
  94. ssfn_dst.y = 160;
  95. ssfn_dst.fg = theme[THEME_FG];
  96. ssfn_dst.bg = theme[THEME_BG];
  97. while((i = ssfn_render(&logofnt, &ssfn_dst, s)) > 0) s += i;
  98. ssfn_dst.fg = 0xFF000000 | ((theme[THEME_BG] >> 2) & 0x3F3F3F);
  99. ssfn_dst.bg = 0;
  100. j = wins[0].field == 7 ? THEME_FG : THEME_BG;
  101. p = (win->w - 360) / 2;
  102. ui_box(win, p - 2, 180, 364, 18, theme[j], theme[wins[0].field == 7 ? THEME_LIGHT: THEME_BG], theme[j]);
  103. ui_text(win, p + 1, 181, repo_url);
  104. ssfn_dst.fg = theme[THEME_FG];
  105. ui_text(win, p, 180, repo_url);
  106. ssfn_dst.y = win->h - 18 * 16;
  107. if(ssfn_dst.y < 208) ssfn_dst.y = 208;
  108. ui_text(win, 8, ssfn_dst.y, lang[HELPSTR]);
  109. ui_text(win, ssfn_dst.x + 8, ssfn_dst.y, uniname_date);
  110. ui_text(win, ssfn_dst.x, ssfn_dst.y, ", unifont:");
  111. while(*ptr) ptr++;
  112. ptr++; while(*ptr) ptr++;
  113. ptr++; while(*ptr) ptr++;
  114. ptr++;
  115. ui_text(win, ssfn_dst.x + 8, ssfn_dst.y, ptr);
  116. ssfn_dst.y += 32;
  117. ui_text(win, 8, ssfn_dst.y, "Copyright (C) 2021 bzt (bztsrc@gitlab) - MIT license");
  118. ssfn_dst.y += 16;
  119. ssfn_dst.fg = theme[THEME_LIGHTER];
  120. for(i = CPYRGT_0; i <= CPYRGT_9 && (int)ssfn_dst.y < win->h - 18; i++) {
  121. ssfn_dst.y += 16;
  122. ui_text(win, 8, ssfn_dst.y, lang[i]);
  123. }
  124. ssfn_dst.fg = theme[THEME_FG];
  125. }
  126. /**
  127. * On mouse move handler
  128. */
  129. void ctrl_about_onmove()
  130. {
  131. int p = (wins[0].w - 360) / 2;
  132. if(event.y >= 180 && event.y < 196 && event.x >= p && event.x < p + 360)
  133. cursor = CURSOR_GRAB;
  134. }
  135. /**
  136. * On click (button release) handler
  137. */
  138. void ctrl_about_onclick()
  139. {
  140. int p = (wins[0].w - 360) / 2;
  141. if(event.y >= 180 && event.y < 196 && event.x >= p && event.x < p + 360)
  142. about_open_repo();
  143. }
  144. /**
  145. * On enter handler
  146. */
  147. void ctrl_about_onenter()
  148. {
  149. if(wins[0].field == 7)
  150. about_open_repo();
  151. }