[dia] transform: use standard GObject macros
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] transform: use standard GObject macros
- Date: Wed, 22 Sep 2021 23:23:55 +0000 (UTC)
commit 6ca280c49ef4e7e87e4f9bf06e907db04fbbc666
Author: Zander Brown <zbrown gnome org>
Date: Wed Sep 22 01:59:15 2021 +0100
transform: use standard GObject macros
Still not sure why this is a GObject and that factor pointer makes me
twitchy
lib/diatransform.c | 66 +++++++++++++++---------------------------------------
lib/diatransform.h | 42 +++++++++++++++++++++-------------
2 files changed, 45 insertions(+), 63 deletions(-)
---
diff --git a/lib/diatransform.c b/lib/diatransform.c
index 5ac873d2e..e50fb2440 100644
--- a/lib/diatransform.c
+++ b/lib/diatransform.c
@@ -22,74 +22,43 @@
#include "diatransform.h"
-typedef struct _DiaTransformClass DiaTransformClass;
-struct _DiaTransform
-{
+struct _DiaTransform {
GObject parent_instance;
/*< private >*/
DiaRectangle *visible; /* pointer to original rectangle for transform_coords */
- real *factor; /* pointer to original factor for transform_length */
+ double *factor; /* pointer to original factor for transform_length */
};
-struct _DiaTransformClass
-{
- GObjectClass parent_class;
-};
+G_DEFINE_TYPE (DiaTransform, dia_transform, G_TYPE_OBJECT)
-static void dia_transform_class_init (DiaTransformClass *klass);
-
-static gpointer parent_class = NULL;
-
-GType
-dia_transform_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type)
- {
- static const GTypeInfo object_info =
- {
- sizeof (DiaTransformClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) dia_transform_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (DiaTransform),
- 0, /* n_preallocs */
- NULL /* init */
- };
-
- object_type = g_type_register_static (G_TYPE_OBJECT,
- "DiaTransform",
- &object_info, 0);
- }
-
- return object_type;
-}
static void
dia_transform_finalize (GObject *object)
{
/* don't free the fields, we don't own them */
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (dia_transform_parent_class)->finalize (object);
}
+
static void
dia_transform_class_init (DiaTransformClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
object_class->finalize = dia_transform_finalize;
+}
+
+static void
+dia_transform_init (DiaTransform *self)
+{
}
+
DiaTransform *
-dia_transform_new (DiaRectangle *rect, real* zoom)
+dia_transform_new (DiaRectangle *rect, double* zoom)
{
DiaTransform *t = g_object_new (DIA_TYPE_TRANSFORM, NULL);
t->visible = rect;
@@ -98,8 +67,9 @@ dia_transform_new (DiaRectangle *rect, real* zoom)
return t;
}
-real
-dia_transform_length (DiaTransform *t, real len)
+
+double
+dia_transform_length (DiaTransform *t, double len)
{
g_return_val_if_fail (DIA_IS_TRANSFORM (t), len);
g_return_val_if_fail (t != NULL && *t->factor != 0.0, len);
@@ -107,9 +77,10 @@ dia_transform_length (DiaTransform *t, real len)
return (len * *(t->factor));
}
+
/* Takes pixel length and returns real length */
-real
-dia_untransform_length(DiaTransform *t, real len)
+double
+dia_untransform_length (DiaTransform *t, double len)
{
g_return_val_if_fail (DIA_IS_TRANSFORM (t), len);
g_return_val_if_fail (t != NULL && *t->factor != 0.0, len);
@@ -146,4 +117,3 @@ dia_transform_coords_double (DiaTransform *t,
*xd = ((x - t->visible->left) * *(t->factor));
*yd = ((y - t->visible->top) * *(t->factor));
}
-
diff --git a/lib/diatransform.h b/lib/diatransform.h
index 8cfb624ed..a54ce6dcd 100644
--- a/lib/diatransform.h
+++ b/lib/diatransform.h
@@ -1,23 +1,37 @@
-#ifndef DIA_TRANSFORM_H
-#define DIA_TRANSFORM_H
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#pragma once
-#include "diatypes.h"
#include <glib-object.h>
+
#include "geometry.h"
G_BEGIN_DECLS
-#define DIA_TYPE_TRANSFORM (dia_transform_get_type ())
-#define DIA_TRANSFORM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_TRANSFORM, DiaTransform))
-#define DIA_TRANSFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_TRANSFORM,
DiaTransformClass))
-#define DIA_IS_TRANSFORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_TRANSFORM))
-#define DIA_TRANSFORM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_TRANSFORM,
DiaTransformClass))
-
-GType dia_transform_get_type (void) G_GNUC_CONST;
+#define DIA_TYPE_TRANSFORM dia_transform_get_type ()
+G_DECLARE_FINAL_TYPE (DiaTransform, dia_transform, DIA, TRANSFORM, GObject)
DiaTransform *dia_transform_new (DiaRectangle *rect,
double *zoom);
-real dia_transform_length (DiaTransform *transform,
+double dia_transform_length (DiaTransform *transform,
double len);
void dia_transform_coords (DiaTransform *transform,
double x,
@@ -29,9 +43,7 @@ void dia_transform_coords_double (DiaTransform *transform,
double y,
double *xd,
double *yd);
-real dia_untransform_length (DiaTransform *t,
- real len);
+double dia_untransform_length (DiaTransform *t,
+ double len);
G_END_DECLS
-
-#endif /* DIA_TRANSFORM_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]