From cc528ab2e13a2d518b90df1734e775eea5132169 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Thu, 28 Nov 2002 04:16:22 +0000 Subject: [PATCH] Added commands to center selected objects to center of label. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@190 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/glabels-ui.xml | 22 ++++++++---- glabels2/src/tools.c | 36 ++++++++++++++++++++ glabels2/src/tools.h | 8 +++++ glabels2/src/ui.c | 10 ++++-- glabels2/src/view.c | 68 +++++++++++++++++++++++++++++++++++++ glabels2/src/view.h | 4 +++ 6 files changed, 140 insertions(+), 8 deletions(-) diff --git a/glabels2/src/glabels-ui.xml b/glabels2/src/glabels-ui.xml index 93000ccc..f884ae1e 100644 --- a/glabels2/src/glabels-ui.xml +++ b/glabels2/src/glabels-ui.xml @@ -189,6 +189,14 @@ _tip="Align objects to bottoms" pixtype="stock" pixname="gl_stock_align_bottom"/> + + + + @@ -339,15 +347,17 @@ - - - + + + + - - - + + + + diff --git a/glabels2/src/tools.c b/glabels2/src/tools.c index edffc407..1f1cff0d 100644 --- a/glabels2/src/tools.c +++ b/glabels2/src/tools.c @@ -477,3 +477,39 @@ gl_tools_align_objects_vcenter (BonoboUIComponent *uic, } } +/*****************************************************************************/ +/* Center objects horizontally callback. */ +/*****************************************************************************/ +void +gl_tools_center_objects_horiz (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_center_selection_horiz (GL_VIEW(window->view)); + } +} + +/*****************************************************************************/ +/* Center objects vertically callback. */ +/*****************************************************************************/ +void +gl_tools_center_objects_vert (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_center_selection_vert (GL_VIEW(window->view)); + } +} + diff --git a/glabels2/src/tools.h b/glabels2/src/tools.h index 5f65e5b3..c99df5e9 100644 --- a/glabels2/src/tools.h +++ b/glabels2/src/tools.h @@ -122,6 +122,14 @@ void gl_tools_align_objects_vcenter (BonoboUIComponent *uic, gpointer user_data, const gchar *verbname); +void gl_tools_center_objects_horiz (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_center_objects_vert (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + G_END_DECLS #endif diff --git a/glabels2/src/ui.c b/glabels2/src/ui.c index 0f694bb2..e4f876ef 100644 --- a/glabels2/src/ui.c +++ b/glabels2/src/ui.c @@ -85,6 +85,8 @@ static BonoboUIVerb gl_ui_verbs [] = { BONOBO_UI_VERB ("ToolsAlignTop", gl_tools_align_objects_top), BONOBO_UI_VERB ("ToolsAlignBottom", gl_tools_align_objects_bottom), BONOBO_UI_VERB ("ToolsAlignVCenter", gl_tools_align_objects_vcenter), + BONOBO_UI_VERB ("ToolsCenterHorizontal", gl_tools_center_objects_horiz), + BONOBO_UI_VERB ("ToolsCenterVertical", gl_tools_center_objects_vert), BONOBO_UI_VERB ("SettingsPreferences", gl_cmd_settings_preferences), BONOBO_UI_VERB ("HelpContents", gl_cmd_help_contents), BONOBO_UI_VERB ("About", gl_cmd_help_about), @@ -131,6 +133,8 @@ static gchar* doc_verbs [] = { "/commands/ToolsAlignTop", "/commands/ToolsAlignBottom", "/commands/ToolsAlignVCenter", + "/commands/ToolsCenterHorizontal", + "/commands/ToolsCenterVertical", "/menu/Objects/CreateObjects", "/menu/Objects/Order", "/menu/Objects/RotateFlip", @@ -159,8 +163,12 @@ static gchar* selection_verbs [] = { "/commands/ToolsRotateRight", "/commands/ToolsFlipHorizontal", "/commands/ToolsFlipVertical", + "/commands/ToolsCenterHorizontal", + "/commands/ToolsCenterVertical", "/menu/Objects/Order", "/menu/Objects/RotateFlip", + "/menu/Objects/AlignHoriz", + "/menu/Objects/AlignVert", NULL }; @@ -178,8 +186,6 @@ static gchar* multi_selection_verbs [] = { "/commands/ToolsAlignTop", "/commands/ToolsAlignBottom", "/commands/ToolsAlignVCenter", - "/menu/Objects/AlignHoriz", - "/menu/Objects/AlignVert", NULL }; diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 410842e2..e15f4599 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -2031,6 +2031,74 @@ gl_view_align_selection_vcenter (glView *view) gl_debug (DEBUG_VIEW, "END"); } +/*****************************************************************************/ +/* Center selected objects to in center of label. */ +/*****************************************************************************/ +void +gl_view_center_selection_horiz (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dx, x_label_center, x_obj_center, x1, y1, x2, y2, w, h; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + g_return_if_fail (!gl_view_is_selection_empty (view)); + + gl_label_get_size (view->label, &w, &h); + x_label_center = w / 2.0; + + /* adjust the object positions */ + for (p = view->selected_object_list; p != NULL; p = p->next) { + view_object = GL_VIEW_OBJECT (p->data); + object = gl_view_object_get_object (view_object); + gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); + x_obj_center = (x1 + x2) / 2.0; + dx = x_label_center - x_obj_center; + gl_label_object_set_position_relative (object, dx, 0.0); + } + + gl_debug (DEBUG_VIEW, "END"); +} + + +/*****************************************************************************/ +/* Center selected objects to in center of label. */ +/*****************************************************************************/ +void +gl_view_center_selection_vert (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dy, y_label_center, y_obj_center, x1, y1, x2, y2, w, h; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + g_return_if_fail (!gl_view_is_selection_empty (view)); + + gl_label_get_size (view->label, &w, &h); + y_label_center = h / 2.0; + + /* adjust the object positions */ + for (p = view->selected_object_list; p != NULL; p = p->next) { + view_object = GL_VIEW_OBJECT (p->data); + object = gl_view_object_get_object (view_object); + gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); + y_obj_center = (y1 + y2) / 2.0; + dy = y_label_center - y_obj_center; + gl_label_object_set_position_relative (object, 0.0, dy); + } + + gl_debug (DEBUG_VIEW, "END"); +} + + /*****************************************************************************/ /* "Cut" selected items and place in clipboard selections. */ /*****************************************************************************/ diff --git a/glabels2/src/view.h b/glabels2/src/view.h index f60dd25d..7106eabd 100644 --- a/glabels2/src/view.h +++ b/glabels2/src/view.h @@ -167,6 +167,10 @@ void gl_view_align_selection_bottom (glView *view); void gl_view_align_selection_vcenter (glView *view); +void gl_view_center_selection_horiz (glView *view); + +void gl_view_center_selection_vert (glView *view); + void gl_view_cut (glView *view); void gl_view_copy (glView *view); -- 2.39.5