2 /*! \file diarenderer.h -- the basic renderer interface definition */
7 #include <glib-object.h>
11 #include "font.h" /* not strictly needed by this header, but needed in almost any plug-in/ */
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 */
31 GObject parent_instance
; /*!< inheritance in object oriented C */
32 gboolean is_interactive
; /*!< if the user can interact */
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
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
);
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
,
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
,
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
,
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
,
112 real width
, real height
,
113 real angle1
, real angle2
,
115 /*! Same a DrawArcFunc except the arc is filled (a pie-chart) */
116 void (*fill_arc
) (DiaRenderer
*renderer
,
118 real width
, real height
,
119 real angle1
, real angle2
,
121 /*! Draw an ellipse, given its center and the bounding box */
122 void (*draw_ellipse
) (DiaRenderer
*renderer
,
124 real width
, real height
,
126 /*! Same a DrawEllipse, except the ellips is filled */
127 void (*fill_ellipse
) (DiaRenderer
*renderer
,
129 real width
, real height
,
131 /*! Print a string at pos, using the current font */
132 void (*draw_string
) (DiaRenderer
*renderer
,
137 /*! Draw an image, given its bounding box */
138 void (*draw_image
) (DiaRenderer
*renderer
,
140 real width
, real height
,
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
,
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
,
159 /*! Draw a line joining multiple points, using color and the current
161 void (*draw_polyline
) (DiaRenderer
*renderer
,
162 Point
*points
, int num_points
,
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
172 void (*draw_polygon
) (DiaRenderer
*renderer
,
173 Point
*points
, int num_points
,
175 /*! Print a Text. It holds its own information. */
176 void (*draw_text
) (DiaRenderer
*renderer
,
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
,
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
,
204 /*! Highest level function doing specific arrow positioning */
205 void (*draw_arc_with_arrows
) (DiaRenderer
*renderer
,
206 Point
*start
, Point
*end
,
212 /*! Highest level function doing specific arrow positioning */
213 void (*draw_polyline_with_arrows
) (DiaRenderer
*renderer
,
214 Point
*points
, int num_points
,
219 void (*draw_rounded_polyline_with_arrows
) (DiaRenderer
*renderer
,
220 Point
*points
, int num_points
,
227 void (*draw_bezier_with_arrows
) (DiaRenderer
*renderer
,
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
,
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
,
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
,
269 void (*copy_to_window
) (DiaRenderer
*renderer
,
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
*);
282 #endif /* DIA_RENDERER_H */