2009-10-20 Chris Toshok <toshok@ximian.com>
[moon.git] / src / moon-path.h
blob2a85cd0a8f3b1d612cc0a87bd5ba097aab107e88
1 /*
2 * moon-path.h: Path-based API, similar to cairo but without requiring a cairo_context_t
4 * Contact:
5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2007, 2008 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
13 #ifndef __MOON_PATH_H__
14 #define __MOON_PATH_H__
16 #include <string.h>
17 #include <math.h>
18 #include <glib.h>
19 #include <cairo.h>
21 G_BEGIN_DECLS
23 // http://graphics.stanford.edu/courses/cs248-98-fall/Final/q1.html
24 #define ARC_TO_BEZIER 0.55228475
26 typedef struct {
27 cairo_path_t cairo;
28 int allocated; /* how many cairo_path_data_t were allocated */
29 } moon_path;
31 /* the numbers of cairo_path_data_t required to hold a path containing the matching call */
32 #define MOON_PATH_MOVE_TO_LENGTH 2
33 #define MOON_PATH_LINE_TO_LENGTH 2
34 #define MOON_PATH_CURVE_TO_LENGTH 4
35 #define MOON_PATH_ELLIPSE_LENGTH 18
36 #define MOON_PATH_RECTANGLE_LENGTH 9
37 #define MOON_PATH_ROUNDED_RECTANGLE_LENGTH 27
38 #define MOON_PATH_CLOSE_PATH_LENGTH 1
40 // is it true only for arcs or for everything ? if so using the same values ?
41 // note: lupus noted this suggest SL uses floats, not doubles, internally (MIL?)
42 #define IS_ZERO(x) (fabs(x) < 0.000019)
43 #define IS_TOO_SMALL(x) (fabs(x) < 0.000117)
46 * These functions are similar to cairo_* functions (with some extra ones) except that they don't require a cairo_context_t
47 * in order to build a cairo_path_t.
50 moon_path* moon_path_new (int size);
51 moon_path* moon_path_renew (moon_path* path, int size);
52 void moon_path_clear (moon_path* path);
53 void moon_path_destroy (moon_path* path);
54 void moon_get_current_point (moon_path *path, double *x, double *y);
55 void moon_move_to (moon_path *path, double x, double y);
56 void moon_line_to (moon_path *path, double x, double y);
57 void moon_curve_to (moon_path *path, double x1, double y1, double x2, double y2, double x3, double y3);
58 void moon_quad_curve_to (moon_path* path, double x1, double y1, double x2, double y2);
59 void moon_arc_to (moon_path *path, double width, double height, double angle, gboolean large, gboolean sweep, double ex, double ey);
60 void moon_ellipse (moon_path *path, double x, double y, double w, double h);
61 void moon_rectangle (moon_path *path, double x, double y, double w, double h);
62 void moon_rounded_rectangle (moon_path *path, double x, double y, double w, double h, double radius_x, double radius_y);
63 void moon_close_path (moon_path *path);
64 void moon_get_origin (moon_path *path, double *ox, double *oy);
65 void moon_merge (moon_path *path, moon_path *subpath);
67 // for debugging purpose
68 void cairo_path_display (cairo_path_t *path);
69 void moon_path_display (moon_path *path);
71 G_END_DECLS
73 #endif