merge gnomecanvas into ardour tree, so that we can fix our own bugs and not wait...
[ardour.git] / libs / gnomecanvas / libgnomecanvas / gnome-canvas-util.h
1 /*
2  * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
3  * All rights reserved.
4  *
5  * This file is part of the Gnome Library.
6  *
7  * The Gnome Library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * The Gnome Library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with the Gnome Library; see the file COPYING.LIB.  If not,
19  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 /*
23   @NOTATION@
24  */
25 /* Miscellaneous utility functions for the GnomeCanvas widget
26  *
27  * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget.  Tk is
28  * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
29  *
30  * Author: Federico Mena <federico@nuclecu.unam.mx>
31  */
32
33 #ifndef GNOME_CANVAS_UTIL_H
34 #define GNOME_CANVAS_UTIL_H
35
36 #include <libgnomecanvas/gnome-canvas.h>
37
38 #include <libart_lgpl/art_svp.h>
39 #include <libart_lgpl/art_vpath.h>
40 #include <libart_lgpl/art_svp_vpath_stroke.h>
41
42
43 G_BEGIN_DECLS
44
45 typedef struct _GnomeCanvasPoints GnomeCanvasPoints;
46
47 /* This structure defines an array of points.  X coordinates are stored in the even-numbered
48  * indices, and Y coordinates are stored in the odd-numbered indices.  num_points indicates the
49  * number of points, so the array is 2*num_points elements big.
50  */
51 struct _GnomeCanvasPoints {
52         double *coords;
53         int num_points;
54         int ref_count;
55 };
56
57
58 /* Allocate a new GnomeCanvasPoints structure with enough space for the specified number of points */
59 GnomeCanvasPoints *gnome_canvas_points_new (int num_points);
60
61 /* Increate ref count */
62 GnomeCanvasPoints *gnome_canvas_points_ref (GnomeCanvasPoints *points);
63 #define gnome_canvas_points_unref gnome_canvas_points_free
64
65 /* Decrease ref count and free structure if it has reached zero */
66 void gnome_canvas_points_free (GnomeCanvasPoints *points);
67
68 /* Given three points forming an angle, compute the coordinates of the inside and outside points of
69  * the mitered corner formed by a line of a given width at that angle.
70  *
71  * If the angle is less than 11 degrees, then FALSE is returned and the return points are not
72  * modified.  Otherwise, TRUE is returned.
73  */
74 int gnome_canvas_get_miter_points (double x1, double y1, double x2, double y2, double x3, double y3,
75                                    double width,
76                                    double *mx1, double *my1, double *mx2, double *my2);
77
78 /* Compute the butt points of a line segment.  If project is FALSE, then the results are as follows:
79  *
80  *            -------------------* (bx1, by1)
81  *                               |
82  *   (x1, y1) *------------------* (x2, y2)
83  *                               |
84  *            -------------------* (bx2, by2)
85  *
86  * that is, the line is not projected beyond (x2, y2).  If project is TRUE, then the results are as
87  * follows:
88  *
89  *            -------------------* (bx1, by1)
90  *                      (x2, y2) |
91  *   (x1, y1) *-------------*    |
92  *                               |
93  *            -------------------* (bx2, by2)
94  */
95 void gnome_canvas_get_butt_points (double x1, double y1, double x2, double y2,
96                                    double width, int project,
97                                    double *bx1, double *by1, double *bx2, double *by2);
98
99 /* Calculate the distance from a polygon to a point.  The polygon's X coordinates are in the even
100  * indices of the poly array, and the Y coordinates are in the odd indices.
101  */
102 double gnome_canvas_polygon_to_point (double *poly, int num_points, double x, double y);
103
104
105 /* Render the svp over the buf. */
106 void gnome_canvas_render_svp (GnomeCanvasBuf *buf, ArtSVP *svp, guint32 rgba);
107
108 /* Sets the svp to the new value, requesting repaint on what's changed. This function takes responsibility for
109  * freeing new_svp.
110  */
111 void gnome_canvas_update_svp (GnomeCanvas *canvas, ArtSVP **p_svp, ArtSVP *new_svp);
112
113 /* Sets the svp to the new value, clipping if necessary, and requesting repaint
114  * on what's changed. This function takes responsibility for freeing new_svp.
115  */
116 void gnome_canvas_update_svp_clip (GnomeCanvas *canvas, ArtSVP **p_svp, ArtSVP *new_svp,
117                                    ArtSVP *clip_svp);
118
119 /* Sets the svp to the new value, requesting repaint on what's changed. This
120  * function takes responsibility for freeing new_svp. This routine also adds the
121  * svp's bbox to the item's.
122  */
123 void gnome_canvas_item_reset_bounds (GnomeCanvasItem *item);
124
125 /* Sets the svp to the new value, requesting repaint on what's changed. This function takes responsibility for
126  * freeing new_svp. This routine also adds the svp's bbox to the item's.
127  */
128 void gnome_canvas_item_update_svp (GnomeCanvasItem *item, ArtSVP **p_svp, ArtSVP *new_svp);
129
130 /* Sets the svp to the new value, clipping if necessary, and requesting repaint
131  * on what's changed. This function takes responsibility for freeing new_svp.
132  */
133 void gnome_canvas_item_update_svp_clip (GnomeCanvasItem *item, ArtSVP **p_svp, ArtSVP *new_svp,
134                                         ArtSVP *clip_svp);
135
136 /* Request redraw of the svp if in aa mode, or the entire item in in xlib
137  * mode.
138  */
139 void gnome_canvas_item_request_redraw_svp (GnomeCanvasItem *item, const ArtSVP *svp);
140
141 /* Sets the bbox to the new value, requesting full repaint. */
142 void gnome_canvas_update_bbox (GnomeCanvasItem *item, int x1, int y1, int x2, int y2);
143
144 /* Ensure that the buffer is in RGB format, suitable for compositing. */
145 void gnome_canvas_buf_ensure_buf (GnomeCanvasBuf *buf);
146
147 /* Convert from GDK line join specifier to libart. */
148 ArtPathStrokeJoinType gnome_canvas_join_gdk_to_art (GdkJoinStyle gdk_join);
149
150 /* Convert from GDK line cap specifier to libart. */
151 ArtPathStrokeCapType gnome_canvas_cap_gdk_to_art (GdkCapStyle gdk_cap);
152
153 G_END_DECLS
154
155 #endif