g_coords.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. * sfnedit/g_coords.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 Glyph window measure coordinates tool
  27. *
  28. */
  29. #include <stdint.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include "libsfn.h"
  34. #include "ui.h"
  35. #include "lang.h"
  36. int mousex = -1, mousey = -1;
  37. /**
  38. * Glyph coordinates and dimensions window
  39. */
  40. void view_coords(int idx)
  41. {
  42. ui_win_t *win = &wins[idx];
  43. int i = 0, j, x = win->w - 74;
  44. char *u, s[48];
  45. if(x < 0) x = 0;
  46. ssfn_dst.w = x - 6;
  47. ssfn_dst.h = win->h - 24;
  48. ui_grid(win, ctx.glyphs[win->unicode].width, ctx.glyphs[win->unicode].height);
  49. ui_gridbg(win, 20 + (win->zx > 0 ? win->zx : 0), 36 + (win->zy > 0 ? win->zy : 0),
  50. win->zoom * ctx.glyphs[win->unicode].width, win->zoom * ctx.glyphs[win->unicode].height, 1, win->data, -1, -1);
  51. ui_edit(win, 20 + win->zx, 36 + win->zy, win->unicode, -1);
  52. ssfn_dst.w = win->w - 1;
  53. ssfn_dst.h = win->h - 20;
  54. u = utf8(win->unicode);
  55. if(!u[1]) u[2] = u[3] = 0; else if(!u[2]) u[3] = 0;
  56. sprintf(s, "U+%06X", win->unicode);
  57. ssfn_dst.fg = theme[THEME_FG]; ui_text(win, 144, 4, s);
  58. ssfn_dst.fg = theme[THEME_LIGHTER]; ui_text(win, 144+80, 4, "UTF-8");
  59. sprintf(s, "%02x %02x %02x %02x", (unsigned char)u[0], (unsigned char)u[1], (unsigned char)u[2], (unsigned char)u[3]);
  60. ssfn_dst.fg = theme[THEME_FG]; ui_text(win, 144+80+6*8, 4, s);
  61. ssfn_dst.fg = theme[THEME_LIGHTER]; ui_text(win, 144+80+6*8+12*8, 4, "DEC");
  62. sprintf(s, "%d", win->unicode);
  63. ssfn_dst.fg = theme[THEME_FG]; ui_text(win, 144+80+6*8+12*8+4*8, 4, s);
  64. ui_box(win, x, 30, 10, 10, theme[THEME_DARKER], theme[THEME_DIM], theme[THEME_LIGHTER]);
  65. ui_num(win, x+18, 26, ctx.glyphs[win->unicode].width, win->field == 4, selfield);
  66. ui_box(win, x, 52, 10, 10, theme[THEME_DARKER], theme[THEME_DIM], theme[THEME_LIGHTER]);
  67. ui_num(win, x+18, 48, ctx.glyphs[win->unicode].height, win->field == 5, selfield - 2);
  68. ui_box(win, x, 74, 10, 10, theme[THEME_DARKER], theme[THEME_BASE], theme[THEME_LIGHTER]);
  69. ui_num(win, x+18, 70, ctx.baseline, win->field == 6, selfield - 4);
  70. ui_box(win, x, 96, 10, 10, theme[THEME_DARKER], theme[THEME_UNDER], theme[THEME_LIGHTER]);
  71. ui_num(win, x+18, 92, ctx.underline, win->field == 7, selfield - 6);
  72. ui_box(win, x, 140, 10, 10, theme[THEME_DARKER], theme[THEME_OVL], theme[THEME_LIGHTER]);
  73. ui_num(win, x+18, 136, ctx.glyphs[win->unicode].ovl_x, win->field == 8, selfield - 8);
  74. ui_box(win, x, 162, 10, 10, theme[THEME_DARKER], theme[THEME_ADV], theme[THEME_LIGHTER]);
  75. ui_num(win, x+18, 158, ctx.glyphs[win->unicode].adv_x, win->field == 9, selfield - 10);
  76. ui_box(win, x, 184, 10, 10, theme[THEME_DARKER], theme[THEME_ADV], theme[THEME_LIGHTER]);
  77. ui_num(win, x+18, 180, ctx.glyphs[win->unicode].adv_y, win->field == 10, selfield - 12);
  78. for(i = 0; i < 3; i++) {
  79. j = win->field == 11 + i;
  80. ui_box(win, x + i * 24, 206, 22, 22, theme[j ? THEME_CURSOR : (selfield==i+14 ? THEME_DARKER : THEME_LIGHT)],
  81. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==i+14 ? THEME_LIGHT : THEME_DARKER)]);
  82. ui_icon(win, x + 3 + i * 24, 209, ICON_RHORIZ + i, 0);
  83. }
  84. j = win->field == 14;
  85. ui_box(win, x + 24, 250, 22, 22, theme[j ? THEME_CURSOR : (selfield==17 ? THEME_DARKER : THEME_LIGHT)],
  86. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==17 ? THEME_LIGHT : THEME_DARKER)]);
  87. ui_icon(win, x + 3 + 24, 253, ICON_UARR, 0);
  88. j = win->field == 15;
  89. ui_box(win, x, 274, 22, 22, theme[j ? THEME_CURSOR : (selfield==18 ? THEME_DARKER : THEME_LIGHT)],
  90. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==18 ? THEME_LIGHT : THEME_DARKER)]);
  91. ui_icon(win, x + 3, 277, ICON_LARR, 0);
  92. j = win->field == 16;
  93. ui_box(win, x + 48, 274, 22, 22, theme[j ? THEME_CURSOR : (selfield==19 ? THEME_DARKER : THEME_LIGHT)],
  94. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==19 ? THEME_LIGHT : THEME_DARKER)]);
  95. ui_icon(win, x + 3 + 48, 277, ICON_RARR, 0);
  96. j = win->field == 17;
  97. ui_box(win, x + 24, 298, 22, 22, theme[j ? THEME_CURSOR : (selfield==20 ? THEME_DARKER : THEME_LIGHT)],
  98. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==20 ? THEME_LIGHT : THEME_DARKER)]);
  99. ui_icon(win, x + 3 + 24, 301, ICON_DARR, 0);
  100. j = win->field == 18;
  101. ui_box(win, x, 342, 22, 22, theme[j ? THEME_CURSOR : (selfield==21 ? THEME_DARKER : THEME_LIGHT)],
  102. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==21 ? THEME_LIGHT : THEME_DARKER)]);
  103. ui_icon(win, x + 3, 345, ICON_SHEAR, 0);
  104. j = win->field == 19;
  105. ui_box(win, x + 24, 342, 22, 22, theme[j ? THEME_CURSOR : (selfield==22 ? THEME_DARKER : THEME_LIGHT)],
  106. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==22 ? THEME_LIGHT : THEME_DARKER)]);
  107. ui_icon(win, x + 27, 345, ICON_HFLIP, 0);
  108. j = win->field == 20;
  109. ui_box(win, x + 48, 342, 22, 22, theme[j ? THEME_CURSOR : (selfield==23 ? THEME_DARKER : THEME_LIGHT)],
  110. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==23 ? THEME_LIGHT : THEME_DARKER)]);
  111. ui_icon(win, x + 51, 345, ICON_MEASURES, 0);
  112. j = win->field == 21;
  113. ui_box(win, x, 366, 22, 22, theme[j ? THEME_CURSOR : (selfield==24 ? THEME_DARKER : THEME_LIGHT)],
  114. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==24 ? THEME_LIGHT : THEME_DARKER)]);
  115. ui_icon(win, x + 3, 369, ICON_UNSHEAR, 0);
  116. j = win->field == 22;
  117. ui_box(win, x + 24, 366, 22, 22, theme[j ? THEME_CURSOR : (selfield==25 ? THEME_DARKER : THEME_LIGHT)],
  118. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==25 ? THEME_LIGHT : THEME_DARKER)]);
  119. ui_icon(win, x + 27, 369, ICON_VFLIP, 0);
  120. j = win->field == 23;
  121. ui_box(win, x + 48, 366, 22, 22, theme[j ? THEME_CURSOR : (selfield==26 ? THEME_DARKER : THEME_LIGHT)],
  122. theme[j ? THEME_LIGHT : THEME_BG], theme[j ? THEME_CURSOR : (selfield==26 ? THEME_LIGHT : THEME_DARKER)]);
  123. ui_icon(win, x + 51, 369, ICON_DELETE, 0);
  124. }
  125. /**
  126. * Zoom in at mouse coordinates
  127. */
  128. void ctrl_zoom_in(int idx, int mx, int my)
  129. {
  130. ui_win_t *win = &wins[idx];
  131. if(win->zoom >= 64) { win->zoom = 64; return; }
  132. win->zoom++;
  133. if(posx == -1 || posy == -1) win->rc = 1;
  134. else {
  135. win->zx = mx - 20 - posx * win->zoom - win->zoom / 2;
  136. win->zy = my - 36 - posy * win->zoom - win->zoom / 2;
  137. }
  138. ui_resizewin(win, win->w, win->h);
  139. ui_refreshwin(idx, 0, 0, win->w, win->h);
  140. }
  141. /**
  142. * Zoom out at mouse coordinates
  143. */
  144. void ctrl_zoom_out(int idx, int mx, int my)
  145. {
  146. ui_win_t *win = &wins[idx];
  147. if(win->zoom <= 1) { win->zoom = 1; return; }
  148. win->zoom--;
  149. if(posx == -1 || posy == -1) win->rc = 1;
  150. else {
  151. win->zx = mx - 20 - posx * win->zoom - win->zoom / 2;
  152. win->zy = my - 36 - posy * win->zoom - win->zoom / 2;
  153. }
  154. ui_resizewin(win, win->w, win->h);
  155. ui_refreshwin(idx, 0, 0, win->w, win->h);
  156. }
  157. /**
  158. * Move glyph around
  159. */
  160. void ctrl_move(int idx, int mx, int my)
  161. {
  162. ui_win_t *win = &wins[idx];
  163. if(mousex == -1 && mousey == -1) return;
  164. win->zx += mx - mousex; mousex = mx;
  165. win->zy += my - mousey; mousey = my;
  166. cursor = CURSOR_MOVE;
  167. ui_resizewin(win, win->w, win->h);
  168. ui_refreshwin(event.win, 0, 0, win->w, win->h - 24);
  169. }
  170. /**
  171. * Set glyph's size
  172. */
  173. void ctrl_setsize(int idx, int dw, int dh)
  174. {
  175. ui_win_t *win = &wins[idx];
  176. sfncont_t *cont;
  177. unsigned char *data;
  178. int i, j, k, l, n, w = ctx.glyphs[win->unicode].width, h = ctx.glyphs[win->unicode].height;
  179. if(ctx.glyphs[win->unicode].width + dw >= 0 && ctx.glyphs[win->unicode].width + dw <= 255)
  180. ctx.glyphs[win->unicode].width += dw;
  181. if(ctx.glyphs[win->unicode].height + dh >= 0 && ctx.glyphs[win->unicode].height + dh <= 255)
  182. ctx.glyphs[win->unicode].height += dh;
  183. if(ctx.glyphs[win->unicode].width != w || ctx.glyphs[win->unicode].height != h) {
  184. for(n = 0; n < ctx.glyphs[win->unicode].numlayer; n++)
  185. switch(ctx.glyphs[win->unicode].layers[n].type) {
  186. case SSFN_FRAG_CONTOUR:
  187. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  188. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  189. if(cont->px >= ctx.glyphs[win->unicode].width) cont->px = ctx.glyphs[win->unicode].width - 1;
  190. if(cont->py >= ctx.glyphs[win->unicode].height) cont->py = ctx.glyphs[win->unicode].height - 1;
  191. if(cont->type >= SSFN_CONTOUR_QUAD) {
  192. if(cont->c1x >= ctx.glyphs[win->unicode].width) cont->c1x = ctx.glyphs[win->unicode].width - 1;
  193. if(cont->c1y >= ctx.glyphs[win->unicode].height) cont->c1y = ctx.glyphs[win->unicode].height - 1;
  194. if(cont->type == SSFN_CONTOUR_CUBIC) {
  195. if(cont->c2x >= ctx.glyphs[win->unicode].width) cont->c2x = ctx.glyphs[win->unicode].width - 1;
  196. if(cont->c2y >= ctx.glyphs[win->unicode].height) cont->c2y = ctx.glyphs[win->unicode].height - 1;
  197. }
  198. }
  199. }
  200. break;
  201. case SSFN_FRAG_BITMAP:
  202. case SSFN_FRAG_PIXMAP:
  203. if(!dw) {
  204. ctx.glyphs[win->unicode].layers[n].data = realloc(ctx.glyphs[win->unicode].layers[n].data,
  205. w * ctx.glyphs[win->unicode].height);
  206. if(!ctx.glyphs[win->unicode].layers[n].data) ui_error("coords", ERR_MEM);
  207. if(dh > 0) memset(ctx.glyphs[win->unicode].layers[n].data + w * h, 0xFF, w);
  208. } else {
  209. data = malloc(ctx.glyphs[win->unicode].width * h);
  210. if(!data) ui_error("coords", ERR_MEM);
  211. for(j = k = l = 0; j < h; j++) {
  212. for(i = 0; i < w + (dw < 0 ? dw : 0); i++)
  213. data[k++] = ctx.glyphs[win->unicode].layers[n].data[l++];
  214. if(dw < 0) l++; else data[k++] = 0xFF;
  215. }
  216. free(ctx.glyphs[win->unicode].layers[n].data);
  217. ctx.glyphs[win->unicode].layers[n].data = data;
  218. }
  219. break;
  220. }
  221. }
  222. ctx.width = ctx.height = 0;
  223. for(i = 0; i < 0x110000; i++) {
  224. if(ctx.glyphs[i].width > ctx.width) ctx.width = ctx.glyphs[i].width;
  225. if(ctx.glyphs[i].height > ctx.height) ctx.height = ctx.glyphs[i].height;
  226. }
  227. win->rc = 1; win->zoom = 0;
  228. modified++;
  229. }
  230. /**
  231. * Set glyph's baseline
  232. */
  233. void ctrl_setbase(int idx, int d)
  234. {
  235. (void)idx;
  236. if(d > 0 && ctx.baseline < 255) { ctx.baseline++; modified++; }
  237. if(d < 0 && ctx.baseline > 0) { ctx.baseline--; modified++; }
  238. }
  239. /**
  240. * Set glyph's underlineline
  241. */
  242. void ctrl_setunder(int idx, int d)
  243. {
  244. (void)idx;
  245. if(d > 0 && ctx.underline < 255) { ctx.underline++; modified++; }
  246. if(d < 0 && ctx.underline > 0) { ctx.underline--; modified++; }
  247. }
  248. /**
  249. * Set glyph's overlap x
  250. */
  251. void ctrl_setox(int idx, int d)
  252. {
  253. ui_win_t *win = &wins[idx];
  254. if(d > 0 && ctx.glyphs[win->unicode].ovl_x < 63) { ctx.glyphs[win->unicode].ovl_x++; modified++; }
  255. if(d < 0 && ctx.glyphs[win->unicode].ovl_x > 0) { ctx.glyphs[win->unicode].ovl_x--; modified++; }
  256. }
  257. /**
  258. * Set glyph's advance x
  259. */
  260. void ctrl_setax(int idx, int d)
  261. {
  262. ui_win_t *win = &wins[idx];
  263. ctx.glyphs[win->unicode].adv_y = 0;
  264. if(d > 0 && ctx.glyphs[win->unicode].adv_x < 255) { ctx.glyphs[win->unicode].adv_x++; modified++; }
  265. if(d < 0 && ctx.glyphs[win->unicode].adv_x > 0) { ctx.glyphs[win->unicode].adv_x--; modified++; }
  266. }
  267. /**
  268. * Set glyph's advance y
  269. */
  270. void ctrl_setay(int idx, int d)
  271. {
  272. ui_win_t *win = &wins[idx];
  273. ctx.glyphs[win->unicode].adv_x = 0;
  274. if(d > 0 && ctx.glyphs[win->unicode].adv_y < 255) { ctx.glyphs[win->unicode].adv_y++; modified++; }
  275. if(d < 0 && ctx.glyphs[win->unicode].adv_y > 0) { ctx.glyphs[win->unicode].adv_y--; modified++; }
  276. }
  277. /**
  278. * Set glyph's advance direction
  279. */
  280. void ctrl_setadv(int idx, int d)
  281. {
  282. ui_win_t *win = &wins[idx];
  283. switch(d) {
  284. case 0:
  285. ctx.glyphs[win->unicode].rtl = 1;
  286. ctx.glyphs[win->unicode].adv_y = 0;
  287. if(ctx.glyphs[win->unicode].adv_x < 1) ctx.glyphs[win->unicode].adv_x = ctx.glyphs[win->unicode].width;
  288. break;
  289. case 1:
  290. ctx.glyphs[win->unicode].rtl = 0;
  291. ctx.glyphs[win->unicode].adv_x = 0;
  292. if(ctx.glyphs[win->unicode].adv_y < 1) ctx.glyphs[win->unicode].adv_y = ctx.glyphs[win->unicode].height;
  293. break;
  294. case 2:
  295. ctx.glyphs[win->unicode].rtl = 0;
  296. ctx.glyphs[win->unicode].adv_y = 0;
  297. if(ctx.glyphs[win->unicode].adv_x < 1) ctx.glyphs[win->unicode].adv_x = ctx.glyphs[win->unicode].width;
  298. break;
  299. }
  300. modified++;
  301. }
  302. /**
  303. * Position glyph
  304. */
  305. void ctrl_pos(int idx, int layer, int dx, int dy)
  306. {
  307. ui_win_t *win = &wins[idx];
  308. sfncont_t *cont;
  309. unsigned char *data;
  310. int i, n, w = ctx.glyphs[win->unicode].width, h = ctx.glyphs[win->unicode].height, s, e;
  311. if(layer < 0 || layer >= ctx.glyphs[win->unicode].numlayer) {
  312. s = 0; e = ctx.glyphs[win->unicode].numlayer;
  313. } else {
  314. s = layer; e = layer + 1;
  315. }
  316. for(n = s; n < e; n++)
  317. switch(ctx.glyphs[win->unicode].layers[n].type) {
  318. case SSFN_FRAG_CONTOUR:
  319. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  320. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  321. if(dx < 0 && cont->px > 0) cont->px--;
  322. if(dx > 0 && cont->px < w - 1) cont->px++;
  323. if(dy < 0 && cont->py > 0) cont->py--;
  324. if(dy > 0 && cont->py < h - 1) cont->py++;
  325. if(cont->type >= SSFN_CONTOUR_QUAD) {
  326. if(dx < 0 && cont->c1x > 0) cont->c1x--;
  327. if(dx > 0 && cont->c1x < w - 1) cont->c1x++;
  328. if(dy < 0 && cont->c1y > 0) cont->c1y--;
  329. if(dy > 0 && cont->c1y < h - 1) cont->c1y++;
  330. if(cont->type == SSFN_CONTOUR_CUBIC) {
  331. if(dx < 0 && cont->c2x > 0) cont->c2x--;
  332. if(dx > 0 && cont->c2x < w - 1) cont->c2x++;
  333. if(dy < 0 && cont->c2y > 0) cont->c2y--;
  334. if(dy > 0 && cont->c2y < h - 1) cont->c2y++;
  335. }
  336. }
  337. }
  338. break;
  339. case SSFN_FRAG_BITMAP:
  340. case SSFN_FRAG_PIXMAP:
  341. data = malloc(w * h);
  342. if(!data) ui_error("coords", ERR_MEM);
  343. memcpy(data, ctx.glyphs[win->unicode].layers[n].data, w * h);
  344. if(dy < 0) {
  345. memcpy(ctx.glyphs[win->unicode].layers[n].data, data + w, w * (h - 1));
  346. memcpy(ctx.glyphs[win->unicode].layers[n].data + w * (h - 1), data, w);
  347. } else
  348. if(dy > 0) {
  349. memcpy(ctx.glyphs[win->unicode].layers[n].data + w, data, w * (h - 1));
  350. memcpy(ctx.glyphs[win->unicode].layers[n].data, data + w * (h - 1), w);
  351. }
  352. if(dx < 0) {
  353. for(i = 0; i < h; i++) {
  354. memcpy(ctx.glyphs[win->unicode].layers[n].data + i * w, data + i * w + 1, w - 1);
  355. ctx.glyphs[win->unicode].layers[n].data[i * w + w - 1] = data[i * w];
  356. }
  357. } else
  358. if(dx > 0) {
  359. for(i = 0; i < h; i++) {
  360. memcpy(ctx.glyphs[win->unicode].layers[n].data + i * w + 1, data + i * w, w - 1);
  361. ctx.glyphs[win->unicode].layers[n].data[i * w] = data[i * w + w - 1];
  362. }
  363. }
  364. free(data);
  365. break;
  366. }
  367. modified++;
  368. }
  369. /**
  370. * Italize glyph
  371. */
  372. void ctrl_italize(int idx)
  373. {
  374. ui_win_t *win = &wins[idx];
  375. sfncont_t *cont;
  376. unsigned char *data;
  377. int i, n, mx, w = ctx.glyphs[win->unicode].width, h = ctx.glyphs[win->unicode].height;
  378. int s = h / SSFN_ITALIC_DIV;
  379. ctx.glyphs[win->unicode].width += s;
  380. mx = ctx.glyphs[win->unicode].width;
  381. for(n = 0; n < ctx.glyphs[win->unicode].numlayer; n++)
  382. switch(ctx.glyphs[win->unicode].layers[n].type) {
  383. case SSFN_FRAG_CONTOUR:
  384. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  385. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  386. cont->px += s * (h - cont->py) / h;
  387. if(cont->px < mx) mx = cont->px;
  388. if(cont->type >= SSFN_CONTOUR_QUAD) {
  389. cont->c1x += s * (h - cont->c1y) / h;
  390. if(cont->c1x < mx) mx = cont->c1x;
  391. if(cont->type == SSFN_CONTOUR_CUBIC) {
  392. cont->c2x += s * (h - cont->c2y) / h;
  393. if(cont->c2x < mx) mx = cont->c2x;
  394. }
  395. }
  396. }
  397. break;
  398. case SSFN_FRAG_BITMAP:
  399. case SSFN_FRAG_PIXMAP:
  400. data = malloc(ctx.glyphs[win->unicode].width * h);
  401. if(!data) ui_error("coords", ERR_MEM);
  402. memset(data, 0xFF, ctx.glyphs[win->unicode].width * h);
  403. for(i = 0; i < h; i++)
  404. memcpy(data + i * ctx.glyphs[win->unicode].width + s * (h - i) / h,
  405. ctx.glyphs[win->unicode].layers[n].data + i * w, w);
  406. free(ctx.glyphs[win->unicode].layers[n].data);
  407. ctx.glyphs[win->unicode].layers[n].data = data;
  408. break;
  409. }
  410. for(n = 0; n < ctx.glyphs[win->unicode].numlayer; n++)
  411. if(ctx.glyphs[win->unicode].layers[n].type == SSFN_FRAG_CONTOUR)
  412. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  413. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  414. cont->px -= mx;
  415. if(cont->type >= SSFN_CONTOUR_QUAD) {
  416. cont->c1x -= mx;
  417. if(cont->type == SSFN_CONTOUR_CUBIC)
  418. cont->c2x -= mx;
  419. }
  420. }
  421. sfn_sanitize(win->unicode);
  422. win->rc = 1;
  423. modified++;
  424. }
  425. /**
  426. * Deitalize glyph
  427. */
  428. void ctrl_deitalize(int idx)
  429. {
  430. ui_win_t *win = &wins[idx];
  431. sfncont_t *cont;
  432. unsigned char *data;
  433. int i, n, mx = 0, w = ctx.glyphs[win->unicode].width, h = ctx.glyphs[win->unicode].height;
  434. int s = h / SSFN_ITALIC_DIV;
  435. ctx.glyphs[win->unicode].width -= s;
  436. for(n = 0; n < ctx.glyphs[win->unicode].numlayer; n++)
  437. switch(ctx.glyphs[win->unicode].layers[n].type) {
  438. case SSFN_FRAG_CONTOUR:
  439. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  440. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  441. if(mx > cont->px - s * (h - cont->py) / h) mx = cont->px - s * (h - cont->py) / h;
  442. if(cont->type >= SSFN_CONTOUR_QUAD) {
  443. if(mx > cont->c1x - s * (h - cont->c1y) / h) mx = cont->c1x - s * (h - cont->c1y) / h;
  444. if(cont->type == SSFN_CONTOUR_CUBIC &&
  445. mx > cont->c2x - s * (h - cont->c2y) / h) mx = cont->c2x - s * (h - cont->c2y) / h;
  446. }
  447. }
  448. break;
  449. case SSFN_FRAG_BITMAP:
  450. case SSFN_FRAG_PIXMAP:
  451. data = malloc(ctx.glyphs[win->unicode].width * h);
  452. if(!data) ui_error("coords", ERR_MEM);
  453. for(i = 0; i < h; i++)
  454. memcpy(data + i * ctx.glyphs[win->unicode].width,
  455. ctx.glyphs[win->unicode].layers[n].data + i * w + s * (h - i) / h, w);
  456. free(ctx.glyphs[win->unicode].layers[n].data);
  457. ctx.glyphs[win->unicode].layers[n].data = data;
  458. break;
  459. }
  460. for(n = 0; n < ctx.glyphs[win->unicode].numlayer; n++)
  461. if(ctx.glyphs[win->unicode].layers[n].type == SSFN_FRAG_CONTOUR)
  462. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  463. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  464. cont->px = cont->px - mx - s * (h - cont->py) / h;
  465. if(cont->type >= SSFN_CONTOUR_QUAD) {
  466. cont->c1x = cont->c1x - mx - s * (h - cont->c1y) / h;
  467. if(cont->type == SSFN_CONTOUR_CUBIC)
  468. cont->c2x = cont->c2x - mx - s * (h - cont->c2y) / h;
  469. }
  470. }
  471. sfn_sanitize(win->unicode);
  472. win->rc = 1;
  473. modified++;
  474. }
  475. /**
  476. * Flip glyph horizontally
  477. */
  478. void ctrl_fliph(int idx, int layer)
  479. {
  480. ui_win_t *win = &wins[idx];
  481. sfncont_t *cont;
  482. unsigned char d, *data;
  483. int i, j, k, n, w = ctx.glyphs[win->unicode].width, h = ctx.glyphs[win->unicode].height, s, e;
  484. if(layer < 0 || layer >= ctx.glyphs[win->unicode].numlayer) {
  485. s = 0; e = ctx.glyphs[win->unicode].numlayer;
  486. } else {
  487. s = layer; e = layer + 1;
  488. }
  489. for(n = s; n < e; n++)
  490. switch(ctx.glyphs[win->unicode].layers[n].type) {
  491. case SSFN_FRAG_CONTOUR:
  492. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  493. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  494. cont->px = w - 1 - cont->px;
  495. if(cont->type >= SSFN_CONTOUR_QUAD) {
  496. cont->c1x = w - 1 - cont->c1x;
  497. if(cont->type == SSFN_CONTOUR_CUBIC)
  498. cont->c2x = w - 1 - cont->c2x;
  499. }
  500. }
  501. break;
  502. case SSFN_FRAG_BITMAP:
  503. case SSFN_FRAG_PIXMAP:
  504. data = ctx.glyphs[win->unicode].layers[n].data;
  505. for(j = k = 0; j < h; j++, k += w)
  506. for(i = 0; i < w/2; i++) {
  507. d = data[k + i];
  508. data[k + i] = data[k + w - 1 - i];
  509. data[k + w - 1 - i] = d;
  510. }
  511. break;
  512. }
  513. modified++;
  514. }
  515. /**
  516. * Flip glyph vertically
  517. */
  518. void ctrl_flipv(int idx, int layer)
  519. {
  520. ui_win_t *win = &wins[idx];
  521. sfncont_t *cont;
  522. unsigned char d, *data;
  523. int i, j, n, w = ctx.glyphs[win->unicode].width, h = ctx.glyphs[win->unicode].height, s, e;
  524. if(layer < 0 || layer >= ctx.glyphs[win->unicode].numlayer) {
  525. s = 0; e = ctx.glyphs[win->unicode].numlayer;
  526. } else {
  527. s = layer; e = layer + 1;
  528. }
  529. for(n = s; n < e; n++)
  530. switch(ctx.glyphs[win->unicode].layers[n].type) {
  531. case SSFN_FRAG_CONTOUR:
  532. for(i = 0, cont = (sfncont_t*)ctx.glyphs[win->unicode].layers[n].data;
  533. i < ctx.glyphs[win->unicode].layers[n].len; i++, cont++) {
  534. cont->py = h - 1 - cont->py;
  535. if(cont->type >= SSFN_CONTOUR_QUAD) {
  536. cont->c1y = h - 1 - cont->c1y;
  537. if(cont->type == SSFN_CONTOUR_CUBIC)
  538. cont->c2y = h - 1 - cont->c2y;
  539. }
  540. }
  541. break;
  542. case SSFN_FRAG_BITMAP:
  543. case SSFN_FRAG_PIXMAP:
  544. data = ctx.glyphs[win->unicode].layers[n].data;
  545. for(j = 0; j < h/2; j++)
  546. for(i = 0; i < w; i++) {
  547. d = data[j*w + i];
  548. data[j*w + i] = data[(h-1-j)*w + i];
  549. data[(h-1-j)*w + i] = d;
  550. }
  551. break;
  552. }
  553. modified++;
  554. }
  555. /**
  556. * On enter handler
  557. */
  558. void ctrl_coords_onenter(int idx)
  559. {
  560. ui_win_t *win = &wins[idx];
  561. switch(win->field) {
  562. case 11: ctrl_setadv(idx, 0); break;
  563. case 12: ctrl_setadv(idx, 1); break;
  564. case 13: ctrl_setadv(idx, 2); break;
  565. case 14: ctrl_pos(idx,-1, 0,-1); break;
  566. case 15: ctrl_pos(idx,-1,-1, 0); break;
  567. case 16: ctrl_pos(idx,-1, 1, 0); break;
  568. case 17: ctrl_pos(idx,-1, 0, 1); break;
  569. case 18: ctrl_italize(idx); break;
  570. case 19: ctrl_fliph(idx, -1); break;
  571. case 20: sfn_sanitize(win->unicode); win->rc = 1; modified++; break;
  572. case 21: ctrl_deitalize(idx); break;
  573. case 22: ctrl_flipv(idx, -1); break;
  574. case 23: sfn_chardel(win->unicode); win->rc = 1; modified++; break;
  575. }
  576. }
  577. /**
  578. * On key handler
  579. */
  580. void ctrl_coords_onkey(int idx)
  581. {
  582. ui_win_t *win = &wins[idx];
  583. switch(event.x) {
  584. case K_UP:
  585. switch(win->field) {
  586. case 4: ctrl_setsize(idx, 1, 0); break;
  587. case 5: ctrl_setsize(idx, 0, 1); break;
  588. case 6: ctrl_setbase(idx, 1); break;
  589. case 7: ctrl_setunder(idx, 1); break;
  590. case 8: ctrl_setox(idx, 1); break;
  591. case 9: ctrl_setax(idx, 1); break;
  592. case 10: ctrl_setay(idx, 1); break;
  593. default: ctrl_pos(idx,-1, 0, -1); break;
  594. }
  595. break;
  596. case K_LEFT: ctrl_pos(idx,-1, -1, 0); break;
  597. case K_DOWN:
  598. switch(win->field) {
  599. case 4: ctrl_setsize(idx, -1, 0); break;
  600. case 5: ctrl_setsize(idx, 0, -1); break;
  601. case 6: ctrl_setbase(idx, -1); break;
  602. case 7: ctrl_setunder(idx, -1); break;
  603. case 8: ctrl_setox(idx, -1); break;
  604. case 9: ctrl_setax(idx, -1); break;
  605. case 10: ctrl_setay(idx, -1); break;
  606. default: ctrl_pos(idx,-1, 0, 1); break;
  607. }
  608. break;
  609. case K_RIGHT: ctrl_pos(idx,-1, 1, 0); break;
  610. case 'h': case 'H': ctrl_fliph(idx, -1); break;
  611. case 'v': case 'V': ctrl_flipv(idx, -1); break;
  612. }
  613. ui_resizewin(win, win->w, win->h);
  614. ui_refreshwin(event.win, 0, 0, win->w, win->h - 24);
  615. }
  616. /**
  617. * On button press handler
  618. */
  619. void ctrl_coords_onbtnpress(int idx)
  620. {
  621. ui_win_t *win = &wins[idx];
  622. int x = win->w - 74, ox = win->zx > 0 ? win->zx : 0, oy = win->zy > 0 ? win->zy : 0;
  623. if(x < 0) x = 0;
  624. selfield = win->field = mousex = mousey = -1;
  625. if(event.x > x) {
  626. if(event.y > 26 && event.y < 48) {
  627. if(event.w & (1 << 3)) ctrl_setsize(idx, 1, 0); else
  628. if(event.w & (1 << 4)) ctrl_setsize(idx,-1, 0); else
  629. if(event.x >= x + 58) selfield = 0 + (event.y - 26 > 12 ? 1 : 0); else win->field = 4;
  630. } else
  631. if(event.y > 52 && event.y < 70) {
  632. if(event.w & (1 << 3)) ctrl_setsize(idx, 0, 1); else
  633. if(event.w & (1 << 4)) ctrl_setsize(idx, 0,-1); else
  634. if(event.x >= x + 58) selfield = 2 + (event.y - 52 > 9 ? 1 : 0); else win->field = 5;
  635. } else
  636. if(event.y > 74 && event.y < 92) {
  637. if(event.w & (1 << 3)) ctrl_setbase(idx, 1); else
  638. if(event.w & (1 << 4)) ctrl_setbase(idx,-1); else
  639. if(event.x >= x + 58) selfield = 4 + (event.y - 74 > 9 ? 1 : 0); else win->field = 6;
  640. } else
  641. if(event.y > 96 && event.y < 114) {
  642. if(event.w & (1 << 3)) ctrl_setunder(idx, 1); else
  643. if(event.w & (1 << 4)) ctrl_setunder(idx,-1); else
  644. if(event.x >= x + 58) selfield = 6 + (event.y - 96 > 9 ? 1 : 0); else win->field = 7;
  645. } else
  646. if(event.y > 140 && event.y < 158) {
  647. if(event.w & (1 << 3)) ctrl_setox(idx, 1); else
  648. if(event.w & (1 << 4)) ctrl_setox(idx,-1); else
  649. if(event.x >= x + 58) selfield = 8 + (event.y - 140 > 9 ? 1 : 0); else win->field = 8;
  650. } else
  651. if(event.y > 162 && event.y < 180) {
  652. if(event.w & (1 << 3)) ctrl_setax(idx, 1); else
  653. if(event.w & (1 << 4)) ctrl_setax(idx,-1); else
  654. if(event.x >= x + 58) selfield = 10 + (event.y - 162 > 9 ? 1 : 0); else win->field = 9;
  655. } else
  656. if(event.y > 184 && event.y < 204) {
  657. if(event.w & (1 << 3)) ctrl_setay(idx, 1); else
  658. if(event.w & (1 << 4)) ctrl_setay(idx,-1); else
  659. if(event.x >= x + 58) selfield = 12 + (event.y - 184 > 9 ? 1 : 0); else win->field = 10;
  660. } else
  661. if(event.y > 206 && event.y < 228) {
  662. if(event.x > x && event.x < x + 24) selfield = 14; else
  663. if(event.x > x + 24 && event.x < x + 48) selfield = 15; else
  664. if(event.x > x + 48 && event.x < x + 72) selfield = 16;
  665. } else
  666. if(event.y > 250 && event.y < 272 && event.x > x + 24 && event.x < x + 48) selfield = 17; else
  667. if(event.y > 274 && event.y < 296) {
  668. if(event.x > x && event.x < x + 24) selfield = 18; else
  669. if(event.x > x + 48 && event.x < x + 72) selfield = 19;
  670. } else
  671. if(event.y > 298 && event.y < 340 && event.x > x + 24 && event.x < x + 48) selfield = 20; else
  672. if(event.y > 342 && event.y < 364) {
  673. if(event.x > x && event.x < x + 24) selfield = 21; else
  674. if(event.x > x + 24 && event.x < x + 48) selfield = 22; else
  675. if(event.x > x + 48 && event.x < x + 72) selfield = 23;
  676. } else
  677. if(event.y > 366 && event.y < 388) {
  678. if(event.x > x && event.x < x + 24) selfield = 24; else
  679. if(event.x > x + 24 && event.x < x + 48) selfield = 25; else
  680. if(event.x > x + 48 && event.x < x + 72) selfield = 26;
  681. }
  682. ui_resizewin(win, win->w, win->h);
  683. ui_refreshwin(event.win, 0, 0, win->w, win->h - 24);
  684. } else
  685. if(event.y < win->h - 22) {
  686. if(event.w & (1 << 3)) ctrl_zoom_in(event.win, event.x, event.y); else
  687. if(event.w & (1 << 4)) ctrl_zoom_out(event.win, event.x, event.y); else
  688. if(event.x >= ox + 20 && event.y >= oy + 36 &&
  689. event.x <= ox + 20 + win->zoom * ctx.glyphs[win->unicode].width &&
  690. event.y <= oy + 36 + win->zoom * ctx.glyphs[win->unicode].height) {
  691. mousex = event.x; mousey = event.y;
  692. }
  693. }
  694. }
  695. /**
  696. * On click (button release) handler
  697. */
  698. void ctrl_coords_onclick(int idx)
  699. {
  700. ui_win_t *win = &wins[idx];
  701. int x = win->w - 74;
  702. if(x < 0) x = 0;
  703. if(event.x > x) {
  704. if(event.y > 26 && event.y < 48 && event.x >= x + 58) {
  705. if(selfield == 0) ctrl_setsize(idx, 1, 0); else
  706. if(selfield == 1) ctrl_setsize(idx,-1, 0);
  707. } else
  708. if(event.y > 52 && event.y < 70 && event.x >= x + 58) {
  709. if(selfield == 2) ctrl_setsize(idx, 0, 1); else
  710. if(selfield == 3) ctrl_setsize(idx, 0,-1);
  711. } else
  712. if(event.y > 74 && event.y < 92 && event.x >= x + 58) {
  713. if(selfield == 4) ctrl_setbase(idx, 1); else
  714. if(selfield == 5) ctrl_setbase(idx,-1);
  715. } else
  716. if(event.y > 96 && event.y < 114 && event.x >= x + 58) {
  717. if(selfield == 6) ctrl_setunder(idx, 1); else
  718. if(selfield == 7) ctrl_setunder(idx,-1);
  719. } else
  720. if(event.y > 140 && event.y < 158 && event.x >= x + 58) {
  721. if(selfield == 8) ctrl_setox(idx, 1); else
  722. if(selfield == 9) ctrl_setox(idx,-1);
  723. } else
  724. if(event.y > 162 && event.y < 180 && event.x >= x + 58) {
  725. if(selfield == 10) ctrl_setax(idx, 1); else
  726. if(selfield == 11) ctrl_setax(idx,-1);
  727. } else
  728. if(event.y > 184 && event.y < 204 && event.x >= x + 58) {
  729. if(selfield == 12) ctrl_setay(idx, 1); else
  730. if(selfield == 13) ctrl_setay(idx,-1);
  731. } else
  732. if(event.y > 206 && event.y < 228) {
  733. if(event.x > x && event.x < x + 24 && selfield == 14) ctrl_setadv(idx, 0); else
  734. if(event.x > x + 24 && event.x < x + 48 && selfield == 15) ctrl_setadv(idx, 1); else
  735. if(event.x > x + 48 && event.x < x + 72 && selfield == 16) ctrl_setadv(idx, 2);
  736. } else
  737. if(event.y > 250 && event.y < 272 && event.x > x + 24 && event.x < x + 48 && selfield == 17) ctrl_pos(idx,-1, 0, -1); else
  738. if(event.y > 274 && event.y < 296) {
  739. if(event.x > x && event.x < x + 24 && selfield == 18) ctrl_pos(idx,-1, -1, 0); else
  740. if(event.x > x + 48 && event.x < x + 72 && selfield == 19) ctrl_pos(idx,-1, 1, 0);
  741. } else
  742. if(event.y > 298 && event.y < 340 && event.x > x + 24 && event.x < x + 48 && selfield == 20) ctrl_pos(idx,-1, 0, 1); else
  743. if(event.y > 342 && event.y < 364) {
  744. if(event.x > x && event.x < x + 24 && selfield == 21) ctrl_italize(idx); else
  745. if(event.x > x + 24 && event.x < x + 48 && selfield == 22) ctrl_fliph(idx, -1); else
  746. if(event.x > x + 48 && event.x < x + 72 && selfield == 23) { sfn_sanitize(win->unicode); win->rc = 1; modified++; }
  747. } else
  748. if(event.y > 366 && event.y < 388) {
  749. if(event.x > x && event.x < x + 24 && selfield == 24) ctrl_deitalize(idx); else
  750. if(event.x > x + 24 && event.x < x + 48 && selfield == 25) ctrl_flipv(idx, -1); else
  751. if(event.x > x + 48 && event.x < x + 72 && selfield == 26) { sfn_chardel(win->unicode); win->rc = 1; modified++; }
  752. }
  753. }
  754. cursor = CURSOR_PTR;
  755. selfield = mousex = mousey = -1;
  756. }
  757. /**
  758. * On mouse move handler
  759. */
  760. void ctrl_coords_onmove(int idx)
  761. {
  762. ui_win_t *win = &wins[idx];
  763. int x = win->w - 74, ox = win->zx > 0 ? win->zx : 0, oy = win->zy > 0 ? win->zy : 0;
  764. if(x < 0) x = 0;
  765. posx = posy = -1;
  766. if(event.x > x) {
  767. if(event.y > 26 && event.y < 48) status = lang[COORDS_WIDTH]; else
  768. if(event.y > 52 && event.y < 70) status = lang[COORDS_HEIGHT]; else
  769. if(event.y > 74 && event.y < 92) status = lang[COORDS_BASELINE]; else
  770. if(event.y > 96 && event.y < 114) status = lang[COORDS_UNDERLINE]; else
  771. if(event.y > 140 && event.y < 158) status = lang[COORDS_OVERLAP]; else
  772. if(event.y > 162 && event.y < 180) status = lang[COORDS_HADV]; else
  773. if(event.y > 184 && event.y < 204) status = lang[COORDS_VADV]; else
  774. if(event.y > 206 && event.y < 228) {
  775. if(event.x > x && event.x < x + 24) status = lang[COORDS_RTL]; else
  776. if(event.x > x + 24 && event.x < x + 48) status = lang[COORDS_UTD]; else
  777. if(event.x > x + 48 && event.x < x + 72) status = lang[COORDS_LTR];
  778. } else
  779. if(event.y > 250 && event.y < 320) status = lang[COORDS_REPOS]; else
  780. if(event.y > 342 && event.y < 364) {
  781. if(event.x > x && event.x < x + 24) status = lang[COORDS_ITALIC]; else
  782. if(event.x > x + 24 && event.x < x + 48) status = lang[COORDS_HFLIP]; else
  783. if(event.x > x + 48 && event.x < x + 72) status = lang[COORDS_RECALC];
  784. } else
  785. if(event.y > 366 && event.y < 388) {
  786. if(event.x > x && event.x < x + 24) status = lang[COORDS_UNITALIC]; else
  787. if(event.x > x + 24 && event.x < x + 48) status = lang[COORDS_VFLIP]; else
  788. if(event.x > x + 48 && event.x < x + 72) status = lang[COORDS_DELETE];
  789. }
  790. } else
  791. if(event.x >= ox + 20 && event.y >= oy + 36 &&
  792. event.x <= ox + 20 + win->zoom * ctx.glyphs[win->unicode].width &&
  793. event.y <= oy + 36 + win->zoom * ctx.glyphs[win->unicode].height && event.y < win->h - 22) {
  794. posx = (event.x - ox - 20 - (win->zx < 0 ? win->zx : 0)) / win->zoom;
  795. if(posx >= ctx.glyphs[win->unicode].width) posx = -1;
  796. posy = (event.y - oy - 36 - (win->zy < 0 ? win->zy : 0)) / win->zoom;
  797. if(posy >= ctx.glyphs[win->unicode].height) posy = -1;
  798. if(mousex != -1 && mousey != -1) ctrl_move(event.win, event.x, event.y);
  799. }
  800. }