]> git.sur5r.net Git - glabels/commitdiff
Added commands to center selected objects to center of label.
authorJim Evins <evins@snaught.com>
Thu, 28 Nov 2002 04:16:22 +0000 (04:16 +0000)
committerJim Evins <evins@snaught.com>
Thu, 28 Nov 2002 04:16:22 +0000 (04:16 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@190 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 93000ccccfc258143c3227d366cbb36a1efd2653..f884ae1e335bf46983235ca9f9de5717c848bbe1 100644 (file)
             _tip="Align objects to bottoms"
              pixtype="stock" pixname="gl_stock_align_bottom"/>
 
+       <cmd name="ToolsCenterHorizontal"
+            _tip="Center objects to horizontal label center"
+             pixtype="stock" pixname="gl_stock_center_horiz"/>
+       
+       <cmd name="ToolsCenterVertical"
+            _tip="Center objects to vertical label center"
+             pixtype="stock" pixname="gl_stock_center_vert"/>
+       
        
        <cmd name="HelpContents" _label="Contents" _tip="Open the glabels manual"
        accel="F1" pixtype="stock" pixname="gtk-help"/>
        </submenu>
 
        <submenu name="AlignHoriz" _label="Align _Horizontal">
-                <menuitem name="ToolsAlignLeft" verb="" _label="_Left"/>
-                <menuitem name="ToolsAlignHCenter" verb="" _label="_Center"/>
-                <menuitem name="ToolsAlignRight" verb="" _label="_Right"/>
+                <menuitem name="ToolsAlignLeft" verb="" _label="_Lefts"/>
+                <menuitem name="ToolsAlignHCenter" verb="" _label="_Centers"/>
+                <menuitem name="ToolsAlignRight" verb="" _label="_Rights"/>
+                <menuitem name="ToolsCenterHorizontal" verb="" _label="Label Ce_nter"/>
        </submenu>
 
        <submenu name="AlignVert" _label="Align _Vertical">
-                <menuitem name="ToolsAlignTop" verb="" _label="_Top"/>
-                <menuitem name="ToolsAlignVCenter" verb="" _label="_Center"/>
-                <menuitem name="ToolsAlignBottom" verb="" _label="_Bottom"/>
+                <menuitem name="ToolsAlignTop" verb="" _label="_Tops"/>
+                <menuitem name="ToolsAlignVCenter" verb="" _label="_Centers"/>
+                <menuitem name="ToolsAlignBottom" verb="" _label="_Bottoms"/>
+                <menuitem name="ToolsCenterVertical" verb="" _label="Label Ce_nter"/>
        </submenu>
 
        <separator/>
index edffc4075ebb484a4cbcfb17fa06e9ee1aee61b2..1f1cff0d4d960ac9ca39207ab17776d7985ed1e5 100644 (file)
@@ -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));
+       }
+}
+
index 5f65e5b378cb494fc27ee3513f736f8adbac305b..c99df5e9f1d366f41f4e9eca5f3fb1c1add9ae6f 100644 (file)
@@ -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
index 0f694bb22d451b70ed46be77d9fb068cdf4c9175..e4f876efc2afa0baf3ec1946a32eac8fab33bd50 100644 (file)
@@ -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
 };
index 410842e237e23994ba18e1f574eb0acbc928d5a9..e15f45991b4c60f4083e7ee12122ae0f3695ca48 100644 (file)
@@ -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.                   */
 /*****************************************************************************/
index f60dd25dc35eada1405cbcd7dc3bba8f791be2ca..7106eabdea560d6a9858be2eb649a78830aefbb4 100644 (file)
@@ -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);