1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * diatransform.c - scaling indirection to connect display
6 * Copyright (C) 2002 Hans Breuer (refactoring)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "diatransform.h"
25 typedef struct _DiaTransformClass DiaTransformClass
;
29 GObject parent_instance
;
31 Rectangle
*visible
; /* pointer to original rectangle for transform_coords */
32 real
*factor
; /* pointer to original factor for transform_length */
35 struct _DiaTransformClass
37 GObjectClass parent_class
;
40 static void dia_transform_class_init (DiaTransformClass
*klass
);
42 static gpointer parent_class
= NULL
;
45 dia_transform_get_type (void)
47 static GType object_type
= 0;
51 static const GTypeInfo object_info
=
53 sizeof (DiaTransformClass
),
55 (GBaseFinalizeFunc
) NULL
,
56 (GClassInitFunc
) dia_transform_class_init
,
57 NULL
, /* class_finalize */
58 NULL
, /* class_data */
59 sizeof (DiaTransform
),
64 object_type
= g_type_register_static (G_TYPE_OBJECT
,
73 dia_transform_finalize (GObject
*object
)
75 /* don't free the fields, we don't own them */
77 G_OBJECT_CLASS (parent_class
)->finalize (object
);
81 dia_transform_class_init (DiaTransformClass
*klass
)
83 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
85 parent_class
= g_type_class_peek_parent (klass
);
87 object_class
->finalize
= dia_transform_finalize
;
92 dia_transform_new (Rectangle
*rect
, real
* zoom
)
94 DiaTransform
*t
= g_object_new (DIA_TYPE_TRANSFORM
, NULL
);
102 dia_transform_length (DiaTransform
*t
, real len
)
104 g_return_val_if_fail (DIA_IS_TRANSFORM (t
), len
);
105 g_return_val_if_fail (t
!= NULL
&& *t
->factor
!= 0.0, len
);
107 return (len
* *(t
->factor
));
110 /* Takes pixel length and returns real length */
112 dia_untransform_length(DiaTransform
*t
, real len
)
114 g_return_val_if_fail (DIA_IS_TRANSFORM (t
), len
);
115 g_return_val_if_fail (t
!= NULL
&& *t
->factor
!= 0.0, len
);
117 return len
/ *(t
->factor
);
121 dia_transform_coords (DiaTransform
*t
,
125 g_return_if_fail (DIA_IS_TRANSFORM (t
));
126 g_return_if_fail (t
!= NULL
&& t
->factor
!= NULL
);
128 *xi
= ROUND ( (x
- t
->visible
->left
) * *(t
->factor
));
129 *yi
= ROUND ( (y
- t
->visible
->top
) * *(t
->factor
));
133 dia_transform_coords_double (DiaTransform
*t
,
135 double *xd
, double *yd
)
137 g_return_if_fail (DIA_IS_TRANSFORM (t
));
138 g_return_if_fail (t
!= NULL
&& t
->factor
!= NULL
);
140 *xd
= ((x
- t
->visible
->left
) * *(t
->factor
));
141 *yd
= ((y
- t
->visible
->top
) * *(t
->factor
));