From 623487f31e674765adf3d543e7752ad6dae0f735 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Sat, 10 Jan 2009 21:13:38 +0100 Subject: [PATCH] [AdgPath] Removed cairo wrappers Useless declarations of cairo wrappers API has been removed and the AdgEntity::invalidate() infrastructure is used instead of the old clear() method. --- adg/adg-path-private.h | 9 ++- adg/adg-path.c | 50 ++++++-------- adg/adg-path.h | 178 ++++++++++++++++++------------------------------- docs/adg-sections.txt | 15 ----- 4 files changed, 90 insertions(+), 162 deletions(-) rewrite adg/adg-path.h (61%) diff --git a/adg/adg-path-private.h b/adg/adg-path-private.h index a6b08576..9c70888d 100644 --- a/adg/adg-path-private.h +++ b/adg/adg-path-private.h @@ -21,17 +21,16 @@ #ifndef __ADG_PATH_PRIVATE_H__ #define __ADG_PATH_PRIVATE_H__ -#include -#include #include G_BEGIN_DECLS struct _AdgPathPrivate { - CpmlPair cp; - cairo_path_t *cairo_path; - AdgCallback callback; + /* Cache */ + AdgPair cp; + cairo_path_t *cairo_path; + AdgCallback callback; }; G_END_DECLS diff --git a/adg/adg-path.c b/adg/adg-path.c index e8b8a22f..0fb45264 100644 --- a/adg/adg-path.c +++ b/adg/adg-path.c @@ -36,23 +36,16 @@ #include #define PARENT_CLASS ((AdgEntityClass *) adg_path_parent_class) -#define ARC_TOLERANCE 0.1 - - -typedef enum _Direction Direction; -enum _Direction { - DIRECTION_FORWARD, - DIRECTION_REVERSE -}; static void finalize (GObject *object); +static void invalidate (AdgEntity *entity); static void render (AdgEntity *entity, cairo_t *cr); -static void clear (AdgPath *path); +static void clear_path_cache (AdgPath *path); -G_DEFINE_TYPE(AdgPath, adg_path, ADG_TYPE_ENTITY); +G_DEFINE_TYPE(AdgPath, adg_path, ADG_TYPE_ENTITY) static void @@ -68,9 +61,8 @@ adg_path_class_init(AdgPathClass *klass) gobject_class->finalize = finalize; + entity_class->invalidate = invalidate; entity_class->render = render; - - klass->clear = clear; } static void @@ -90,7 +82,8 @@ adg_path_init(AdgPath *path) static void finalize(GObject *object) { - ADG_PATH_GET_CLASS(object)->clear((AdgPath *) object); + clear_path_cache((AdgPath *) object); + ((GObjectClass *) PARENT_CLASS)->finalize(object); } @@ -103,7 +96,7 @@ finalize(GObject *object) * the cairo context after the @callback call. * * Return value: the new entity - */ + **/ AdgEntity * adg_path_new(AdgCallback callback) { @@ -115,14 +108,6 @@ adg_path_new(AdgCallback callback) return entity; } -void -adg_path_clear(AdgPath *path) -{ - g_return_if_fail(ADG_IS_PATH(path)); - ADG_PATH_GET_CLASS(path)->clear(path); -} - - const cairo_path_t * adg_path_get_cairo_path(AdgPath *path) { @@ -174,6 +159,14 @@ adg_path_dump(AdgPath *path) static void +invalidate(AdgEntity *entity) +{ + clear_path_cache((AdgPath *) entity); + + PARENT_CLASS->invalidate(entity); +} + +static void render(AdgEntity *entity, cairo_t *cr) { AdgPath *path = (AdgPath *) entity; @@ -199,13 +192,14 @@ render(AdgEntity *entity, cairo_t *cr) } static void -clear(AdgPath *path) +clear_path_cache(AdgPath *path) { - if (path->priv->cairo_path != NULL) { - cairo_path_destroy(path->priv->cairo_path); - path->priv->cairo_path = NULL; + AdgPathPrivate *priv = path->priv; + + if (priv->cairo_path != NULL) { + cairo_path_destroy(priv->cairo_path); + priv->cairo_path = NULL; } - path->priv->cp.x = 0.; - path->priv->cp.y = 0.; + priv->cp.x = priv->cp.y = 0.; } diff --git a/adg/adg-path.h b/adg/adg-path.h dissimilarity index 61% index 5ad73159..4503633f 100644 --- a/adg/adg-path.h +++ b/adg/adg-path.h @@ -1,114 +1,64 @@ -/* ADG - Automatic Drawing Generation - * Copyright (C) 2007-2008, Nicola Fontana - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#ifndef __ADG_PATH_H__ -#define __ADG_PATH_H__ - -#include - - -G_BEGIN_DECLS - -#define ADG_TYPE_PATH (adg_path_get_type ()) -#define ADG_PATH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ADG_TYPE_PATH, AdgPath)) -#define ADG_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ADG_TYPE_PATH, AdgPathClass)) -#define ADG_IS_PATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ADG_TYPE_PATH)) -#define ADG_IS_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ADG_TYPE_PATH)) -#define ADG_PATH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ADG_TYPE_PATH, AdgPathClass)) - -typedef struct _AdgPath AdgPath; -typedef struct _AdgPathClass AdgPathClass; -typedef struct _AdgPathPrivate AdgPathPrivate; - -struct _AdgPath { - AdgEntity entity; - /*< private >*/ - AdgPathPrivate *priv; -}; - -struct _AdgPathClass { - AdgEntityClass parent_class; - - void (*clear) (AdgPath *path); -}; - - -GType adg_path_get_type (void) G_GNUC_CONST; -AdgEntity * adg_path_new (AdgCallback callback); -void adg_path_clear (AdgPath *path); -const cairo_path_t * - adg_path_get_cairo_path (AdgPath *path); -void adg_path_chain_ymirror (AdgPath *path); -void adg_path_dump (AdgPath *path); - -/* Cairo wrappers */ -gboolean adg_path_get_current_point (AdgPath *path, - double *x, - double *y); -void adg_path_close (AdgPath *path); -void adg_path_arc (AdgPath *path, - double xc, - double yc, - double radius, - double angle1, - double angle2); -void adg_path_arc_negative (AdgPath *path, - double xc, - double yc, - double radius, - double angle1, - double angle2); -void adg_path_curve_to (AdgPath *path, - double x1, - double y1, - double x2, - double y2, - double x3, - double y3); -void adg_path_line_to (AdgPath *path, - double x, - double y); -void adg_path_move_to (AdgPath *path, - double x, - double y); -void adg_path_rectangle (AdgPath *path, - double x, - double y, - double width, - double height); -void adg_path_rel_curve_to (AdgPath *path, - double dx1, - double dy1, - double dx2, - double dy2, - double dx3, - double dy3); -void adg_path_rel_line_to (AdgPath *path, - double dx, - double dy); -void adg_path_rel_move_to (AdgPath *path, - double dx, - double dy); - - -G_END_DECLS - - -#endif /* __ADG_PATH_H__ */ +/* ADG - Automatic Drawing Generation + * Copyright (C) 2007-2008, Nicola Fontana + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __ADG_PATH_H__ +#define __ADG_PATH_H__ + +#include + + +G_BEGIN_DECLS + +#define ADG_TYPE_PATH (adg_path_get_type ()) +#define ADG_PATH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ADG_TYPE_PATH, AdgPath)) +#define ADG_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ADG_TYPE_PATH, AdgPathClass)) +#define ADG_IS_PATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ADG_TYPE_PATH)) +#define ADG_IS_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ADG_TYPE_PATH)) +#define ADG_PATH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ADG_TYPE_PATH, AdgPathClass)) + +typedef struct _AdgPath AdgPath; +typedef struct _AdgPathClass AdgPathClass; +typedef struct _AdgPathPrivate AdgPathPrivate; + +struct _AdgPath { + AdgEntity entity; + + /*< private >*/ + AdgPathPrivate *priv; +}; + +struct _AdgPathClass { + AdgEntityClass parent_class; + + /* Virtual table */ + void (*clear) (AdgPath *path); +}; + + +GType adg_path_get_type (void) G_GNUC_CONST; +AdgEntity * adg_path_new (AdgCallback callback); +const cairo_path_t * + adg_path_get_cairo_path (AdgPath *path); +void adg_path_dump (AdgPath *path); + +G_END_DECLS + + +#endif /* __ADG_PATH_H__ */ diff --git a/docs/adg-sections.txt b/docs/adg-sections.txt index 8174c2f8..c86ec655 100644 --- a/docs/adg-sections.txt +++ b/docs/adg-sections.txt @@ -432,23 +432,8 @@ AdgPath adg_path_new -adg_path_clear adg_path_get_cairo_path adg_path_dump - -adg_path_move_to -adg_path_line_to -adg_path_curve_to -adg_path_arc -adg_path_arc_negative -adg_path_rectangle -adg_path_close -adg_path_rel_move_to -adg_path_rel_line_to -adg_path_rel_curve_to -adg_path_get_current_point - -adg_path_chain_ymirror AdgPathClass AdgPathPrivate -- 2.11.4.GIT