1 /* This file is part of Ganv.
2  * Copyright 2007-2015 David Robillard <http://drobilla.net>
3  *
4  * Ganv is free software: you can redistribute it and/or modify it under the
5  * terms of the GNU General Public License as published by the Free Software
6  * Foundation, either version 3 of the License, or any later version.
7  *
8  * Ganv is distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with Ganv.  If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef GANV_PRIVATE_H
17 #define GANV_PRIVATE_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include "ganv/canvas.h"
24 #include "ganv/item.h"
25 #include "ganv/text.h"
26 #include "ganv/types.h"
27 
28 #include <cairo.h>
29 #include <gdk/gdk.h>
30 #include <glib.h>
31 #include <gtk/gtk.h>
32 #include <pango/pango-layout.h>
33 
34 #define GANV_CLOSE_ENOUGH 1
35 
36 extern guint signal_moved;
37 
38 /* Box */
39 
40 typedef struct {
41 	double   x1, y1, x2, y2;
42 	double   border_width;
43 	gboolean stacked;
44 } GanvBoxCoords;
45 
46 struct _GanvBoxPrivate {
47 	GanvBoxCoords coords;
48 	GanvBoxCoords old_coords;
49 	double        radius_tl;
50 	double        radius_tr;
51 	double        radius_br;
52 	double        radius_bl;
53 	gboolean      beveled;
54 };
55 
56 /* Circle */
57 
58 typedef struct {
59 	double x, y, radius, radius_ems;
60 	double width;
61 } GanvCircleCoords;
62 
63 struct _GanvCirclePrivate {
64 	GanvCircleCoords coords;
65 	GanvCircleCoords old_coords;
66 	gboolean         fit_label;
67 };
68 
69 /* Edge */
70 
71 typedef struct {
72 	double   x1, y1, x2, y2;
73 	double   cx1, cy1, cx2, cy2;
74 	double   handle_x, handle_y, handle_radius;
75 	double   width;
76 	gboolean constraining;
77 	gboolean curved;
78 	gboolean arrowhead;
79 } GanvEdgeCoords;
80 
81 struct _GanvEdgePrivate
82 {
83 	GanvNode*       tail;
84 	GanvNode*       head;
85 	GanvEdgeCoords  coords;
86 	GanvEdgeCoords  old_coords;
87 	double          dash_length;
88 	double          dash_offset;
89 	guint           color;
90 	gboolean        selected;
91 	gboolean        highlighted;
92 	gboolean        ghost;
93 };
94 
95 /* Module */
96 
97 struct _GanvModulePrivate
98 {
99 	GPtrArray* ports;
100 	GanvItem*  embed_item;
101 	int        embed_width;
102 	int        embed_height;
103 	double     widest_input;
104 	double     widest_output;
105 	gboolean   must_reorder;
106 };
107 
108 /* Node */
109 
110 #ifdef GANV_FDGL
111 typedef struct {
112 	double x;
113 	double y;
114 } Vector;
115 #endif
116 
117 struct _GanvNodePrivate {
118 	struct _GanvNode* partner;
119 	GanvText*         label;
120 	double            dash_length;
121 	double            dash_offset;
122 	double            border_width;
123 	guint             fill_color;
124 	guint             border_color;
125 	gboolean          can_tail;
126 	gboolean          can_head;
127 	gboolean          is_source;
128 	gboolean          selected;
129 	gboolean          highlighted;
130 	gboolean          draggable;
131 	gboolean          show_label;
132 	gboolean          grabbed;
133 	gboolean          must_resize;
134 #ifdef GANV_FDGL
135 	Vector            force;
136 	Vector            vel;
137 	gboolean          connected;
138 #endif
139 };
140 
141 /* Widget */
142 
143 struct _GanvWidgetPrivate {
144 	GtkWidget* widget;          /* The child widget */
145 
146 	double        x, y;			/* Position at anchor */
147 	double        width, height; /* Dimensions of widget */
148 	GtkAnchorType anchor;		/* Anchor side for widget */
149 
150 	int cx, cy;                 /* Top-left canvas coordinates for widget */
151 	int cwidth, cheight;		/* Size of widget in pixels */
152 
153 	guint destroy_id;           /* Signal connection id for destruction of child widget */
154 
155 	guint size_pixels : 1;		/* Is size specified in (unchanging) pixels or units (get scaled)? */
156 	guint in_destroy : 1;		/* Is child widget being destroyed? */
157 };
158 
159 /* Group */
160 struct _GanvGroupPrivate {
161 	GList* item_list;
162 	GList* item_list_end;
163 };
164 
165 /* Item */
166 struct _GanvItemPrivate {
167 	/* Parent canvas for this item */
168 	struct _GanvCanvas* canvas;
169 
170 	/* Parent for this item */
171 	GanvItem* parent;
172 
173 	/* Wrapper object for this item, if any */
174 	void* wrapper;
175 
176 	/* Layer (z order), higher values are on top */
177 	guint layer;
178 
179 	/* Position in parent-relative coordinates. */
180 	double x, y;
181 
182 	/* Bounding box for this item (in world coordinates) */
183 	double x1, y1, x2, y2;
184 
185 	/* True if parent manages this item (don't call add/remove) */
186 	gboolean managed;
187 };
188 
189 void
190 ganv_node_tick(GanvNode* self, double seconds);
191 
192 void
193 ganv_node_tail_vector(const GanvNode* self,
194                       const GanvNode* head,
195                       double*         x1,
196                       double*         y1,
197                       double*         x2,
198                       double*         y2);
199 
200 void
201 ganv_node_head_vector(const GanvNode* self,
202                       const GanvNode* tail,
203                       double*         x1,
204                       double*         y1,
205                       double*         x2,
206                       double*         y2);
207 
208 /**
209  * ganv_node_get_draw_properties:
210  *
211  * Get the colours that should currently be used for drawing this node.  Note
212  * these may not be identical to the property values because of highlighting
213  * and selection.
214  */
215 void
216 ganv_node_get_draw_properties(const GanvNode* node,
217                               double*         dash_length,
218                               double*         border_color,
219                               double*         fill_color);
220 
221 /* Port */
222 
223 typedef struct {
224 	GanvBox*  rect;
225 	float     value;
226 	float     min;
227 	float     max;
228 	gboolean  is_toggle;
229 	gboolean  is_integer;
230 } GanvPortControl;
231 
232 struct _GanvPortPrivate {
233 	GanvPortControl* control;
234 	GanvText*        value_label;
235 	gboolean         is_input;
236 	gboolean         is_controllable;
237 };
238 
239 /* Text */
240 
241 typedef struct
242 {
243 	double x;
244 	double y;
245 	double width;
246 	double height;
247 } GanvTextCoords;
248 
249 struct _GanvTextPrivate
250 {
251 	PangoLayout*     layout;
252 	char*            text;
253 	GanvTextCoords   coords;
254 	GanvTextCoords   old_coords;
255 	double           font_size;
256 	guint            color;
257 	gboolean         needs_layout;
258 };
259 
260 /* Canvas */
261 
262 typedef struct {
263 	GanvPortOrderFunc port_cmp;
264 	void*             data;
265 } PortOrderCtx;
266 
267 void
268 ganv_canvas_move_selected_items(GanvCanvas* canvas,
269                                 double      dx,
270                                 double      dy);
271 
272 void
273 ganv_canvas_selection_move_finished(GanvCanvas* canvas);
274 
275 void
276 ganv_canvas_add_node(GanvCanvas* canvas,
277                      GanvNode*   node);
278 
279 void
280 ganv_canvas_remove_node(GanvCanvas* canvas,
281                         GanvNode*   node);
282 
283 void
284 ganv_canvas_select_node(GanvCanvas* canvas,
285                         GanvNode*   node);
286 
287 void
288 ganv_canvas_unselect_node(GanvCanvas* canvas,
289                           GanvNode*   node);
290 
291 void
292 ganv_canvas_add_edge(GanvCanvas* canvas,
293                      GanvEdge*   edge);
294 
295 void
296 ganv_canvas_select_edge(GanvCanvas* canvas,
297                         GanvEdge*   edge);
298 
299 void
300 ganv_canvas_unselect_edge(GanvCanvas* canvas,
301                           GanvEdge*   edge);
302 
303 void
304 ganv_canvas_disconnect_edge(GanvCanvas* canvas,
305                             GanvEdge*   edge);
306 
307 gboolean
308 ganv_canvas_port_event(GanvCanvas* canvas,
309                        GanvPort*   port,
310                        GdkEvent*   event);
311 
312 void
313 ganv_canvas_contents_changed(GanvCanvas* canvas);
314 
315 void
316 ganv_item_i2w_offset(GanvItem* item, double* px, double* py);
317 
318 void
319 ganv_item_i2w_pair(GanvItem* item, double* x1, double* y1, double* x2, double* y2);
320 
321 void
322 ganv_item_invoke_update(GanvItem* item, int flags);
323 
324 void
325 ganv_item_emit_event(GanvItem* item, GdkEvent* event, gint* finished);
326 
327 void
328 ganv_canvas_request_update(GanvCanvas* canvas);
329 
330 int
331 ganv_canvas_emit_event(GanvCanvas* canvas, GdkEvent* event);
332 
333 void
334 ganv_canvas_set_need_repick(GanvCanvas* canvas);
335 
336 void
337 ganv_canvas_forget_item(GanvCanvas* canvas, GanvItem* item);
338 
339 void
340 ganv_canvas_grab_focus(GanvCanvas* canvas, GanvItem* item);
341 
342 void
343 ganv_canvas_get_zoom_offsets(GanvCanvas* canvas, int* x, int* y);
344 
345 int
346 ganv_canvas_grab_item(GanvItem* item, guint event_mask, GdkCursor* cursor, guint32 etime);
347 
348 void
349 ganv_canvas_ungrab_item(GanvItem* item, guint32 etime);
350 
351 /* Request a redraw of the specified rectangle in canvas coordinates */
352 void
353 ganv_canvas_request_redraw_c(GanvCanvas* canvas,
354                              int x1, int y1, int x2, int y2);
355 
356 /* Request a redraw of the specified rectangle in world coordinates */
357 void
358 ganv_canvas_request_redraw_w(GanvCanvas* canvas,
359                              double x1, double y1, double x2, double y2);
360 
361 PortOrderCtx
362 ganv_canvas_get_port_order(GanvCanvas* canvas);
363 
364 gboolean
365 ganv_canvas_exporting(GanvCanvas* canvas);
366 
367 /* Edge */
368 
369 void
370 ganv_edge_update_location(GanvEdge* edge);
371 
372 void
373 ganv_edge_get_coords(const GanvEdge* edge, GanvEdgeCoords* coords);
374 
375 void
376 ganv_edge_request_redraw(GanvItem*             item,
377                          const GanvEdgeCoords* coords);
378 
379 void
380 ganv_edge_tick(GanvEdge* edge, double seconds);
381 
382 /* Box */
383 
384 void
385 ganv_box_path(GanvBox* box,
386               cairo_t* cr, double x1, double y1, double x2, double  y2,
387               double dr);
388 
389 void
390 ganv_box_request_redraw(GanvItem*            item,
391                         const GanvBoxCoords* coords,
392                         gboolean             world);
393 
394 /* Port */
395 
396 void
397 ganv_port_set_control_value_internal(GanvPort* port,
398                                      float     value);
399 
400 void
401 ganv_port_set_direction(GanvPort*     port,
402                         GanvDirection direction);
403 
404 #ifdef __cplusplus
405 }  /* extern "C" */
406 #endif
407 
408 #endif  /* GANV_PRIVATE_H */
409