]> git.donarmstrong.com Git - xournal.git/blob - src/xournal.h
0b94190f73ca5f3adc38ff1c5961938703d3518f
[xournal.git] / src / xournal.h
1 #include <gtk/gtk.h>
2 #include <libgnomecanvas/libgnomecanvas.h>
3
4 // DATA STRUCTURES AND CONSTANTS
5
6 #define PIXEL_MOTION_THRESHOLD 0.3
7 #define MAX_AXES 12
8 #define EPSILON 1E-7
9 #define MAX_ZOOM 20
10 #define DEFAULT_ZOOM 1.3333333333
11 #define MIN_ZOOM 0.2
12
13 /* a string (+ aux data) that maintains a refcount */
14
15 typedef struct Refstring {
16   int nref;
17   char *s;
18   gpointer aux;
19 } Refstring;
20
21
22 /* The journal is mostly a list of pages. Each page is a list of layers,
23    and a background. Each layer is a list of items, from bottom to top.
24 */
25
26 typedef struct Background {
27   int type;
28   GnomeCanvasItem *canvas_item;
29   int color_no;
30   guint color_rgba;
31   int ruling;
32   GdkPixbuf *pixbuf;
33   Refstring *filename;
34   int file_domain;
35   int file_page_seq;
36   int pixbuf_dpi;      // for PDF only - the *current* dpi value
37   double pixbuf_scale; // for PIXMAP, this is the *current* zoom value
38                        // for PDF, this is the *requested* zoom value
39 } Background;
40
41 #define BG_SOLID 0
42 #define BG_PIXMAP 1
43 #define BG_PDF 2      // not implemented yet
44
45 #define RULING_NONE 0
46 #define RULING_LINED 1
47 #define RULING_RULED 2
48 #define RULING_GRAPH 3
49
50 #define DOMAIN_ABSOLUTE 0
51 #define DOMAIN_ATTACH 1
52 #define DOMAIN_CLONE 2  // only while loading file
53
54 typedef struct Brush {
55   int tool_type;
56   int color_no;
57   guint color_rgba;
58   int thickness_no;
59   double thickness;
60   int tool_options;
61 } Brush;
62
63 #define COLOR_BLACK      0
64 #define COLOR_BLUE       1
65 #define COLOR_RED        2
66 #define COLOR_GREEN      3
67 #define COLOR_GRAY       4
68 #define COLOR_LIGHTBLUE  5
69 #define COLOR_LIGHTGREEN 6
70 #define COLOR_MAGENTA    7
71 #define COLOR_ORANGE     8
72 #define COLOR_YELLOW     9
73 #define COLOR_WHITE     10
74 #define COLOR_OTHER     -1
75 #define COLOR_MAX       11
76
77 extern guint predef_colors_rgba[COLOR_MAX];
78 extern guint predef_bgcolors_rgba[COLOR_MAX];
79
80 #define THICKNESS_VERYFINE  0
81 #define THICKNESS_FINE      1
82 #define THICKNESS_MEDIUM    2
83 #define THICKNESS_THICK     3
84 #define THICKNESS_VERYTHICK 4
85 #define THICKNESS_MAX       5
86
87 #define TOOL_PEN          0
88 #define TOOL_ERASER       1
89 #define TOOL_HIGHLIGHTER  2
90 #define TOOL_TEXT         3
91 #define TOOL_SELECTREGION 4
92 #define TOOL_SELECTRECT   5
93 #define TOOL_VERTSPACE    6
94 #define NUM_STROKE_TOOLS  3
95
96 #define TOOLOPT_ERASER_STANDARD     0
97 #define TOOLOPT_ERASER_WHITEOUT     1
98 #define TOOLOPT_ERASER_STROKES      2
99
100 #define HILITER_ALPHA_MASK 0xffffff80
101
102 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
103
104 typedef struct BBox {
105   double left, right, top, bottom;
106 } BBox;
107
108 struct UndoErasureData;
109
110 typedef struct Item {
111   int type;
112   struct Brush brush; // the brush to use, if ITEM_STROKE
113   GnomeCanvasPoints *path;
114   GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
115   struct BBox bbox;
116   struct UndoErasureData *erasure; // for temporary use during erasures
117 } Item;
118
119 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
120 // (not all are valid in all places)
121 #define ITEM_NONE -1
122 #define ITEM_STROKE 0
123 #define ITEM_TEMP_STROKE 1
124 #define ITEM_ERASURE 2
125 #define ITEM_SELECTRECT 3
126 #define ITEM_MOVESEL 4
127 #define ITEM_PASTE 5
128 #define ITEM_NEW_LAYER 6
129 #define ITEM_DELETE_LAYER 7
130 #define ITEM_NEW_BG_ONE 8
131 #define ITEM_NEW_BG_RESIZE 9
132 #define ITEM_PAPER_RESIZE 10
133 #define ITEM_NEW_DEFAULT_BG 11
134 #define ITEM_NEW_PAGE 13
135 #define ITEM_DELETE_PAGE 14
136
137 typedef struct Layer {
138   GList *items; // the items on the layer, from bottom to top
139   int nitems;
140   GnomeCanvasGroup *group;
141 } Layer;
142
143 typedef struct Page {
144   GList *layers; // the layers on the page
145   int nlayers;
146   double height, width;
147   double hoffset, voffset; // offsets of canvas group rel. to canvas root
148   struct Background *bg;
149   GnomeCanvasGroup *group;
150 } Page;
151
152 typedef struct Journal {
153   GList *pages;  // the pages in the journal
154   int npages;
155   int last_attach_no; // for naming of attached backgrounds
156 } Journal;
157
158 typedef struct Selection {
159   int type;
160   BBox bbox; // the rectangle bbox of the selection
161   struct Layer *layer; // the layer on which the selection lives
162   double anchor_x, anchor_y, last_x, last_y; // for selection motion
163   GnomeCanvasItem *canvas_item; // if the selection box is on screen 
164   GList *items; // the selected items (a list of struct Item)
165 } Selection;
166
167 typedef struct UIData {
168   int pageno, layerno; // the current page and layer
169   struct Page *cur_page;
170   struct Layer *cur_layer;
171   int toolno;  // the number of the currently selected tool
172   gboolean saved; // is file saved ?
173   struct Brush *cur_brush;  // the brush in use (one of brushes[...])
174   struct Brush brushes[NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
175   struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
176   gboolean ruler; // whether we're in ruler mode
177   struct Page default_page;  // the model for the default page
178   int layerbox_length;  // the number of entries registered in the layers combo-box
179   struct Item *cur_item; // the item being drawn, or NULL
180   int cur_item_type;
181   GnomeCanvasPoints cur_path; // the path being drawn
182   int cur_path_storage_alloc;
183   int which_mouse_button; // the mouse button drawing the current path
184   int saved_toolno;  // while using an eraser device
185   gboolean saved_ruler;
186   double zoom; // zoom factor, in pixels per pt
187   gboolean use_xinput; // use input devices instead of core pointer
188   gboolean allow_xinput; // allow use of xinput ?
189   int screen_width, screen_height; // initial screen size, for XInput events
190   char *filename;
191   gboolean view_continuous, fullscreen;
192   gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
193   struct Selection *selection;
194   GdkCursor *cursor;
195   gboolean emulate_eraser;
196   gboolean antialias_bg; // bilinear interpolation on bg pixmaps
197   gboolean progressive_bg; // rescale bg's one at a time
198 } UIData;
199
200 typedef struct UndoErasureData {
201   struct Item *item; // the item that got erased
202   int npos; // its position in its layer
203   int nrepl; // the number of replacement items
204   GList *replacement_items;
205 } UndoErasureData;
206
207 typedef struct UndoItem {
208   int type;
209   struct Item *item; // for ITEM_STROKE
210   struct Layer *layer; // for ITEM_STROKE, ITEM_ERASURE, ITEM_PASTE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER
211   struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1
212   struct Page *page;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
213   GList *erasurelist; // for ITEM_ERASURE
214   GList *itemlist;  // for ITEM_MOVESEL, ITEM_PASTE
215   struct Background *bg;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
216   int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
217   double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG
218   struct UndoItem *next;
219   int multiop;
220 } UndoItem;
221
222 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
223 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
224
225
226 typedef struct BgPdfRequest {
227   int pageno;
228   int dpi;
229   gboolean initial_request; // if so, loop over page numbers
230   gboolean is_printing;     // this is for printing, not for display
231 } BgPdfRequest;
232
233 typedef struct BgPdfPage {
234   int dpi;
235   GdkPixbuf *pixbuf;
236 } BgPdfPage;
237
238 typedef struct BgPdf {
239   int status; // the rest only makes sense if this is not STATUS_NOT_INIT
240   int pid; // PID of the converter process
241   Refstring *filename;
242   int file_domain;
243   gchar *tmpfile_copy; // the temporary work copy of the file (in tmpdir)
244   int npages;
245   GList *pages; // a list of BgPdfPage structures
246   GList *requests; // a list of BgPdfRequest structures
247   gchar *tmpdir; // where to look for pages coming from pdf converter
248   gboolean create_pages; // create journal pages as we find stuff in PDF
249   gboolean has_failed; // has failed in the past...
250 } BgPdf;
251
252 #define STATUS_NOT_INIT 0
253 #define STATUS_IDLE     1
254 #define STATUS_RUNNING  2  // currently running child process on head(requests)
255 #define STATUS_ABORTED  3  // child process running, but head(requests) aborted
256 #define STATUS_SHUTDOWN 4  // waiting for child process to shut down
257
258 // UTILITY MACROS
259
260 // getting a component of the interface by name
261 #define GET_COMPONENT(a)  GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
262
263 // the margin between consecutive pages in continuous view
264 #define VIEW_CONTINUOUS_SKIP 20.0
265
266
267 // GLOBAL VARIABLES
268
269 // the main window and the canvas
270
271 extern GtkWidget *winMain;
272 extern GnomeCanvas *canvas;
273
274 // the data
275
276 extern struct Journal journal;
277 extern struct UIData ui;
278 extern struct BgPdf bgpdf;
279 extern struct UndoItem *undo, *redo;