From 7d676b96b7ee534ab36054be2febb8086eeef278 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 14 Oct 2002 01:53:36 +0000 Subject: [PATCH] Includes support for flipping. Added function for copying properties from one object to another. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@161 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/label-object.c | 111 +++++++++++++++++++++++++++++++++++- glabels2/src/label-object.h | 40 +++++++++++-- 2 files changed, 143 insertions(+), 8 deletions(-) diff --git a/glabels2/src/label-object.c b/glabels2/src/label-object.c index 4499b57b..03eecf6a 100644 --- a/glabels2/src/label-object.c +++ b/glabels2/src/label-object.c @@ -32,14 +32,17 @@ /*========================================================*/ struct _glLabelObjectPrivate { - gchar *name; - gdouble x, y; - gdouble w, h; + gchar *name; + gdouble x, y; + gdouble w, h; + glLabelObjectFlip flip; + gdouble rotate_degs; }; enum { CHANGED, MOVED, + FLIP_ROTATE, TOP, BOTTOM, LAST_SIGNAL @@ -125,6 +128,15 @@ gl_label_object_class_init (glLabelObjectClass *klass) gl_marshal_VOID__DOUBLE_DOUBLE, G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE); + signals[FLIP_ROTATE] = + g_signal_new ("flip_rotate", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glLabelObjectClass, flip_rotate), + NULL, NULL, + gl_marshal_VOID__INT_DOUBLE, + G_TYPE_NONE, + 2, G_TYPE_INT, G_TYPE_DOUBLE); signals[TOP] = g_signal_new ("top", G_OBJECT_CLASS_TYPE (object_class), @@ -179,6 +191,9 @@ gl_label_object_finalize (GObject *object) gl_debug (DEBUG_LABEL, "END"); } +/*****************************************************************************/ +/* New label object. */ +/*****************************************************************************/ GObject * gl_label_object_new (glLabel *label) { @@ -195,6 +210,28 @@ gl_label_object_new (glLabel *label) return G_OBJECT (object); } +/*****************************************************************************/ +/* Copy properties of one label object to another. */ +/*****************************************************************************/ +void +gl_label_object_copy_props (glLabelObject *dst_object, + glLabelObject *src_object) +{ + gdouble x, y, w, h; + glLabelObjectFlip flip; + + g_return_if_fail (src_object && GL_IS_LABEL_OBJECT (src_object)); + g_return_if_fail (dst_object && GL_IS_LABEL_OBJECT (dst_object)); + + gl_label_object_get_position (src_object, &x, &y); + gl_label_object_get_size (src_object, &w, &h); + flip = gl_label_object_get_flip (src_object); + + gl_label_object_set_position (dst_object, x, y); + gl_label_object_set_size (dst_object, w, h); + gl_label_object_set_flip (dst_object, flip); +} + /*****************************************************************************/ /* Emit "changed" signal (for derived objects). */ /*****************************************************************************/ @@ -395,6 +432,74 @@ gl_label_object_get_size (glLabelObject *object, gl_debug (DEBUG_LABEL, "END"); } +/****************************************************************************/ +/* Set flip state of object. */ +/****************************************************************************/ +void +gl_label_object_set_flip (glLabelObject *object, + glLabelObjectFlip flip) +{ + gl_debug (DEBUG_LABEL, "START"); + + g_return_if_fail (object && GL_IS_LABEL_OBJECT (object)); + + object->private->flip = flip; + + g_signal_emit (G_OBJECT(object), signals[FLIP_ROTATE], 0, + flip, object->private->rotate_degs); + + gl_debug (DEBUG_LABEL, "END"); +} + +/****************************************************************************/ +/* Flip object horizontally. */ +/****************************************************************************/ +void +gl_label_object_flip_horiz (glLabelObject *object) +{ + gl_debug (DEBUG_LABEL, "START"); + + g_return_if_fail (object && GL_IS_LABEL_OBJECT (object)); + + object->private->flip ^= GL_LABEL_OBJECT_FLIP_HORIZ; + + g_signal_emit (G_OBJECT(object), signals[FLIP_ROTATE], 0, + object->private->flip, object->private->rotate_degs); + + gl_debug (DEBUG_LABEL, "END"); +} + +/****************************************************************************/ +/* Flip object vertically. */ +/****************************************************************************/ +void +gl_label_object_flip_vert (glLabelObject *object) +{ + gl_debug (DEBUG_LABEL, "START"); + + g_return_if_fail (object && GL_IS_LABEL_OBJECT (object)); + + object->private->flip ^= GL_LABEL_OBJECT_FLIP_VERT; + + g_signal_emit (G_OBJECT(object), signals[FLIP_ROTATE], 0, + object->private->flip, object->private->rotate_degs); + + gl_debug (DEBUG_LABEL, "END"); +} + +/****************************************************************************/ +/* Get flip state of object. */ +/****************************************************************************/ +glLabelObjectFlip +gl_label_object_get_flip (glLabelObject *object) +{ + gl_debug (DEBUG_LABEL, ""); + + g_return_if_fail (object && GL_IS_LABEL_OBJECT (object)); + + return object->private->flip; +} + /****************************************************************************/ /* Bring label object to front/top. */ /****************************************************************************/ diff --git a/glabels2/src/label-object.h b/glabels2/src/label-object.h index 1a24cf68..0e7d4df8 100644 --- a/glabels2/src/label-object.h +++ b/glabels2/src/label-object.h @@ -38,6 +38,13 @@ typedef enum { GL_LABEL_OBJECT_N_TYPES } glLabelObjectType; +typedef enum { + GL_LABEL_OBJECT_FLIP_NONE = 0, + GL_LABEL_OBJECT_FLIP_HORIZ = 1, + GL_LABEL_OBJECT_FLIP_VERT = 2, + GL_LABEL_OBJECT_FLIP_BOTH = (GL_LABEL_OBJECT_FLIP_HORIZ|GL_LABEL_OBJECT_FLIP_VERT) +} glLabelObjectFlip; + #define GL_TYPE_LABEL_OBJECT (gl_label_object_get_type ()) #define GL_LABEL_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_LABEL_OBJECT, glLabelObject)) @@ -63,19 +70,33 @@ struct _glLabelObject { struct _glLabelObjectClass { GObjectClass parent_class; - void (*changed) (glLabelObject *object, gpointer user_data); + void (*changed) (glLabelObject *object, + gpointer user_data); + + void (*moved) (glLabelObject *object, + gdouble dx, + gdouble dy, + gpointer user_data); - void (*moved) (glLabelObject *object, - gdouble dx, gdouble dy, gpointer user_data); + void (*flip_rotate) (glLabelObject *object, + glLabelObjectFlip flip, + gdouble rotate, + gpointer user_data); - void (*top) (glLabelObject *object, gpointer user_data); - void (*bottom) (glLabelObject *object, gpointer user_data); + void (*top) (glLabelObject *object, + gpointer user_data); + + void (*bottom) (glLabelObject *object, + gpointer user_data); }; GType gl_label_object_get_type (void); GObject *gl_label_object_new (glLabel *label); +void gl_label_object_copy_props (glLabelObject *dst_object, + glLabelObject *src_object); + void gl_label_object_emit_changed (glLabelObject *object); void gl_label_object_set_parent (glLabelObject *object, @@ -105,6 +126,15 @@ void gl_label_object_get_size (glLabelObject *object, void gl_label_object_raise_to_top (glLabelObject *object); void gl_label_object_lower_to_bottom (glLabelObject *object); +void gl_label_object_set_flip (glLabelObject *object, + glLabelObjectFlip flip); + +void gl_label_object_flip_horiz (glLabelObject *object); + +void gl_label_object_flip_vert (glLabelObject *object); + +glLabelObjectFlip gl_label_object_get_flip (glLabelObject *object); + G_END_DECLS #endif /* __LABEL_OBJECT_H__ */ -- 2.39.5