From: Jim Evins Date: Mon, 25 Nov 2002 02:15:16 +0000 (+0000) Subject: Added object alignment commands. X-Git-Tag: glabels-2_3_0~705 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e745ae478b6bada6bac871e50d084b9cb4ce93d1;p=glabels Added object alignment commands. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@182 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/src/glabels-ui.xml b/glabels2/src/glabels-ui.xml index 9c00a0f3..57ade849 100644 --- a/glabels2/src/glabels-ui.xml +++ b/glabels2/src/glabels-ui.xml @@ -160,22 +160,28 @@ _tip="Flip object vertically"/> + _tip="Align objects to left edges" + pixtype="stock" pixname="gl_stock_align_left"/> - + + _tip="Align objects to right edges" + pixtype="stock" pixname="gl_stock_align_right"/> + _tip="Align objects to tops" + pixtype="stock" pixname="gl_stock_align_top"/> - + + _tip="Align objects to bottoms" + pixtype="stock" pixname="gl_stock_align_bottom"/> + + + + + + + + + diff --git a/glabels2/src/tools.c b/glabels2/src/tools.c index 4744f867..edffc407 100644 --- a/glabels2/src/tools.c +++ b/glabels2/src/tools.c @@ -369,3 +369,111 @@ gl_tools_flip_objects_vert (BonoboUIComponent *uic, } } +/*****************************************************************************/ +/* Align objects left callback. */ +/*****************************************************************************/ +void +gl_tools_align_objects_left (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_align_selection_left (GL_VIEW(window->view)); + } +} + +/*****************************************************************************/ +/* Align objects right callback. */ +/*****************************************************************************/ +void +gl_tools_align_objects_right (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_align_selection_right (GL_VIEW(window->view)); + } +} + +/*****************************************************************************/ +/* Align objects horizontal center callback. */ +/*****************************************************************************/ +void +gl_tools_align_objects_hcenter (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_align_selection_hcenter (GL_VIEW(window->view)); + } +} + +/*****************************************************************************/ +/* Align objects top callback. */ +/*****************************************************************************/ +void +gl_tools_align_objects_top (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_align_selection_top (GL_VIEW(window->view)); + } +} + +/*****************************************************************************/ +/* Align objects bottom callback. */ +/*****************************************************************************/ +void +gl_tools_align_objects_bottom (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_align_selection_bottom (GL_VIEW(window->view)); + } +} + +/*****************************************************************************/ +/* Align objects vertical center callback. */ +/*****************************************************************************/ +void +gl_tools_align_objects_vcenter (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_align_selection_vcenter (GL_VIEW(window->view)); + } +} + diff --git a/glabels2/src/tools.h b/glabels2/src/tools.h index 2c205cf4..5f65e5b3 100644 --- a/glabels2/src/tools.h +++ b/glabels2/src/tools.h @@ -98,6 +98,30 @@ void gl_tools_flip_objects_vert (BonoboUIComponent *uic, gpointer user_data, const gchar *verbname); +void gl_tools_align_objects_left (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_align_objects_right (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_align_objects_hcenter (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_align_objects_top (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_align_objects_bottom (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_align_objects_vcenter (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 68e414ca..9232ec41 100644 --- a/glabels2/src/ui.c +++ b/glabels2/src/ui.c @@ -33,55 +33,61 @@ #include "debug.h" -/*=======================================================================================*/ -/* Private macros and constants. */ -/*=======================================================================================*/ +/*==========================================================================*/ +/* Private macros and constants. */ +/*==========================================================================*/ #define GLABELS_UI_XML GLABELS_UI_DIR "glabels-ui.xml" -/*=======================================================================================*/ -/* Private types. */ -/*=======================================================================================*/ +/*==========================================================================*/ +/* Private types. */ +/*==========================================================================*/ -/*=======================================================================================*/ -/* Private globals */ -/*=======================================================================================*/ +/*==========================================================================*/ +/* Private globals */ +/*==========================================================================*/ static BonoboUIVerb gl_ui_verbs [] = { - BONOBO_UI_VERB ("FileNew", gl_cmd_file_new), - BONOBO_UI_VERB ("FileOpen", gl_cmd_file_open), - BONOBO_UI_VERB ("FileSave", gl_cmd_file_save), - BONOBO_UI_VERB ("FileSaveAs", gl_cmd_file_save_as), - BONOBO_UI_VERB ("FilePrint", gl_cmd_file_print), - BONOBO_UI_VERB ("FileClose", gl_cmd_file_close), - BONOBO_UI_VERB ("FileExit", gl_cmd_file_exit), - BONOBO_UI_VERB ("EditCut", gl_cmd_edit_cut), - BONOBO_UI_VERB ("EditCopy", gl_cmd_edit_copy), - BONOBO_UI_VERB ("EditPaste", gl_cmd_edit_paste), - BONOBO_UI_VERB ("EditDelete", gl_cmd_edit_delete), - BONOBO_UI_VERB ("EditSelectAll", gl_cmd_edit_select_all), - BONOBO_UI_VERB ("EditUnSelectAll", gl_cmd_edit_unselect_all), - BONOBO_UI_VERB ("ToolsArrow", gl_tools_arrow), - BONOBO_UI_VERB ("ToolsText", gl_tools_text), - BONOBO_UI_VERB ("ToolsBox", gl_tools_box), - BONOBO_UI_VERB ("ToolsLine", gl_tools_line), - BONOBO_UI_VERB ("ToolsEllipse", gl_tools_ellipse), - BONOBO_UI_VERB ("ToolsImage", gl_tools_image), - BONOBO_UI_VERB ("ToolsBarcode", gl_tools_barcode), - BONOBO_UI_VERB ("ToolsZoomIn", gl_tools_zoomin), - BONOBO_UI_VERB ("ToolsZoomOut", gl_tools_zoomout), - BONOBO_UI_VERB ("ToolsZoom1to1", gl_tools_zoom1to1), - BONOBO_UI_VERB ("ToolsMergeProperties", gl_tools_merge_properties), + BONOBO_UI_VERB ("FileNew", gl_cmd_file_new), + BONOBO_UI_VERB ("FileOpen", gl_cmd_file_open), + BONOBO_UI_VERB ("FileSave", gl_cmd_file_save), + BONOBO_UI_VERB ("FileSaveAs", gl_cmd_file_save_as), + BONOBO_UI_VERB ("FilePrint", gl_cmd_file_print), + BONOBO_UI_VERB ("FileClose", gl_cmd_file_close), + BONOBO_UI_VERB ("FileExit", gl_cmd_file_exit), + BONOBO_UI_VERB ("EditCut", gl_cmd_edit_cut), + BONOBO_UI_VERB ("EditCopy", gl_cmd_edit_copy), + BONOBO_UI_VERB ("EditPaste", gl_cmd_edit_paste), + BONOBO_UI_VERB ("EditDelete", gl_cmd_edit_delete), + BONOBO_UI_VERB ("EditSelectAll", gl_cmd_edit_select_all), + BONOBO_UI_VERB ("EditUnSelectAll", gl_cmd_edit_unselect_all), + BONOBO_UI_VERB ("ToolsArrow", gl_tools_arrow), + BONOBO_UI_VERB ("ToolsText", gl_tools_text), + BONOBO_UI_VERB ("ToolsBox", gl_tools_box), + BONOBO_UI_VERB ("ToolsLine", gl_tools_line), + BONOBO_UI_VERB ("ToolsEllipse", gl_tools_ellipse), + BONOBO_UI_VERB ("ToolsImage", gl_tools_image), + BONOBO_UI_VERB ("ToolsBarcode", gl_tools_barcode), + BONOBO_UI_VERB ("ToolsZoomIn", gl_tools_zoomin), + BONOBO_UI_VERB ("ToolsZoomOut", gl_tools_zoomout), + BONOBO_UI_VERB ("ToolsZoom1to1", gl_tools_zoom1to1), + BONOBO_UI_VERB ("ToolsMergeProperties", gl_tools_merge_properties), BONOBO_UI_VERB ("ToolsObjectProperties", gl_tools_object_properties), - BONOBO_UI_VERB ("ToolsRaiseObjects", gl_tools_raise_objects), - BONOBO_UI_VERB ("ToolsLowerObjects", gl_tools_lower_objects), - BONOBO_UI_VERB ("ToolsRotateLeft", gl_tools_rotate_objects_left), - BONOBO_UI_VERB ("ToolsRotateRight", gl_tools_rotate_objects_right), - BONOBO_UI_VERB ("ToolsFlipHorizontal", gl_tools_flip_objects_horiz), - BONOBO_UI_VERB ("ToolsFlipVertical", gl_tools_flip_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), + BONOBO_UI_VERB ("ToolsRaiseObjects", gl_tools_raise_objects), + BONOBO_UI_VERB ("ToolsLowerObjects", gl_tools_lower_objects), + BONOBO_UI_VERB ("ToolsRotateLeft", gl_tools_rotate_objects_left), + BONOBO_UI_VERB ("ToolsRotateRight", gl_tools_rotate_objects_right), + BONOBO_UI_VERB ("ToolsFlipHorizontal", gl_tools_flip_objects_horiz), + BONOBO_UI_VERB ("ToolsFlipVertical", gl_tools_flip_objects_vert), + BONOBO_UI_VERB ("ToolsAlignLeft", gl_tools_align_objects_left), + BONOBO_UI_VERB ("ToolsAlignRight", gl_tools_align_objects_right), + BONOBO_UI_VERB ("ToolsAlignHCenter", gl_tools_align_objects_hcenter), + 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 ("SettingsPreferences", gl_cmd_settings_preferences), + BONOBO_UI_VERB ("HelpContents", gl_cmd_help_contents), + BONOBO_UI_VERB ("About", gl_cmd_help_about), BONOBO_UI_VERB_END }; @@ -119,9 +125,16 @@ static gchar* doc_verbs [] = { "/commands/ToolsRotateRight", "/commands/ToolsFlipHorizontal", "/commands/ToolsFlipVertical", + "/commands/ToolsAlignLeft", + "/commands/ToolsAlignRight", + "/commands/ToolsAlignHCenter", + "/commands/ToolsAlignTop", + "/commands/ToolsAlignBottom", + "/commands/ToolsAlignVCenter", "/menu/Objects/CreateObjects", "/menu/Objects/Order", "/menu/Objects/RotateFlip", + "/menu/Objects/Align", "/commands/ViewGrid", "/commands/ViewMarkup", @@ -157,10 +170,22 @@ static gchar* atomic_selection_verbs [] = { NULL }; +static gchar* multi_selection_verbs [] = { + "/commands/ToolsAlignLeft", + "/commands/ToolsAlignRight", + "/commands/ToolsAlignHCenter", + "/commands/ToolsAlignTop", + "/commands/ToolsAlignBottom", + "/commands/ToolsAlignVCenter", + "/menu/Objects/Align", -/*=======================================================================================*/ -/* Local function prototypes */ -/*=======================================================================================*/ + NULL +}; + + +/*==========================================================================*/ +/* Local function prototypes */ +/*==========================================================================*/ static void view_menu_item_toggled_cb (BonoboUIComponent *ui_component, const char *path, @@ -347,6 +372,11 @@ gl_ui_update_all (BonoboUIComponent *ui_component, atomic_selection_verbs, gl_view_is_selection_atomic (view)); + set_verb_list_sensitive (ui_component, + multi_selection_verbs, + !gl_view_is_selection_empty (view) + && !gl_view_is_selection_atomic (view)); + bonobo_ui_component_thaw (ui_component, NULL); gl_debug (DEBUG_UI, "END"); @@ -408,6 +438,11 @@ gl_ui_update_selection_verbs (BonoboUIComponent *ui_component, atomic_selection_verbs, gl_view_is_selection_atomic (view)); + set_verb_list_sensitive (ui_component, + multi_selection_verbs, + !gl_view_is_selection_empty (view) + && !gl_view_is_selection_atomic (view)); + bonobo_ui_component_thaw (ui_component, NULL); gl_debug (DEBUG_UI, "END"); diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 0257cfdd..194c97fb 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -1630,9 +1630,9 @@ gl_view_edit_object_props (glView *view) void gl_view_raise_selection (glView *view) { - GList *p; - glViewObject *view_object; - glLabelObject *label_object; + GList *p; + glViewObject *view_object; + glLabelObject *object; gl_debug (DEBUG_VIEW, "START"); @@ -1640,8 +1640,8 @@ gl_view_raise_selection (glView *view) for (p = view->selected_object_list; p != NULL; p = p->next) { view_object = GL_VIEW_OBJECT (p->data); - label_object = gl_view_object_get_object (view_object); - gl_label_object_raise_to_top (label_object); + object = gl_view_object_get_object (view_object); + gl_label_object_raise_to_top (object); } gl_debug (DEBUG_VIEW, "END"); @@ -1653,9 +1653,9 @@ gl_view_raise_selection (glView *view) void gl_view_lower_selection (glView *view) { - GList *p; - glViewObject *view_object; - glLabelObject *label_object; + GList *p; + glViewObject *view_object; + glLabelObject *object; gl_debug (DEBUG_VIEW, "START"); @@ -1663,8 +1663,8 @@ gl_view_lower_selection (glView *view) for (p = view->selected_object_list; p != NULL; p = p->next) { view_object = GL_VIEW_OBJECT (p->data); - label_object = gl_view_object_get_object (view_object); - gl_label_object_lower_to_bottom (label_object); + object = gl_view_object_get_object (view_object); + gl_label_object_lower_to_bottom (object); } gl_debug (DEBUG_VIEW, "END"); @@ -1677,9 +1677,9 @@ void gl_view_rotate_selection (glView *view, gdouble theta_degs) { - GList *p; - glViewObject *view_object; - glLabelObject *label_object; + GList *p; + glViewObject *view_object; + glLabelObject *object; gl_debug (DEBUG_VIEW, "START"); @@ -1687,8 +1687,8 @@ gl_view_rotate_selection (glView *view, for (p = view->selected_object_list; p != NULL; p = p->next) { view_object = GL_VIEW_OBJECT (p->data); - label_object = gl_view_object_get_object (view_object); - gl_label_object_rotate (label_object, theta_degs); + object = gl_view_object_get_object (view_object); + gl_label_object_rotate (object, theta_degs); } gl_debug (DEBUG_VIEW, "END"); @@ -1700,9 +1700,9 @@ gl_view_rotate_selection (glView *view, void gl_view_flip_selection_horiz (glView *view) { - GList *p; - glViewObject *view_object; - glLabelObject *label_object; + GList *p; + glViewObject *view_object; + glLabelObject *object; gl_debug (DEBUG_VIEW, "START"); @@ -1710,8 +1710,8 @@ gl_view_flip_selection_horiz (glView *view) for (p = view->selected_object_list; p != NULL; p = p->next) { view_object = GL_VIEW_OBJECT (p->data); - label_object = gl_view_object_get_object (view_object); - gl_label_object_flip_horiz (label_object); + object = gl_view_object_get_object (view_object); + gl_label_object_flip_horiz (object); } gl_debug (DEBUG_VIEW, "END"); @@ -1723,18 +1723,309 @@ gl_view_flip_selection_horiz (glView *view) void gl_view_flip_selection_vert (glView *view) { - GList *p; - glViewObject *view_object; - glLabelObject *label_object; + GList *p; + glViewObject *view_object; + glLabelObject *object; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + 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_flip_vert (object); + } + + gl_debug (DEBUG_VIEW, "END"); +} + +/*****************************************************************************/ +/* Align selected objects to left most edge. */ +/*****************************************************************************/ +void +gl_view_align_selection_left (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dx, x1min, x1, y1, x2, y2; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + g_return_if_fail (!gl_view_is_selection_empty (view) && + !gl_view_is_selection_atomic (view)); + + /* find left most edge */ + p = view->selected_object_list; + view_object = GL_VIEW_OBJECT (p->data); + object = gl_view_object_get_object (view_object); + gl_label_object_get_extent (object, &x1min, &y1, &x2, &y2); + for (p = p->next; 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); + if ( x1 < x1min ) x1min = x1; + } + + /* now adjust the object positions to line up the left edges */ + 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); + dx = x1min - x1; + gl_label_object_set_position_relative (object, dx, 0.0); + } + + gl_debug (DEBUG_VIEW, "END"); +} + + +/*****************************************************************************/ +/* Align selected objects to right most edge. */ +/*****************************************************************************/ +void +gl_view_align_selection_right (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dx, x2max, x1, y1, x2, y2; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + g_return_if_fail (!gl_view_is_selection_empty (view) && + !gl_view_is_selection_atomic (view)); + + /* find right most edge */ + p = view->selected_object_list; + view_object = GL_VIEW_OBJECT (p->data); + object = gl_view_object_get_object (view_object); + gl_label_object_get_extent (object, &x1, &y1, &x2max, &y2); + for (p = p->next; 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); + if ( x2 > x2max ) x2max = x2; + } + + /* now adjust the object positions to line up the right edges */ + 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); + dx = x2max - x2; + gl_label_object_set_position_relative (object, dx, 0.0); + } + + gl_debug (DEBUG_VIEW, "END"); +} + +/*****************************************************************************/ +/* Align selected objects to horizontal center of objects. */ +/*****************************************************************************/ +void +gl_view_align_selection_hcenter (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dx, dxmin, xsum, xavg, xcenter, x1, y1, x2, y2; + gint n; gl_debug (DEBUG_VIEW, "START"); g_return_if_fail (GL_IS_VIEW (view)); + g_return_if_fail (!gl_view_is_selection_empty (view) && + !gl_view_is_selection_atomic (view)); + + /* find average center of objects */ + xsum = 0.0; + n = 0; + 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); + xsum += (x1 + x2) / 2.0; + n++; + } + xavg = xsum / n; + + /* find center of object closest to average center */ + p = view->selected_object_list; + 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); + dxmin = fabs (xavg - (x1 + x2)/2.0); + xcenter = (x1 + x2)/2.0; + for (p = p->next; 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); + dx = fabs (xavg - (x1 + x2)/2.0); + if ( dx < dxmin ) { + dxmin = dx; + xcenter = (x1 + x2)/2.0; + } + } + + /* now adjust the object positions to line up this center */ + 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); + dx = xcenter - (x1 + x2)/2.0; + gl_label_object_set_position_relative (object, dx, 0.0); + } + + gl_debug (DEBUG_VIEW, "END"); +} + +/*****************************************************************************/ +/* Align selected objects to top most edge. */ +/*****************************************************************************/ +void +gl_view_align_selection_top (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dy, y1min, x1, y1, x2, y2; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + g_return_if_fail (!gl_view_is_selection_empty (view) && + !gl_view_is_selection_atomic (view)); + + /* find top most edge */ + p = view->selected_object_list; + view_object = GL_VIEW_OBJECT (p->data); + object = gl_view_object_get_object (view_object); + gl_label_object_get_extent (object, &x1, &y1min, &x2, &y2); + for (p = p->next; 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); + if ( y1 < y1min ) y1min = y1; + } + + /* now adjust the object positions to line up the top edges */ + 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); + dy = y1min - y1; + gl_label_object_set_position_relative (object, 0.0, dy); + } + + gl_debug (DEBUG_VIEW, "END"); +} + +/*****************************************************************************/ +/* Align selected objects to bottom most edge. */ +/*****************************************************************************/ +void +gl_view_align_selection_bottom (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dy, y2max, x1, y1, x2, y2; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + g_return_if_fail (!gl_view_is_selection_empty (view) && + !gl_view_is_selection_atomic (view)); + + /* find bottom most edge */ + p = view->selected_object_list; + view_object = GL_VIEW_OBJECT (p->data); + object = gl_view_object_get_object (view_object); + gl_label_object_get_extent (object, &x1, &y1, &x2, &y2max); + for (p = p->next; 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); + if ( y2 > y2max ) y2max = y2; + } + + /* now adjust the object positions to line up the bottom edges */ + 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); + dy = y2max - y2; + gl_label_object_set_position_relative (object, 0.0, dy); + } + + gl_debug (DEBUG_VIEW, "END"); +} + +/*****************************************************************************/ +/* Align selected objects to viertical center of objects. */ +/*****************************************************************************/ +void +gl_view_align_selection_vcenter (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *object; + gdouble dy, dymin, ysum, yavg, ycenter, x1, y1, x2, y2; + gint n; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + g_return_if_fail (!gl_view_is_selection_empty (view) && + !gl_view_is_selection_atomic (view)); + + /* find average center of objects */ + ysum = 0.0; + n = 0; + 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); + ysum += (y1 + y2) / 2.0; + n++; + } + yavg = ysum / n; + + /* find center of object closest to average center */ + p = view->selected_object_list; + 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); + dymin = fabs (yavg - (y1 + y2)/2.0); + ycenter = (y1 + y2)/2.0; + for (p = p->next; 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); + dy = fabs (yavg - (y1 + y2)/2.0); + if ( dy < dymin ) { + dymin = dy; + ycenter = (y1 + y2)/2.0; + } + } + + /* now adjust the object positions to line up this center */ for (p = view->selected_object_list; p != NULL; p = p->next) { view_object = GL_VIEW_OBJECT (p->data); - label_object = gl_view_object_get_object (view_object); - gl_label_object_flip_vert (label_object); + object = gl_view_object_get_object (view_object); + gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); + dy = ycenter - (y1 + y2)/2.0; + gl_label_object_set_position_relative (object, 0.0, dy); } gl_debug (DEBUG_VIEW, "END"); diff --git a/glabels2/src/view.h b/glabels2/src/view.h index 56ddd9ac..f60dd25d 100644 --- a/glabels2/src/view.h +++ b/glabels2/src/view.h @@ -155,6 +155,18 @@ void gl_view_flip_selection_horiz (glView *view); void gl_view_flip_selection_vert (glView *view); +void gl_view_align_selection_left (glView *view); + +void gl_view_align_selection_right (glView *view); + +void gl_view_align_selection_hcenter (glView *view); + +void gl_view_align_selection_top (glView *view); + +void gl_view_align_selection_bottom (glView *view); + +void gl_view_align_selection_vcenter (glView *view); + void gl_view_cut (glView *view); void gl_view_copy (glView *view);