* installer/win32/dia.nsi: don't uninstall old version; overwrite
[dia.git] / lib / render.h
blob4a285aedaa9ebad407a5be82c2f13ae066cd38a3
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.
18 #ifndef RENDER_H
19 #define RENDER_H
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"
27 #include "geometry.h"
28 typedef struct _DiaFont DiaFont;
29 typedef struct _Color Color;
30 typedef struct _DiaImage* DiaImage;
31 #include "arrows.h"
32 #include "object.h"
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,
73 Color *color);
75 /* Draw a line joining multiple points, using color and the current
76 line style */
77 typedef void (*DrawPolyLineFunc) (Renderer *renderer,
78 Point *points, int num_points,
79 Color *color);
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
83 last point */
84 typedef void (*DrawPolygonFunc) (Renderer *renderer,
85 Point *points, int num_points,
86 Color *color);
88 /* Same a DrawPolygonFunc, expect the polygon is filled using the current
89 fill type */
90 typedef void (*FillPolygonFunc) (Renderer *renderer,
91 Point *points, int num_points,
92 Color *color);
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,
97 Color *color);
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,
103 Color *color);
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,
119 Point *center,
120 real width, real height,
121 real angle1, real angle2,
122 Color *color);
124 /* Same a DrawArcFunc except the arc is filled (a pie-chart) */
125 typedef void (*FillArcFunc) (Renderer *renderer,
126 Point *center,
127 real width, real height,
128 real angle1, real angle2,
129 Color *color);
131 /* Draw an ellipse, given its center and the bounding box */
132 typedef void (*DrawEllipseFunc) (Renderer *renderer,
133 Point *center,
134 real width, real height,
135 Color *color);
137 /* Same a DrawEllipse, except the ellips is filled */
138 typedef void (*FillEllipseFunc) (Renderer *renderer,
139 Point *center,
140 real width, real height,
141 Color *color);
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
145 * MOVE_TO's.
147 typedef void (*DrawBezierFunc) (Renderer *renderer,
148 BezPoint *points,
149 int numpoints,
150 Color *color);
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,
155 BezPoint *points,
156 int numpoints,
157 Color *color);
159 /* Print a string at pos, using the current font */
160 typedef void (*DrawStringFunc) (Renderer *renderer,
161 const gchar *text,
162 Point *pos,
163 Alignment alignment,
164 Color *color);
166 /* Draw an image, given its bounding box */
167 typedef void (*DrawImageFunc) (Renderer *renderer,
168 Point *point,
169 real width, real height,
170 DiaImage image);
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
188 renderers.
190 typedef void (*ClipRegionClearFunc) (Renderer *renderer);
192 /* Add a rectangle to the current clipping region.
193 This function needs only be defined for interactive
194 renderers.
196 typedef void (*ClipRegionAddRectangleFunc) (Renderer *renderer,
197 Rectangle *rect);
199 /* Draw a line from start to end, using color and the current line style */
200 typedef void (*DrawPixelLineFunc) (Renderer *renderer,
201 int x1, int y1,
202 int x2, int y2,
203 Color *color);
205 /* Draw a rectangle, given its upper-left and lower-right corners
206 in pixels.
208 typedef void (*DrawPixelRectangleFunc) (Renderer *renderer,
209 int x, int y,
210 int width, int height,
211 Color *color);
213 /* Same a DrawPixelRectangleFunc, except the rectangle is filled using the
214 current fill style */
215 typedef void (*FillPixelRectangleFunc) (Renderer *renderer,
216 int x, int y,
217 int width, int height,
218 Color *color);
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,
227 real line_width,
228 Color *color,
229 Arrow *start_arrow,
230 Arrow *end_arrow);
232 typedef void (*DrawPolyLineWithArrowsFunc) (Renderer *renderer,
233 Point *points, int num_points,
234 real line_width,
235 Color *color,
236 Arrow *start_arrow,
237 Arrow *end_arrow);
239 /* Note that this is different from the normal DrawArc function */
240 typedef void (*DrawArcWithArrowsFunc) (Renderer *renderer,
241 Point *start, Point *end,
242 Point *mid,
243 real line_width,
244 Color *color,
245 Arrow *start_arrow,
246 Arrow *end_arrow);
248 typedef void (*DrawBezierWithArrowsFunc) (Renderer *renderer,
249 BezPoint *points,
250 int num_points,
251 real line_width,
252 Color *color,
253 Arrow *start_arrow,
254 Arrow *end_arrow);
256 typedef void (*DrawObjectFunc) (Renderer *renderer,
257 DiaObject *object);
259 struct _RenderOps {
260 /* Control ops: */
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;
272 /* DiaFont stuff: */
273 SetFontFunc set_font;
275 /* Lines: */
276 DrawLineFunc draw_line;
277 DrawPolyLineFunc draw_polyline;
279 /* Polygons: */
280 DrawPolygonFunc draw_polygon;
281 FillPolygonFunc fill_polygon;
283 /* Rectangles: */
284 DrawRectangleFunc draw_rect;
285 FillRectangleFunc fill_rect;
287 /* Arcs: */
288 DrawArcFunc draw_arc;
289 FillArcFunc fill_arc;
291 /* Ellipses: */
292 DrawEllipseFunc draw_ellipse;
293 FillEllipseFunc fill_ellipse;
295 /* Bezier curves: */
296 DrawBezierFunc draw_bezier;
297 FillBezierFunc fill_bezier;
299 /* Text: */
300 DrawStringFunc draw_string;
302 /* Images: */
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;
327 struct _Renderer {
328 RenderOps *ops;
330 int is_interactive;
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 */