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.
21 #error "The old Renderer is dead."
22 typedef struct _RenderOps RenderOps
;
23 typedef struct _InteractiveRenderOps InteractiveRenderOps
;
24 typedef struct _Renderer Renderer
;
26 #include "dia-enums.h"
28 typedef struct _DiaFont DiaFont
;
29 typedef struct _Color Color
;
30 typedef struct _DiaImage
* DiaImage
;
34 /******************************************************
35 ** Functions defined for every Renderer
37 ******************************************************/
39 /* Called before rendering begins.
40 Can be used to do various pre-rendering setup. */
41 typedef void (*BeginRenderFunc
) (Renderer
*renderer
);
43 /* Called after all rendering is done.
44 Used to do various clean-ups.*/
45 typedef void (*EndRenderFunc
) (Renderer
*renderer
);
47 /* Set the current line width
48 if linewidth==0, the line will be an 'hairline' */
49 typedef void (*SetLineWidthFunc
) (Renderer
*renderer
, real linewidth
);
51 /* Set the current linecap (the way lines are ended) */
52 typedef void (*SetLineCapsFunc
) (Renderer
*renderer
, LineCaps mode
);
54 /* Set the current linejoin (the way two lines are joined together) */
55 typedef void (*SetLineJoinFunc
) (Renderer
*renderer
, LineJoin mode
);
57 /* Set the current line style */
58 typedef void (*SetLineStyleFunc
) (Renderer
*renderer
, LineStyle mode
);
60 /* Set the dash length, when the style is not SOLID
61 A dot will be 10% of length */
62 typedef void (*SetDashLengthFunc
) (Renderer
*renderer
, real length
);
64 /* Set the fill style */
65 typedef void (*SetFillStyleFunc
) (Renderer
*renderer
, FillStyle mode
);
67 /* Set the current font */
68 typedef void (*SetFontFunc
) (Renderer
*renderer
, DiaFont
*font
, real height
);
70 /* Draw a line from start to end, using color and the current line style */
71 typedef void (*DrawLineFunc
) (Renderer
*renderer
,
72 Point
*start
, Point
*end
,
75 /* Draw a line joining multiple points, using color and the current
77 typedef void (*DrawPolyLineFunc
) (Renderer
*renderer
,
78 Point
*points
, int num_points
,
81 /* Draw a polygone, using the current line style
82 The polygon is closed even if the first point is not the same as the
84 typedef void (*DrawPolygonFunc
) (Renderer
*renderer
,
85 Point
*points
, int num_points
,
88 /* Same a DrawPolygonFunc, expect the polygon is filled using the current
90 typedef void (*FillPolygonFunc
) (Renderer
*renderer
,
91 Point
*points
, int num_points
,
94 /* Draw a rectangle, given its upper-left and lower-right corners */
95 typedef void (*DrawRectangleFunc
) (Renderer
*renderer
,
96 Point
*ul_corner
, Point
*lr_corner
,
99 /* Same a DrawRectangleFunc, except the rectangle is filled using the
100 current fill style */
101 typedef void (*FillRectangleFunc
) (Renderer
*renderer
,
102 Point
*ul_corner
, Point
*lr_corner
,
105 /* Draw a rounded rectangle, given its upper-left and lower-right corners */
106 typedef void (*DrawRoundedRectangleFunc
) (Renderer
*renderer
,
107 Point
*ul_corner
, Point
*lr_corner
,
108 Color
*color
, real rounding
);
110 /* Same a DrawRoundedRectangleFunc, except the rectangle is filled using the
111 current fill style */
112 typedef void (*FillRoundedRectangleFunc
) (Renderer
*renderer
,
113 Point
*ul_corner
, Point
*lr_corner
,
114 Color
*color
, real rounding
);
116 /* Draw an arc, given its center, the bounding box (widget, height),
117 the start angle and the end angle */
118 typedef void (*DrawArcFunc
) (Renderer
*renderer
,
120 real width
, real height
,
121 real angle1
, real angle2
,
124 /* Same a DrawArcFunc except the arc is filled (a pie-chart) */
125 typedef void (*FillArcFunc
) (Renderer
*renderer
,
127 real width
, real height
,
128 real angle1
, real angle2
,
131 /* Draw an ellipse, given its center and the bounding box */
132 typedef void (*DrawEllipseFunc
) (Renderer
*renderer
,
134 real width
, real height
,
137 /* Same a DrawEllipse, except the ellips is filled */
138 typedef void (*FillEllipseFunc
) (Renderer
*renderer
,
140 real width
, real height
,
143 /* Draw a bezier curve, given it's control points.
144 * The first BezPoint must be of type MOVE_TO, and no other ones may be
147 typedef void (*DrawBezierFunc
) (Renderer
*renderer
,
152 /* Same as DrawBezierFunc, except the last point must be the same as the
153 first point, and the resulting shape is filled */
154 typedef void (*FillBezierFunc
) (Renderer
*renderer
,
159 /* Print a string at pos, using the current font */
160 typedef void (*DrawStringFunc
) (Renderer
*renderer
,
166 /* Draw an image, given its bounding box */
167 typedef void (*DrawImageFunc
) (Renderer
*renderer
,
169 real width
, real height
,
172 /******************************************************
173 ** Functions defined for every Interactive Renderer
174 ** Interactive renderers are renderers that render
175 ** to pixels on the screen.
176 ******************************************************/
178 /* Returns the EXACT width of text in cm, using the current font.
179 There has been some confusion as to the definition of this.
180 It used to say the width was in pixels, but actual width returned
181 was cm. You shouldn't know about pixels anyway.
183 typedef real (*GetTextWidthFunc
) (Renderer
*renderer
,
184 const gchar
*text
, int length
);
186 /* Clear the current clipping region.
187 This function needs only be defined for interactive
190 typedef void (*ClipRegionClearFunc
) (Renderer
*renderer
);
192 /* Add a rectangle to the current clipping region.
193 This function needs only be defined for interactive
196 typedef void (*ClipRegionAddRectangleFunc
) (Renderer
*renderer
,
199 /* Draw a line from start to end, using color and the current line style */
200 typedef void (*DrawPixelLineFunc
) (Renderer
*renderer
,
205 /* Draw a rectangle, given its upper-left and lower-right corners
208 typedef void (*DrawPixelRectangleFunc
) (Renderer
*renderer
,
210 int width
, int height
,
213 /* Same a DrawPixelRectangleFunc, except the rectangle is filled using the
214 current fill style */
215 typedef void (*FillPixelRectangleFunc
) (Renderer
*renderer
,
217 int width
, int height
,
220 /* Functions to draw lines with various arrows */
221 /* All Draw*WithArrowsFuncs assume that any arrow transformation is included
222 in the points. If a renderer wants to get the original points, it must
223 untransform the points.
225 typedef void (*DrawLineWithArrowsFunc
) (Renderer
*renderer
,
226 Point
*from
, Point
*to
,
232 typedef void (*DrawPolyLineWithArrowsFunc
) (Renderer
*renderer
,
233 Point
*points
, int num_points
,
239 /* Note that this is different from the normal DrawArc function */
240 typedef void (*DrawArcWithArrowsFunc
) (Renderer
*renderer
,
241 Point
*start
, Point
*end
,
248 typedef void (*DrawBezierWithArrowsFunc
) (Renderer
*renderer
,
256 typedef void (*DrawObjectFunc
) (Renderer
*renderer
,
261 BeginRenderFunc begin_render
;
262 EndRenderFunc end_render
;
264 /* Line attributes: */
265 SetLineWidthFunc set_linewidth
;
266 SetLineCapsFunc set_linecaps
;
267 SetLineJoinFunc set_linejoin
;
268 SetLineStyleFunc set_linestyle
;
269 SetDashLengthFunc set_dashlength
;
270 /* Fill attributes: */
271 SetFillStyleFunc set_fillstyle
;
273 SetFontFunc set_font
;
276 DrawLineFunc draw_line
;
277 DrawPolyLineFunc draw_polyline
;
280 DrawPolygonFunc draw_polygon
;
281 FillPolygonFunc fill_polygon
;
284 DrawRectangleFunc draw_rect
;
285 FillRectangleFunc fill_rect
;
288 DrawArcFunc draw_arc
;
289 FillArcFunc fill_arc
;
292 DrawEllipseFunc draw_ellipse
;
293 FillEllipseFunc fill_ellipse
;
296 DrawBezierFunc draw_bezier
;
297 FillBezierFunc fill_bezier
;
300 DrawStringFunc draw_string
;
303 DrawImageFunc draw_image
;
305 DrawRoundedRectangleFunc draw_rounded_rect
;
306 FillRoundedRectangleFunc fill_rounded_rect
;
308 DrawLineWithArrowsFunc draw_line_with_arrows
;
309 DrawPolyLineWithArrowsFunc draw_polyline_with_arrows
;
310 DrawArcWithArrowsFunc draw_arc_with_arrows
;
311 DrawBezierWithArrowsFunc draw_bezier_with_arrows
;
313 DrawObjectFunc draw_object
;
316 struct _InteractiveRenderOps
{
317 GetTextWidthFunc get_text_width
;
319 ClipRegionClearFunc clip_region_clear
;
320 ClipRegionAddRectangleFunc clip_region_add_rect
;
322 DrawPixelLineFunc draw_pixel_line
;
323 DrawPixelRectangleFunc draw_pixel_rect
;
324 FillPixelRectangleFunc fill_pixel_rect
;
331 InteractiveRenderOps
*interactive_ops
;
332 int pixel_width
; /* Only needed for interactive renderers.*/
333 int pixel_height
; /* Only needed for interactive renderers.*/
336 /* Use this function to initialize all empty ops slots */
337 void inherit_renderer(Renderer
*child_ops
);
338 RenderOps
*create_renderops_table(void);
340 #endif /* RENDER_H */