1 /* Dia -- an diagram creation/manipulation program 2 * Copyright (C) 1998 Alexander Larsson 3 * 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. 8 * 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. 13 * 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. 17 */ 18 19 /*! \file diarenderer.h -- the basic renderer interface definition */ 20 #ifndef DIA_RENDERER_H 21 #define DIA_RENDERER_H 22 23 #include "diatypes.h" 24 #include <glib-object.h> 25 26 #include "dia-enums.h" 27 #include "geometry.h" 28 #include "font.h" /* not strictly needed by this header, but needed in almost any plug-in/ */ 29 30 G_BEGIN_DECLS 31 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)) 42 43 GType dia_renderer_get_type (void) G_GNUC_CONST; 44 45 /*! \brief The member variables part of _DiaRenderer */ 46 struct _DiaRenderer 47 { 48 GObject parent_instance; /*!< inheritance in object oriented C */ 49 gboolean is_interactive; /*!< if the user can interact */ 50 /*< private >*/ 51 DiaFont *font; 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 55 */ 56 BezierApprox *bezier; 57 }; 58 59 /*! 60 * \class _DiaRendererClass 61 * 62 * \brief Base class for all of Dia's render facilities 63 * 64 * Renderers work in close cooperation with DiaObject. They provide the way to 65 * make all the object drawing independent of concrete drawing backends 66 */ 67 struct _DiaRendererClass 68 { 69 GObjectClass parent_class; /*!< the base class */ 70 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. 81 */ 82 real (*get_text_width) (DiaRenderer *renderer, 83 const gchar *text, int length); 84 85 86 /* 87 * Function which MUST be implemented by any DiaRenderer 88 */ 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 *); 95 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); 112 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, 116 Color *color); 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, 120 Color *color); 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, 124 Color *color); 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, 128 Point *center, 129 real width, real height, 130 real angle1, real angle2, 131 Color *color); 132 /*! Same a DrawArcFunc except the arc is filled (a pie-chart) */ 133 void (*fill_arc) (DiaRenderer *renderer, 134 Point *center, 135 real width, real height, 136 real angle1, real angle2, 137 Color *color); 138 /*! Draw an ellipse, given its center and the bounding box */ 139 void (*draw_ellipse) (DiaRenderer *renderer, 140 Point *center, 141 real width, real height, 142 Color *color); 143 /*! Same a DrawEllipse, except the ellips is filled */ 144 void (*fill_ellipse) (DiaRenderer *renderer, 145 Point *center, 146 real width, real height, 147 Color *color); 148 /*! Print a string at pos, using the current font */ 149 void (*draw_string) (DiaRenderer *renderer, 150 const gchar *text, 151 Point *pos, 152 Alignment alignment, 153 Color *color); 154 /*! Draw an image, given its bounding box */ 155 void (*draw_image) (DiaRenderer *renderer, 156 Point *point, 157 real width, real height, 158 DiaImage *image); 159 160 /* 161 * Functions which SHOULD be implemented by specific renderer, but 162 * have a default implementation based on the above functions 163 */ 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, 167 BezPoint *points, 168 int numpoints, 169 Color *color); 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, 173 BezPoint *points, 174 int numpoints, 175 Color *color); 176 /*! Draw a line joining multiple points, using color and the current 177 line style */ 178 void (*draw_polyline) (DiaRenderer *renderer, 179 Point *points, int num_points, 180 Color *color); 181 /*! Draw a polygone, using the current line style 182 The polygon is closed even if the first point is not the same as the 183 last point */ 184 void (*draw_polygon) (DiaRenderer *renderer, 185 Point *points, int num_points, 186 Color *color); 187 /*! Print a Text. It holds its own information. */ 188 void (*draw_text) (DiaRenderer *renderer, 189 Text *text); 190 /*! Print a TextLine. It holds its own font/size information. */ 191 void (*draw_text_line) (DiaRenderer *renderer, 192 TextLine *text_line, Point *pos, Alignment alignment, Color *color); 193 /*! Draw a rectangle, given its upper-left and lower-right corners */ 194 void (*draw_rect) (DiaRenderer *renderer, 195 Point *ul_corner, Point *lr_corner, 196 Color *color); 197 198 /* 199 * Highest level functions, probably only to be implemented by 200 * special 'high level' renderers 201 */ 202 /*! Draw a rounded rectangle, given its upper-left and lower-right corners */ 203 void (*draw_rounded_rect) (DiaRenderer *renderer, 204 Point *ul_corner, Point *lr_corner, 205 Color *color, real radius); 206 /*! Same a DrawRoundedRectangleFunc, except the rectangle is filled using the 207 current fill style */ 208 void (*fill_rounded_rect) (DiaRenderer *renderer, 209 Point *ul_corner, Point *lr_corner, 210 Color *color, real radius); 211 /*! Draw a line joining multiple points, using color and the current 212 line style with rounded corners between segments */ 213 void (*draw_rounded_polyline) (DiaRenderer *renderer, 214 Point *points, int num_points, 215 Color *color, real radius ); 216 217 /*! Highest level function doing specific arrow positioning */ 218 void (*draw_line_with_arrows) (DiaRenderer *renderer, 219 Point *start, Point *end, 220 real line_width, 221 Color *line_color, 222 Arrow *start_arrow, 223 Arrow *end_arrow); 224 /*! Highest level function doing specific arrow positioning */ 225 void (*draw_arc_with_arrows) (DiaRenderer *renderer, 226 Point *start, Point *end, 227 Point *midpoint, 228 real line_width, 229 Color *color, 230 Arrow *start_arrow, 231 Arrow *end_arrow); 232 /*! Highest level function doing specific arrow positioning */ 233 void (*draw_polyline_with_arrows) (DiaRenderer *renderer, 234 Point *points, int num_points, 235 real line_width, 236 Color *color, 237 Arrow *start_arrow, 238 Arrow *end_arrow); 239 void (*draw_rounded_polyline_with_arrows) (DiaRenderer *renderer, 240 Point *points, int num_points, 241 real line_width, 242 Color *color, 243 Arrow *start_arrow, 244 Arrow *end_arrow, 245 real radius); 246 247 void (*draw_bezier_with_arrows) (DiaRenderer *renderer, 248 BezPoint *points, 249 int num_points, 250 real line_width, 251 Color *color, 252 Arrow *start_arrow, 253 Arrow *end_arrow); 254 }; 255 256 /* 257 * Declare the Interactive Renderer Interface, which get's added 258 * to some renderer classes by app/ 259 */ 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)) 262 263 struct _DiaInteractiveRendererInterface 264 { 265 GTypeInterface base_iface; 266 267 /* Clear the current clipping region. */ 268 void (*set_size) (DiaRenderer *renderer, gpointer, int, int); 269 270 /* Clear the current clipping region. */ 271 void (*clip_region_clear) (DiaRenderer *renderer); 272 273 /* Add a rectangle to the current clipping region. */ 274 void (*clip_region_add_rect) (DiaRenderer *renderer, Rectangle *rect); 275 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, 279 Color *color); 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, 283 Color *color); 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, 287 Color *color); 288 289 void (*copy_to_window) (DiaRenderer *renderer, 290 gpointer window, 291 int x, int y, int width, int height); 292 }; 293 294 GType dia_interactive_renderer_interface_get_type (void) G_GNUC_CONST; 295 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*); 299 300 G_END_DECLS 301 302 #endif /* DIA_RENDERER_H */ 303