gl-app.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // Copyright (C) 2004-2022 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #ifndef MUPDF_GL_APP_H
  23. #define MUPDF_GL_APP_H
  24. #ifdef _WIN32
  25. #include <windows.h>
  26. void win_install(void);
  27. #endif
  28. #include "mupdf/fitz.h"
  29. #include "mupdf/ucdn.h"
  30. #include "mupdf/pdf.h" /* for pdf specifics and forms */
  31. #ifndef __APPLE__
  32. #include <GL/freeglut.h>
  33. #else
  34. #include <GLUT/glut.h>
  35. #endif
  36. /* UI */
  37. enum
  38. {
  39. /* regular control characters */
  40. KEY_ESCAPE = 27,
  41. KEY_ENTER = '\r',
  42. KEY_TAB = '\t',
  43. KEY_BACKSPACE = '\b',
  44. KEY_DELETE = 127,
  45. KEY_CTL_A = 'A' - 64,
  46. KEY_CTL_B, KEY_CTL_C, KEY_CTL_D, KEY_CTL_E, KEY_CTL_F,
  47. KEY_CTL_G, KEY_CTL_H, KEY_CTL_I, KEY_CTL_J, KEY_CTL_K, KEY_CTL_L,
  48. KEY_CTL_M, KEY_CTL_N, KEY_CTL_O, KEY_CTL_P, KEY_CTL_Q, KEY_CTL_R,
  49. KEY_CTL_S, KEY_CTL_T, KEY_CTL_U, KEY_CTL_V, KEY_CTL_W, KEY_CTL_X,
  50. KEY_CTL_Y, KEY_CTL_Z,
  51. /* reuse control characters > 127 for special keys */
  52. KEY_INSERT = 128,
  53. KEY_PAGE_UP,
  54. KEY_PAGE_DOWN,
  55. KEY_HOME,
  56. KEY_END,
  57. KEY_LEFT,
  58. KEY_UP,
  59. KEY_RIGHT,
  60. KEY_DOWN,
  61. KEY_F1,
  62. KEY_F2,
  63. KEY_F3,
  64. KEY_F4,
  65. KEY_F5,
  66. KEY_F6,
  67. KEY_F7,
  68. KEY_F8,
  69. KEY_F9,
  70. KEY_F10,
  71. KEY_F11,
  72. KEY_F12,
  73. };
  74. enum side { ALL, T, R, B, L };
  75. enum fill { NONE = 0, X = 1, Y = 2, BOTH = 3 };
  76. enum anchor { CENTER, N, NE, E, SE, S, SW, W, NW };
  77. struct layout
  78. {
  79. enum side side;
  80. enum fill fill;
  81. enum anchor anchor;
  82. int padx, pady;
  83. };
  84. struct ui
  85. {
  86. int window_w, window_h;
  87. int x, y;
  88. int down, down_x, down_y;
  89. int middle, middle_x, middle_y;
  90. int right, right_x, right_y;
  91. int scroll_x, scroll_y;
  92. int key, mod, plain;
  93. int grab_down, grab_middle, grab_right;
  94. const void *hot, *active, *focus;
  95. int last_cursor, cursor;
  96. float scale;
  97. int fontsize;
  98. int baseline;
  99. int lineheight;
  100. int gridsize;
  101. int padsize;
  102. struct layout *layout;
  103. fz_irect *cavity;
  104. struct layout layout_stack[32];
  105. fz_irect cavity_stack[32];
  106. int overlay;
  107. GLuint overlay_list;
  108. void (*dialog)(void);
  109. pdf_annot *selected_annot;
  110. };
  111. extern struct ui ui;
  112. void ui_init_dpi(float override_ui_scale);
  113. void ui_init(int w, int h, const char *title);
  114. void ui_quit(void);
  115. void ui_invalidate(void);
  116. void ui_finish(void);
  117. void ui_set_clipboard(const char *buf);
  118. const char *ui_get_clipboard(void);
  119. void ui_init_fonts(void);
  120. void ui_finish_fonts(void);
  121. void ui_draw_string(float x, float y, const char *str);
  122. void ui_draw_string_part(float x, float y, const char *s, const char *e);
  123. void ui_draw_character(float x, float y, int c);
  124. float ui_measure_character(int ucs);
  125. float ui_measure_string(const char *str);
  126. float ui_measure_string_part(const char *s, const char *e);
  127. struct line { char *a, *b; };
  128. int ui_break_lines(char *a, struct line *lines, int nlines, int width, int *maxwidth);
  129. void ui_draw_lines(float x, float y, struct line *lines, int n);
  130. struct texture
  131. {
  132. GLuint id;
  133. int x, y, w, h;
  134. float s, t;
  135. };
  136. void ui_texture_from_pixmap(struct texture *tex, fz_pixmap *pix);
  137. void ui_draw_image(struct texture *tex, float x, float y);
  138. enum
  139. {
  140. UI_INPUT_NONE = 0,
  141. UI_INPUT_EDIT = 1,
  142. UI_INPUT_ACCEPT = 2,
  143. };
  144. #define UI_INPUT_SIZE (16*1024)
  145. struct input
  146. {
  147. char text[UI_INPUT_SIZE];
  148. char *end, *p, *q;
  149. int scroll;
  150. pdf_annot *widget;
  151. };
  152. #define UI_READLINE_SIZE 20
  153. struct readline
  154. {
  155. struct input input;
  156. char buffer[UI_READLINE_SIZE][UI_INPUT_SIZE];
  157. char *history[UI_READLINE_SIZE];
  158. int used;
  159. int current;
  160. };
  161. struct list
  162. {
  163. fz_irect area;
  164. int scroll_y;
  165. int item_y;
  166. int is_tree;
  167. };
  168. void ui_begin(void);
  169. void ui_end(void);
  170. int ui_mouse_inside(fz_irect area);
  171. void ui_layout(enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
  172. fz_irect ui_pack_layout(int slave_w, int slave_h, enum side side, enum fill fill, enum anchor anchor, int padx, int pady);
  173. fz_irect ui_pack(int slave_w, int slave_h);
  174. int ui_available_width(void);
  175. int ui_available_height(void);
  176. void ui_pack_push(fz_irect cavity);
  177. void ui_pack_pop(void);
  178. void ui_dialog_begin(int w, int h);
  179. void ui_dialog_end(void);
  180. void ui_panel_begin(int w, int h, int padx, int pady, int opaque);
  181. void ui_panel_end(void);
  182. void ui_spacer(void);
  183. void ui_splitter(int *start, int *x, int min, int max, enum side side);
  184. void ui_label(const char *fmt, ...);
  185. void ui_label_with_scrollbar(char *text, int width, int height, int *scroll, int *sticky);
  186. int ui_button(const char *label);
  187. /* flags: bit 0 -> disabled. all other bits 0 for now. */
  188. int ui_button_aux(const char *label, int flags);
  189. int ui_checkbox(const char *label, int *value);
  190. int ui_checkbox_aux(const char *label, int *value, int flags);
  191. int ui_slider(int *value, int min, int max, int width);
  192. int ui_select(const void *id, const char *current, const char *options[], int n);
  193. int ui_select_aux(const void *id, const char *current, const char *options[], int n, int flags);
  194. void ui_input_init(struct input *input, const char *text);
  195. int ui_input(struct input *input, int width, int height);
  196. void ui_scrollbar(int x0, int y0, int x1, int y1, int *value, int page_size, int max, int *sticky);
  197. void ui_readline_init(struct readline *readline, const char *text);
  198. const char *ui_readline(struct readline *readline, int width);
  199. void ui_tree_begin(struct list *list, int count, int req_w, int req_h, int is_tree);
  200. int ui_tree_item(struct list *list, const void *id, const char *label, int selected, int depth, int is_branch, int *is_open);
  201. void ui_tree_end(struct list *list);
  202. void ui_list_begin(struct list *list, int count, int req_w, int req_h);
  203. int ui_list_item(struct list *list, const void *id, const char *label, int selected);
  204. void ui_list_end(struct list *list);
  205. int ui_popup(const void *id, const char *label, int is_button, int count);
  206. int ui_popup_item(const char *title);
  207. int ui_popup_aux(const void *id, const char *label, int is_button, int count, int flags);
  208. int ui_popup_item_aux(const char *title, int flags);
  209. void ui_popup_end(void);
  210. void ui_init_open_file(const char *dir, int (*filter)(const char *fn));
  211. int ui_open_file(char *filename, const char *label);
  212. void ui_init_save_file(const char *path, int (*filter)(const char *fn));
  213. int ui_save_file(char *filename, void (*extra_panel)(void), const char *label);
  214. void ui_show_warning_dialog(const char *fmt, ...);
  215. void ui_show_error_dialog(const char *fmt, ...);
  216. void ui_select_annot(pdf_annot *annot);
  217. /* Theming */
  218. enum
  219. {
  220. UI_COLOR_PANEL = 0xc0c0c0,
  221. UI_COLOR_BUTTON = 0xc0c0c0,
  222. UI_COLOR_SCROLLBAR = 0xdfdfdf,
  223. UI_COLOR_TEXT_BG = 0xffffff,
  224. UI_COLOR_TEXT_FG = 0x000000,
  225. UI_COLOR_TEXT_GRAY = 0x808080,
  226. UI_COLOR_TEXT_SEL_BG = 0x000080,
  227. UI_COLOR_TEXT_SEL_FG = 0xffffff,
  228. UI_COLOR_BEVEL_1 = 0x000000,
  229. UI_COLOR_BEVEL_2 = 0x808080,
  230. UI_COLOR_BEVEL_3 = 0xdfdfdf,
  231. UI_COLOR_BEVEL_4 = 0xffffff,
  232. };
  233. void glColorHex(unsigned int hex);
  234. void ui_draw_bevel(fz_irect area, int depressed);
  235. void ui_draw_ibevel(fz_irect area, int depressed);
  236. void ui_draw_bevel_rect(fz_irect area, unsigned int fill, int depressed);
  237. void ui_draw_ibevel_rect(fz_irect area, unsigned int fill, int depressed);
  238. /* App */
  239. extern fz_context *ctx;
  240. extern fz_colorspace *profile;
  241. extern pdf_document *pdf;
  242. extern pdf_page *page;
  243. extern fz_stext_page *page_text;
  244. extern fz_matrix draw_page_ctm, view_page_ctm, view_page_inv_ctm;
  245. extern fz_rect page_bounds, draw_page_bounds, view_page_bounds;
  246. extern fz_irect view_page_area;
  247. extern char filename[];
  248. extern int showform;
  249. extern int showannotate;
  250. extern int reloadrequested;
  251. extern char *search_needle;
  252. extern int search_hit_count;
  253. extern fz_quad search_hit_quads[];
  254. extern int page_contents_changed;
  255. extern int page_annots_changed;
  256. int search_has_results(void);
  257. enum {
  258. ANNOTATE_MODE_NONE = 0,
  259. ANNOTATE_MODE_NORMAL = 1,
  260. ANNOTATE_MODE_REDACT = 2
  261. };
  262. void toggle_annotate(int mode);
  263. void run_main_loop(void);
  264. void do_annotate_panel(void);
  265. void do_annotate_canvas(fz_irect canvas_area);
  266. void do_redact_panel(void);
  267. void do_widget_canvas(fz_irect canvas_area);
  268. void load_page(void);
  269. void update_title(void);
  270. void reload_document(void);
  271. void reload(void);
  272. void do_save_pdf_file(void);
  273. void do_save_signed_pdf_file(void);
  274. int do_sign(void);
  275. void trace_action(const char *fmt, ...);
  276. void trace_page_update(void);
  277. void trace_save_snapshot(void);
  278. const char *format_date(int64_t secs);
  279. #endif