]> git.sur5r.net Git - glabels/commitdiff
Added object alignment commands.
authorJim Evins <evins@snaught.com>
Mon, 25 Nov 2002 02:15:16 +0000 (02:15 +0000)
committerJim Evins <evins@snaught.com>
Mon, 25 Nov 2002 02:15:16 +0000 (02:15 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@182 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/glabels-ui.xml
glabels2/src/tools.c
glabels2/src/tools.h
glabels2/src/ui.c
glabels2/src/view.c
glabels2/src/view.h

index 9c00a0f3caa428f820b62fa2ad59efbefbe8cdc2..57ade849391edb1c79fe5353d012cd019fdfd7eb 100644 (file)
             _tip="Flip object vertically"/>
 
        <cmd name="ToolsAlignLeft"
-            _tip="Align objects to left edges"/>
+            _tip="Align objects to left edges"
+             pixtype="stock" pixname="gl_stock_align_left"/>
        
-       <cmd name="ToolsAlignCenter"
-            _tip="Align objects to centers"/>
+       <cmd name="ToolsAlignHCenter"
+            _tip="Align objects to horizontal centers"
+             pixtype="stock" pixname="gl_stock_align_hcenter"/>
        
        <cmd name="ToolsAlignRight"
-            _tip="Align objects to right edges"/>
+            _tip="Align objects to right edges"
+             pixtype="stock" pixname="gl_stock_align_right"/>
        
        <cmd name="ToolsAlignTop"
-            _tip="Align objects to tops"/>
+            _tip="Align objects to tops"
+             pixtype="stock" pixname="gl_stock_align_top"/>
        
-       <cmd name="ToolsAlignMiddle"
-            _tip="Align objects to middles"/>
+       <cmd name="ToolsAlignVCenter"
+            _tip="Align objects to vertical centers"
+             pixtype="stock" pixname="gl_stock_align_vcenter"/>
        
        <cmd name="ToolsAlignBottom"
-            _tip="Align objects to bottoms"/>
+            _tip="Align objects to bottoms"
+             pixtype="stock" pixname="gl_stock_align_bottom"/>
 
        
        <cmd name="HelpContents" _label="Contents" _tip="Open the glabels manual"
                 <menuitem name="ToolsFlipVertical" verb="" _label="Flip vertically"/>
        </submenu>
 
+       <submenu name="Align" _label="_Align">
+                <menuitem name="ToolsAlignLeft" verb="" _label="Align lefts"/>
+                <menuitem name="ToolsAlignRight" verb="" _label="Align rights"/>
+                <menuitem name="ToolsAlignHCenter" verb="" _label="Align horizontal centers"/>
+                <menuitem name="ToolsAlignTop" verb="" _label="Align tops"/>
+                <menuitem name="ToolsAlignBottom" verb="" _label="Align bottoms"/>
+                <menuitem name="ToolsAlignVCenter" verb="" _label="Align vertical centers"/>
+       </submenu>
+
        <separator/>
 
         <menuitem name="ToolsObjectProperties" verb="" _label="Object Properties..."/>
index 4744f867500e7452bfdebda3a6a9742fe49a1429..edffc4075ebb484a4cbcfb17fa06e9ee1aee61b2 100644 (file)
@@ -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));
+       }
+}
+
index 2c205cf4e26fc180331f1f26dc2e56df46eba654..5f65e5b378cb494fc27ee3513f736f8adbac305b 100644 (file)
@@ -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
index 68e414ca2772e43a3397e965dd52b36095977925..9232ec41c38bf3fa001eff0a93686976347e3740 100644 (file)
 
 #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");
index 0257cfdd2f2bc10b112523ea6da803ce1dfaf060..194c97fba4adedba392d198cce29c78d656feb37 100644 (file)
@@ -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");
index 56ddd9ac46544b3572658aa85f7b6335e82fe797..f60dd25dc35eada1405cbcd7dc3bba8f791be2ca 100644 (file)
@@ -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);