1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 /*! \file diarenderer.h -- the basic renderer interface definition */
20 #ifndef DIA_RENDERER_H
21 #define DIA_RENDERER_H
24 #include <glib-object.h>
26 #include "dia-enums.h"
28 #include "font.h" /* not strictly needed by this header, but needed in almost any plug-in/ */
32 /*! GObject boiler plate, create runtime information */
33 #define DIA_TYPE_RENDERER (dia_renderer_get_type ())
34 /*! GObject boiler plate, a safe type cast */
35 #define DIA_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_RENDERER, DiaRenderer))
36 /*! GObject boiler plate, in C++ this would be the vtable */
37 #define DIA_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_RENDERER, DiaRendererClass))
38 /*! GObject boiler plate, type check */
39 #define DIA_IS_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_RENDERER))
40 /*! GObject boiler plate, get from object to class (vtable) */
41 #define DIA_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_RENDERER, DiaRendererClass))
43 GType
dia_renderer_get_type (void) G_GNUC_CONST
;
45 /*! \brief The member variables part of _DiaRenderer */
48 GObject parent_instance
; /*!< inheritance in object oriented C */
49 gboolean is_interactive
; /*!< if the user can interact */
52 real font_height
; /* IMO It should be possible use the font's size to keep
53 * this info, but currently _not_ : multiline text is
54 * growing on every line when zoomed: BUG in font.c --hb
60 * \class _DiaRendererClass
62 * \brief Base class for all of Dia's render facilities
64 * Renderers work in close cooperation with DiaObject. They provide the way to
65 * make all the object drawing independent of concrete drawing backends
67 struct _DiaRendererClass
69 GObjectClass parent_class
; /*!< the base class */
71 /*! return width in pixels, only for interactive renderers */
72 int (*get_width_pixels
) (DiaRenderer
*);
73 /*! return width in pixels, only for interactive renderers */
74 int (*get_height_pixels
) (DiaRenderer
*);
75 /*! simply calls the objects draw function, which calls this again */
76 void (*draw_object
) (DiaRenderer
*, DiaObject
*);
77 /*! Returns the EXACT width of text in cm, using the current font.
78 There has been some confusion as to the definition of this.
79 It used to say the width was in pixels, but actual width returned
80 was cm. You shouldn't know about pixels anyway.
82 real (*get_text_width
) (DiaRenderer
*renderer
,
83 const gchar
*text
, int length
);
87 * Function which MUST be implemented by any DiaRenderer
89 /*! Called before rendering begins.
90 Can be used to do various pre-rendering setup. */
91 void (*begin_render
) (DiaRenderer
*);
92 /*! Called after all rendering is done.
93 Used to do various clean-ups.*/
94 void (*end_render
) (DiaRenderer
*);
96 /*! Set the current line width
97 if linewidth==0, the line will be an 'hairline' */
98 void (*set_linewidth
) (DiaRenderer
*renderer
, real linewidth
);
99 /*! Set the current linecap (the way lines are ended) */
100 void (*set_linecaps
) (DiaRenderer
*renderer
, LineCaps mode
);
101 /*! Set the current linejoin (the way two lines are joined together) */
102 void (*set_linejoin
) (DiaRenderer
*renderer
, LineJoin mode
);
103 /*! Set the current line style */
104 void (*set_linestyle
) (DiaRenderer
*renderer
, LineStyle mode
);
105 /*! Set the dash length, when the style is not SOLID
106 A dot will be 10% of length */
107 void (*set_dashlength
) (DiaRenderer
*renderer
, real length
);
108 /*! Set the fill style */
109 void (*set_fillstyle
) (DiaRenderer
*renderer
, FillStyle mode
);
110 /*! Set the current font */
111 void (*set_font
) (DiaRenderer
*renderer
, DiaFont
*font
, real height
);
113 /*! Draw a line from start to end, using color and the current line style */
114 void (*draw_line
) (DiaRenderer
*renderer
,
115 Point
*start
, Point
*end
,
117 /*! Fill a rectangle, given its upper-left and lower-right corners */
118 void (*fill_rect
) (DiaRenderer
*renderer
,
119 Point
*ul_corner
, Point
*lr_corner
,
121 /*! the polygon is filled using the current fill type, no border is drawn */
122 void (*fill_polygon
) (DiaRenderer
*renderer
,
123 Point
*points
, int num_points
,
125 /*! Draw an arc, given its center, the bounding box (widget, height),
126 the start angle and the end angle */
127 void (*draw_arc
) (DiaRenderer
*renderer
,
129 real width
, real height
,
130 real angle1
, real angle2
,
132 /*! Same a DrawArcFunc except the arc is filled (a pie-chart) */
133 void (*fill_arc
) (DiaRenderer
*renderer
,
135 real width
, real height
,
136 real angle1
, real angle2
,
138 /*! Draw an ellipse, given its center and the bounding box */
139 void (*draw_ellipse
) (DiaRenderer
*renderer
,
141 real width
, real height
,
143 /*! Same a DrawEllipse, except the ellips is filled */
144 void (*fill_ellipse
) (DiaRenderer
*renderer
,
146 real width
, real height
,
148 /*! Print a string at pos, using the current font */
149 void (*draw_string
) (DiaRenderer
*renderer
,
154 /*! Draw an image, given its bounding box */
155 void (*draw_image
) (DiaRenderer
*renderer
,
157 real width
, real height
,
161 * Functions which SHOULD be implemented by specific renderer, but
162 * have a default implementation based on the above functions
164 /*! Draw a bezier curve, given it's control points. The first BezPoint must
165 be of type MOVE_TO, and no other ones may be MOVE_TO's. */
166 void (*draw_bezier
) (DiaRenderer
*renderer
,
170 /*! Same as DrawBezierFunc, except the last point must be the same as the
171 first point, and the resulting shape is filled */
172 void (*fill_bezier
) (DiaRenderer
*renderer
,
176 /*! Draw a line joining multiple points, using color and the current
178 void (*draw_polyline
) (DiaRenderer
*renderer
,
179 Point
*points
, int num_points
,
181 /*! Draw a line joining multiple points, using color and the current
182 line style with rounded corners between segments */
183 void (*draw_rounded_polyline
) (DiaRenderer
*renderer
,
184 Point
*points
, int num_points
,
185 Color
*color
, real radius
);
186 /*! Draw a polygone, using the current line style
187 The polygon is closed even if the first point is not the same as the
189 void (*draw_polygon
) (DiaRenderer
*renderer
,
190 Point
*points
, int num_points
,
192 /*! Print a Text. It holds its own information. */
193 void (*draw_text
) (DiaRenderer
*renderer
,
195 /*! Print a TextLine. It holds its own font/size information. */
196 void (*draw_text_line
) (DiaRenderer
*renderer
,
197 TextLine
*text_line
, Point
*pos
, Color
*color
);
198 /*! Draw a rectangle, given its upper-left and lower-right corners */
199 void (*draw_rect
) (DiaRenderer
*renderer
,
200 Point
*ul_corner
, Point
*lr_corner
,
204 * Highest level functions, probably only to be implemented by
205 * special 'high level' renderers
207 /*! Draw a rounded rectangle, given its upper-left and lower-right corners */
208 void (*draw_rounded_rect
) (DiaRenderer
*renderer
,
209 Point
*ul_corner
, Point
*lr_corner
,
210 Color
*color
, real radius
);
211 /*! Same a DrawRoundedRectangleFunc, except the rectangle is filled using the
212 current fill style */
213 void (*fill_rounded_rect
) (DiaRenderer
*renderer
,
214 Point
*ul_corner
, Point
*lr_corner
,
215 Color
*color
, real radius
);
217 /*! Highest level function doing specific arrow positioning */
218 void (*draw_line_with_arrows
) (DiaRenderer
*renderer
,
219 Point
*start
, Point
*end
,
224 /*! Highest level function doing specific arrow positioning */
225 void (*draw_arc_with_arrows
) (DiaRenderer
*renderer
,
226 Point
*start
, Point
*end
,
232 /*! Highest level function doing specific arrow positioning */
233 void (*draw_polyline_with_arrows
) (DiaRenderer
*renderer
,
234 Point
*points
, int num_points
,
239 void (*draw_rounded_polyline_with_arrows
) (DiaRenderer
*renderer
,
240 Point
*points
, int num_points
,
247 void (*draw_bezier_with_arrows
) (DiaRenderer
*renderer
,
257 * Declare the Interactive Renderer Interface, which get's added
258 * to some renderer classes by app/
260 #define DIA_TYPE_INTERACTIVE_RENDERER_INTERFACE (dia_interactive_renderer_interface_get_type ())
261 #define DIA_GET_INTERACTIVE_RENDERER_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), DIA_TYPE_INTERACTIVE_RENDERER_INTERFACE, DiaInteractiveRendererInterface))
263 struct _DiaInteractiveRendererInterface
265 GTypeInterface base_iface
;
267 /* Clear the current clipping region. */
268 void (*set_size
) (DiaRenderer
*renderer
, gpointer
, int, int);
270 /* Clear the current clipping region. */
271 void (*clip_region_clear
) (DiaRenderer
*renderer
);
273 /* Add a rectangle to the current clipping region. */
274 void (*clip_region_add_rect
) (DiaRenderer
*renderer
, Rectangle
*rect
);
276 /* Draw a line from start to end, using color and the current line style */
277 void (*draw_pixel_line
) (DiaRenderer
*renderer
,
278 int x1
, int y1
, int x2
, int y2
,
280 /* Draw a rectangle, given its upper-left and lower-right corners in pixels. */
281 void (*draw_pixel_rect
) (DiaRenderer
*renderer
,
282 int x
, int y
, int width
, int height
,
284 /* Fill a rectangle, given its upper-left and lower-right corners in pixels. */
285 void (*fill_pixel_rect
) (DiaRenderer
*renderer
,
286 int x
, int y
, int width
, int height
,
289 void (*copy_to_window
) (DiaRenderer
*renderer
,
291 int x
, int y
, int width
, int height
);
294 GType
dia_interactive_renderer_interface_get_type (void) G_GNUC_CONST
;
296 void dia_renderer_set_size (DiaRenderer
*, gpointer window
, int, int);
297 int dia_renderer_get_width_pixels (DiaRenderer
*);
298 int dia_renderer_get_height_pixels (DiaRenderer
*);
302 #endif /* DIA_RENDERER_H */