ui.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * sfnedit/ui.h
  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 Common user interface definitions and prototypes
  27. *
  28. */
  29. #include <stdint.h>
  30. #include "hist.h"
  31. /*** used by UI drivers too ***/
  32. enum {
  33. CURSOR_LOADING, /* cursor to indicate that sfnedit is working */
  34. CURSOR_PTR, /* the default normal cursor pointer */
  35. CURSOR_CROSS, /* a cross-hair, used when selecting pixels and contour points */
  36. CURSOR_MOVE, /* used when user drags the layers and moves it around */
  37. CURSOR_GRAB /* used for links and the color picker */
  38. };
  39. #define E_NONE 0 /* no event */
  40. #define E_CLOSE 1 /* window close button clicked */
  41. #define E_RESIZE 2 /* window is resized */
  42. #define E_REFRESH 3 /* window has to be updated (expose) */
  43. #define E_KEY 4 /* key press event */
  44. #define E_MOUSEMOVE 5 /* mouse pointer is moving */
  45. #define E_BTNPRESS 6 /* mouse button is pressed */
  46. #define E_BTNRELEASE 7 /* mouse button is released */
  47. #define K_DOWN 1 /* cursor down arrow */
  48. #define K_UP 2 /* cursor up arrow */
  49. #define K_LEFT 3 /* cursor left arrow */
  50. #define K_RIGHT 4 /* cursor right arrow */
  51. #define K_PGDN 5 /* page down key */
  52. #define K_PGUP 6 /* page up key */
  53. #define K_DEL 7 /* delete key */
  54. #define K_BACKSPC 8 /* backspace key */
  55. #define K_TAB 9 /* tab key */
  56. #define K_HOME 11 /* home key */
  57. #define K_END 12 /* end key */
  58. #define K_ENTER 13 /* enter or return key */
  59. #define K_F1 14 /* function one (help) key */
  60. #define K_ESC 27 /* escape key */
  61. typedef struct {
  62. int win; /* internal numerical window id where the event happened. 0 is the main window */
  63. int type; /* one of E_x defines */
  64. long x; /* for key press, K_x define or UTF-8 character sequence */
  65. int y;
  66. int w; /* for button events, bit 0: left button, 1: middle, 2: right, 3: wheel up, 4: wheel down */
  67. int h; /* for key and button events, bit 0: shift, 1: ctrl, 2: alt/meta */
  68. } ui_event_t;
  69. typedef struct {
  70. /* available for drivers */
  71. void *winid; /* transparent, driver specific window id */
  72. void *surface; /* available to driver (SDL_Surface or XImage for example) */
  73. uint32_t *data; /* backstore pixel buffer */
  74. int w, h, p; /* window width, height, pitch (number of bytes in a line) */
  75. /* don't care, internal window state */
  76. uint32_t unicode;
  77. char *uniname;
  78. int field, tool, help;
  79. int zoom, zx, zy, rc;
  80. int histmin, histmax;
  81. hist_t *hist;
  82. } ui_win_t;
  83. /* driver specific, these are the functions that must be implemented in every UI driver, see ui_dummy.c */
  84. void ui_copy(char *s);
  85. void *ui_createwin(int w, int h);
  86. void ui_titlewin(ui_win_t *win, char *title);
  87. void ui_resizewin(ui_win_t *win, int w, int h);
  88. void ui_flushwin(ui_win_t *win, int x, int y, int w, int h);
  89. void ui_destroywin(ui_win_t *win);
  90. void ui_focuswin(ui_win_t *win);
  91. void ui_cursorwin(ui_win_t *win, int cursor);
  92. void ui_init();
  93. void ui_fini();
  94. void ui_getevent();
  95. /*** common definitions and prototypes for ui ***/
  96. #ifdef __WIN32__
  97. # define DIRSEP '\\'
  98. # define DIRSEPS "\\"
  99. #else
  100. # define DIRSEP '/'
  101. # define DIRSEPS "/"
  102. #endif
  103. #define MAIN_W 800
  104. #define MAIN_H 600
  105. #define WINTYPE_MAIN -1U
  106. enum {
  107. THEME_BG,
  108. THEME_FG,
  109. THEME_LIGHT,
  110. THEME_DARK,
  111. THEME_LIGHTER,
  112. THEME_DARKER,
  113. THEME_INPBG,
  114. THEME_BTNB,
  115. THEME_BTN0L,
  116. THEME_BTN0BL,
  117. THEME_BTN0BD,
  118. THEME_BTN0D,
  119. THEME_BTN1L,
  120. THEME_BTN1BL,
  121. THEME_BTN1BD,
  122. THEME_BTN1D,
  123. THEME_SELBG,
  124. THEME_SELFG,
  125. THEME_CURSOR,
  126. THEME_UNDEF,
  127. THEME_AXIS,
  128. THEME_GRID,
  129. THEME_DIM,
  130. THEME_BASE,
  131. THEME_UNDER,
  132. THEME_OVL,
  133. THEME_ADV,
  134. THEME_HINT,
  135. THEME_POINT,
  136. THEME_CPOINT,
  137. THEME_CURVE,
  138. THEME_GUIDE,
  139. THEME_LAST
  140. };
  141. enum {
  142. ICON_ABOUT,
  143. ICON_LOAD,
  144. ICON_SAVE,
  145. ICON_PROPS,
  146. ICON_RANGES,
  147. ICON_GLYPHS,
  148. ICON_TEST,
  149. ICON_MEASURES,
  150. ICON_LAYERS,
  151. ICON_KERNING,
  152. ICON_FOLDER,
  153. ICON_FILE,
  154. ICON_SEARCH,
  155. ICON_ZOOMOUT,
  156. ICON_ZOOMIN,
  157. ICON_CUT,
  158. ICON_COPY,
  159. ICON_PASTE,
  160. ICON_DELETE,
  161. ICON_UARR,
  162. ICON_LARR,
  163. ICON_RARR,
  164. ICON_DARR,
  165. ICON_RHORIZ,
  166. ICON_VERT,
  167. ICON_HORIZ,
  168. ICON_SHEAR,
  169. ICON_UNSHEAR,
  170. ICON_BOLDER,
  171. ICON_UNBOLD,
  172. ICON_HFLIP,
  173. ICON_VFLIP,
  174. ICON_VECTOR,
  175. ICON_BITMAP,
  176. ICON_PIXMAP,
  177. ICON_PICKER
  178. };
  179. enum {
  180. MAIN_TOOL_ABOUT,
  181. MAIN_TOOL_LOAD,
  182. MAIN_TOOL_SAVE,
  183. MAIN_TOOL_PROPS,
  184. MAIN_TOOL_RANGES,
  185. MAIN_TOOL_GLYPHS,
  186. MAIN_TOOL_TEST,
  187. MAIN_TOOL_DOSAVE,
  188. MAIN_TOOL_NEW
  189. };
  190. enum {
  191. GLYPH_TOOL_COORD,
  192. GLYPH_TOOL_LAYER,
  193. GLYPH_TOOL_KERN,
  194. GLYPH_TOOL_COLOR
  195. };
  196. extern char verstr[], ws[], *status, *errstatus;
  197. extern uint32_t theme[];
  198. extern int numwin, cursor, zip, ascii, selfield, rs, re, modified, posx, posy, scrolly;
  199. extern ui_win_t *wins;
  200. extern ui_event_t event;
  201. extern uint8_t *icon16, *icon64, *tools, *bga;
  202. extern int input_maxlen, input_refresh;
  203. extern char *input_str;
  204. /* copy'n'paste functions */
  205. void copypaste_start(int minunicode);
  206. void copypaste_copy(int fromunicode, int layer);
  207. void copypaste_paste(int tounicode, int oneunicode);
  208. void copypaste_fini();
  209. /* history functions */
  210. void hist_free(ui_win_t *win);
  211. /* ui widgets */
  212. void ui_toolbox(int idx);
  213. void ui_rect(ui_win_t *win, int x, int y, int w, int h, uint32_t l, uint32_t d);
  214. void ui_box(ui_win_t *win, int x, int y, int w, int h, uint32_t l, uint32_t b, uint32_t d);
  215. void ui_grid(ui_win_t *win, int w, int h);
  216. void ui_gridbg(ui_win_t *win, int x, int y, int w, int h, int a, uint32_t *d, int gx, int gy);
  217. void ui_icon(ui_win_t *win, int x, int y, int icon, int inactive);
  218. int ui_textwidth(char *str);
  219. void ui_text(ui_win_t *win, int x, int y, char *str);
  220. char *ui_input(ui_win_t *win, int x, int y, int w, char *str, int active, int maxlen, int callback);
  221. void ui_button(ui_win_t *win, int x, int y, int w, char *str, int pressed, int active);
  222. void ui_bool(ui_win_t *win, int x, int y, char *s, int state, int active);
  223. void ui_tri(ui_win_t *win, int x, int y, int up);
  224. void ui_num(ui_win_t *win, int x, int y, int num, int active, int sel);
  225. void ui_number(ui_win_t *win, int x, int y, int n, uint32_t c);
  226. void ui_hex(ui_win_t *win, char c);
  227. void ui_argb(ui_win_t *win, int x, int y, int w, int h, uint32_t c);
  228. void ui_glyph(ui_win_t *win, int x, int y, int size, uint32_t unicode, int layer, int wa);
  229. int ui_render(ui_win_t *win, int *x, int *y, int size, char *str);
  230. void ui_edit(ui_win_t *win, int x, int y, uint32_t unicode, int layer);
  231. void ui_hscrbar(ui_win_t *win, int x, int y, int w, int h, int scroll, int page, int num, int pressed);
  232. /* common */
  233. void ui_gettheme(char *fn);
  234. int ui_casecmp(char *a, char *b, int l);
  235. void ui_error(char *subsystem, int fmt, ...);
  236. void ui_openwin(uint32_t unicode);
  237. void ui_updatetitle(int idx);
  238. void ui_closewin(int idx);
  239. int ui_getwin(void *wid);
  240. void ui_pb(int step, int numstep, int curr, int total, int msg);
  241. void ui_chrinfo(int unicode);
  242. void ui_refreshwin(int idx, int wx, int wy, int ww, int wh);
  243. void ui_refreshall();
  244. void ui_main(char *fn);
  245. void ui_quit(int sig);
  246. void ui_inputfinish();
  247. /* views */
  248. void view_help();
  249. void view_about();
  250. void view_fileops(int save);
  251. void view_dosave();
  252. void view_new();
  253. void view_props();
  254. void view_ranges();
  255. void view_glyphs();
  256. void view_test();
  257. void view_coords(int idx);
  258. void view_layers(int idx);
  259. void view_kern(int idx);
  260. void view_color(int idx);
  261. /* controllers */
  262. void ctrl_about_onmove();
  263. void ctrl_about_onclick();
  264. void ctrl_about_onenter();
  265. void ctrl_fileops_onenter(int save);
  266. void ctrl_fileops_onkey();
  267. void ctrl_fileops_onbtnpress(int save);
  268. void ctrl_fileops_onclick(int save);
  269. void ctrl_fileops_onmove();
  270. void ctrl_dosave_onenter();
  271. void ctrl_dosave_onbtnpress();
  272. void ctrl_dosave_onclick();
  273. void ctrl_new_onenter();
  274. void ctrl_new_onkey();
  275. void ctrl_new_onbtnpress();
  276. void ctrl_new_onclick();
  277. void ctrl_props_onenter();
  278. void ctrl_props_onkey();
  279. void ctrl_props_onbtnpress();
  280. void ctrl_props_onclick();
  281. void ctrl_ranges_onenter();
  282. void ctrl_ranges_onkey();
  283. void ctrl_ranges_onbtnpress();
  284. void ctrl_ranges_onmove();
  285. void ctrl_glyphs_onenter();
  286. void ctrl_glyphs_onkey();
  287. void ctrl_glyphs_onbtnpress();
  288. void ctrl_glyphs_onclick();
  289. void ctrl_glyphs_onmove();
  290. void ctrl_test_onenter();
  291. void ctrl_test_onkey();
  292. void ctrl_test_onbtnpress();
  293. void ctrl_test_onclick();
  294. void ctrl_coords_onenter(int idx);
  295. void ctrl_coords_onkey(int idx);
  296. void ctrl_coords_onbtnpress(int idx);
  297. void ctrl_coords_onclick(int idx);
  298. void ctrl_coords_onmove(int idx);
  299. void ctrl_layers_onenter(int idx);
  300. void ctrl_layers_onkey(int idx);
  301. void ctrl_layers_onbtnpress(int idx);
  302. void ctrl_layers_onclick(int idx);
  303. void ctrl_layers_onmove(int idx);
  304. void ctrl_kern_onenter(int idx);
  305. void ctrl_kern_onkey(int idx);
  306. void ctrl_kern_onbtnpress(int idx);
  307. void ctrl_kern_onclick(int idx);
  308. void ctrl_kern_onmove(int idx);
  309. void ctrl_colors_onenter(int idx);
  310. void ctrl_colors_onbtnpress(int idx);
  311. void ctrl_colors_onclick(int idx);
  312. void ctrl_colors_onmove(int idx);