pre3 updates
[dia.git] / lib / diarenderer.h
blob8275bc28e4e3d4c5ac808012f529df942352d65a
2 /*! \file diarenderer.h -- the basic renderer interface definition */
3 #ifndef DIA_RENDERER_H
4 #define DIA_RENDERER_H
6 #include "diatypes.h"
7 #include <glib-object.h>
9 #include "dia-enums.h"
10 #include "geometry.h"
11 #include "font.h" /* not strictly needed by this header, but needed in almost any plug-in/ */
13 G_BEGIN_DECLS
15 /*! GObject boiler plate, create runtime information */
16 #define DIA_TYPE_RENDERER (dia_renderer_get_type ())
17 /*! GObject boiler plate, a safe type cast */
18 #define DIA_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_RENDERER, DiaRenderer))
19 /*! GObject boiler plate, in C++ this would be the vtable */
20 #define DIA_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_RENDERER, DiaRendererClass))
21 /*! GObject boiler plate, type check */
22 #define DIA_IS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_RENDERER))
23 /*! GObject boiler plate, get from object to class (vtable) */
24 #define DIA_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_RENDERER, DiaRendererClass))
26 GType dia_renderer_get_type (void) G_GNUC_CONST;
28 /*! \brief The member variables part of _DiaRenderer */
29 struct _DiaRenderer
31 GObject parent_instance; /*!< inheritance in object oriented C */
32 gboolean is_interactive; /*!< if the user can interact */
33 /*< private >*/
34 DiaFont *font;
35 real font_height; /* IMO It should be possible use the font's size to keep
36 * this info, but currently _not_ : multiline text is
37 * growing on every line when zoomed: BUG in font.c --hb
39 BezierApprox *bezier;
42 /*!
43 * \class _DiaRendererClass
45 * \brief Base class for all of Dia's render facilities
47 * Renderers work in close cooperation with DiaObject. They provide the way to
48 * make all the object drawing independent of concrete drawing backends
50 struct _DiaRendererClass
52 GObjectClass parent_class; /*!< the base class */
54 /*! return width in pixels, only for interactive renderers */
55 int (*get_width_pixels) (DiaRenderer*);
56 /*! return width in pixels, only for interactive renderers */
57 int (*get_height_pixels) (DiaRenderer*);
58 /*! simply calls the objects draw function, which calls this again */
59 void (*draw_object) (DiaRenderer*, DiaObject*);
60 /*! Returns the EXACT width of text in cm, using the current font.
61 There has been some confusion as to the definition of this.
62 It used to say the width was in pixels, but actual width returned
63 was cm. You shouldn't know about pixels anyway.
65 real (*get_text_width) (DiaRenderer *renderer,
66 const gchar *text, int length);
69 /*
70 * Function which MUST be implemented by any DiaRenderer
72 /*! Called before rendering begins.
73 Can be used to do various pre-rendering setup. */
74 void (*begin_render) (DiaRenderer *);
75 /*! Called after all rendering is done.
76 Used to do various clean-ups.*/
77 void (*end_render) (DiaRenderer *);
79 /*! Set the current line width
80 if linewidth==0, the line will be an 'hairline' */
81 void (*set_linewidth) (DiaRenderer *renderer, real linewidth);
82 /*! Set the current linecap (the way lines are ended) */
83 void (*set_linecaps) (DiaRenderer *renderer, LineCaps mode);
84 /*! Set the current linejoin (the way two lines are joined together) */
85 void (*set_linejoin) (DiaRenderer *renderer, LineJoin mode);
86 /*! Set the current line style */
87 void (*set_linestyle) (DiaRenderer *renderer, LineStyle mode);
88 /*! Set the dash length, when the style is not SOLID
89 A dot will be 10% of length */
90 void (*set_dashlength) (DiaRenderer *renderer, real length);
91 /*! Set the fill style */
92 void (*set_fillstyle) (DiaRenderer *renderer, FillStyle mode);
93 /*! Set the current font */
94 void (*set_font) (DiaRenderer *renderer, DiaFont *font, real height);
96 /*! Draw a line from start to end, using color and the current line style */
97 void (*draw_line) (DiaRenderer *renderer,
98 Point *start, Point *end,
99 Color *color);
100 /*! Fill a rectangle, given its upper-left and lower-right corners */
101 void (*fill_rect) (DiaRenderer *renderer,
102 Point *ul_corner, Point *lr_corner,
103 Color *color);
104 /*! the polygon is filled using the current fill type, no border is drawn */
105 void (*fill_polygon) (DiaRenderer *renderer,
106 Point *points, int num_points,
107 Color *color);
108 /*! Draw an arc, given its center, the bounding box (widget, height),
109 the start angle and the end angle */
110 void (*draw_arc) (DiaRenderer *renderer,
111 Point *center,
112 real width, real height,
113 real angle1, real angle2,
114 Color *color);
115 /*! Same a DrawArcFunc except the arc is filled (a pie-chart) */
116 void (*fill_arc) (DiaRenderer *renderer,
117 Point *center,
118 real width, real height,
119 real angle1, real angle2,
120 Color *color);
121 /*! Draw an ellipse, given its center and the bounding box */
122 void (*draw_ellipse) (DiaRenderer *renderer,
123 Point *center,
124 real width, real height,
125 Color *color);
126 /*! Same a DrawEllipse, except the ellips is filled */
127 void (*fill_ellipse) (DiaRenderer *renderer,
128 Point *center,
129 real width, real height,
130 Color *color);
131 /*! Print a string at pos, using the current font */
132 void (*draw_string) (DiaRenderer *renderer,
133 const gchar *text,
134 Point *pos,
135 Alignment alignment,
136 Color *color);
137 /*! Draw an image, given its bounding box */
138 void (*draw_image) (DiaRenderer *renderer,
139 Point *point,
140 real width, real height,
141 DiaImage image);
144 * Functions which SHOULD be implemented by specific renderer, but
145 * have a default implementation based on the above functions
147 /*! Draw a bezier curve, given it's control points. The first BezPoint must
148 be of type MOVE_TO, and no other ones may be MOVE_TO's. */
149 void (*draw_bezier) (DiaRenderer *renderer,
150 BezPoint *points,
151 int numpoints,
152 Color *color);
153 /*! Same as DrawBezierFunc, except the last point must be the same as the
154 first point, and the resulting shape is filled */
155 void (*fill_bezier) (DiaRenderer *renderer,
156 BezPoint *points,
157 int numpoints,
158 Color *color);
159 /*! Draw a line joining multiple points, using color and the current
160 line style */
161 void (*draw_polyline) (DiaRenderer *renderer,
162 Point *points, int num_points,
163 Color *color);
164 /*! Draw a line joining multiple points, using color and the current
165 line style with rounded corners between segments */
166 void (*draw_rounded_polyline) (DiaRenderer *renderer,
167 Point *points, int num_points,
168 Color *color, real radius );
169 /*! Draw a polygone, using the current line style
170 The polygon is closed even if the first point is not the same as the
171 last point */
172 void (*draw_polygon) (DiaRenderer *renderer,
173 Point *points, int num_points,
174 Color *color);
175 /*! Print a Text. It holds its own information. */
176 void (*draw_text) (DiaRenderer *renderer,
177 Text *text);
178 /*! Draw a rectangle, given its upper-left and lower-right corners */
179 void (*draw_rect) (DiaRenderer *renderer,
180 Point *ul_corner, Point *lr_corner,
181 Color *color);
184 * Highest level functions, probably only to be implemented by
185 * special 'high level' renderers
187 /*! Draw a rounded rectangle, given its upper-left and lower-right corners */
188 void (*draw_rounded_rect) (DiaRenderer *renderer,
189 Point *ul_corner, Point *lr_corner,
190 Color *color, real radius);
191 /*! Same a DrawRoundedRectangleFunc, except the rectangle is filled using the
192 current fill style */
193 void (*fill_rounded_rect) (DiaRenderer *renderer,
194 Point *ul_corner, Point *lr_corner,
195 Color *color, real radius);
197 /*! Highest level function doing specific arrow positioning */
198 void (*draw_line_with_arrows) (DiaRenderer *renderer,
199 Point *start, Point *end,
200 real line_width,
201 Color *line_color,
202 Arrow *start_arrow,
203 Arrow *end_arrow);
204 /*! Highest level function doing specific arrow positioning */
205 void (*draw_arc_with_arrows) (DiaRenderer *renderer,
206 Point *start, Point *end,
207 Point *midpoint,
208 real line_width,
209 Color *color,
210 Arrow *start_arrow,
211 Arrow *end_arrow);
212 /*! Highest level function doing specific arrow positioning */
213 void (*draw_polyline_with_arrows) (DiaRenderer *renderer,
214 Point *points, int num_points,
215 real line_width,
216 Color *color,
217 Arrow *start_arrow,
218 Arrow *end_arrow);
219 void (*draw_rounded_polyline_with_arrows) (DiaRenderer *renderer,
220 Point *points, int num_points,
221 real line_width,
222 Color *color,
223 Arrow *start_arrow,
224 Arrow *end_arrow,
225 real radius);
227 void (*draw_bezier_with_arrows) (DiaRenderer *renderer,
228 BezPoint *points,
229 int num_points,
230 real line_width,
231 Color *color,
232 Arrow *start_arrow,
233 Arrow *end_arrow);
237 * Declare the Interactive Renderer Interface, which get's added
238 * to some renderer classes by app/
240 #define DIA_TYPE_INTERACTIVE_RENDERER_INTERFACE (dia_interactive_renderer_interface_get_type ())
241 #define DIA_GET_INTERACTIVE_RENDERER_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), DIA_TYPE_INTERACTIVE_RENDERER_INTERFACE, DiaInteractiveRendererInterface))
243 struct _DiaInteractiveRendererInterface
245 GTypeInterface base_iface;
247 /* Clear the current clipping region. */
248 void (*set_size) (DiaRenderer *renderer, gpointer, int, int);
250 /* Clear the current clipping region. */
251 void (*clip_region_clear) (DiaRenderer *renderer);
253 /* Add a rectangle to the current clipping region. */
254 void (*clip_region_add_rect) (DiaRenderer *renderer, Rectangle *rect);
256 /* Draw a line from start to end, using color and the current line style */
257 void (*draw_pixel_line) (DiaRenderer *renderer,
258 int x1, int y1, int x2, int y2,
259 Color *color);
260 /* Draw a rectangle, given its upper-left and lower-right corners in pixels. */
261 void (*draw_pixel_rect) (DiaRenderer *renderer,
262 int x, int y, int width, int height,
263 Color *color);
264 /* Fill a rectangle, given its upper-left and lower-right corners in pixels. */
265 void (*fill_pixel_rect) (DiaRenderer *renderer,
266 int x, int y, int width, int height,
267 Color *color);
269 void (*copy_to_window) (DiaRenderer *renderer,
270 gpointer window,
271 int x, int y, int width, int height);
274 GType dia_interactive_renderer_interface_get_type (void) G_GNUC_CONST;
276 void dia_renderer_set_size (DiaRenderer*, gpointer window, int, int);
277 int dia_renderer_get_width_pixels (DiaRenderer*);
278 int dia_renderer_get_height_pixels (DiaRenderer*);
280 G_END_DECLS
282 #endif /* DIA_RENDERER_H */